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, )
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_vm(api, options): """Adding a VM.""" vms_service = api.system_service().vms_service() try: vms_service.add( types.Vm( name=options['vm_name'], memory=options['vmem'], cpu=types.Cpu(topology=options['vcpus']), type=types.VmType('server'), os=types.OperatingSystem(type=options['os_type']), cluster=types.Cluster(name=options['vm_dc'], ), template=types.Template(name='Blank', ), ), ) except Exception as e: print "Can't add VM: %s" % str(e) api.close() sys.exit(1)