Ejemplo n.º 1
0
def image_disk(auth_client, server_uuid, default_user, diskIndex):
    # Details of the server
    print("Details for the server we will Image:")
    print("============================")
    server_resultset = list_resource_by_uuid(auth_client, server_uuid, res_type='SERVER')
    for l in range(0, server_resultset['totalCount']):
        server = server_resultset['list'][l]

    #baseUUID = server['resourceUUID']
    clusterUUID = server['clusterUUID']
    vdcUUID = server['vdcUUID']
    # Image should be same size as the source disk
    disk = server['disks'][diskIndex]
    size = disk['size']
    baseUUID = disk['resourceUUID']

    print("Create Image input:")
    response = rest_create_image(auth_client, baseUUID, clusterUUID, vdcUUID, size, default_user)
    print("=============================")
    print response
    print("Details for newly created image:")
    createdImage = list_resource_by_uuid(auth_client, response['itemUUID'],"IMAGE")
    for l in range(0, createdImage['totalCount']):
        image = createdImage['list'][l]

    print image
    sys.stdout.flush()
    return image
    def _detach_disk(self, node_instance):
        """Detach disk from the VM.
        :param node_instance: node instance object
        :type node_instance: <NodeInstance>
        """
        print 'Scaling down in progress for NODE INSTANCE name: %s' %node_instance.get_name()
        machine_name = node_instance.get_name()
        vm = self._get_vm(machine_name)
        vm_uuid = vm['id']

        print 'Stopping the VM: %s to detach disk' %vm
        # Stop the VM before detaching the disk
        try:
            ret = StopVM(
                vm_uuid,
                self.user_info.get_cloud('user.uuid'),
                self.user_info.get_cloud_username(),
                self.user_info.get_cloud_password(),
                self.user_info.get_cloud_endpoint(),
                self.verbose)
        except Exception as ex:
            raise CloudError('Failed to stop VM %s with: %s' % (vm_uuid, str(ex)))

        endpoint = self.user_info.get_cloud_endpoint()
        token = getToken(self.user_info.get_cloud_endpoint(), self.user_info.get_cloud_username(),
                        self.user_info.get_cloud('user.uuid'), self.user_info.get_cloud_password())
        auth = dict(endpoint=endpoint, token=token)
        server_resultset = list_resource_by_uuid(auth, vm_uuid, res_type='SERVER')
        for l in range(0, server_resultset['totalCount']):
            server = server_resultset['list'][l]
            disks = server['disks']

        # Get the UUID of the disk to be detached
        detach_diskUUID = node_instance.get_disk_detach_device()
        print '\n\n\n'
        print 'detach_diskUUID passed = %s' %detach_diskUUID

        found = False
        for disk in disks:
            if(disk['resourceUUID'] == detach_diskUUID):
                print 'Disk found on the server'
                found = True
        if (found == False):
            raise Exceptions.ExecutionException("Disk not found on the server %s" %vm_uuid)

        print 'Detaching the additional volatile disk'
        # Detach it now
        if (detach_diskUUID != ""):
	    detach_disk(auth, vm_uuid, detach_diskUUID)
            # Delete the resource
            rest_delete_resource(auth, detach_diskUUID, "DISK")

        print 'Restart the VM'
        server_data=[vm_uuid]
        start_server(auth, server_data)

        print("Waiting for the server to get in RUNNING state")
        ret = wait_for_server(auth, vm_uuid, 'RUNNING')
        if (ret != 0):
            raise Exceptions.ExecutionException("Server is not in RUNNING state")
