cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1384
Views
3
Helpful
7
Replies

loop in UCSD 5.4

Florent TYMEN
Level 1
Level 1

Hi all,

My question is probably simple but i don't understand how it's work.

I just want to create a loop.

i want to delete an entry in the PSC Database.

first , i get a name in UCSD and i delete the corresponding entry in the PSC Database.

And i'd like to do it as many time as i get a name. if i don't get a name, i want to quit the loop.

Easy ??? Sure but i don't find how to chain the conditionnal tasks ...

Thanks a lot

1 Accepted Solution

Accepted Solutions

Orf Gelbrich
Cisco Employee
Cisco Employee

Is the name coming from a file, or UCSD , or another DB?

Here is a UCSD loop example:

UCSD - Loop Example

if you search here

UCSD Workflow INDEX (UCSD Technical Content Index)

for CSV or SQL you find all sorts of example on reading from a CSV file

As to the PSC connection, that would be a http(s) connection to PSC.

you would have to create a custom task in UCSD to talk to PSC

something like this...

importPackage(java.util);

importPackage(java.lang);

importPackage(java.io);

importPackage(java.net);

importPackage(org.apache.http);

importPackage(org.apache.http.client.methods);

importPackage(org.apache.http.entity);

importPackage(org.apache.http.impl.client);

importPackage(org.apache.http.util);

importClass(java.security.KeyManagementException);

importClass(java.security.KeyStoreException);

importClass(java.security.NoSuchAlgorithmException);

importClass(java.security.UnrecoverableKeyException);

importClass(org.apache.http.Header);

importClass(org.apache.http.annotation.NotThreadSafe);

importClass(org.apache.http.client.ClientProtocolException);

importClass(org.apache.http.client.methods.CloseableHttpResponse);

importClass(org.apache.http.client.methods.HttpEntityEnclosingRequestBase);

importClass(org.apache.http.conn.ssl.SSLConnectionSocketFactory);

importClass(org.apache.http.conn.ssl.SSLContextBuilder);

importClass(org.apache.http.conn.ssl.TrustSelfSignedStrategy);

importClass(org.apache.http.entity.ContentType);

importClass(org.apache.http.entity.StringEntity);

importClass(org.apache.http.impl.client.CloseableHttpClient);

importClass(org.apache.http.impl.client.HttpClients);

importClass(org.apache.http.util.EntityUtils);

var host = "10.95.33.95";

var uri = "/RequestCenter/nsapi/serviceitem/process";

var username = "admin";

var password = "Cisco321";

var msgXML = "<serviceitem><name>UCSServers</name>"

+"<serviceItemData>"

+"<serviceItemAttribute name=\"Name\">"

+"PHXlab-UCS-Pod3\;sys/chassis-1/blade-5"

+"</serviceItemAttribute>"

+"</serviceItemData></serviceitem>";

var HttpEntityEnclosingRequestBase = Java.type("org.apache.http.client.methods.HttpEntityEnclosingRequestBase");

var HttpDeleteWithBody = Java.extend(HttpEntityEnclosingRequestBase);

var httpDelete = new HttpDeleteWithBody({ getMethod: function() { return "DELETE" } });

// SSL stuff.

var builder = new SSLContextBuilder();

builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());

var sslsf = new SSLConnectionSocketFactory( builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER );

var httpclient = HttpClients.custom().setSSLSocketFactory( sslsf ).build();

httpDelete.setURI( URI.create("https://"+host+uri) );

httpDelete.setHeader( "username", username );

httpDelete.setHeader( "password", password );

var input = new StringEntity(msgXML, ContentType.APPLICATION_XML);

httpDelete.setEntity(input);

var response = httpclient.execute(httpDelete);

logger.addInfo("Status: ");

logger.addInfo(response.getStatusLine());

logger.addInfo("Content:");

logger.addInfo( EntityUtils.toString(response.getEntity()) );

View solution in original post

7 Replies 7

Orf Gelbrich
Cisco Employee
Cisco Employee

Is the name coming from a file, or UCSD , or another DB?

Here is a UCSD loop example:

UCSD - Loop Example

if you search here

UCSD Workflow INDEX (UCSD Technical Content Index)

for CSV or SQL you find all sorts of example on reading from a CSV file

As to the PSC connection, that would be a http(s) connection to PSC.

you would have to create a custom task in UCSD to talk to PSC

something like this...

importPackage(java.util);

importPackage(java.lang);

importPackage(java.io);

importPackage(java.net);

importPackage(org.apache.http);

importPackage(org.apache.http.client.methods);

importPackage(org.apache.http.entity);

importPackage(org.apache.http.impl.client);

importPackage(org.apache.http.util);

importClass(java.security.KeyManagementException);

importClass(java.security.KeyStoreException);

importClass(java.security.NoSuchAlgorithmException);

importClass(java.security.UnrecoverableKeyException);

importClass(org.apache.http.Header);

importClass(org.apache.http.annotation.NotThreadSafe);

importClass(org.apache.http.client.ClientProtocolException);

importClass(org.apache.http.client.methods.CloseableHttpResponse);

importClass(org.apache.http.client.methods.HttpEntityEnclosingRequestBase);

importClass(org.apache.http.conn.ssl.SSLConnectionSocketFactory);

importClass(org.apache.http.conn.ssl.SSLContextBuilder);

importClass(org.apache.http.conn.ssl.TrustSelfSignedStrategy);

importClass(org.apache.http.entity.ContentType);

importClass(org.apache.http.entity.StringEntity);

importClass(org.apache.http.impl.client.CloseableHttpClient);

importClass(org.apache.http.impl.client.HttpClients);

importClass(org.apache.http.util.EntityUtils);

var host = "10.95.33.95";

var uri = "/RequestCenter/nsapi/serviceitem/process";

var username = "admin";

var password = "Cisco321";

var msgXML = "<serviceitem><name>UCSServers</name>"

+"<serviceItemData>"

+"<serviceItemAttribute name=\"Name\">"

+"PHXlab-UCS-Pod3\;sys/chassis-1/blade-5"

+"</serviceItemAttribute>"

+"</serviceItemData></serviceitem>";

var HttpEntityEnclosingRequestBase = Java.type("org.apache.http.client.methods.HttpEntityEnclosingRequestBase");

var HttpDeleteWithBody = Java.extend(HttpEntityEnclosingRequestBase);

var httpDelete = new HttpDeleteWithBody({ getMethod: function() { return "DELETE" } });

// SSL stuff.

var builder = new SSLContextBuilder();

builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());

var sslsf = new SSLConnectionSocketFactory( builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER );

var httpclient = HttpClients.custom().setSSLSocketFactory( sslsf ).build();

httpDelete.setURI( URI.create("https://"+host+uri) );

httpDelete.setHeader( "username", username );

httpDelete.setHeader( "password", password );

var input = new StringEntity(msgXML, ContentType.APPLICATION_XML);

httpDelete.setEntity(input);

var response = httpclient.execute(httpDelete);

logger.addInfo("Status: ");

logger.addInfo(response.getStatusLine());

logger.addInfo("Content:");

logger.addInfo( EntityUtils.toString(response.getEntity()) );

Thanks a lot.

Thanks to your links, i think i understood.

My confusion was that we don't have a "for each" task.

Many thanks again.

Floretn

The loop can do two things

Loop a number of times lets say 12 times.

Or it can follow a list (comma separated with out spaces) i.e. 1,4,7,9,12

So you could have it go down a list of VM id’s for example

Or you could have a list of switches POD@1.1.1.1,POD@1.1.1.2,POD@1.1.1.3<mailto:POD@1.1.1.1,POD@1.1.1.2,POD@1.1.1.3>

Orf Gelbrich

Check out UCS Director Workflow INDEX<https://communities.cisco.com/docs/DOC-56419> on Cisco Communities Site (Twitter @UCSDGURU)

Thanks for the explanation.

To talk with the PSC, i use the Alejandro Madurga (almadurg@cisco.com)'s scripts.

But i have some other issues. I think i'll ask to Alejandro or i'll create a new discussion.


Thanks

I have not connected to PSC via API. Sorry.

Orf Gelbrich

Check out UCS Director Workflow INDEX<https://communities.cisco.com/docs/DOC-56419> on Cisco Communities Site (Twitter @UCSDGURU)

Hello,

Don't worry. You have helped me a lot.

Thanks

That is good to know. Thank you.

Orf Gelbrich

Check out UCS Director Workflow INDEX<https://communities.cisco.com/docs/DOC-56419> on Cisco Communities Site (Twitter @UCSDGURU)

Cisco UCS X-Series Energy Efficiency Offer