def build_entity(self): logical_unit = self._module.params.get('logical_unit') disk = otypes.Disk( id=self._module.params.get('id'), name=self._module.params.get('name'), description=self._module.params.get('description'), format=otypes.DiskFormat(self._module.params.get('format')) if self._module.params.get('format') else None, sparse=self._module.params.get('format') != 'raw', provisioned_size=convert_to_bytes(self._module.params.get('size')), storage_domains=[ otypes.StorageDomain( name=self._module.params.get('storage_domain'), ), ], shareable=self._module.params.get('shareable'), lun_storage=otypes.HostStorage( type=otypes.StorageType( logical_unit.get('storage_type', 'iscsi')), logical_units=[ otypes.LogicalUnit( address=logical_unit.get('address'), port=logical_unit.get('port', 3260), target=logical_unit.get('target'), id=logical_unit.get('id'), username=logical_unit.get('username'), password=logical_unit.get('password'), ) ], ) if logical_unit else None, ) if hasattr(disk, 'initial_size'): disk.initial_size = convert_to_bytes( self._module.params.get('size')) return disk
def add_disk(self, storage_domain=None, size=None, interface='VIRTIO', format=None, active=True): """ Add disk to VM Args: storage_domain: string name of the storage domain (datastore) size: integer size of disk in bytes, ex 8GB: 8*1024*1024 interface: string disk interface type format: string disk format type active: boolean whether the disk is active Returns: None Notes: Disk format and interface type definitions, and their valid values, can be found in ovirtsdk documentation: http://ovirt.github.io/ovirt-engine-sdk/4.1/types.m.html#ovirtsdk4.types.DiskInterface http://ovirt.github.io/ovirt-engine-sdk/4.1/types.m.html#ovirtsdk4.types.DiskFormat """ disk_attachments_service = self.api.disk_attachments_service() disk_attach = types.DiskAttachment( disk=types.Disk(format=types.DiskFormat(format), provisioned_size=size, storage_domains=[types.StorageDomain(name=storage_domain)]), interface=getattr(types.DiskInterface, interface), active=active ) disk_attachment = disk_attachments_service.add(disk_attach) wait_for(self._is_disk_ok, func_args=[disk_attachment.disk.id], delay=5, num_sec=900, message="check if disk is attached")
def build_entity(self): hosts_service = self._connection.system_service().hosts_service() logical_unit = self._module.params.get('logical_unit') size = convert_to_bytes(self._module.params.get('size')) if not size and self._module.params.get('upload_image_path'): size = os.path.getsize(self._module.params.get('upload_image_path')) disk = otypes.Disk( id=self._module.params.get('id'), name=self._module.params.get('name'), description=self._module.params.get('description'), format=otypes.DiskFormat( self._module.params.get('format') ) if self._module.params.get('format') else None, content_type=otypes.DiskContentType( self._module.params.get('content_type') ) if self._module.params.get('content_type') else None, sparse=self._module.params.get( 'sparse' ) if self._module.params.get( 'sparse' ) is not None else self._module.params.get('format') != 'raw', openstack_volume_type=otypes.OpenStackVolumeType( name=self.param('openstack_volume_type') ) if self.param('openstack_volume_type') else None, provisioned_size=size, storage_domains=[ otypes.StorageDomain( name=self._module.params.get('storage_domain'), ), ], quota=otypes.Quota(id=self._module.params.get('quota_id')) if self.param('quota_id') else None, shareable=self._module.params.get('shareable'), sgio=otypes.ScsiGenericIO(self.param('scsi_passthrough')) if self.param('scsi_passthrough') else None, propagate_errors=self.param('propagate_errors'), backup=otypes.DiskBackup(self.param('backup')) if self.param('backup') else None, wipe_after_delete=self.param('wipe_after_delete'), lun_storage=otypes.HostStorage( host=otypes.Host( id=get_id_by_name(hosts_service, self._module.params.get('host')) ) if self.param('host') else None, type=otypes.StorageType( logical_unit.get('storage_type', 'iscsi') ), logical_units=[ otypes.LogicalUnit( address=logical_unit.get('address'), port=logical_unit.get('port', 3260), target=logical_unit.get('target'), id=logical_unit.get('id'), username=logical_unit.get('username'), password=logical_unit.get('password'), ) ], ) if logical_unit else None, ) if hasattr(disk, 'initial_size') and self._module.params['upload_image_path']: disk.initial_size = size return disk
def build_entity(self): logical_unit = self._module.params.get('logical_unit') disk = otypes.Disk( id=self._module.params.get('id'), name=self._module.params.get('name'), description=self._module.params.get('description'), format=otypes.DiskFormat( self._module.params.get('format') ) if self._module.params.get('format') else None, content_type=otypes.DiskContentType( self._module.params.get('content_type') ) if self._module.params.get('content_type') else None, sparse=self._module.params.get( 'sparse' ) if self._module.params.get( 'sparse' ) is not None else self._module.params.get('format') != 'raw', openstack_volume_type=otypes.OpenStackVolumeType( name=self.param('openstack_volume_type') ) if self.param('openstack_volume_type') else None, provisioned_size=convert_to_bytes( self._module.params.get('size') ), storage_domains=[ otypes.StorageDomain( name=self._module.params.get('storage_domain'), ), ], quota=otypes.Quota(id=self._module.params.get('quota_id')) if self.param('quota_id') else None, shareable=self._module.params.get('shareable'), wipe_after_delete=self.param('wipe_after_delete'), lun_storage=otypes.HostStorage( type=otypes.StorageType( logical_unit.get('storage_type', 'iscsi') ), logical_units=[ otypes.LogicalUnit( address=logical_unit.get('address'), port=logical_unit.get('port', 3260), target=logical_unit.get('target'), id=logical_unit.get('id'), username=logical_unit.get('username'), password=logical_unit.get('password'), ) ], ) if logical_unit else None, ) if hasattr(disk, 'initial_size') and self._module.params['upload_image_path']: disk.initial_size = convert_to_bytes( self._module.params.get('size') ) return disk
def build_entity(self): hosts_service = self._connection.system_service().hosts_service() logical_unit = self._module.params.get('logical_unit') size = convert_to_bytes(self._module.params.get('size')) if not size and self._module.params.get('upload_image_path'): out = subprocess.check_output( ["qemu-img", "info", "--output", "json", self._module.params.get('upload_image_path')]) image_info = json.loads(out) size = image_info["virtual-size"] disk = otypes.Disk( id=self._module.params.get('id'), name=self._module.params.get('name'), description=self._module.params.get('description'), format=otypes.DiskFormat( self._module.params.get('format') ) if self._module.params.get('format') else None, content_type=otypes.DiskContentType( self._module.params.get('content_type') ) if self._module.params.get('content_type') else None, sparse=self._module.params.get( 'sparse' ) if self._module.params.get( 'sparse' ) is not None else self._module.params.get('format') != 'raw', openstack_volume_type=otypes.OpenStackVolumeType( name=self.param('openstack_volume_type') ) if self.param('openstack_volume_type') else None, provisioned_size=size, storage_domains=[ otypes.StorageDomain( name=self._module.params.get('storage_domain'), ), ], quota=otypes.Quota(id=self._module.params.get('quota_id')) if self.param('quota_id') else None, shareable=self._module.params.get('shareable'), sgio=otypes.ScsiGenericIO(self.param('scsi_passthrough')) if self.param('scsi_passthrough') else None, propagate_errors=self.param('propagate_errors'), backup=otypes.DiskBackup(self.param('backup')) if self.param('backup') else None, wipe_after_delete=self.param('wipe_after_delete'), lun_storage=otypes.HostStorage( host=otypes.Host( id=get_id_by_name(hosts_service, self._module.params.get('host')) ) if self.param('host') else None, type=otypes.StorageType( logical_unit.get('storage_type', 'iscsi') ), logical_units=[ otypes.LogicalUnit( address=logical_unit.get('address'), port=logical_unit.get('port', 3260), target=logical_unit.get('target'), id=logical_unit.get('id'), username=logical_unit.get('username'), password=logical_unit.get('password'), ) ], ) if logical_unit else None, ) if hasattr(disk, 'initial_size') and self._module.params['upload_image_path']: out = subprocess.check_output([ 'qemu-img', 'measure', '-O', 'qcow2' if self._module.params.get('format') == 'cow' else 'raw', '--output', 'json', self._module.params['upload_image_path'] ]) measure = json.loads(out) disk.initial_size = measure["required"] return disk