cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1856
Views
0
Helpful
2
Comments
Orf Gelbrich
Cisco Employee
Cisco Employee
Task NameCreate Tenant VDC and its policies
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
Output

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.

A big thank you goes out to Lucas Hoge for this contribution:

This also uses datastore clusters!

The workflow via custom task:

Screen Shot 2015-07-24 at 10.00.42 AM.png

The User input:

Screen Shot 2015-07-24 at 10.00.59 AM.pngScreen Shot 2015-07-24 at 10.01.06 AM.png

The Code all done in functions and no API calls:

importPackage(java.lang);

importPackage(java.util);

importPackage(com.cloupia.model.cIM);

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

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

importPackage(com.cloupia.lib.cIaaS.vmware);

var vDCID;

var compPolicyId;

var storPolicyId;

var netPolicyId;

var sysPolicyId;

function createTenantPolicy(){

var vdcProfile = input.vDCProfile;

var vdcName = input.VDCName;

var sysPolicyName = input.SysPolicyName;

var compPolicyName = input.CompPolicyName;

var storPolicyName = input.StorPolicyName;

var netPolicyName = input.NetPolicyName;

var groupId = input.GroupId;

var cluster = input.Cluster;

var resourcePool = input.ResourcePool;

//var datastore = input.Datastore;

var datastoreClusterIdentity = input.DatastoreCluster;

var datastoreClusterArray =[];

datastoreClusterArray = datastoreClusterIdentity.split("@");

var datastoreCluster=[];

datastoreCluster[0] = datastoreClusterArray[2];

var scopeType=input.datastoreClusterScope;

logger.addInfo("scopeType Var Defined, Value: " +scopeType);

var dvPortGroup = input.PortGroup;

var ipPool = input.StaticIPPool;

var domainName = input.DomainName;

var userName = input.UserName;

var password = input.Password;

var nicAlias = input.NICAlias;

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

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

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

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

var oldVDC = VDCUtil.getVDC(vdcProfile);

var vdcExists = VDCUtil.getVDCByName(vdcName);

try{

  if(oldVDC != null){

  if(vdcExists == null){

  var compPolicy =  createCompPolicy(oldVDC, compPolicyName, cluster, resourcePool);

  var netPolicy = createNetPolicy(oldVDC, netPolicyName, nicAlias, dvPortGroup, ipPool);

  var storPolicy =  createStorPolicy(oldVDC, storPolicyName, datastoreCluster, scopeType);

  var sysPolicy =  createSysPolicy(oldVDC, sysPolicyName, domainName, userName, password);

  }else{

  throw new Exception("VDC with name "+vdcName+" already exist");

  }

  }else{

  throw new Exception("vDC Profile does not exist");

  }

    var vdc = new VDC();

  vdc.setVdcName(vdcName);

  vdc.setVdcDescription("Desc");

  vdc.setGroupId(groupId);

  vdc.setCloudName(oldVDC.getCloudName());

  if (oldVDC.getApproverList() != null) {

        vdc.setApproverList(oldVDC.getApproverList());

    }

    vdc.setPrimaryApprovers(oldVDC.getPrimaryApprovers());

    vdc.setSecondaryApprovers(oldVDC.getSecondaryApprovers());

  vdc.setApprovalReqUsers(oldVDC.isApprovalReqUsers());

  vdc.setResendMailCount(oldVDC.getResendMailCount());

  vdc.setReminderInterval(oldVDC.getReminderInterval());

  vdc.setVdcSupportEmail(oldVDC.getVdcSupportEmail());

  vdc.setVdcCustomerNoticationEmail(oldVDC.getVdcCustomerNoticationEmail());

  vdc.setComputingPolicy(compPolicy.getPolicyName());

  vdc.setStoragePolicy(storPolicy.getPolicyName());

  vdc.setNetworkPolicy(netPolicy.getPolicyName());

  vdc.setPrimaryDeployPolicy(sysPolicy.getPolicyName());

  vdc.setSecondaryDeployPolicy(null);

  vdc.setIsoMappingPolicy(oldVDC.getIsoMappingPolicy());

  vdc.setCostModel(oldVDC.getCostModel());

  vdc.setDisableCostModelDisplay(oldVDC.isDisableCostModelDisplay());

  vdc.setUserActionsPolicy(oldVDC.getUserActionsPolicy());

  vdc.setEnableStorageEfficiency(oldVDC.isEnableStorageEfficiency());

  vdc.setDeletable(true);

  vdc.setInactivityPeriodForDeletion(-1);

  vdc.setSelfServiceEndUserPolicyId(oldVDC.getSelfServiceEndUserPolicyId());

            var appCatList = AppCategoryUtil.getAllCategories();

            var vdcCatList = new ArrayList();

        for (var i=0; i<appCatList.size(); i++)

        {

            var vdcCat = new VDCAppCategory();

            vdcCat.setVdcCatId(appCatList.get(i).getCategoryId());

            vdcCatList.add(vdcCat);

        }

        vdc.setAppCategoryList(vdcCatList);

  var isCreated = VDCUtil.addVDC(vdc);

  logger.addInfo("VDC created: "+isCreated);

  vDCID = vdc.getVdcId();

    }catch(e){

        logger.addError("Error occured"+e);

        ctxt.setFailed("error occured while creating VDC");

        ctxt.exit();

    }

}

