Unsupported content This version of the documentation is no longer supported. However, the documentation is available for your convenience. You will not be able to leave comments.

Syntax and usage


This topic describes the syntax for using the SDK, and includes the following sections:

Syntax

The SDK syntax is structured according to tasks, with each command including the following items:

  • A noun indicating the item acted upon, such as pod, cluster, and provider. 
  • A verb indicating the action taken, such as create, delete, update, and list. 
  • Parameters that provide detail about the noun-verb pair, such as a pod name.

Python commands are structured using the following general format:

python com/bmc/cloud/sdk/commandline/clmcmd.py noun-verb --parameterName1 parameterValue1 --parameterName2 parameterValue2... --parameterNameN parameterValueN

For example, to onboard a pod named BabyPod from BMC BladeLogic Network Automation, enter the following Python command:

python com/bmc/cloud/sdk/commandline/clmcmd.py pod-onboard --providername BBNA --podname BabyPod

If your parameter values have spaces, the values must be enclosed in quotation marks and preceded by an equal sign. To modify the example above, if the name of the pod you want to onboard is Baby Pod 3, enter the following command:

python com/bmc/cloud/sdk/commandline/clmcmd.py pod-onboard --providername BBNA --podname="Baby Pod 3"

Note

You can enter most commands in any order. However, you first need to establish access to BMC Cloud Lifecycle Management, which requires the login command. See login for more information.

SDK user roles

The SDK can be used by different people at your company for various purposes. Consider the following roles, and the types of tasks they might perform with the SDK:

  • Cloud end users—While most end users will use the BMC Cloud Lifecycle Management graphical user interface to request and manage their services, some might prefer to use the command-line SDK interface to request a service or add options to an existing service.
  • Cloud administrators—For these users the SDK can speed the bulk creation of services, or the setup of the cloud infrastructure. These users have scripting experience, and perhaps not much coding experience, so they might use shell scripting to run a series of command-lines in the SDK.
  • IT developers—These users might want to build a separate portal or a customized user interface to work with BMC Cloud Lifecycle Management. IT Developers would use the Python SDK exposed as functions instead of the command-line interface.

Using the SDK from the command line

To use the SDK from the command line, start your Python client and begin entering SDK commands using the syntax explained earlier this topic.

You also can also include multiple SDK commands in a single file (such as a .bat file), as shown in the following examples:

Click here to expand an example of a file a cloud administrator might use to set up an infrastructure.
#!/bin/sh

CLM_URL="http://serverName:8080/csm"
CLM_USER="cloudadmin"
CLM_PASSWORD="password"

PROVIDER_NAME="BBNA"

POD_NAME="SA4Pod"

ENV_BP_NAME="Blueprint for Reprovisioning Compact Bronze - 2 Access Switches"
ENVIRONMENT_NAME="LHE_shell"

CLUSTER_PROVIDER_NAME="BBSA"
CLUSTER_NAME="CLM-CLUSTER-01"
DATASTORE_NAME="CLMnetappbnfsSDRS1"

CLUSTER_POOL_NAME="VC"
CLUSTER_POOL_VENDOR_NAME="VMWare"
CLUSTER_POOL_HW_ARCH="X86"

DATASTORE_POOL_NAME="VD"
DATASTORE_POOL_VENDOR_NAME="VMWare"

SERVICE_BP_NAME="serviceBP"
SERVICE_BP_JSON="test.json"
SERVICE_BP_DEP_MODEL_NAME="Definition 1"

OFFERING_NAME="sdkso_shell"
OFFERING_CATALOG_NAME="sdkcat_shell"
OFFERING_ENT_PKG_NAME="GlobalEP"

echo "Logging to $CLM_URL using $CLM_USER..."
python com/bmc/cloud/sdk/commandline/clmcmd.py login --url "$CLM_URL" --user "$CLM_USER" --password "$CLM_PASSWORD"

