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 add_instance_type(api): instance_types_service = api.system_service().instance_types_service() nt.assert_true( instance_types_service.add( types.InstanceType( name='myinstancetype', description='My instance type', memory=1 * 2**30, memory_policy=types.MemoryPolicy(max=1 * 2**30, ), high_availability=types.HighAvailability(enabled=True, ), cpu=types.Cpu(topology=types.CpuTopology( cores=2, sockets=2, ), ), ), ))
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, )
# Create the connection to the server: connection = sdk.Connection( url='https://engine40.example.com/ovirt-engine/api', username='******', password='******', ca_file='ca.pem', debug=True, log=logging.getLogger(), ) # Get the reference to the instance types service: instance_types_service = connection.system_service().instance_types_service() # Add the instance type. Note that the size of the memory, the `memory` # attribute, is specified in bytes, so to create a instance type with # 2 GiB of memory the value should be 2 * 2^30. instance_types_service.add( types.InstanceType( name='myinstancetype', description='My instance type', memory=2 * 2**30, high_availability=types.HighAvailability(enabled=True, ), cpu=types.Cpu(topology=types.CpuTopology( cores=2, sockets=2, ), ), ), ) # Close the connection to the server: connection.close()