cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1741
Views
0
Helpful
0
Comments
Orf Gelbrich
Cisco Employee
Cisco Employee
Task Name

APIC REST API format

Description
  1. Change the user of a running workflow
Prerequisites
  1. Tested on 5.3.1
CategoryWorkflow
ComponentsvSphere 5.x
User Inputs
  1. userid to change to
OutputInstructions for Regular Workflow Use:
  1. Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
  2. Unzip the file on your computer. Should end up with a .WFD file.
  3. Log in to UCS Director as a user that has "system-admin" privileges.
  4. Navigate to "Policies-->Orchestration" and click on "Import".
  5. Click "Browse" and navigate to the location on your computer where the .WFD file resides. Choose the .WFD file and click "Open".
  6. Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
  7. Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
  8. Click "Submit".
  9. A new folder should appear in "Policies-->Orchestration" that contains the imported workflow. You will now need to update the included tasks with information about the specific environment.

Thank you Mohamed Arif Hajamohideen

Potential issue with JDK1.8 result could be  ‘Access denied’ exception.

This is the permission issue and Creating the https connection from custom task is blocked by JDK.

We are aware of this issue.



//ssl,apic

/*Example code for RestAPI execution on APIC*/

importPackage(java.util);

importPackage(java.lang);

importPackage(java.io);

importPackage(java.net);

importPackage(java.security);

importPackage(com.cloupia.lib.connector.account);

importPackage(com.cloupia.lib.connector.account.credential);

importPackage(com.cloupia.lib.util);

importClass(com.cloupia.lib.util.JSON);

importPackage(javax.net.ssl);

importPackage(com.cloupia.model.cIM);

importPackage(com.cloupia.service.cIM.inframgr);

importPackage(org.apache.commons.httpclient);

importPackage(org.apache.commons.httpclient.methods);

importPackage(org.apache.commons.httpclient.protocol);

importPackage(com.cloupia.lib.util.easytrust);

importPackage(com.cloupia.lib.cIaaS.vcd.api);

//FUNCTIONS

function apicLogin(apicAccountName){

                //Get the IP, user name, password, port and protocol from the APIC Device Identity object.

                var apicAccount = AccountUtil.getAccountByName(apicAccountName);

                var creds = apicAccount.getCredential();

                logger.addInfo("creds :"+creds);

                var username = JSON.getJsonElement(creds,"username").toString();  

                logger.addInfo("Username "+username);

                var password = JSON.getJsonElement(creds,"password");

                var ip = apicAccount.getServerAddress().toString();

                logger.addInfo("IP "+ip);

                var protocol = JSON.getJsonElement(creds,"protocol");

                logger.addInfo("protocol "+protocol);

                var port = JSON.getJsonElement(creds,"port").toString().trim();

                port = Integer.parseInt(port);

                logger.addInfo("port "+port);

                var httpsClient = CustomEasySSLSocketFactory.getIgnoreSSLClient(ip,port);

                httpsClient.getParams().setCookiePolicy("default");

                var loginURL = "/api/aaaLogin.json";

                /*

                                {

                                                "aaaUser" : {

                                                                "attributes" : {

                                                                                "name" : "georgewa",

                                                                                "pwd" : "paSSword1"

                                                                }

                                                }

                                }

                */

                var buf = new StringBuffer();

                buf.append("{");

                buf.append("\"aaaUser\" : {");

                buf.append("\"attributes\" : {");

                buf.append("\"name\" : "+username+",");

                buf.append("\"pwd\" : "+password+"");

                buf.append("}");

                buf.append("}");

                buf.append("}");

                var loginPayload = buf.toString();

              

                logger.addInfo("loginPayload :"+loginPayload);

                var httpMethod = new PostMethod(loginURL);

                var requestEntity = new StringRequestEntity(loginPayload,"application/json","UTF-8");

                httpMethod.setRequestEntity(requestEntity);

                httpsClient.executeMethod(httpMethod);

                var statuscode = httpMethod.getStatusCode();

                logger.addInfo("statuscode :"+statuscode);      

                logger.addInfo("Status message : "+httpMethod.getStatusText());

                logger.addInfo("Response body: "+httpMethod.getResponseBodyAsString());

}

var accountName = "apic185";//apic account name

apicLogin(accountName);



Coding suggestions by Russ...


var buf = new StringBuffer();

buf.append("{);

buf.append("\"aaaUser\" : {);

buf.append("\"attributes\" : {);

buf.append("\"name\" : "+username+",);

buf.append("\"pwd\" : "+password+");

buf.append("});

buf.append("});

buf.append("});

var loginPayload = buf.toString();

…can be much more elegantly written like this:

importPackage(java.util);

importPackage(com.cloupia.lib.util);


var username = "georgwa";

var password = "paSSword1";


var map_userDetails = new HashMap();

var map_attributes = new HashMap();

var map_aaaUser = new HashMap();


map_userDetails.put("name",username);

map_userDetails.put("pwd","password);


map_attributes.put("attributes",map_userDetails);


map_aaaUser.put("aaaUser",map_attributes);

var loginPayload = JSON.javaToJsonString(map_aaaUser, map_aaaUser.getClass());


( OutPut: {"aaaUser":{"attributes":{"pwd":"paSSword1","name":"georgewa"}}}      )



Unknown.png


Unknown-1.png

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links

Review Cisco Networking for a $25 gift card