03-31-2017 03:19 AM - edited 03-01-2019 06:24 AM
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
Solved! Go to Solution.
03-31-2017 05:40 AM
Is the name coming from a file, or UCSD , or another DB?
Here is a 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()) );
03-31-2017 05:40 AM
Is the name coming from a file, or UCSD , or another DB?
Here is a 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()) );
03-31-2017 06:40 AM
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
03-31-2017 06:55 AM
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)
03-31-2017 08:55 AM
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
03-31-2017 09:17 AM
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)
04-03-2017 02:16 AM
Hello,
Don't worry. You have helped me a lot.
Thanks
04-03-2017 03:46 AM
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)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide