Beispiel #1
0
def setup_test():
    """Function to set up api session, import credentials etc."""
    # Setup root login etc from config file
    token = getToken(config.HOST_NAME, config.USER_LOGIN, config.CUST_UUID,
                     config.USER_PASSWORD)
    auth_client = dict(endpoint=config.HOST_NAME, token=token)
    return auth_client
    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")
Beispiel #3
0
def MakeVM(image_uuid,
           customerUUID,
           customerUsername,
           customerPassword,
           endpoint,
           networkType,
           extra_disk_size,
           ramAmount,
           vmName,
           cpuCount,
           public_key,
           isVerbose=False,
           contextScript=None):
    """Main Function"""

    # 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

    # Does this need to be parameterised, or picked up by some other means ?
    config.PROD_OFFER = 'Generic Disk'

    if (isVerbose):
        print("MakeVM() args:\n")
        print(config.CUST_UUID)
        print(config.USER_LOGIN)
        print(config.USER_PASSWORD)
        print(config.HOST_NAME)
        print(config.NETWORK_TYPE)
        print("MakeVM: publicKey=" + public_key)
        print("Memory (ramAmount):" + ramAmount)
        print("NumCPU (cpuCount):" + cpuCount)
        print("extra_disk_size: " + str(extra_disk_size))
        print("=-=-=-=-=-=-\n")
        # See what SlipStream is passing us by way of environment variables
        print("SlipStream environment:\n")
        for param in os.environ.keys():
            print "%20s %s" % (param, os.environ[param])
        print("=-=-=-=-=-=-\n")

    # 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 Exceptions.ExecutionException("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 Exceptions.ExecutionException("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 Exceptions.ExecutionException(
            "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"
    print("extra_disk_size = " + str(extra_disk_size))
    extra_disk_uuid = ""
    if (int(extra_disk_size) > 0):
        print("Creating additional volatile disk")
        extra_disk_uuid = create_disk(auth, 'Standard Disk', extra_disk_size,
                                      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=public_key,
                               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)

    # This is the string that SlipStream picks up to let it know that the launch has been
    # successful. Don't change it unless you also amend FCOConnector. The statement below will
    # yield a line like:
    # Server UUID and IP:6885959f-c53e-3b7d-aac2-4ff4b4327620:AAb5XUn6niUmQih9:ubuntu:109.231.122.249
    #
    # print "Server UUID and IP:"  +  ':'.join(server_data)
    if (isVerbose):
        print("server_data[0]=" + server_data[0])
        print("server_data[1]=" + server_data[1])
        print("server_data[2]=" + server_data[2])
        print("server_data[3]=" + server_data[3])

    # ret = "Server UUID and IP:"  +  ':'.join(server_data)

    ret = dict(server_uuid=server_data[0],
               ip=server_data[3],
               password=server_data[1],
               login=server_data[2])

    if (isVerbose):
        print ret

    return ret
def setup():
    """Function to set up api session, import credentials etc."""
    token = getToken(config.HOST_NAME, config.USER_LOGIN, config.CUST_UUID, config.USER_PASSWORD)
    auth_client = dict(endpoint=config.HOST_NAME, token=token)
    return auth_client
    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 MakeVM(image_uuid, customerUUID, customerUsername, customerPassword, endpoint, networkType,
           extra_disk_size, ramAmount, vmName, cpuCount, public_key, isVerbose=False, contextScript=None):
    """Main Function"""

    # 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

    # Does this need to be parameterised, or picked up by some other means ?
    config.PROD_OFFER = 'Generic Disk'

    if (isVerbose):
        print("MakeVM() args:\n")
        print(config.CUST_UUID)
        print(config.USER_LOGIN)
        print(config.USER_PASSWORD)
        print(config.HOST_NAME)
        print(config.NETWORK_TYPE)
        print("MakeVM: publicKey=" + public_key)
        print("Memory (ramAmount):" + ramAmount)
        print("NumCPU (cpuCount):" + cpuCount)
        print("extra_disk_size: " + str(extra_disk_size))
        print("=-=-=-=-=-=-\n")
        # See what SlipStream is passing us by way of environment variables
        print("SlipStream environment:\n")
        for param in os.environ.keys():
            print "%20s %s" % (param, os.environ[param])
        print("=-=-=-=-=-=-\n")

    # 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 Exceptions.ExecutionException("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 Exceptions.ExecutionException("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 Exceptions.ExecutionException("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"
    print("extra_disk_size = " + str(extra_disk_size))
    extra_disk_uuid = ""
    if (int(extra_disk_size) > 0):
        print("Creating additional volatile disk")
        extra_disk_uuid = create_disk(auth, 'Standard Disk', extra_disk_size, 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=public_key,
                               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)

    # This is the string that SlipStream picks up to let it know that the launch has been
    # successful. Don't change it unless you also amend FCOConnector. The statement below will
    # yield a line like:
    # Server UUID and IP:6885959f-c53e-3b7d-aac2-4ff4b4327620:AAb5XUn6niUmQih9:ubuntu:109.231.122.249
    #
    # print "Server UUID and IP:"  +  ':'.join(server_data)
    if (isVerbose):
        print("server_data[0]=" + server_data[0]);
        print("server_data[1]=" + server_data[1]);
        print("server_data[2]=" + server_data[2]);
        print("server_data[3]=" + server_data[3]);

    # ret = "Server UUID and IP:"  +  ':'.join(server_data)

    ret = dict(server_uuid=server_data[0],
             ip=server_data[3],
             password=server_data[1],
             login=server_data[2]
            )

    if (isVerbose):
        print ret

    return ret
Beispiel #8
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")
Beispiel #9
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")
Beispiel #10
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