示例#1
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,
     )
 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(),
     )
示例#3
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,
     )
示例#4
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,
                ),
            ),
        ))
示例#6
0
# Get the reference to the "vms" service:
vms_service = connection.system_service().vms_service()

vm = types.Vm()
vm.name = VMName
vm.comment = VMComment
vm.description = VMDescription
cpu = types.CpuTopology(cores=VMCores, sockets=VMSockets)
vm.cpu = types.Cpu(topology=cpu)
vm.cluster = types.Cluster(name=VMCluster)
vm.template = types.Template(name=VMTemplate)
vm.os = types.OperatingSystem(boot=types.Boot(devices=[types.BootDevice.HD]),
                              type='rhel_8x64')
#vm.instance_type = types.InstanceType(id="00000003-0003-0003-0003-0000000000be")
vm.memory = VMMemory
vm.time_zone = types.TimeZone(name='Asia/Tehran')
netlist = connection.system_service().operating_systems_service().list()
for host in netlist:
    if host.name == 'rhel_8x64':
        myos = host
        print("%s (%s)" % (host.name, host.id))
vm.type = types.VmType.SERVER
vm.soundcard_enabled = False
provider = connection.system_service().external_host_providers_service().list(
)[0]
#vm.externalhostproviders = types.ExternalHostProvider(id='d78051b5-37c8-43bc-8eeb-04e49e59bf3')
#vm.memory_policy=types.MemoryPolicy( guaranteed=VMMemoryGuaranteed )
vms_service.add(vm)
####################################

#vms_service = connection.system_service().vms_service()