def start_server(auth_parms, server_data):
    """Function to start server, uuid in server_data"""
    server_uuid = server_data[0]
    server_state = get_server_state(auth_parms, server_uuid)
    if server_state == 'STOPPED':
        rc = change_server_status(auth_parms=auth_parms, server_uuid=server_uuid, state='RUNNING')
        # change_server_status() waits on the server getting to the requested state, so we don't
        # need to call wait_for_server() here. However, we do (1) need to check the status and (2)
        # wait on the server actually being accessible (as opposed to having a RUNNING state in
        # FCO, which really just means that the underlying kvm process has started).
        #
        # 1. Check rc (0 is good)
        if (rc != 0):
            raise Exceptions.ExecutionException("Failed to put server " + server_uuid + " in to running state")


    server_resultset = list_resource_by_uuid(auth_parms, uuid=server_uuid, res_type='SERVER')
    print("Server result set is:")
    print server_resultset

    server_ip = server_resultset['list'][0]['nics'][0]['ipAddresses'][0]['ipAddress']  # yuk
    print("server IP=" + server_ip)

    # Step 2. Wait on it being accessible. It is possible that the server doesn't have ssh installed,
    # or it is firewalled, so don't fail here if we can't connect, just carry on and let
    # the caller deal with any potential issue. The alternative is a hard-coded sleep, or
    # trying a ping (platform specific and/or root privs needed).
    is_ssh_port_open(server_ip, 30)

    server_data.append(server_ip)
    return server_data
Ejemplo n.º 4
0
def ListVM(server_uuid, customerUUID, customerUsername, customerPassword, endpoint, isVerbose=False):

    # Actually just defines the global variables now (since all config bits are passed on the command line)
    config.get_config("")

    config.CUST_UUID = customerUUID
    config.USER_LOGIN = customerUsername
    config.USER_PASSWORD = customerPassword
    config.HOST_NAME = endpoint
    # config.NETWORK_TYPE  = networkType

    auth_client = setup_test()
    server_resultset = list_resource_by_uuid(auth_client, server_uuid, res_type='SERVER')
    for l in range(0, server_resultset['totalCount']):
        server = server_resultset['list'][l]
    return server
Ejemplo n.º 5
0
def ListVM(server_uuid,
           customerUUID,
           customerUsername,
           customerPassword,
           endpoint,
           isVerbose=False):

    # Actually just defines the global variables now (since all config bits are passed on the command line)
    config.get_config("")

    config.CUST_UUID = customerUUID
    config.USER_LOGIN = customerUsername
    config.USER_PASSWORD = customerPassword
    config.HOST_NAME = endpoint
    # config.NETWORK_TYPE  = networkType

    auth_client = setup_test()
    server_resultset = list_resource_by_uuid(auth_client,
                                             server_uuid,
                                             res_type='SERVER')
    for l in range(0, server_resultset['totalCount']):
        server = server_resultset['list'][l]
    return server
Ejemplo n.º 6
0
def start_server(auth_parms, server_data):
    """Function to start server, uuid in server_data"""
    server_uuid = server_data[0]
    server_state = get_server_state(auth_parms, server_uuid)
    if server_state == 'STOPPED':
        rc = change_server_status(auth_parms=auth_parms,
                                  server_uuid=server_uuid,
                                  state='RUNNING')
        # change_server_status() waits on the server getting to the requested state, so we don't
        # need to call wait_for_server() here. However, we do (1) need to check the status and (2)
        # wait on the server actually being accessible (as opposed to having a RUNNING state in
        # FCO, which really just means that the underlying kvm process has started).
        #
        # 1. Check rc (0 is good)
        if (rc != 0):
            raise Exceptions.ExecutionException("Failed to put server " +
                                                server_uuid +
                                                " in to running state")

    server_resultset = list_resource_by_uuid(auth_parms,
                                             uuid=server_uuid,
                                             res_type='SERVER')
    print("Server result set is:")
    print server_resultset

    server_ip = server_resultset['list'][0]['nics'][0]['ipAddresses'][0][
        'ipAddress']  # yuk
    print("server IP=" + server_ip)

    # Step 2. Wait on it being accessible. It is possible that the server doesn't have ssh installed,
    # or it is firewalled, so don't fail here if we can't connect, just carry on and let
    # the caller deal with any potential issue. The alternative is a hard-coded sleep, or
    # trying a ping (platform specific and/or root privs needed).
    is_ssh_port_open(server_ip, 30)

    server_data.append(server_ip)
    return server_data