function createCompPolicy(oldVDC, compPolicyName, cluster, resourcePool)

{

  var policy;

    policy = InfraPersistenceUtil.getPrivateCloudComputingPolicy(compPolicyName);

    if (policy != null)

       {

               ctxt.setFailed("Compute policy with name "+compPolicyName+" already exists");

               ctxt.exit();

       }

 

    var profile = InfraPersistenceUtil.getPrivateCloudComputingPolicy(oldVDC.getComputingPolicy());

    policy = new PrivateCloudComputingPolicy();

 

       policy.setPolicyName(compPolicyName);

       policy.setPolicyDescription(compPolicyName+" created by SR "+ctxt.getSrId());

       policy.setCloudName(oldVDC.getCloudName());

 

    var scopeList = new ArrayList();

    var scope = new DRAPScope();

    scope.setEnabled(true);

    scope.setInclude(true);

    scope.setScopeContextName("Clusters");

    scope.setScopeContextValue(cluster);

    scopeList.add(scope);

  policy.setScopeList(scopeList);

  var rps = resourcePool.split(",");

    var resourcePoolName = new StringBuffer();

    for(var i = 0; i<rps.length; i++){

  var detailedIdentity = new ResourcePoolDetailedIdentity(rps[i]);

     resourcePoolName = resourcePoolName.append(detailedIdentity.getRpIdentity());

  resourcePoolName = resourcePoolName.append(",");

    }

    resourcePoolName = resourcePoolName.substring(0,resourcePoolName.lastIndexOf(","));

    policy.setResourcePoolName(resourcePoolName);

 

  policy.setEsxType(profile.getEsxType());

  policy.setEsxVersion(profile.getEsxVersion());

  policy.setRules(profile.getRules());

  policy.setOverrideTemplateProperties(profile.isOverrideTemplateProperties());

  if(profile.isOverrideTemplateProperties()){

  policy.setNumVCPUs(profile.getNumVCPUs());

  policy.setCpuReservationMhz(profile.getCpuReservationMhz());

  policy.setCpuLimitMhz(profile.getCpuLimitMhz());

  policy.setCpuShares(profile.getCpuShares());

  policy.setMemoryMB(profile.getMemoryMB());

  policy.setReserveAllGuestMem(profile.isReserveAllGuestMem());

  if(!profile.isReserveAllGuestMem()){

  policy.setMemReservationMB(profile.getMemReservationMB());

  policy.setMemLimitMB(profile.getMemLimitMB());

  policy.setMemShares(profile.getMemShares());

  }

  }

  policy.setAllowResizing(profile.isAllowResizing());

  if(profile.isAllowResizing()){

  policy.setResizeAllowedCPUs(profile.getResizeAllowedCPUs());

  policy.setResizeAllowedMemoryMB(profile.getResizeAllowedMemoryMB());

  }

  if(profile.getDeployToFolder() != null)

  policy.setDeployToFolder(profile.getDeployToFolder());

  InfraPersistenceUtil.persistPrivateCloudComputingPolicy(policy);

  compPolicyId = policy.getPolicyId();

  logger.addInfo("Compute Policy Created: " +compPolicyName)

       return policy;

}

function createNetPolicy(oldVDC, netPolicyName, nicAlias, dvPortGroup, ipPool)

