def build_entity(self):
     return otypes.Host(
         id=self._module.params.get('id'),
         name=self.param('name'),
         cluster=otypes.Cluster(
             name=self.param('cluster')
         ) if self.param('cluster') else None,
         comment=self.param('comment'),
         address=self.param('address'),
         root_password=self.param('password'),
         ssh=otypes.Ssh(
             authentication_method=otypes.SshAuthenticationMethod.PUBLICKEY if self.param('public_key') else None,
             port=self.param('ssh_port'),
         ),
         spm=otypes.Spm(
             priority=self.param('spm_priority'),
         ) if self.param('spm_priority') else None,
         override_iptables=self.param('override_iptables'),
         display=otypes.Display(
             address=self.param('override_display'),
         ) if self.param('override_display') else None,
         os=otypes.OperatingSystem(
             custom_kernel_cmdline=' '.join(self.param('kernel_params')),
         ) if self.param('kernel_params') else None,
         power_management=otypes.PowerManagement(
             enabled=self.param('power_management_enabled'),
             kdump_detection=self.param('kdump_integration') == 'enabled',
         ) if self.param('power_management_enabled') is not None or self.param('kdump_integration') else None,
         vgpu_placement=otypes.VgpuPlacement(
             self.param('vgpu_placement')
         ) if self.param('vgpu_placement') is not None else None,
     )
Esempio n. 2
0
 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,
     )
Esempio n. 3
0
 def build_entity(self):
     return otypes.Host(
         name=self._module.params['name'],
         cluster=otypes.Cluster(
             name=self._module.params['cluster']
         ) if self._module.params['cluster'] else None,
         comment=self._module.params['comment'],
         address=self._module.params['address'],
         root_password=self._module.params['password'],
         ssh=otypes.Ssh(
             authentication_method=otypes.SshAuthenticationMethod.PUBLICKEY,
         ) if self._module.params['public_key'] else None,
         kdump_status=otypes.KdumpStatus(
             self._module.params['kdump_integration']
         ) if self._module.params['kdump_integration'] else None,
         spm=otypes.Spm(
             priority=self._module.params['spm_priority'],
         ) if self._module.params['spm_priority'] else None,
         override_iptables=self._module.params['override_iptables'],
         display=otypes.Display(
             address=self._module.params['override_display'],
         ) if self._module.params['override_display'] else None,
         os=otypes.OperatingSystem(
             custom_kernel_cmdline=' '.join(self._module.params['kernel_params']),
         ) if self._module.params['kernel_params'] else None,
     )
 def build_entity(self):
     return otypes.Host(
         name=self.param('name'),
         cluster=otypes.Cluster(
             name=self.param('cluster')
         ) if self.param('cluster') else None,
         comment=self.param('comment'),
         address=self.param('address'),
         root_password=self.param('password'),
         ssh=otypes.Ssh(
             authentication_method=otypes.SshAuthenticationMethod.PUBLICKEY,
         ) if self.param('public_key') else None,
         kdump_status=otypes.KdumpStatus(
             self.param('kdump_integration')
         ) if self.param('kdump_integration') else None,
         spm=otypes.Spm(
             priority=self.param('spm_priority'),
         ) if self.param('spm_priority') else None,
         override_iptables=self.param('override_iptables'),
         display=otypes.Display(
             address=self.param('override_display'),
         ) if self.param('override_display') else None,
         os=otypes.OperatingSystem(
             custom_kernel_cmdline=' '.join(self.param('kernel_params')),
         ) if self.param('kernel_params') else None,
         power_management=otypes.PowerManagement(
             enabled=self.param('power_management_enabled'),
         ) if self.param('power_management_enabled') is not None else None,
     )
Esempio n. 5
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
    )
 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 add_vm_template(api):
    #TODO: Fix the exported domain generation
    raise SkipTest('Exported domain generation not supported yet')
    vm_params = types.VM(
        name=VM1_NAME,
        memory=512 * MB,
        cluster=types.Cluster(name=TEST_CLUSTER, ),
        template=types.Template(name=TEMPLATE_CENTOS7, ),
        display=types.Display(type_='spice', ),
    )
    api.vms.add(vm_params)
    testlib.assert_true_within_long(
        lambda: api.vms.get(VM1_NAME).status.state == 'down', )
    disk_name = api.vms.get(VM1_NAME).disks.list()[0].name
    testlib.assert_true_within_long(lambda: api.vms.get(VM1_NAME).disks.get(
        disk_name).status.state == 'ok')
