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 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 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))
예제 #4
0
    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
예제 #5
0
 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(),
     )
예제 #6
0
 def _update_check(self, entity):
     return (
         equal(self._module.params.get('name'), entity.name) and
         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) and
         equal(self.param('wipe_after_delete'), entity.wipe_after_delete)
     )
 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,
     )