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