Esempio n. 1
0
 def build_entity(self):
     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(name=self._module.params['template'])
         if self._module.params['template'] else None,
         stateless=self._module.params['stateless'],
         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,
     )
Esempio n. 2
0
def test_remove_vm2_lease(api_v4):
    engine = api_v4.system_service()
    vm2_service = test_utils.get_vm_service(engine, VM2_NAME)

    vm2_service.update(
        vm=types.Vm(high_availability=types.HighAvailability(enabled=False, ),
                    lease=types.StorageDomainLease(storage_domain=None)))
    testlib.assert_true_within_short(lambda: vm2_service.get().lease is None)
Esempio n. 3
0
def add_vm_blank(api):

    # Get the vms service
    vms_service=api.system_service().vms_service()

    #Create VM from blank template
    vm_memory=256*MB
    vm=types.Vm(
        name=VM0_NAME,
        memory=vm_memory,
        type=types.VmType.SERVER,
        os=types.OperatingSystem(
            type='other_linux',
            boot=types.Boot(
                devices=[types.BootDevice.HD, types.BootDevice.NETWORK]
            ),
        ),
        high_availability=types.HighAvailability(
            enabled=False
        ),
        cluster=types.Cluster(
            name=TEST_CLUSTER
        ),
        template=types.Template(
            name=TEMPLATE_BLANK
        ),
        display=types.Display(
            smartcard_enabled=True,
            keyboard_layout='en-us',
            file_transfer_enabled=True,
            copy_paste_enabled=True
        ),
        memory_policy=types.MemoryPolicy(
            guaranteed=vm_memory//2
        )
    )

    #Add this VM
    vm=vms_service.add(vm)

    #Check that VM was added
    vm_service=vms_service.vm_service(vm.id)
    testlib.assert_true_within_short(
        lambda: vm_service.get().status == types.VmStatus.DOWN
    )

    #Add another VM
    vm.id=None
    vm.name=VM1_NAME
    vm.initialization=None
    vm=vms_service.add(vm)

    #Check that the second VM was added
    vm_service=vms_service.vm_service(vm.id)
    testlib.assert_true_within_short(
        lambda: vm_service.get().status == types.VmStatus.DOWN
    )
Esempio n. 4
0
 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,
                ), ),
            ), ))
Esempio n. 6
0
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 root of the tree of services:
system_service = connection.system_service()

# Find the virtual machine:
vms_service = system_service.vms_service()
vm = vms_service.list(search='name=myvm')[0]

# Find the storage domain:
sds_service = system_service.storage_domains_service()
sd = sds_service.list(search='name=mydata')[0]

# Update the virtual machine so that high availability is enabled and
# the lease is created in the selected storage domain:
vm_service = vms_service.vm_service(vm.id)
vm_service.update(
    vm=types.Vm(high_availability=types.HighAvailability(enabled=True),
                lease=types.StorageDomainLease(
                    storage_domain=types.StorageDomain(id=sd.id))))

# Close the connection to the server:
connection.close()
Esempio n. 7
0
 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,
     )
Esempio n. 8
0
# 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()