UCSD Chop/Massage Variables by Certain Separators (Java Script / Powershell)

Version 5
    Task NameUCSD chop variables by a certain Character
    Description
    Prerequisites
    1. Tested on 5.3.1
    CategoryWorkflow
    ComponentsvSphere 5.x
    User Inputs

    Instructions 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.

     

     

    Here are 4 examples on how to chop/split variables and typecast them:

     

     

    Screen Shot 2015-09-16 at 5.00.58 PM.png

     

     

    The Split:

     

    Screen Shot 2015-09-16 at 4.59.51 PM.png

     

    Screen Shot 2015-09-16 at 5.00.00 PM.png

     

    Screen Shot 2015-09-16 at 5.00.27 PM.png

     

    Screen Shot 2015-09-16 at 5.00.41 PM.png

     

    token = 'X-SDS-AUTH-TOKEN: BAAcS1kyYUNLTkhrK1BhQ1BVaFJLdTJGUzdPdjlBPQMAVAQADTE0NDY1ODU5MjM0MDYCAAEABQA9dXJuOnN0b3JhZ2VvczpUb2tlbjphYjY1NTMwYi1iZmRmLTRkOGMtODBiNy05ZjcxNjExYjM3MjM6dmRjMQIAAtAP'

     

    var tokencookie = token.replaceAll(': ', '=');

     

     

     

    PowerShell Example:

     

    Unknown.png

     

    Unknown-1.png

     

     

    Massage example to go from

          Input = A1B2C3

         output = A1:B2:C3 ..

     

    Screen Shot 2016-04-13 at 12.03.48 AM.png

     

    The custom task code...

     

     

    importClass(org.apache.log4j.Logger);

    importPackage(com.cloupia.model.serviceContainer.fenced);

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

    importPackage(com.cloupia.feature.customactions);

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

    importPackage(java.lang);

    importPackage(java.util);

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

    importPackage(com.cloupia.model.cIM);

    importPackage(com.cloupia.model.serviceContainer);

    importClass(com.cloupia.service.cIM.inframgr.GroupManagerImpl);

    importClass(org.apache.commons.lang3.builder.ReflectionToStringBuilder);

    importPackage(java.io);

    importPackage(java.net);

    importPackage(java.security);

    importPackage(javax.xml.xpath);

    importPackage(org.xml.sax);

    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(com.cloupia.lib.util.easytrust);

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

    importPackage(org.apache.http);

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

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

    importPackage(org.apache.http.conn.scheme);

    importPackage(org.apache.http.entity);

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

    importPackage(org.apache.http.util);

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

    importClass(javax.net.ssl.SSLContext);

    importClass(javax.net.ssl.TrustManager);

    importClass(javax.net.ssl.X509TrustManager);

     

     

     

     

    var in1 = input.a;

     

     

    var str1 = in1.substring(0,2);

    var str2 = in1.substring(2,4);

    var str3 = in1.substring(4,6);

    var str4 = in1.substring(6,8);

     

     

    var str5 = in1.substring(8,10);

    var str6 = in1.substring(10,12);

    var str7 = in1.substring(12,14);

    var str8 = in1.substring(14,16);

     

     

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

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

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

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

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

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

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

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

     

     

    var out1 = str1 + ":" + str2 + ":" + str3 + ":" + str4 + ":" + str5 + ":" + str6 + ":" + str7 + ":" + str8;

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

     

     

    output.b = out1;