Ejemplo n.º 7
0
def build_server(auth_parms, customer_uuid, image_uuid, vdc_uuid,
                 server_po_uuid, boot_disk_po_uuid, server_name, ram_amount,
                 cpu_count, networkType, cluster_uuid, public_key,
                 context_script):
    """Function to create a server"""

    print "FCOMakeOrchestrator.py:build_server args:"
    print "customer_uuid: " + customer_uuid
    print "image_uuid: " + image_uuid
    print "cluster_uuid: " + cluster_uuid
    print "vdc_uuid: " + vdc_uuid
    print "server_po_uuid: " + server_po_uuid
    print "boot_disk_po_uuid:" + boot_disk_po_uuid,
    print "server_name: " + server_name
    print "ram_amount: " + ram_amount
    print "cpu_count: " + str(cpu_count)
    print "public_key: " + public_key
    print "context_script: " + context_script
    print "=== end FCOMakeOrchestrator.py:build_server args ==="

    create_server_job = rest_create_server(auth_parms, server_name,
                                           server_po_uuid, image_uuid,
                                           cluster_uuid, vdc_uuid, cpu_count,
                                           ram_amount, boot_disk_po_uuid,
                                           context_script)
    #    print create_server_jobid

    server_uuid = create_server_job['itemUUID']
    print "--- createServer done with UUID " + server_uuid + " -----"

    print("public_key = " + public_key)
    #
    # The public_key arg might be a list of public keys, separated by cr/lf. So split
    # the list and process each key individually
    for single_key in public_key.splitlines():
        print("Processing key: " + single_key)
        add_ret = AddKey(auth_parms, server_uuid, customer_uuid, single_key)
        print("== AddKey Result ==")
        print add_ret
        print("====")

    wait_for_install(auth_parms, server_uuid=server_uuid)

    # Add NIC to server
    print "Calling create_nic for network " + networkType
    nic_uuid = create_nic(auth_parms=auth_parms,
                          nic_count='0',
                          network_type=networkType,
                          cluster_uuid=cluster_uuid,
                          vdc_uuid=vdc_uuid)
    print "create_nic returned nic_uuid: " + nic_uuid
    wait_for_resource(auth_parms=auth_parms,
                      res_uuid=nic_uuid,
                      state='ACTIVE',
                      res_type='nic')
    print "nic uuid: " + nic_uuid

    add_nic_response = add_nic_to_server(auth_parms=auth_parms,
                                         server_uuid=server_uuid,
                                         nic_uuid=nic_uuid,
                                         index='1')

    # Wait on the addNic job completing
    status = wait_for_job(auth_parms, add_nic_response['resourceUUID'],
                          "SUCCESSFUL", 90)
    if (status != 0):
        raise Exceptions.ExecutionException("Failed to add NIC to server")

    # Lookup server properties to get UUID, and password, that have been assigned to it
    server_resultset = list_resource_by_uuid(auth_parms,
                                             uuid=server_uuid,
                                             res_type='SERVER')
    server = server_resultset['list'][0]

    #    print server_resultset
    server_uuid = server['resourceUUID']
    server_pw = server['initialPassword']
    server_user = server['initialUser']
    #    server_ip = server_resultset.list[0].nics[0].ipAddresses[0].ipAddress
    server_data = [server_uuid, server_pw, server_user]
    return server_data
    def _resize(self, node_instance):
        """
        :param node_instance: node instance object
        :type node_instance: <NodeInstance>
        """
        print 'Node instance name: %s' %node_instance.get_name()
        machine_name = node_instance.get_name()
        vm = self._get_vm(machine_name)
        vm_uuid = vm['id']
        # Get the Product Offer UUID of the Standard Server product
        product_offer = 'Standard Server'

        endpoint = self.user_info.get_cloud_endpoint()
        token = getToken(self.user_info.get_cloud_endpoint(), self.user_info.get_cloud_username(),
                        self.user_info.get_cloud('user.uuid'), self.user_info.get_cloud_password())
        auth = dict(endpoint=endpoint, token=token)

        server_resultset = list_resource_by_uuid(auth, vm_uuid, res_type='SERVER')
        for l in range(0, server_resultset['totalCount']):
            server = server_resultset['list'][l]
            vdc_uuid = server['vdcUUID']

        ram = 0
        cpu = 0
        # get the RAM in GB.
        ram = node_instance.get_ram()
        # get the Number of CPUs.
        cpu = node_instance.get_cpu()
        print '\n\n\n'
        print 'CPU = ', cpu
        print 'RAM = ', ram
        # Validate the size of the CPU and the RAM input
        validate_ram_cpu_size(auth, product_offer, cpu, ram)

        print 'Resizing in progress'
        print 'Stopping the VM: %s to resize CPU/RAM' %vm
        # Stop the VM before attaching the disk
        try:
            ret = StopVM(
                vm_uuid,
                self.user_info.get_cloud('user.uuid'),
                self.user_info.get_cloud_username(),
                self.user_info.get_cloud_password(),
                self.user_info.get_cloud_endpoint(),
                self.verbose)
        except Exception as ex:
            raise CloudError('Failed to stop VM %s with: %s' % (vm_uuid, str(ex)))

        clusterUUID = server['clusterUUID']
        vdcUUID = server['vdcUUID']
        disks = server['disks']
        serverName = server['resourceName']
        # Resize the server
        resize_cpu_ram(auth, vm_uuid, serverName, clusterUUID, vdcUUID, cpu, ram)

        # Restart the VM and wait till it gets in RUNNING state
        print 'Restart the VM'
        server_data = [vm_uuid]
        start_server(auth, server_data)

        print("Waiting for the server to get in RUNNING state")
        ret = wait_for_server(auth, vm_uuid, 'RUNNING')
        if (ret != 0):
            raise Exceptions.ExecutionException("Server is not in RUNNING state")
    def _attach_disk(self, node_instance):

        """Attach extra disk to the VM.
        :param node_instance: node instance object
        :type node_instance: <NodeInstance>
        :return: name of the device that was attached
        :rtype: string
        """
        print 'Scaling in progress'
        current_time = time.strftime("%Y-%m-%d %H:%M:%S")
        disk_device_name =  "Disk " + current_time + " #2"
        print 'Node instance name: %s' %node_instance.get_name()
        machine_name = node_instance.get_name()
        vm = self._get_vm(machine_name)
        vm_uuid = vm['id']
        
        endpoint = self.user_info.get_cloud_endpoint()
        token = getToken(self.user_info.get_cloud_endpoint(), self.user_info.get_cloud_username(),
                        self.user_info.get_cloud('user.uuid'), self.user_info.get_cloud_password())
        auth = dict(endpoint=endpoint, token=token)
       
        # Size of the disk to attach (in GB).
        disk_size_GB = int(node_instance.get_disk_attach_size())
        print '\n\n\n'
        print 'disk_size = ',disk_size_GB
        
        server_resultset = list_resource_by_uuid(auth, vm_uuid, res_type='SERVER')
        for l in range(0, server_resultset['totalCount']):
                vdc = server_resultset['list'][l]
                vdc_uuid = vdc['vdcUUID']

        # Validate the size of the disk to be attached        
        validate_disk_size(auth, 'Standard Disk', disk_size_GB, disk_device_name, vdc_uuid)
        
        print 'Stopping the VM: %s to attach disk' %vm
        # Stop the VM before attaching the disk
        try:
            ret = StopVM(
                vm_uuid,
                self.user_info.get_cloud('user.uuid'),
                self.user_info.get_cloud_username(),
                self.user_info.get_cloud_password(),
                self.user_info.get_cloud_endpoint(),
                self.verbose)
        except Exception as ex:
            raise CloudError('Failed to stop VM %s with: %s' % (vm_uuid, str(ex)))
    
        disk_uuid = ""
        if (int(disk_size_GB) > 0):
            print('Creating additional volatile disk')
            # Create the disk
            disk_uuid = create_disk(auth, 'Standard Disk', disk_size_GB, disk_device_name, vdc_uuid)

        print 'Attaching the additional volatile disk'
        # If we created an extra disk, attach it now
        if (disk_uuid != ""):
            attach_disk(auth, vm_uuid, disk_uuid=disk_uuid, index='2')

	print 'Restart the VM'
        server_data=[vm_uuid]
        start_server(auth, server_data)

	print("Waiting for the server to get in RUNNING state")
        ret = wait_for_server(auth, vm_uuid, 'RUNNING')
        if (ret != 0):
            raise Exceptions.ExecutionException("Server is not in RUNNING state")
        # Return the created disk's uuid
	return disk_uuid
