Exemple #1
0
    def update_disk(self,
                    name,
                    size,
                    new_name=None,
                    description=None,
                    storage_profile_name=None,
                    iops=None,
                    disk_id=None):
        """
        Update an existing independent disk.
        :param name: (str): The existing name of the Disk.
        :param size: (str): The size of the new disk in MB.
        :param new_name: (str): The new name for the Disk.
        :param iops: (str): The new iops for the disk. 
        :param storage_profile_name: (str): The storage profile that the disk belongs to.
        :param description: (str): A description of the new disk.
        :param disk_id: (str): The disk_id of the existing disk.
        :return:  A :class:`lxml.objectify.StringElement` object describing the asynchronous Task creating the disk.
        """  # NOQA
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)

        if iops is None:
            diskParms = E.Disk(name=name, size=size)
        else:
            diskParms = E.Disk(name=name, size=size, iops=iops)

        if description is not None:
            diskParms.append(E.Description(description))

        if disk_id is not None:
            disk = self.get_disk(None, disk_id)
        else:
            disk = self.get_disk(name)

        if storage_profile_name is not None:
            storage_profile = self.get_storage_profile(storage_profile_name)
            sp = etree.XML(etree.tostring(storage_profile, pretty_print=True))
            sp_href = sp.attrib['href']
            diskParms.append(E.StorageProfile(href=sp_href,
                                              name=storage_profile_name))
        if disk is None:
            raise Exception('Could not locate Disk %s for update. ' % disk_id)

        return self.client.put_linked_resource(disk,
                                               RelationType.EDIT,
                                               EntityType.DISK.value,
                                               diskParms)
Exemple #2
0
    def update_disk(self,
                    name,
                    size,
                    new_name=None,
                    description=None,
                    disk_id=None):
        """
        Update an existing independent disk.
        :param name: (str): The existing name of the Disk.
        :param new_name: (str): The new name for the Disk.
        :param size: (str): The size of the new disk in MB.
        :param description: (str): A description of the new disk.
        :param description: (str): The disk_id of the existing disk.
        :return:  A :class:`lxml.objectify.StringElement` object describing the asynchronous Task creating the disk.
        """  # NOQA
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)

        diskParms = E.Disk(name=name, size=size)

        if description is not None:
            diskParms.append(E.Description(description))

        if disk_id is not None:
            disk = self.get_disk(None, disk_id)
        else:
            disk = self.get_disk(name)

        if disk is None:
            raise Exception('Could not locate Disk %s for update. ' % disk_id)

        return self.client.put_linked_resource(disk, RelationType.EDIT,
                                               EntityType.DISK.value,
                                               diskParms)
Exemple #3
0
    def update_disk(self,
                    name=None,
                    disk_id=None,
                    new_name=None,
                    new_size=None,
                    new_description=None,
                    new_storage_profile_name=None,
                    new_iops=None):
        """Update an existing independent disk.

        :param name: (str): The name of the existing disk.
        :param disk_id: (str): The id of the existing disk.
        :param new_name: (str): The new name of the disk.
        :param new_size: (int): The new size of the disk in bytes.
        :param new_description: (str): The new description of the disk.
        :param new_storage_profile_name: (str): The new storage profile that
            the disk will be moved to.
        :param new_iops: (int): The new iops requirement of the disk.

        :return:  A :class:`lxml.objectify.StringElement` object describing
            the asynchronous task updating the disk.

        :raises: Exception: If the named disk cannot be located or some
            other error occurs.
        """
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)

        if disk_id is not None:
            disk = self.get_disk(disk_id=disk_id)
        else:
            disk = self.get_disk(name=name)

        disk_params = E.Disk()
        if new_name is not None:
            disk_params.set('name', new_name)
        else:
            disk_params.set('name', disk.get('name'))

        if new_size is not None:
            disk_params.set('size', str(new_size))
        else:
            disk_params.set('size', disk.get('size'))

        if new_description is not None:
            disk_params.append(E.Description(new_description))

        if new_storage_profile_name is not None:
            new_sp = self.get_storage_profile(new_storage_profile_name)
            disk_params.append(
                E.StorageProfile(name=new_storage_profile_name,
                                 href=new_sp.get('href'),
                                 type=new_sp.get('type')))

        if new_iops is not None:
            disk_params.set('iops', str(new_iops))

        return self.client.put_linked_resource(disk, RelationType.EDIT,
                                               EntityType.DISK.value,
                                               disk_params)
