def update_check(self, entity): cpu_mode = getattr(entity.cpu, 'mode') it_display = entity.display return ( not self.param('kernel_params_persist') and equal(convert_to_bytes(self.param('memory_guaranteed')), entity.memory_policy.guaranteed) and equal(convert_to_bytes(self.param('memory_max')), entity.memory_policy.max) and equal(self.param('cpu_cores'), entity.cpu.topology.cores) and equal(self.param('cpu_sockets'), entity.cpu.topology.sockets) and equal(self.param('cpu_threads'), entity.cpu.topology.threads) and equal(self.param('cpu_mode'), str(cpu_mode) if cpu_mode else None) and equal(self.param('type'), str(entity.type)) and equal(self.param('name'), str(entity.name)) and equal(self.param('operating_system'), str(entity.os.type)) and equal(self.param('soundcard_enabled'), entity.soundcard_enabled) and equal(self.param('smartcard_enabled'), getattr(it_display, 'smartcard_enabled', False)) and equal(self.param('io_threads'), entity.io.threads) and equal(self.param('ballooning_enabled'), entity.memory_policy.ballooning) and equal(self.param('serial_console'), getattr(entity.console, 'enabled', None)) and equal(self.param('usb_support'), entity.usb.enabled) and equal(self.param('virtio_scsi'), getattr(entity, 'smartcard_enabled', False)) and equal(self.param('high_availability'), entity.high_availability.enabled) and equal(self.param('high_availability_priority'), entity.high_availability.priority) and equal(self.param('boot_devices'), [str(dev) for dev in getattr(entity.os.boot, 'devices', [])]) and equal(self.param('description'), entity.description) and equal(self.param('rng_device'), str(entity.rng_device.source) if entity.rng_device else None) and equal(self.param('rng_bytes'), entity.rng_device.rate.bytes if entity.rng_device else None) and equal(self.param('rng_period'), entity.rng_device.rate.period if entity.rng_device else None) and equal(self.param('placement_policy'), str(entity.placement_policy.affinity) if entity.placement_policy else None) )
def update_check(self, entity): template_display = entity.display return ( equal(self._module.params.get('cluster'), get_link_name(self._connection, entity.cluster)) and equal(self._module.params.get('description'), entity.description) and equal(self.param('operating_system'), str(entity.os.type)) and equal(self.param('name'), str(entity.name)) and equal(self.param('smartcard_enabled'), getattr(template_display, 'smartcard_enabled', False)) and equal(self.param('soundcard_enabled'), entity.soundcard_enabled) and equal(self.param('ballooning_enabled'), entity.memory_policy.ballooning) and equal(self.param('sso'), True if entity.sso.methods else False) and equal(self.param('timezone'), getattr(entity.time_zone, 'name', None)) and equal(self.param('usb_support'), entity.usb.enabled) and equal(convert_to_bytes(self.param('memory_guaranteed')), entity.memory_policy.guaranteed) and equal(convert_to_bytes(self.param('memory_max')), entity.memory_policy.max) and equal(convert_to_bytes(self.param('memory')), entity.memory) and equal(self._module.params.get('cpu_profile'), get_link_name(self._connection, entity.cpu_profile)) and equal(self.param('io_threads'), entity.io.threads))
def update_check(self, entity): return ( equal(self.param('cluster'), get_link_name(self._connection, entity.cluster)) and equal(convert_to_bytes(self.param('memory')), entity.memory) and equal(convert_to_bytes(self.param('memory_guaranteed')), entity.memory_policy.guaranteed) and equal(self.param('cpu_cores'), entity.cpu.topology.cores) and equal(self.param('cpu_sockets'), entity.cpu.topology.sockets) and equal(self.param('type'), str(entity.type)) and equal(self.param('operating_system'), str(entity.os.type)) and equal(self.param('high_availability'), entity.high_availability.enabled) and equal(self.param('stateless'), entity.stateless) and equal(self.param('cpu_shares'), entity.cpu_shares) and equal(self.param('delete_protected'), entity.delete_protected) and equal(self.param('use_latest_template_version'), entity.use_latest_template_version) and equal(self.param('boot_devices'), [str(dev) for dev in getattr(entity.os, 'devices', [])]) and equal(self.param('instance_type'), get_link_name(self._connection, entity.instance_type), ignore_case=True) and equal(self.param('description'), entity.description) and equal(self.param('comment'), entity.comment) and equal(self.param('timezone'), entity.time_zone.name) and equal(self.param('serial_policy'), str(getattr(entity.serial_number, 'policy', None))) and equal(self.param('serial_policy_value'), getattr(entity.serial_number, 'value', None)))
def build_entity(self): return otypes.Template( name=self._module.params['name'], cluster=otypes.Cluster( name=self._module.params['cluster'] ) if self._module.params['cluster'] else None, vm=otypes.Vm( name=self._module.params['vm'] ) if self._module.params['vm'] else None, description=self._module.params['description'], cpu_profile=otypes.CpuProfile( id=search_by_name( self._connection.system_service().cpu_profiles_service(), self._module.params['cpu_profile'], ).id ) if self._module.params['cpu_profile'] else None, os=otypes.OperatingSystem( type=self.param('operating_system'), ) if self.param('operating_system') else None, memory=convert_to_bytes( self.param('memory') ) if self.param('memory') else None, memory_policy=otypes.MemoryPolicy( guaranteed=convert_to_bytes(self.param('memory_guaranteed')), max=convert_to_bytes(self.param('memory_max')), ) if any(( self.param('memory_guaranteed'), self.param('memory_max') )) else None, )
def update_check(self, entity): return (equal(self._module.params.get('cluster'), get_link_name(self._connection, entity.cluster)) and equal(convert_to_bytes(self._module.params['memory']), entity.memory) and equal( convert_to_bytes(self._module.params['memory_guaranteed']), entity.memory_policy.guaranteed) and equal(self._module.params.get('cpu_cores'), entity.cpu.topology.cores) and equal(self._module.params.get('cpu_sockets'), entity.cpu.topology.sockets) and equal(self._module.params.get('type'), str(entity.type)) and equal(self._module.params.get('operating_system'), str(entity.os.type)) and equal(self._module.params.get('high_availability'), entity.high_availability.enabled) and equal(self._module.params.get('stateless'), entity.stateless) and equal(self._module.params.get('cpu_shares'), entity.cpu_shares) and equal(self._module.params.get('delete_protected'), entity.delete_protected) and equal( self._module.params.get('use_latest_template_version'), entity.use_latest_template_version) and equal(self._module.params.get('boot_devices'), [str(dev) for dev in getattr(entity.os, 'devices', [])]))
def build_entity(self): return otypes.Template( id=self._module.params['id'], name=self._module.params['name'], cluster=otypes.Cluster(name=self._module.params['cluster']) if self._module.params['cluster'] else None, vm=otypes.Vm(name=self._module.params['vm']) if self._module.params['vm'] else None, description=self._module.params['description'], cpu_profile=otypes.CpuProfile(id=search_by_name( self._connection.system_service().cpu_profiles_service(), self._module.params['cpu_profile'], ).id) if self._module.params['cpu_profile'] else None, os=otypes.OperatingSystem(type=self.param('operating_system'), ) if self.param('operating_system') else None, memory=convert_to_bytes(self.param('memory')) if self.param('memory') else None, version=otypes.TemplateVersion( base_template=self._get_base_template(), version_name=self.param('version').get('name'), ) if self.param('version') else None, memory_policy=otypes.MemoryPolicy( guaranteed=convert_to_bytes(self.param('memory_guaranteed')), max=convert_to_bytes(self.param('memory_max')), ) if any((self.param('memory_guaranteed'), self.param('memory_max'))) else None, io=otypes.Io(threads=self.param('io_threads'), ) if self.param('io_threads') is not None else None, )
def build_vm(self, vm): return otypes.Vm( comment=vm.get('comment'), memory=convert_to_bytes( vm.get('memory') ) if vm.get('memory') else None, memory_policy=otypes.MemoryPolicy( guaranteed=convert_to_bytes(vm.get('memory_guaranteed')), max=convert_to_bytes(vm.get('memory_max')), ) if any(( vm.get('memory_guaranteed'), vm.get('memory_max') )) else None, initialization=self.get_initialization(vm), display=otypes.Display( smartcard_enabled=vm.get('smartcard_enabled') ) if vm.get('smartcard_enabled') is not None else None, sso=( otypes.Sso( methods=[otypes.Method(id=otypes.SsoMethod.GUEST_AGENT)] if vm.get('sso') else [] ) ) if vm.get('sso') is not None else None, time_zone=otypes.TimeZone( name=vm.get('timezone'), ) if vm.get('timezone') else None, )
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 build_entity(self): hosts_service = self._connection.system_service().hosts_service() 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( 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 = convert_to_bytes( self._module.params.get('size') ) return disk
def update_check(self, entity): return ( equal(self._module.params.get('cluster'), get_link_name(self._connection, entity.cluster)) and equal(self._module.params.get('description'), entity.description) and equal(self.param('operating_system'), str(entity.os.type)) and equal(convert_to_bytes(self.param('memory_guaranteed')), entity.memory_policy.guaranteed) and equal(convert_to_bytes(self.param('memory_max')), entity.memory_policy.max) and equal(convert_to_bytes(self.param('memory')), entity.memory) and equal(self._module.params.get('cpu_profile'), get_link_name(self._connection, entity.cpu_profile)) )
def update_check(self, entity): return (equal(self._module.params.get('cluster'), get_link_name(self._connection, entity.cluster)) and equal(self._module.params.get('description'), entity.description) and equal(self.param('operating_system'), str(entity.os.type)) and equal(convert_to_bytes(self.param('memory_guaranteed')), entity.memory_policy.guaranteed) and equal(convert_to_bytes(self.param('memory_max')), entity.memory_policy.max) and equal(convert_to_bytes(self.param('memory')), entity.memory) and equal(self._module.params.get('cpu_profile'), get_link_name(self._connection, entity.cpu_profile)))
def build_entity(self): template = self.__get_template_with_version() return otypes.Vm( name=self.param('name'), cluster=otypes.Cluster( name=self.param('cluster')) if self.param('cluster') else None, template=otypes.Template(id=template.id, ) if template else None, use_latest_template_version=self.param( 'use_latest_template_version'), stateless=self.param('stateless') or self.param('use_latest_template_version'), delete_protected=self.param('delete_protected'), high_availability=otypes.HighAvailability( enabled=self.param('high_availability')) if self.param('high_availability') is not None else None, cpu=otypes.Cpu(topology=otypes.CpuTopology( cores=self.param('cpu_cores'), sockets=self.param('cpu_sockets'), )) if (self.param('cpu_cores') or self.param('cpu_sockets')) else None, cpu_shares=self.param('cpu_shares'), os=otypes.OperatingSystem( type=self.param('operating_system'), boot=otypes.Boot(devices=[ otypes.BootDevice(dev) for dev in self.param('boot_devices') ], ) if self.param('boot_devices') else None, ) if (self.param('operating_system') or self.param('boot_devices')) else None, type=otypes.VmType(self.param('type')) if self.param('type') else None, memory=convert_to_bytes(self.param('memory')) if self.param('memory') else None, memory_policy=otypes.MemoryPolicy(guaranteed=convert_to_bytes( self.param('memory_guaranteed')), ) if self.param('memory_guaranteed') else None, instance_type=otypes.InstanceType(id=get_id_by_name( self._connection.system_service().instance_types_service(), self.param('instance_type'), ), ) if self.param('instance_type') else None, description=self.param('description'), comment=self.param('comment'), time_zone=otypes.TimeZone(name=self.param('timezone'), ) if self.param('timezone') else None, serial_number=otypes.SerialNumber( policy=otypes.SerialNumberPolicy(self.param('serial_policy')), value=self.param('serial_policy_value'), ) if (self.param('serial_policy') is not None or self.param('serial_policy_value') is not None) else None, )
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( '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'), 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 _update_check(self, entity): return ( equal(self._module.params.get('description'), entity.description) and equal(convert_to_bytes(self._module.params.get('size')), entity.provisioned_size) and equal(self._module.params.get('format'), str(entity.format)) and equal(self._module.params.get('shareable'), entity.shareable) )
def _update_check(self, entity): return ( equal(self._module.params.get('description'), entity.description) and equal(self.param('quota_id'), getattr(entity.quota, 'id')) and equal(convert_to_bytes(self._module.params.get('size')), entity.provisioned_size) and equal(self._module.params.get('shareable'), entity.shareable))
def _update_check(self, entity): return ( equal(self._module.params.get('description'), entity.description) and equal(self.param('quota_id'), getattr(entity.quota, 'id', None)) and equal(convert_to_bytes(self._module.params.get('size')), entity.provisioned_size) and equal(self._module.params.get('shareable'), entity.shareable) )
def build_entity(self): logical_unit = self._module.params.get('logical_unit') return 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, )
def _update_check(self, entity): return ( equal(self._module.params.get('description'), entity.description) and equal(convert_to_bytes(self._module.params.get('size')), entity.provisioned_size) and equal(self._module.params.get('format'), str(entity.format)) and equal(self._module.params.get('shareable'), entity.shareable))
def build_entity(self): template = self.__get_template_with_version() return otypes.Vm( name=self._module.params['name'], cluster=otypes.Cluster( name=self._module.params['cluster'] ) if self._module.params['cluster'] else None, template=otypes.Template( id=template.id, ) if template else None, use_latest_template_version=self._module.params['use_latest_template_version'], stateless=self._module.params['stateless'] or self._module.params['use_latest_template_version'], delete_protected=self._module.params['delete_protected'], high_availability=otypes.HighAvailability( enabled=self._module.params['high_availability'] ) if self._module.params['high_availability'] is not None else None, cpu=otypes.Cpu( topology=otypes.CpuTopology( cores=self._module.params['cpu_cores'], sockets=self._module.params['cpu_sockets'], ) ) if ( self._module.params['cpu_cores'] or self._module.params['cpu_sockets'] ) else None, cpu_shares=self._module.params['cpu_shares'], os=otypes.OperatingSystem( type=self._module.params['operating_system'], boot=otypes.Boot( devices=[ otypes.BootDevice(dev) for dev in self._module.params['boot_devices'] ], ) if self._module.params['boot_devices'] else None, ) if ( self._module.params['operating_system'] or self._module.params['boot_devices'] ) else None, type=otypes.VmType( self._module.params['type'] ) if self._module.params['type'] else None, memory=convert_to_bytes( self._module.params['memory'] ) if self._module.params['memory'] else None, memory_policy=otypes.MemoryPolicy( guaranteed=convert_to_bytes(self._module.params['memory_guaranteed']), ) if self._module.params['memory_guaranteed'] else None, )
def build_entity(self): return otypes.Template( id=self._module.params['id'], name=self._module.params['name'], cluster=otypes.Cluster(name=self._module.params['cluster']) if self._module.params['cluster'] else None, vm=otypes.Vm(name=self._module.params['vm']) if self._module.params['vm'] else None, description=self._module.params['description'], cpu_profile=otypes.CpuProfile(id=search_by_name( self._connection.system_service().cpu_profiles_service(), self._module.params['cpu_profile'], ).id) if self._module.params['cpu_profile'] else None, display=otypes.Display( smartcard_enabled=self.param('smartcard_enabled')) if self.param('smartcard_enabled') is not None else None, os=otypes.OperatingSystem(type=self.param('operating_system'), ) if self.param('operating_system') else None, memory=convert_to_bytes(self.param('memory')) if self.param('memory') else None, soundcard_enabled=self.param('soundcard_enabled'), usb=(otypes.Usb(enabled=self.param('usb_support'))) if self.param('usb_support') is not None else None, sso=(otypes.Sso( methods=[otypes.Method(id=otypes.SsoMethod.GUEST_AGENT )] if self.param('sso') else [])) if self.param('sso') is not None else None, time_zone=otypes.TimeZone(name=self.param('timezone'), ) if self.param('timezone') else None, version=otypes.TemplateVersion( base_template=self._get_base_template(), version_name=self.param('version').get('name'), ) if self.param('version') else None, memory_policy=otypes.MemoryPolicy( guaranteed=convert_to_bytes(self.param('memory_guaranteed')), ballooning=self.param('ballooning_enabled'), max=convert_to_bytes(self.param('memory_max')), ) if any((self.param('memory_guaranteed'), self.param('ballooning_enabled'), self.param('memory_max'))) else None, io=otypes.Io(threads=self.param('io_threads'), ) if self.param('io_threads') is not None else None, initialization=self.get_initialization(), )
def build_entity(self): return otypes.InstanceType( id=self.param('id'), name=self.param('name'), console=( otypes.Console(enabled=self.param('serial_console')) ) if self.param('serial_console') is not None else None, usb=( otypes.Usb(enabled=self.param('usb_support')) ) if self.param('usb_support') is not None else None, high_availability=otypes.HighAvailability( enabled=self.param('high_availability'), priority=self.param('high_availability_priority'), ) if self.param('high_availability') is not None or self.param('high_availability_priority') else None, cpu=otypes.Cpu( topology=otypes.CpuTopology( cores=self.param('cpu_cores'), sockets=self.param('cpu_sockets'), threads=self.param('cpu_threads'), ) if any(( self.param('cpu_cores'), self.param('cpu_sockets'), self.param('cpu_threads') )) else None, cpu_tune=otypes.CpuTune( vcpu_pins=[ otypes.VcpuPin(vcpu=int(pin['vcpu']), cpu_set=str(pin['cpu'])) for pin in self.param('cpu_pinning') ], ) if self.param('cpu_pinning') else None, mode=otypes.CpuMode(self.param('cpu_mode')) if self.param( 'cpu_mode') else None, ) if any(( self.param('cpu_cores'), self.param('cpu_sockets'), self.param('cpu_threads'), self.param('cpu_mode'), self.param('cpu_pinning') )) else None, os=otypes.OperatingSystem( type=self.param('operating_system'), boot=otypes.Boot( devices=[ otypes.BootDevice(dev) for dev in self.param('boot_devices') ], ) if self.param('boot_devices') else None ), rng_device=otypes.RngDevice( source=otypes.RngSource(self.param('rng_device')), rate=otypes.Rate( bytes=self.param('rng_bytes'), period=self.param('rng_period') ) ) if self.param('rng_device') else None, memory=convert_to_bytes( self.param('memory') ) if self.param('memory') else None, virtio_scsi=otypes.VirtioScsi( enabled=self.param('virtio_scsi') ) if self.param('virtio_scsi') else None, memory_policy=otypes.MemoryPolicy( guaranteed=convert_to_bytes(self.param('memory_guaranteed')), ballooning=self.param('ballooning_enabled'), max=convert_to_bytes(self.param('memory_max')), ) if any(( self.param('memory_guaranteed'), self.param('ballooning_enabled') is not None, self.param('memory_max') )) else None, description=self.param('description'), placement_policy=otypes.VmPlacementPolicy( affinity=otypes.VmAffinity(self.param('placement_policy')), hosts=[ otypes.Host(name=self.param('host')), ] if self.param('host') else None, ) if self.param('placement_policy') else None, soundcard_enabled=self.param('soundcard_enabled'), display=otypes.Display( smartcard_enabled=self.param('smartcard_enabled') ) if self.param('smartcard_enabled') is not None else None, io=otypes.Io( threads=self.param('io_threads'), ) if self.param('io_threads') is not None else None, )