{

       var policy;

       policy = InfraPersistenceUtil.getPrivateCloudNetworkPolicy(netPolicyName);

    if (policy !== null)

       {

               ctxt.setFailed("Network policy with name "+netPolicyName+" already exists");

               ctxt.exit();

       }

 

    var profilePolicy = InfraPersistenceUtil.getPrivateCloudNetworkPolicy(oldVDC.getNetworkPolicy());

 

    var policy = new PrivateCloudNetworkPolicy();

 

       policy.setPolicyName(netPolicyName);

       policy.setPolicyDescription(netPolicyName+" created by SR "+ctxt.getSrId());

       policy.setCloudName(oldVDC.getCloudName());

    policy.setAllowOptionalNICs(profilePolicy.isAllowOptionalNICs());

    

    var nicList = profilePolicy.getVmNetworks().getList();

    /*for(var i = 0; i<nicList.size(); i++){

  if(nicList.get(i).getNicAlias().equalsIgnoreCase(nicAlias)){

  ctxt.setFailed("NIC Alias name should be unique");

  ctxt.exit();

  }

    }*/

    var profileNIC = nicList.get(0);

  var nic = new PrivateCloudNetworkPolicyNIC();

  nic.setNicAlias(nicAlias);

  nic.setMandatory(true);

  nic.setAllowToChangePortGroups(profileNIC.isAllowToChangePortGroups());

  nic.setCopyFromTemplate(profileNIC.isCopyFromTemplate());

  if(!profileNIC.isCopyFromTemplate())

  nic.setAdapterType(profileNIC.getAdapterType());

 

    var nicPortGroup = new PrivateCloudNetworkPolicyNICPortGroup();

    nicPortGroup.setPortGroup(dvPortGroup);

    nicPortGroup.setIpAddressType(1);//DHCP:0,Static:1

    nicPortGroup.setIpAddressSource(0);//IP Pool Policy:0, Inline Pool Policy:1

 

    var staticIPs = ipPool.split(",");

    nicPortGroup.setStaticIPPool(staticIPs);

 

    nic.getVmPortGroups().getList().add(nicPortGroup);

 

     var newNICList = new ArrayList();

  //newNICList.addAll(nicList);

  newNICList.add(nic);

    var def=new PrivateCloudNetworkPolicyNICDef();

       def.setNics(newNICList);

       var vmNicsDefInfoStr=VMWareUtils.getPrivateCloudNetworkPolicyNICDefStr(def);

       policy.setVmNicsDefInfoStr(vmNicsDefInfoStr);

       InfraPersistenceUtil.persistPrivateCloudNetworkPolicy(policy);

  netPolicyId = policy.getPolicyId();

  logger.addInfo("Network Policy Created: " +netPolicyName);

       return policy;

}

function createStorPolicy(oldVDC, storPolicyName, datastoreCluster, scopeType)

{

  var policy;

       var policy = InfraPersistenceUtil.getPrivateCloudStoragePolicy(storPolicyName);

    if (policy != null)

       {

               ctxt.setFailed("Storage policy with name "+storPolicyName+" already exists");

               ctxt.exit();

       }

    var profile = InfraPersistenceUtil.getPrivateCloudStoragePolicy(oldVDC.getStoragePolicy());

    policy = new PrivateCloudStoragePolicy();

    policy.setPolicyName(storPolicyName);

       policy.setPolicyDescription(storPolicyName+" created by SR "+ctxt.getSrId());

       policy.setCloudName(oldVDC.getCloudName());

  var result = new DRAPScope();

        result.setEnabled(true);

        result.setInclude(true);

        result.setScopeContextName(DRAPFormUtil.SCOPE_CONTEXT_NAME_DATASTORE_CLUSTERS);

        result.setScopeContextValue(datastoreCluster);

        var list = new ArrayList();

        list.add(result);

  logger.addInfo("ScopeType Output: " +scopeType);

  policy.setScopeType(scopeType);

  policy.setDatastoreCluster(datastoreCluster);

  policy.setScopeList(list);

  policy.setLocalStorage(profile.isLocalStorage());

  policy.setNfsStorage(profile.isNfsStorage());

  policy.setISCSIStorage(profile.isISCSIStorage());

  policy.setRules(profile.getRules());

  policy.setUseLinkedClone(profile.isUseLinkedClone());

  if(profile.isOverrideTemplateProperties()){

  policy.setOverrideTemplateProperties(profile.isOverrideTemplateProperties());

  policy.setDoThinProvisioning(profile.isDoThinProvisioning());

  if(profile.isManualDiskSize()){

  policy.setManualDiskSize(profile.isManualDiskSize());

  policy.setCustomDiskSizeGB(profile.getCustomDiskSizeGB());

  }

  }

  if(profile.isAllowResizing()){

  policy.setAllowResizing(profile.isAllowResizing());

  policy.setResizeAllowedDiskGB(profile.getResizeAllowedDiskGB());

  }

  policy.setAllowDataStoreSelect(profile.isAllowDataStoreSelect());

       InfraPersistenceUtil.persistPrivateCloudStoragePolicy(policy);

  storPolicyId = policy.getPolicyId();

  logger.addInfo("Storage Policy Created: " +storPolicyName);

       return policy;

}

function createSysPolicy(oldVDC, sysPolicyName, domainName, userName, password)