def build_server(auth_parms, customer_uuid, image_uuid, vdc_uuid, server_po_uuid, boot_disk_po_uuid,
                server_name, ram_amount, cpu_count, networkType, cluster_uuid, public_key, context_script):
    """Function to create a server"""

    print "FCOMakeOrchestrator.py:build_server args:"
    print "customer_uuid: " + customer_uuid
    print "image_uuid: " + image_uuid
    print "cluster_uuid: " + cluster_uuid
    print "vdc_uuid: " + vdc_uuid
    print "server_po_uuid: " + server_po_uuid
    print "boot_disk_po_uuid:" + boot_disk_po_uuid,
    print "server_name: " + server_name
    print "ram_amount: " + ram_amount
    print "cpu_count: " + str(cpu_count)
    print "public_key: " + public_key
    print "context_script: " + context_script
    print "=== end FCOMakeOrchestrator.py:build_server args ==="


    create_server_job = rest_create_server(auth_parms, server_name, server_po_uuid, image_uuid,
                                             cluster_uuid, vdc_uuid, cpu_count,
                                             ram_amount, boot_disk_po_uuid, context_script)
#    print create_server_jobid

    server_uuid = create_server_job['itemUUID']
    print "--- createServer done with UUID " + server_uuid + " -----"


    print("public_key = " + public_key)
    #
    # The public_key arg might be a list of public keys, separated by cr/lf. So split
    # the list and process each key individually
    for single_key in public_key.splitlines():
        print("Processing key: " + single_key)
        add_ret = AddKey(auth_parms, server_uuid, customer_uuid, single_key)
        print("== AddKey Result ==")
        print add_ret
        print("====")

    wait_for_install(auth_parms, server_uuid=server_uuid)

    # Add NIC to server
    print "Calling create_nic for network " + networkType
    nic_uuid = create_nic(auth_parms=auth_parms, nic_count='0', network_type=networkType,
                          cluster_uuid=cluster_uuid, vdc_uuid=vdc_uuid)
    print "create_nic returned nic_uuid: " + nic_uuid
    wait_for_resource(auth_parms=auth_parms, res_uuid=nic_uuid, state='ACTIVE', res_type='nic')
    print "nic uuid: " + nic_uuid

    add_nic_response = add_nic_to_server(auth_parms=auth_parms, server_uuid=server_uuid, nic_uuid=nic_uuid, index='1')

    # Wait on the addNic job completing
    status = wait_for_job(auth_parms, add_nic_response['resourceUUID'], "SUCCESSFUL", 90)
    if (status != 0):
        raise Exceptions.ExecutionException("Failed to add NIC to server")

    # Lookup server properties to get UUID, and password, that have been assigned to it
    server_resultset = list_resource_by_uuid(auth_parms, uuid=server_uuid, res_type='SERVER')
    server = server_resultset['list'][0]