Exemple #4
0
    def add_disk(self,
                 name,
                 size,
                 bus_type=None,
                 bus_sub_type=None,
                 description=None,
                 storage_profile_name=None):
        """
        Request the creation of an indendent disk.
        :param name: (str): The name of the new Disk.
        :param size: (str): The size of the new disk in MB.
        :param bus_type: (str): The bus type of the new disk.
        :param bus_subtype: (str): The bus subtype  of the new disk.
        :param description: (str): A description of the new disk.
        :param storage_profile_name: (str): The name of an existing storage profile to be used by the new disk.
        :return:  A :class:`lxml.objectify.StringElement` object describing the asynchronous Task creating the disk.
        """  # NOQA
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)

        diskParms = E.DiskCreateParams(E.Disk(name=name, size=size))

        if description is not None:
            diskParms.Disk.append(E.Description(description))

        if bus_type is not None and bus_sub_type is not None:
            diskParms.Disk.attrib['busType'] = bus_type
            diskParms.Disk.attrib['busSubType'] = bus_sub_type

        if storage_profile_name is not None:
            storage_profile = self.get_storage_profile(storage_profile_name)
            print((etree.tostring(storage_profile, pretty_print=True)))
            diskParms.Disk.append(storage_profile)
            # etree.SubElement(diskParms.Disk, 'StorageProfile')
            # diskParms.Disk.append(
            # E.StorageProfile(name=storage_profile_name))
            # diskParms.Disk.StorageProfile.attrib['href'] =
            # storage_profile.get('href')
            # diskParms.Disk.StorageProfile.attrib['name'] =
            # storage_profile.get('name')
            # diskParms.Disk.StorageProfile.attrib['type'] =
            # storage_profile.get('type')

            print((etree.tostring(diskParms, pretty_print=True)))

        return self.client.post_linked_resource(
            self.resource,
            RelationType.ADD,
            EntityType.DISK_CREATE_PARMS.value,
            diskParms)
Exemple #5
0
    def create_disk(self,
                    name,
                    size,
                    bus_type=None,
                    bus_sub_type=None,
                    description=None,
                    storage_profile_name=None,
                    iops=None):
        """Request the creation of an indendent disk.

        :param name: (str): The name of the new disk.
        :param size: (int): The size of the new disk in bytes.
        :param bus_type: (str): The bus type of the new disk.
        :param bus_subtype: (str): The bus subtype  of the new disk.
        :param description: (str): A description of the new disk.
        :param storage_profile_name: (str): The name of an existing
            storage profile to be used by the new disk.
        :param iops: (int): Iops requirement of the new disk.

        :return:  A :class:`lxml.objectify.StringElement` object containing
            the sparse representation of the new disk and the asynchronus task
            that is creating the disk.
        """
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)

        disk_params = E.DiskCreateParams(E.Disk(name=name, size=str(size)))
        if iops is not None:
            disk_params.Disk.set('iops', iops)

        if description is not None:
            disk_params.Disk.append(E.Description(description))

        if bus_type is not None and bus_sub_type is not None:
            disk_params.Disk.set('busType', bus_type)
            disk_params.Disk.set('busSubType', bus_sub_type)

        if storage_profile_name is not None:
            storage_profile = self.get_storage_profile(storage_profile_name)
            disk_params.Disk.append(
                E.StorageProfile(
                    name=storage_profile_name,
                    href=storage_profile.get('href'),
                    type=storage_profile.get('type')))

        return self.client.post_linked_resource(
            self.resource, RelationType.ADD,
            EntityType.DISK_CREATE_PARMS.value, disk_params)
Exemple #6
0
 def detach_disk_from_vm(self, disk_href, disk_type, disk_name, vm_name):
     """
     Detach the independent disk from the VM with the given name in the vApp within a Virtual Data Center.
     :param disk_href: (str): The href of the disk resource.
     :param vm_name: (str): The name of the VM.
     :return: (vmType)  A :class:`lxml.objectify.StringElement` object describing the requested VM.
     """  # NOQA
     if self.resource is None:
         self.resource = self.client.get_resource(self.href)
     disk_attach_or_detach_params = E.DiskAttachOrDetachParams(
         E.Disk(type=disk_type, href=disk_href))
     vm = self.get_vm(vm_name)
     return self.client.post_linked_resource(
         vm, RelationType.DISK_DETACH,
         EntityType.DISK_ATTACH_DETACH_PARAMS.value,
         disk_attach_or_detach_params)
Exemple #7
0
    def detach_disk_from_vm(self, disk_href, vm_name):
        """Detach the independent disk from the VM with the given name.

        :param disk_href: (str): The href of the disk to be detached.
        :param vm_name: (str): The name of the VM to which the disk
            will be detached.

        :return:  A :class:`lxml.objectify.StringElement` object describing
            the asynchronous Task of detaching the disk.

        :raises: Exception: If the named VM cannot be located or another error
            occurs.
        """
        disk_attach_or_detach_params = E.DiskAttachOrDetachParams(
            E.Disk(type=EntityType.DISK.value, href=disk_href))
        vm = self.get_vm(vm_name)
        return self.client.post_linked_resource(
            vm, RelationType.DISK_DETACH,
            EntityType.DISK_ATTACH_DETACH_PARAMS.value,
            disk_attach_or_detach_params)
Exemple #8
0
    def detach_disk_from_vm(self, disk_href, vm_name):
        """Detach the independent disk from the vm with the given name.

        :param str disk_href: href of the disk to be detached.
        :param str vm_name: name of the vm to which the disk will be detached.

        :return: an object containing EntityType.TASK XML data which represents
            the asynchronous task of dettaching the disk.

        :rtype: lxml.objectify.ObjectifiedElement

        :raises: EntityNotFoundException: if the named vm or disk cannot be
            located.
        """
        disk_attach_or_detach_params = E.DiskAttachOrDetachParams(
            E.Disk(type=EntityType.DISK.value, href=disk_href))
        vm = self.get_vm(vm_name)
        return self.client.post_linked_resource(
            vm, RelationType.DISK_DETACH,
            EntityType.DISK_ATTACH_DETACH_PARAMS.value,
            disk_attach_or_detach_params)