{

  var policy;

  policy = InfraPersistenceUtil.getPrivateCloudSystemProfile(sysPolicyName);

       if (policy != null)

       {

               ctxt.setFailed("System policy with name "+sysPolicyName+" already exists");

               ctxt.exit();

       }

  var profile = InfraPersistenceUtil.getPrivateCloudSystemProfile(oldVDC.getPrimaryDeployPolicy());

    

    policy = new PrivateCloudSystemProfile();

    policy.setPolicyName(sysPolicyName);

       policy.setPolicyDescription(sysPolicyName+" created by SR "+ctxt.getSrId());

    policy.setVmNameTemplate(profile.getVmNameTemplate());

    policy.setVmNameValidationPolicy(profile.getVmNameValidationPolicy());

    policy.setAllowEndUserSuffix(profile.isAllowEndUserSuffix());

    policy.setPowerOn(profile.isPowerOn());

    policy.setHostNameTemplate(profile.getHostNameTemplate());

    policy.setHostNameValidationPolicy(profile.getHostNameValidationPolicy());

    policy.setDnsDomain(profile.getDnsDomain());

    policy.setLinuxTimezone(profile.getLinuxTimezone());

 

    if(profile.getDnsSuffixList() != null)

  policy.setDnsSuffixList(profile.getDnsSuffixList());

  if(profile.getDnsServerList() != null)

  policy.setDnsServerList(profile.getDnsServerList());

    policy.setImageType(profile.getImageType());

 

    if(profile.getProductId() != null)

  policy.setProductId(profile.getProductId());

    policy.setFullName(profile.getFullName());

    policy.setOrgName(profile.getOrgName());

    policy.setLicenseMode(profile.getLicenseMode());

 

    if(profile.getLicenseUsers() != null)

  policy.setLicenseUsers(profile.getLicenseUsers());

 

    if(profile.getWinList() != null)

  policy.setWinList(profile.getWinList());

    policy.setSIDUnique(profile.isSIDUnique());

    policy.setAutoLogon(profile.isAutoLogon());

 

    if(profile.getAutoLogonCount() != null)

  policy.setAutoLogonCount(profile.getAutoLogonCount());

    policy.setPassword(profile.getPassword());

    policy.setWindowsTimezone(profile.getWindowsTimezone());

    policy.setDomain(domainName);

    policy.setDomainAdmin(userName);

    policy.setDomainPassword(password);

 

    if(profile.isDefineAnnotation()){

  policy.setDefineAnnotation(profile.isDefineAnnotation());

  if(profile.getNotes() != null)

  policy.setNotes(profile.getNotes());

  policy.setCustomAttributesList(profile.getCustomAttributesList());

    }

    

       InfraPersistenceUtil.persistPrivateCloudSystemProfile(policy);

  sysPolicyId = policy.getPolicyId();

  logger.addInfo("Storage Policy Created: " +sysPolicyName);

       return policy;

}

function registerUndoTask(vDCID, compPolicyId, netPolicyId, storPolicyId, sysPolicyId) {

    // register undo task 

    var undoHandler = "custom_rollback_tenant_vdc";

    var undoContext = ctxt.createInnerTaskContext(undoHandler);

    var undoConfig = undoContext.getConfigObject();

  undoConfig.vDCId = vDCID;

  undoConfig.compPolicyId = compPolicyId;

  undoConfig.netPolicyId = netPolicyId;

  undoConfig.storPolicyId = storPolicyId;

  undoConfig.sysPolicyId = sysPolicyId;

    ctxt.getChangeTracker().undoableResourceModified("Rollback vdc ",

                ""+vDCID,"rollback ",

                "Rollback "+vDCID,undoHandler,undoConfig);

}

createTenantPolicy();

//registerUndoTask(vDCID, compPolicyId, netPolicyId, storPolicyId, sysPolicyId);

Comments
phirobin
Community Member

This is very helpful - but what if you want to create the Tenant and then the vDC?  The above assumes that there is a vDC profile to select - I am looking to create a Tenant and then a set of vDCs - there is no function I can find to create the vDC service profile specifying the Tenant/Group and then selecting the cloud.

I have 3x vCenters - one for Linux (but not Oracle) and Windows, 1x for Oracle Single and 1x for Oracle RAC - Is there a function that can be written to create the vDC Service Profile too (or supply the values for it)?

Thanks

Phil

31-05-2017 - Update

I have resolved this by creating 3x Service profiles (one for each vCenter for the Default Group) and the built in task to Create a vDC has the GroupID as an input - so I then ran this 3 times in my workflow using the vDC profile as a Base and supplying the GroupId input.  This goes and creates a Network, Storage, Compute and Service Delivery Policy based on the vDC Profile and associates them within each of the new vDCs. I end up with 3x of each of the Network, Storage, Compute and Service Delivery (one for each vDC) per Tenant/Group but I am happy with that

Orf Gelbrich
Cisco Employee
Cisco Employee

Cool – glad it is working.

Orf Gelbrich

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

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