#    print server_resultset
    server_uuid = server['resourceUUID']
    server_pw = server['initialPassword']
    server_user = server['initialUser']
#    server_ip = server_resultset.list[0].nics[0].ipAddresses[0].ipAddress
    server_data = [server_uuid, server_pw, server_user]
    return server_data
Ejemplo n.º 11
0
    def _resize(self, node_instance):
        """
        :param node_instance: node instance object
        :type node_instance: <NodeInstance>
        """
        print 'Node instance name: %s' % node_instance.get_name()
        machine_name = node_instance.get_name()
        vm = self._get_vm(machine_name)
        vm_uuid = vm['id']
        # Get the Product Offer UUID of the Standard Server product
        product_offer = 'Standard Server'

        endpoint = self.user_info.get_cloud_endpoint()
        token = getToken(self.user_info.get_cloud_endpoint(),
                         self.user_info.get_cloud_username(),
                         self.user_info.get_cloud('user.uuid'),
                         self.user_info.get_cloud_password())
        auth = dict(endpoint=endpoint, token=token)

        server_resultset = list_resource_by_uuid(auth,
                                                 vm_uuid,
                                                 res_type='SERVER')
        for l in range(0, server_resultset['totalCount']):
            server = server_resultset['list'][l]
            vdc_uuid = server['vdcUUID']

        ram = 0
        cpu = 0
        # get the RAM in GB.
        ram = node_instance.get_ram()
        # get the Number of CPUs.
        cpu = node_instance.get_cpu()
        print '\n\n\n'
        print 'CPU = ', cpu
        print 'RAM = ', ram
        # Validate the size of the CPU and the RAM input
        validate_ram_cpu_size(auth, product_offer, cpu, ram)

        print 'Resizing in progress'
        print 'Stopping the VM: %s to resize CPU/RAM' % vm
        # Stop the VM before attaching the disk
        try:
            ret = StopVM(vm_uuid, self.user_info.get_cloud('user.uuid'),
                         self.user_info.get_cloud_username(),
                         self.user_info.get_cloud_password(),
                         self.user_info.get_cloud_endpoint(), self.verbose)
        except Exception as ex:
            raise CloudError('Failed to stop VM %s with: %s' %
                             (vm_uuid, str(ex)))

        clusterUUID = server['clusterUUID']
        vdcUUID = server['vdcUUID']
        disks = server['disks']
        serverName = server['resourceName']
        # Resize the server
        resize_cpu_ram(auth, vm_uuid, serverName, clusterUUID, vdcUUID, cpu,
                       ram)

        # Restart the VM and wait till it gets in RUNNING state
        print 'Restart the VM'
        server_data = [vm_uuid]
        start_server(auth, server_data)

        print("Waiting for the server to get in RUNNING state")
        ret = wait_for_server(auth, vm_uuid, 'RUNNING')
        if (ret != 0):
            raise Exceptions.ExecutionException(
                "Server is not in RUNNING state")