Esempio n. 8
0
def test_add_vm1_from_template(engine_api, cirros_image_glance_template_name):
    engine = engine_api.system_service()
    templates_service = engine.templates_service()
    glance_template = templates_service.list(
        search='name=%s' % cirros_image_glance_template_name)[0]
    if glance_template is None:
        pytest.skip('%s: template %s not available.' %
                    (add_vm1_from_template.__name__,
                     cirros_image_glance_template_name))

    vm_memory = 128 * MB  # runs with 64 ok, but we need to do a hotplug later (64+256 is too much difference)
    vms_service = engine.vms_service()
    vms_service.add(
        types.Vm(
            name=VM1_NAME,
            description='CirrOS imported from Glance as Template',
            memory=vm_memory,
            cluster=types.Cluster(name=TEST_CLUSTER, ),
            template=types.Template(name=cirros_image_glance_template_name, ),
            use_latest_template_version=True,
            stateless=True,
            display=types.Display(type=types.DisplayType.VNC, ),
            memory_policy=types.MemoryPolicy(
                guaranteed=
                vm_memory,  # with so little memory we don't want guaranteed to be any lower
                ballooning=False,
            ),
            os=types.OperatingSystem(
                type=
                'rhel_7x64',  # even though it's CirrOS we want to check a non-default OS type
            ),
            time_zone=types.TimeZone(name='Etc/GMT', ),
            type=types.VmType.SERVER,
            serial_number=types.SerialNumber(
                policy=types.SerialNumberPolicy.CUSTOM,
                value='12345678',
            ),
            cpu=types.Cpu(
                architecture=types.Architecture.X86_64,
                topology=types.CpuTopology(
                    sockets=1,
                    cores=1,
                    threads=2,
                ),
            ),
        ))