POD_COUNT=`python com/bmc/cloud/sdk/commandline/clmcmd.py pod-list -n | grep -c "$POD_NAME"`

if [ "$POD_COUNT" -eq "0" ] ; then
   echo "Onboarding pod $POD_NAME from $PROVIDER_NAME provider..."
    python com/bmc/cloud/sdk/commandline/clmcmd.py pod-onboard --providername "$PROVIDER_NAME" --podname "$POD_NAME"
fi

ENV_BP_COUNT=`python com/bmc/cloud/sdk/commandline/clmcmd.py environmentblueprint-list --podname "$POD_NAME" -n | grep -c "$ENV_BP_NAME"`

if [ "$ENV_BP_COUNT" -eq "0" ] ; then
   echo "Onboarding environment blueprint $ENV_BP_NAME from $PROVIDER_NAME provider..."
    python com/bmc/cloud/sdk/commandline/clmcmd.py environmentblueprint-onboard --blueprintname "$ENV_BP_NAME" --providername "$PROVIDER_NAME" --podname "$POD_NAME"
fi


CLUSTER_COUNT=`python com/bmc/cloud/sdk/commandline/clmcmd.py cluster-list -n | grep -c "$CLUSTER_NAME"`

if [ "$CLUSTER_COUNT" -eq "0" ] ; then
   echo "Onboarding cluster $CLUSTER_NAME from $CLUSTER_PROVIDER_NAME provider..."
    python com/bmc/cloud/sdk/commandline/clmcmd.py cluster-onboard --clustername "$CLUSTER_NAME" --providername "$CLUSTER_PROVIDER_NAME" --podname "$POD_NAME"
fi

ENV_COUNT=`python com/bmc/cloud/sdk/commandline/clmcmd.py environment-list -n | grep -c "$ENVIRONMENT_NAME"`

if [ "$ENV_COUNT" -eq "0" ] ; then
   echo "Creating $ENVIRONMENT_NAME environment in pod $POD_NAME..."
    python com/bmc/cloud/sdk/commandline/clmcmd.py environment-create --name "$ENVIRONMENT_NAME" --description "$ENVIRONMENT_NAME description" --environmentblueprint "$ENV_BP_NAME" --podname "$POD_NAME"
fi

CLUSTER_POOL_COUNT=`python com/bmc/cloud/sdk/commandline/clmcmd.py pool-list -n | grep -c "$CLUSTER_POOL_NAME"`

if [ "$CLUSTER_POOL_COUNT" -eq "0" ] ; then
   echo "Creating cluster compute pool $CLUSTER_POOL_NAME with $CLUSTER_NAME..."
    python com/bmc/cloud/sdk/commandline/clmcmd.py cluster-pool-create --poolname "$CLUSTER_POOL_NAME" --description "$CLUSTER_POOL_NAME description" --clustername "$CLUSTER_NAME" --podname "$POD_NAME" --environmentname "$ENVIRONMENT_NAME" --providername "$CLUSTER_PROVIDER_NAME" --vendorname "$CLUSTER_POOL_VENDOR_NAME" --hwarch "$CLUSTER_POOL_HW_ARCH"
fi

DATASTORE_POOL_COUNT=`python com/bmc/cloud/sdk/commandline/clmcmd.py pool-list -n | grep -c "$DATASTORE_POOL_NAME"`

if [ "$DATASTORE_POOL_COUNT" -eq "0" ] ; then
   echo "Creating cluster compute pool $DATASTORE_POOL_NAME with $DATASTORE_NAME..."
    python com/bmc/cloud/sdk/commandline/clmcmd.py datastore-pool-create --poolname "$DATASTORE_POOL_NAME" --description "$DATASTORE_POOL_NAME description" --datastore "$DATASTORE_NAME" --podname "$POD_NAME" --environmentname "$ENVIRONMENT_NAME" --providername "$CLUSTER_PROVIDER_NAME" --vendorname "$DATASTORE_POOL_VENDOR_NAME"
fi

