'''
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")