def add_vm1_from_template(api):
    engine = api.system_service()
    templates_service = engine.templates_service()
    glance_template = templates_service.list(search='name=%s' %
                                             TEMPLATE_CIRROS)[0]
    if glance_template is None:
        raise SkipTest('%s: template %s not available.' % (
            add_vm1_from_template.__name__,
            TEMPLATE_CIRROS,
        ))

    vm_memory = 512 * MB
    vms_service = engine.vms_service()
    vms_service.add(
        types.Vm(
            name=VM1_NAME,
            description='CirrOS imported from Glance as Template',
            memory=512 * MB,
            cluster=types.Cluster(name=TEST_CLUSTER, ),
            template=types.Template(name=TEMPLATE_CIRROS, ),
            use_latest_template_version=True,
            stateless=True,
            display=types.Display(type=types.DisplayType.VNC, ),
            memory_policy=types.MemoryPolicy(
                guaranteed=vm_memory / 2,
                ballooning=False,
            ),
            os=types.OperatingSystem(type='other_lnux', ),
            time_zone=types.TimeZone(name='Etc/GMT', ),
            type=types.VmType.SERVER,
            serial_number=types.SerialNumber(
                policy=types.SerialNumberPolicy.CUSTOM,
                value='12345678',
            ),
            cpu=types.Cpu(
                architecture=types.Architecture.X86_64,
                topology=types.CpuTopology(
                    sockets=1,
                    cores=1,
                    threads=2,
                ),
            ),
        ))
 def build_entity(self):
     sched_policy = self._get_sched_policy()
     return otypes.Cluster(
         id=self.param('id'),
         name=self.param('name'),
         comment=self.param('comment'),
         description=self.param('description'),
         ballooning_enabled=self.param('ballooning'),
         gluster_service=self.param('gluster'),
         virt_service=self.param('virt'),
         threads_as_cores=self.param('threads_as_cores'),
         ha_reservation=self.param('ha_reservation'),
         trusted_service=self.param('trusted_service'),
         optional_reason=self.param('vm_reason'),
         maintenance_reason_required=self.param('host_reason'),
         scheduling_policy=otypes.SchedulingPolicy(id=sched_policy.id, )
         if sched_policy 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,
         migration=otypes.MigrationOptions(
             auto_converge=otypes.InheritableBoolean(
                 self.param('migration_auto_converge'), )
             if self.param('migration_auto_converge') else None,
             bandwidth=otypes.MigrationBandwidth(
                 assignment_method=otypes.
                 MigrationBandwidthAssignmentMethod(
                     self.param('migration_bandwidth'), )
                 if self.param('migration_bandwidth') else None,
                 custom_value=self.param('migration_bandwidth_limit'),
             ) if (self.param('migration_bandwidth')
                   or self.param('migration_bandwidth_limit')) else None,
             compressed=otypes.InheritableBoolean(
                 self.param('migration_compressed'), )
             if self.param('migration_compressed') else None,
             policy=otypes.MigrationPolicy(id=self._get_policy_id())
             if self.param('migration_policy') else None,
         ) if (self.param('migration_bandwidth') is not None
               or self.param('migration_bandwidth_limit') is not None
               or self.param('migration_auto_converge') is not None
               or self.param('migration_compressed') is not None
               or self.param('migration_policy') is not None) else None,
         error_handling=otypes.ErrorHandling(on_error=otypes.MigrateOnError(
             self.param('resilience_policy')), )
         if self.param('resilience_policy') else None,
         fencing_policy=otypes.FencingPolicy(
             enabled=self.param('fence_enabled'),
             skip_if_gluster_bricks_up=self.param(
                 'fence_skip_if_gluster_bricks_up'),
             skip_if_gluster_quorum_not_met=self.param(
                 'fence_skip_if_gluster_quorum_not_met'),
             skip_if_connectivity_broken=otypes.SkipIfConnectivityBroken(
                 enabled=self.param('fence_skip_if_connectivity_broken'),
                 threshold=self.param('fence_connectivity_threshold'),
             ) if
             (self.param('fence_skip_if_connectivity_broken') is not None
              or self.param('fence_connectivity_threshold') is not None)
             else None,
             skip_if_sd_active=otypes.SkipIfSdActive(
                 enabled=self.param('fence_skip_if_sd_active'), )
             if self.param('fence_skip_if_sd_active') is not None else None,
         ) if
         (self.param('fence_enabled') is not None
          or self.param('fence_skip_if_sd_active') is not None
          or self.param('fence_skip_if_connectivity_broken') is not None
          or self.param('fence_skip_if_gluster_bricks_up') is not None
          or self.param('fence_skip_if_gluster_quorum_not_met') is not None
          or self.param('fence_connectivity_threshold') is not None) else
         None,
         display=otypes.Display(proxy=self.param('spice_proxy'), )
         if self.param('spice_proxy') else None,
         required_rng_sources=[
             otypes.RngSource(rng) for rng in self.param('rng_sources')
         ] if self.param('rng_sources') else None,
         memory_policy=otypes.MemoryPolicy(
             over_commit=otypes.MemoryOverCommit(
                 percent=self._get_memory_policy(), ), )
         if self.param('memory_policy') else None,
         ksm=otypes.Ksm(
             enabled=self.param('ksm'),
             merge_across_nodes=not self.param('ksm_numa'),
         ) if (self.param('ksm_numa') is not None
               or self.param('ksm') is not None) else None,
         data_center=otypes.DataCenter(name=self.param('data_center'), )
         if self.param('data_center') else None,
         management_network=otypes.Network(name=self.param('network'), )
         if self.param('network') else None,
         cpu=otypes.Cpu(
             architecture=otypes.Architecture(self.param('cpu_arch'))
             if self.param('cpu_arch') else None,
             type=self.param('cpu_type'),
         ) if (self.param('cpu_arch') or self.param('cpu_type')) else None,
         version=otypes.Version(
             major=self.__get_major(self.param('compatibility_version')),
             minor=self.__get_minor(self.param('compatibility_version')),
         ) if self.param('compatibility_version') else None,
         switch_type=otypes.SwitchType(self.param('switch_type'))
         if self.param('switch_type') else None,
         mac_pool=otypes.MacPool(id=get_id_by_name(
             self._connection.system_service().mac_pools_service(),
             self.param('mac_pool'))) if self.param('mac_pool') else None,
         external_network_providers=self.
         _get_external_network_providers_entity(),
         custom_scheduling_policy_properties=[
             otypes.Property(
                 name=sp.get('name'),
                 value=str(sp.get('value')),
             ) for sp in self.param('scheduling_policy_properties') if sp
         ] if self.param('scheduling_policy_properties') is not None else
         None,
         firewall_type=otypes.FirewallType(self.param('firewall_type'))
         if self.param('firewall_type') else None,
         gluster_tuned_profile=self.param('gluster_tuned_profile'),
     )
Esempio n. 11
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,
     )