echo "Creating service blueprint $SERVICE_BP_NAME..."
python com/bmc/cloud/sdk/commandline/clmcmd.py serviceblueprint-create --blueprintname "$SERVICE_BP_NAME" --jsonfile "$SERVICE_BP_JSON"

OFFERING_COUNT=`python com/bmc/cloud/sdk/commandline/clmcmd.py offering-list -n | grep -c "$OFFERING_NAME"`

if [ "$OFFERING_COUNT" -eq "0" ] ; then
   echo "Creating offering $OFFERING_NAME..."
    python com/bmc/cloud/sdk/commandline/clmcmd.py offering-create --offeringname "$OFFERING_NAME" --catalogservicename "$OFFERING_CATALOG_NAME" --blueprintname "$SERVICE_BP_NAME" --deploymentmodelname "$SERVICE_BP_DEP_MODEL_NAME" --entitlementpackagename "$OFFERING_ENT_PKG_NAME"
fi
Click here to expand an example of a file a cloud administrator might use to create a service offering instance.
Command-line Example 3: Creating a service offering instance
#!/bin/sh

CLM_URL="http://serverName:8080/csm"
CLM_USER="cloudadmin"
CLM_PASSWORD="password"

OFFERING_NAME="test"

SERVICE_NAME="test"
SERVICE_TENANT_NAME="test"

SERVER_USER="test"
SERVER_PASSWORD="test"
SERVER_HOST_PREFIX="test"


echo "Logging to $CLM_URL using $CLM_USER..."
python com/bmc/cloud/sdk/commandline/clmcmd.py login --url "$CLM_URL" --user "$CLM_USER" --password "$CLM_PASSWORD"

SERVICE_COUNT=`python com/bmc/cloud/sdk/commandline/clmcmd.py service-list -n | grep -c "$SERVICE_NAME"`

if [ "$SERVICE_COUNT" -eq "0" ] ; then
   echo "Creating service $SERVICE_NAME..."
    python com/bmc/cloud/sdk/commandline/clmcmd.py service-create --offeringname "$OFFERING_NAME" --servicename "$SERVICE_NAME" --serverusername "$SERVER_USER" --serverpassword "$SERVER_PASSWORD" --serverhostprefix "$SERVER_HOST_PREFIX" --tenantname "$SERVICE_TENANT_NAME"
fi
Click here to expand an example of a file an end user might use to add an option to a service, a common day-2 activity.
#!/bin/sh

CLM_URL="http://serverName:8080/csm"
CLM_USER="AltoCloudAdmin"
CLM_PASSWORD="password"

SERVICE_NAME="sdksoi-20"

SERVICE_OPTION="TRO_CPU"
SERVICE_OPTION_CHOICE="TRO_5CPU"


SERVER_NAME="SG-3"

echo "Logging to $CLM_URL using $CLM_USER..."
python com/bmc/cloud/sdk/commandline/clmcmd.py login --url "$CLM_URL" --user "$CLM_USER" --password "$CLM_PASSWORD"

echo "Stopping service $SERVICE_NAME..."
python com/bmc/cloud/sdk/commandline/clmcmd.py service-stop --servicename "$SERVICE_NAME"

echo "Applying day 2 option $SERVICE_OPTION=$SERVICE_OPTION_CHOICE to service $SERVICE_NAME..."
python com/bmc/cloud/sdk/commandline/clmcmd.py service-update-option --servicename "$SERVICE_NAME" --servername "$SERVER_NAME" --optionname "$SERVICE_OPTION" --optionchoicename "$SERVICE_OPTION_CHOICE"

echo "Starting service $SERVICE_NAME..."
python com/bmc/cloud/sdk/commandline/clmcmd.py service-start --servicename "$SERVICE_NAME"

Using the SDK in a Python program

To use the SDK in a Python program, the first non-commented line in your program must be:
from com.bmc.cloud.sdk.client.generated import, followed by the commands you want to use in the program. For example, if you want to have all SDK commands available to your program, the line would be:
from com.bmc.cloud.sdk.client.generated import *.