Ejemplo n.º 12
0
    def _detach_disk(self, node_instance):
        """Detach disk from the VM.
        :param node_instance: node instance object
        :type node_instance: <NodeInstance>
        """
        print 'Scaling down in progress for NODE INSTANCE name: %s' % node_instance.get_name(
        )
        machine_name = node_instance.get_name()
        vm = self._get_vm(machine_name)
        vm_uuid = vm['id']

        print 'Stopping the VM: %s to detach disk' % vm
        # Stop the VM before detaching the disk
        try:
            ret = StopVM(vm_uuid, self.user_info.get_cloud('user.uuid'),
                         self.user_info.get_cloud_username(),
                         self.user_info.get_cloud_password(),
                         self.user_info.get_cloud_endpoint(), self.verbose)
        except Exception as ex:
            raise CloudError('Failed to stop VM %s with: %s' %
                             (vm_uuid, str(ex)))

        endpoint = self.user_info.get_cloud_endpoint()
        token = getToken(self.user_info.get_cloud_endpoint(),
                         self.user_info.get_cloud_username(),
                         self.user_info.get_cloud('user.uuid'),
                         self.user_info.get_cloud_password())
        auth = dict(endpoint=endpoint, token=token)
        server_resultset = list_resource_by_uuid(auth,
                                                 vm_uuid,
                                                 res_type='SERVER')
        for l in range(0, server_resultset['totalCount']):
            server = server_resultset['list'][l]
            disks = server['disks']

        # Get the UUID of the disk to be detached
        detach_diskUUID = node_instance.get_disk_detach_device()
        print '\n\n\n'
        print 'detach_diskUUID passed = %s' % detach_diskUUID

        found = False
        for disk in disks:
            if (disk['resourceUUID'] == detach_diskUUID):
                print 'Disk found on the server'
                found = True
        if (found == False):
            raise Exceptions.ExecutionException(
                "Disk not found on the server %s" % vm_uuid)

        print 'Detaching the additional volatile disk'
        # Detach it now
        if (detach_diskUUID != ""):
            detach_disk(auth, vm_uuid, detach_diskUUID)
            # Delete the resource
            rest_delete_resource(auth, detach_diskUUID, "DISK")

        print 'Restart the VM'
        server_data = [vm_uuid]
        start_server(auth, server_data)

        print("Waiting for the server to get in RUNNING state")
        ret = wait_for_server(auth, vm_uuid, 'RUNNING')
        if (ret != 0):
            raise Exceptions.ExecutionException(
                "Server is not in RUNNING state")
