def api_session(customerUsername, customerUUID, customerPassword): """Function to set up api session, import credentials etc.""" token = getToken(ENDPOINT, customerUsername, customerUUID, customerPassword) auth_client = dict(endpoint=ENDPOINT, token=token) return auth_client
def MakeVM(customerUUID, customerUsername, customerPassword, publicKey, vmName, localRepoDir, isVerbose): ramAmount = DEFAULT_RAM_SIZE cpuCount = DEFAULT_CPU_COUNT diskSize = DEFAULT_EXTRA_DISK_SIZE print customerUUID print customerUsername print customerPassword print publicKey print cpuCount print ramAmount print vmName print isVerbose # Authenticate to the FCO API, getting a token for furture use token = getToken(ENDPOINT, customerUsername, customerUUID, customerPassword) auth = dict(endpoint=ENDPOINT, token=token) print("Details for image_uuid " + IMAGE_UUID + ":\n"); img_ret = list_image(auth, IMAGE_UUID) vdc_uuid_for_image = img_ret['vdcUUID'] if (isVerbose): print("vdc_uuid_for_image is " + vdc_uuid_for_image) cluster_uuid_for_image = img_ret['clusterUUID'] print("cluster_uuid_for_image is " + cluster_uuid_for_image) customer_vdc_uuid = get_first_vdc_in_cluster(auth, cluster_uuid_for_image) if (isVerbose): print("The VDC to use is: " + customer_vdc_uuid) # Setup VDC in this cluster if user doesn't have one if (customer_vdc_uuid == ''): vdc_uuid = create_vdc_in_cluster(auth, cluster_uuid_for_image) if (isVerbose): print("VDC we created is " + vdc_uuid) customer_vdc_uuid = vdc_uuid # Sanity check that we have a VDC to work with if (customer_vdc_uuid == ''): raise Exception("No VDC to create the server in !") current_time = time.strftime("%Y-%m-%d %H:%M:%S") if vmName == None: server_name = "VM " + current_time else: server_name = vmName # Get the Product Offer UUID of the Standard Server product product_offer = 'Standard Server' server_po_uuid = get_prod_offer_uuid(auth, product_offer) if (server_po_uuid == ""): raise Exception("No '" + product_offer + "' Product Offer found") # Base the boot disk on the PO of the same size storage disk as the Image must have been; that way # we can be reasonably sure it will exist. image_disk_po_name = str(img_ret['size']) + " GB Storage Disk" boot_disk_po_uuid = get_prod_offer_uuid(auth, image_disk_po_name) if (boot_disk_po_uuid == ""): raise Exception("No suitable disk product offer found (expected a '" + image_disk_po_name + "' PO)") # Create the additional disk (if any). We'll attach it later. disk_name = "Disk " + current_time + " #2" extra_disk_uuid = create_disk(auth, 'Standard Disk', diskSize, disk_name, customer_vdc_uuid) server_data = build_server(auth_parms=auth, customer_uuid=customerUUID, image_uuid=IMAGE_UUID, vdc_uuid=customer_vdc_uuid, server_po_uuid=server_po_uuid, boot_disk_po_uuid=boot_disk_po_uuid, server_name=server_name, ram_amount=ramAmount, cpu_count=cpuCount, networkType=NETWORKTYPE, cluster_uuid=cluster_uuid_for_image, public_key=publicKey, context_script=CONTEXTSCRIPT) if (isVerbose): print "Return from build_server() is:" print server_data print "==== End build_server() details ====" # If we created an extra disk, attach it now if (extra_disk_uuid != ""): attach_disk(auth_parms=auth, server_uuid=server_data[0], disk_uuid=extra_disk_uuid, index='2') server_data = start_server(auth_parms=auth, server_data=server_data) ret = dict(server_uuid=server_data[0], ip=server_data[3], password=server_data[1], login=server_data[2] ) add_remote_git(server_data[3], localRepoDir) print ret