def vms_create(self, params): t_name = template_name_from_uri(params['template']) name = get_vm_name(params.get('name'), t_name, self._mock_vms.keys()) if name in self._mock_vms: raise InvalidOperation("KCHVM0001E", {'name': name}) vm_uuid = str(uuid.uuid4()) vm_overrides = dict() pool_uri = params.get('storagepool') if pool_uri: vm_overrides['storagepool'] = pool_uri t = self._get_template(t_name, vm_overrides) t.validate() t_info = copy.deepcopy(t.info) graphics = params.get('graphics') if graphics: t_info.update({'graphics': graphics}) vm = MockVM(vm_uuid, name, t_info) icon = t_info.get('icon') if icon: vm.info['icon'] = icon vm.disk_paths = t.fork_vm_storage(vm_uuid) self._mock_vms[name] = vm return name
def create(self, params): t_name = template_name_from_uri(params['template']) vm_list = self.get_list() name = get_vm_name(params.get('name'), t_name, vm_list) # incoming text, from js json, is unicode, do not need decode if name in vm_list: raise InvalidOperation("KCHVM0001E", {'name': name}) vm_overrides = dict() pool_uri = params.get('storagepool') if pool_uri: vm_overrides['storagepool'] = pool_uri vm_overrides['fc_host_support'] = self.caps.fc_host_support t = TemplateModel.get_template(t_name, self.objstore, self.conn, vm_overrides) if not self.caps.qemu_stream and t.info.get('iso_stream', False): raise InvalidOperation("KCHVM0005E") t.validate() data = {'name': name, 'template': t, 'graphics': params.get('graphics', {})} taskid = add_task(u'/vms/%s' % name, self._create_task, self.objstore, data) return self.task.lookup(taskid)
def vms_create(self, params): t_name = template_name_from_uri(params['template']) name = get_vm_name(params.get('name'), t_name, self._mock_vms.keys()) if name in self._mock_vms: raise InvalidOperation("KCHVM0001E", {'name': name}) vm_uuid = str(uuid.uuid4()) vm_overrides = dict() pool_uri = params.get('storagepool') if pool_uri: vm_overrides['storagepool'] = pool_uri t = self._get_template(t_name, vm_overrides) t.validate() t_info = copy.deepcopy(t.info) graphics = params.get('graphics') if graphics: t_info.update({'graphics': graphics}) vm = MockVM(vm_uuid, name, t_info) icon = t_info.get('icon') if icon: vm.info['icon'] = icon pool = t._storage_validate() if pool.info['type'] == 'scsi': vm.disk_paths = [] if not params.get('volumes'): raise MissingParameter('KCHVM0017E') for vol in params['volumes']: vm.disk_paths.append({'pool': pool.name, 'volume': vol}) else: vm.disk_paths = t.fork_vm_storage(vm_uuid) index = 0 for disk in vm.disk_paths: storagepath = self._mock_storagepools[disk['pool']].info['path'] fullpath = os.path.join(storagepath, disk['volume']) dev_name = "hd" + string.ascii_lowercase[index] params = {'dev': dev_name, 'path': fullpath, 'type': 'disk'} vm.storagedevices[dev_name] = MockVMStorageDevice(params) index += 1 cdrom = "hd" + string.ascii_lowercase[index + 1] cdrom_params = {'dev': cdrom, 'path': t_info['cdrom'], 'type': 'cdrom'} vm.storagedevices[cdrom] = MockVMStorageDevice(cdrom_params) self._mock_vms[name] = vm return name
def create(self, params): conn = self.conn.get() t_name = template_name_from_uri(params['template']) vm_uuid = str(uuid.uuid4()) vm_list = self.get_list() name = get_vm_name(params.get('name'), t_name, vm_list) # incoming text, from js json, is unicode, do not need decode if name in vm_list: raise InvalidOperation("KCHVM0001E", {'name': name}) vm_overrides = dict() pool_uri = params.get('storagepool') if pool_uri: vm_overrides['storagepool'] = pool_uri t = TemplateModel.get_template(t_name, self.objstore, self.conn, vm_overrides) if not self.caps.qemu_stream and t.info.get('iso_stream', False): raise InvalidOperation("KCHVM0005E") t.validate() vol_list = t.fork_vm_storage(vm_uuid) # Store the icon for displaying later icon = t.info.get('icon') if icon: with self.objstore as session: session.store('vm', vm_uuid, {'icon': icon}) libvirt_stream = False if len(self.caps.libvirt_stream_protocols) == 0: libvirt_stream = True graphics = params.get('graphics') xml = t.to_vm_xml(name, vm_uuid, libvirt_stream=libvirt_stream, qemu_stream_dns=self.caps.qemu_stream_dns, graphics=graphics) try: conn.defineXML(xml.encode('utf-8')) except libvirt.libvirtError as e: for v in vol_list: vol = conn.storageVolLookupByPath(v['path']) vol.delete(0) raise OperationFailed("KCHVM0007E", {'name': name, 'err': e.get_error_message()}) return name
def create(self, params): conn = self.conn.get() t_name = template_name_from_uri(params['template']) vm_uuid = str(uuid.uuid4()) vm_list = self.get_list() name = get_vm_name(params.get('name'), t_name, vm_list) # incoming text, from js json, is unicode, do not need decode if name in vm_list: raise InvalidOperation("KCHVM0001E", {'name': name}) vm_overrides = dict() pool_uri = params.get('storagepool') if pool_uri: vm_overrides['storagepool'] = pool_uri vm_overrides['fc_host_support'] = self.caps.fc_host_support t = TemplateModel.get_template(t_name, self.objstore, self.conn, vm_overrides) if not self.caps.qemu_stream and t.info.get('iso_stream', False): raise InvalidOperation("KCHVM0005E") t.validate() # Store the icon for displaying later icon = t.info.get('icon') if icon: try: with self.objstore as session: session.store('vm', vm_uuid, {'icon': icon}) except Exception as e: # It is possible to continue Kimchi executions without store # vm icon info kimchi_log.error( 'Error trying to update database with guest ' 'icon information due error: %s', e.message) # If storagepool is SCSI, volumes will be LUNs and must be passed by # the user from UI or manually. vol_list = [] if t._get_storage_type() in ["iscsi", "scsi"]: vol_list = [] else: vol_list = t.fork_vm_storage(vm_uuid) graphics = params.get('graphics') stream_protocols = self.caps.libvirt_stream_protocols xml = t.to_vm_xml(name, vm_uuid, libvirt_stream_protocols=stream_protocols, qemu_stream_dns=self.caps.qemu_stream_dns, graphics=graphics, volumes=vol_list) try: conn.defineXML(xml.encode('utf-8')) except libvirt.libvirtError as e: if t._get_storage_type() not in READONLY_POOL_TYPE: for v in vol_list: vol = conn.storageVolLookupByPath(v['path']) vol.delete(0) raise OperationFailed("KCHVM0007E", { 'name': name, 'err': e.get_error_message() }) VMModel.vm_update_os_metadata(VMModel.get_vm(name, self.conn), t.info) return name
def create(self, params): conn = self.conn.get() t_name = template_name_from_uri(params['template']) vm_uuid = str(uuid.uuid4()) vm_list = self.get_list() name = get_vm_name(params.get('name'), t_name, vm_list) # incoming text, from js json, is unicode, do not need decode if name in vm_list: raise InvalidOperation("KCHVM0001E", {'name': name}) vm_overrides = dict() pool_uri = params.get('storagepool') if pool_uri: vm_overrides['storagepool'] = pool_uri vm_overrides['fc_host_support'] = self.caps.fc_host_support t = TemplateModel.get_template(t_name, self.objstore, self.conn, vm_overrides) if not self.caps.qemu_stream and t.info.get('iso_stream', False): raise InvalidOperation("KCHVM0005E") t.validate() # Store the icon for displaying later icon = t.info.get('icon') if icon: try: with self.objstore as session: session.store('vm', vm_uuid, {'icon': icon}) except Exception as e: # It is possible to continue Kimchi executions without store # vm icon info kimchi_log.error('Error trying to update database with guest ' 'icon information due error: %s', e.message) # If storagepool is SCSI, volumes will be LUNs and must be passed by # the user from UI or manually. vol_list = [] if t._get_storage_type() not in ["iscsi", "scsi"]: vol_list = t.fork_vm_storage(vm_uuid) graphics = params.get('graphics', {}) stream_protocols = self.caps.libvirt_stream_protocols xml = t.to_vm_xml(name, vm_uuid, libvirt_stream_protocols=stream_protocols, qemu_stream_dns=self.caps.qemu_stream_dns, graphics=graphics, volumes=vol_list) try: conn.defineXML(xml.encode('utf-8')) except libvirt.libvirtError as e: if t._get_storage_type() not in READONLY_POOL_TYPE: for v in vol_list: vol = conn.storageVolLookupByPath(v['path']) vol.delete(0) raise OperationFailed("KCHVM0007E", {'name': name, 'err': e.get_error_message()}) VMModel.vm_update_os_metadata(VMModel.get_vm(name, self.conn), t.info, self.caps.metadata_support) return name
def create(self, params): conn = self.conn.get() t_name = template_name_from_uri(params['template']) vm_uuid = str(uuid.uuid4()) vm_list = self.get_list() name = get_vm_name(params.get('name'), t_name, vm_list) # incoming text, from js json, is unicode, do not need decode if name in vm_list: raise InvalidOperation("KCHVM0001E", {'name': name}) vm_overrides = dict() pool_uri = params.get('storagepool') if pool_uri: vm_overrides['storagepool'] = pool_uri vm_overrides['fc_host_support'] = self.caps.fc_host_support t = TemplateModel.get_template(t_name, self.objstore, self.conn, vm_overrides) if not self.caps.qemu_stream and t.info.get('iso_stream', False): raise InvalidOperation("KCHVM0005E") t.validate() # If storagepool is SCSI, volumes will be LUNs and must be passed by # the user from UI or manually. vol_list = [] if t._get_storage_type() in READONLY_POOL_TYPE: if not params.get('volumes'): raise MissingParameter('KCHVM0017E') else: # Get system path of the LUNs pool = t.info['storagepool'].split('/')[-1] for vol in params.get('volumes'): path = self._get_volume_path(pool, vol) vol_list.append((vol, path)) else: vol_list = t.fork_vm_storage(vm_uuid) # Store the icon for displaying later icon = t.info.get('icon') if icon: with self.objstore as session: session.store('vm', vm_uuid, {'icon': icon}) libvirt_stream = False if len(self.caps.libvirt_stream_protocols) == 0: libvirt_stream = True graphics = params.get('graphics') xml = t.to_vm_xml(name, vm_uuid, libvirt_stream=libvirt_stream, qemu_stream_dns=self.caps.qemu_stream_dns, graphics=graphics, volumes=vol_list) try: conn.defineXML(xml.encode('utf-8')) except libvirt.libvirtError as e: if t._get_storage_type() not in READONLY_POOL_TYPE: for v in vol_list: vol = conn.storageVolLookupByPath(v['path']) vol.delete(0) raise OperationFailed("KCHVM0007E", {'name': name, 'err': e.get_error_message()}) return name