Click here to expand an example of a program an IT developer might use to set up an infrastructure.
'''
Created on 04-Mar-2014
@summary: Sample flow for python API
'''

from com.bmc.cloud.sdk.client.generated import login,pod_list,pod_onboard,environment_blueprint_onboard,environment_blueprint_list,onboard_cluster,cluster_list,\
                                    environment_create,environment_list,cluster_pool_create,pool_list,task_status,offering_create,offering_list
from com.bmc.cloud.sdk.sessionmanager.session import SessionManager

sessionManager = SessionManager()
global authToken,postRequest,authToken
# Login   
gcac = login('http://172.22.200.6:9090/csm', "clmadmin", "password")       
def onboard_pod(podName):
   print "Let's on-board a pod using BBNA provider using API script"
   try:
       # Call pod list to check whether pod is on-boarded or not.
        podlist = pod_list(gcac, "BBNA", onboarded=True)
       print "pod-list output", podlist
       
       # Collect the on-boarded pod names
       #records = podlist[0].name
       
       # Check if given podname is not in onboarded records then on-board the pod.
       if podlist == []:
           # Check if given pod is present in search result
            podOutput = pod_onboard(gcac, "BBNA", podName)
               
           #Verify if on-boarded pod is present in records.
           assert podName in podOutput.name
           #podName = pod.name
           print "Pod %s on-boarded successfully:" %podName
       else:
           print "Pod %s on-boarded already" %podName
   except Exception, error:
       print "Error of pod-onboard : " , error
       
def container_BP_Onboard(containerBP,providerName,podName):
   print "Let's on-board a LHE-blueprint using BBNA provider..."
   try:    
        environmentBlueprintList = environment_blueprint_list(gcac, podName, onboarded=True)
       print "environment_blueprint_list output", environmentBlueprintList
       
       # Collect the on-boarded pod names
       #records = environmentBlueprintList.name
       
       # Check if given pod is present in search result
       if environmentBlueprintList == []:
            containerOutput=environment_blueprint_onboard(gcac, containerBP, providerName, podName)
           #Verify if on-boarded pod is present in records.
           assert containerBP in containerOutput.name
           #podName = pod.name
           print "Container blueprint %s on-boarded successfully:" %containerBP
       else:
           print "Blueprint is on-boarded already"        
   except Exception, error:
       print "Error of container blueprint on-board : " , error
                       
# Function to on-board vc using API
def vc_onboard(clusterName,podName,providerName):
   print "On-board a virtual cluster using BBSA provider..."
   try:    
        clusterList = cluster_list(gcac, onboarded=True)
       print "cluster_list output", clusterList
       
       import ipdb;ipdb.set_trace()
       
       # Collect the on-boarded pod names
       #records = clusterList.name
       
       # Check if given cluster is present in search result
       if clusterList == []:
            clusterOutput=onboard_cluster(gcac, clusterName, podName, providerName)
           #Verify if on-boarded cluster is present in records.
           assert clusterName in clusterOutput[0].name
           print "Virtual cluster %s on-boarded successfully:" %clusterName
       else:
           print "Cluster is on-boarded already"            
   except Exception, error:
       print "Error of container blueprint on-board : " , error  
       
def lhe_create(name, description, environmentBlueprintName,podName):
       print "Create LHE using API script"
       import ipdb;ipdb.set_trace()
       try:
            lhe = environment_create(gcac, name=name, description=description, blueprint=environmentBlueprintName,podName=podName, allowsPublicIP=True)
           
           # if task then call task status
           try:
               if lhe.taskstate == 'FAILED':
                   print "LHE create failed."
                   return None
               try:
                   while lhe.taskstate == "SUSPENDED" or lhe.taskstate == "QUEUED":
                       # form command
                        task_get_command = task_status(gcac, lhe.taskInternalUUID)
               except:
                   print "LHE created successfully."
           except:
               assert name in lhe.name
       except Exception, error:
           print "Error of lhe_create : " , error.message
       
       # Search the created lhe
        environmentList = environment_list(gcac)
       print "environment_list output", environmentList
       
       assert environmentList[0].name == name                  
       