Ejemplo n.º 13
0
    def _attach_disk(self, node_instance):
        """Attach extra disk to the VM.
        :param node_instance: node instance object
        :type node_instance: <NodeInstance>
        :return: name of the device that was attached
        :rtype: string
        """
        print 'Scaling in progress'
        current_time = time.strftime("%Y-%m-%d %H:%M:%S")
        disk_device_name = "Disk " + current_time + " #2"
        print 'Node instance name: %s' % node_instance.get_name()
        machine_name = node_instance.get_name()
        vm = self._get_vm(machine_name)
        vm_uuid = vm['id']

        endpoint = self.user_info.get_cloud_endpoint()
        token = getToken(self.user_info.get_cloud_endpoint(),
                         self.user_info.get_cloud_username(),
                         self.user_info.get_cloud('user.uuid'),
                         self.user_info.get_cloud_password())
        auth = dict(endpoint=endpoint, token=token)

        # Size of the disk to attach (in GB).
        disk_size_GB = int(node_instance.get_disk_attach_size())
        print '\n\n\n'
        print 'disk_size = ', disk_size_GB

        server_resultset = list_resource_by_uuid(auth,
                                                 vm_uuid,
                                                 res_type='SERVER')
        for l in range(0, server_resultset['totalCount']):
            vdc = server_resultset['list'][l]
            vdc_uuid = vdc['vdcUUID']

        # Validate the size of the disk to be attached
        validate_disk_size(auth, 'Standard Disk', disk_size_GB,
                           disk_device_name, vdc_uuid)

        print 'Stopping the VM: %s to attach disk' % vm
        # Stop the VM before attaching the disk
        try:
            ret = StopVM(vm_uuid, self.user_info.get_cloud('user.uuid'),
                         self.user_info.get_cloud_username(),
                         self.user_info.get_cloud_password(),
                         self.user_info.get_cloud_endpoint(), self.verbose)
        except Exception as ex:
            raise CloudError('Failed to stop VM %s with: %s' %
                             (vm_uuid, str(ex)))

        disk_uuid = ""
        if (int(disk_size_GB) > 0):
            print('Creating additional volatile disk')
            # Create the disk
            disk_uuid = create_disk(auth, 'Standard Disk', disk_size_GB,
                                    disk_device_name, vdc_uuid)

        print 'Attaching the additional volatile disk'
        # If we created an extra disk, attach it now
        if (disk_uuid != ""):
            attach_disk(auth, vm_uuid, disk_uuid=disk_uuid, index='2')

        print 'Restart the VM'
        server_data = [vm_uuid]
        start_server(auth, server_data)

        print("Waiting for the server to get in RUNNING state")
        ret = wait_for_server(auth, vm_uuid, 'RUNNING')
        if (ret != 0):
            raise Exceptions.ExecutionException(
                "Server is not in RUNNING state")
        # Return the created disk's uuid
        return disk_uuid