def create_compute_pool(poolName, description, listofClusterNames, podName, networkContainerName, providerName, vendorName, hwArch):
   print "Create compute cluster pool..."
   try:   
       import ipdb;ipdb.set_trace()    
       #List the pools
        poollistOutput = pool_list(gcac)
       print "pool_list output", poollistOutput
       
       # Collect the on-boarded pod names
        records = poollistOutput[0].name
       
       # Check if given cluster is present in search result
       if poolName not in records:
            staticPool = cluster_pool_create(gcac, poolName, description, listofClusterNames, podName, networkContainerName, providerName, vendorName, hwArch)
           assert poolName in staticPool.name
       else:
           print "Pool is created already"            
   except Exception, error:
       print "Error of pool create : " , error  

def create_SO(offeringname,catalogservicename,depolymentmodelname,blueprintname):
   print "Let's Create Service offering..."
   try:   
       #List the offering
        solistOutput = offering_list(gcac)
       print "offering_list output", solistOutput
       
       # Collect the on-boarded pod names
        records = solistOutput[0].name
       
       # Check if given cluster is present in search result
       if offeringname not in records:
            offeringinstance= offering_create(gcac, offeringname, catalogservicename, depolymentmodelname,blueprintname)
           assert offeringname in offeringinstance.name
       else:
           print "SO is created already"            
   except Exception, error:
       print "Error of offering create : " , error       
      
       
if __name__=="__main__":
   #onboard_pod("SAPod3")
   #container_BP_Onboard("Baby Pod Container Blueprint","BBNA","SAPod3")
   #vc_onboard("CLM-CLUSTER-02", "SAPod3", "BBSA")
   #lhe_create("APILhe" ,"test" , "Baby Pod Container Blueprint", "SAPod3" )
    create_compute_pool("APIPool", "test", "CLM-CLUSTER-02", "SAPod3","SDKLhe1", "BBSA", "VMWare" , "X86")
Click here to expand an example of a python script a cloud administrator might use to transfer ownership of a user's service offering instances to another user
# transfer all of one user's service offering instances to another user
# usage >python transfer.py -u <username> -p <password> -f <from user> -t <to user> -n <to tenant>
from com.bmc.cloud.sdk.client.generated import login, service_list, service_transfer
import sys, getopt

def transfer(fromUser, toUser, toTenant):
   try:
        serviceList = service_list(sesn)    
       for theService in serviceList:
           if theService.owner == fromUser:
               print "Transferring service %s from %s to user %s in tenant %s" % (theService.name, fromUser, toUser, toTenant)
                service_transfer(sesn, theService.name, toUser, toTenant)
   except Exception, error:
       print "Error in transferring ownership :", error

if __name__ == "__main__":
   try:
       #initialize variables
        userName = ""
        passWord = ""
        fromUser = ""
        toUser = ""
        toTenant = ""
       
       #get command line parameters
        argv = sys.argv[1:]
        opts, args = getopt.getopt(argv, "u:p:f:t:n:", ["user=", "pword=", "fuser=", "tuser=","tnnt="])
       for opt, arg in opts:
           if opt in ("-u", "--user"):
                userName = arg
           elif opt in ("-p", "--pword"):
                passWord = arg
           elif opt in ("-f", "--fuser"):
                fromUser = arg
           elif opt in ("-t", "--tuser"):
                toUser = arg
           elif opt in ("-n", "--tnnt"):
                toTenant = arg
       
       # login
        sesn = login("http://clm-pm.bmc.local:7070/csm", userName, passWord)
       
       #transfer all of one user's services to another user
        transfer(fromUser, toUser, toTenant)
   except Exception, error:
       print "Error in main: ", error

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*