def fork_vm_storage(self, vm_uuid): # Provision storages: disk_and_vol_list = self.to_volume_list(vm_uuid) try: for v in disk_and_vol_list: if v['pool'] is not None: pool = self._get_storage_pool(v['pool']) # outgoing text to libvirt, decode('utf-8') pool.createXML(v['xml'].decode('utf-8'), 0) else: capacity = v['capacity'] format_type = v['format'] path = v['path'] create_disk_image(format_type=format_type, path=path, capacity=capacity) except libvirt.libvirtError as e: raise OperationFailed('KCHVMSTOR0008E', {'error': str(e)}) return disk_and_vol_list
def fork_vm_storage(self, vm_uuid): # Provision storages: disk_and_vol_list = self.to_volume_list(vm_uuid) try: for v in disk_and_vol_list: if v['pool'] is not None: pool = self._get_storage_pool(v['pool']) # outgoing text to libvirt, decode('utf-8') pool.createXML(v['xml'].decode('utf-8'), 0) else: capacity = v['capacity'] format_type = v['format'] path = v['path'] create_disk_image( format_type=format_type, path=path, capacity=capacity ) except libvirt.libvirtError as e: raise OperationFailed('KCHVMSTOR0008E', {'error': str(e)}) return disk_and_vol_list
def create(self, vm_name, params): # Path will never be blank due to API.json verification. # There is no need to cover this case here. if not ('vol' in params) ^ ('path' in params): if not is_s390x(): raise InvalidParameter('KCHVMSTOR0017E') if 'dir_path' not in params: raise InvalidParameter('KCHVMSTOR0019E') dom = VMModel.get_vm(vm_name, self.conn) params['bus'] = _get_device_bus(params['type'], dom) if is_s390x() and params['type'] == 'disk' and 'dir_path' in params: if 'format' not in params: raise InvalidParameter('KCHVMSTOR0020E') size = params['size'] name = params['name'] dir_path = params.get('dir_path') params['path'] = dir_path + '/' + name if os.path.exists(params['path']): raise InvalidParameter('KCHVMSTOR0021E', {'disk_path': params['path']}) create_disk_image(format_type=params['format'], path=params['path'], capacity=size) else: params['format'] = 'raw' dev_list = [ dev for dev, bus in get_vm_disks(dom).items() if bus == params['bus'] ] dev_list.sort() if len(dev_list) == 0: params['index'] = 0 else: char = dev_list.pop()[2] params['index'] = string.ascii_lowercase.index(char) + 1 if (params['bus'] not in HOTPLUG_TYPE and DOM_STATE_MAP[dom.info()[0]] != 'shutoff'): raise InvalidOperation('KCHVMSTOR0011E') if params.get('vol'): vol_info = self._get_vol_info(params) params['path'] = vol_info['path'] params['disk'] = vol_info['type'] params.update(self._get_available_bus_address(params['bus'], vm_name)) # Add device to VM dev, xml = get_disk_xml(params) try: dom = VMModel.get_vm(vm_name, self.conn) dom.attachDeviceFlags(xml, get_vm_config_flag(dom, 'all')) except Exception as e: raise OperationFailed('KCHVMSTOR0008E', {'error': str(e)}) # Don't put a try-block here. Let the exception be raised. If we # allow disks used_by to be out of sync, data corruption could # occur if a disk is added to two guests unknowingly. if params.get('vol'): used_by = vol_info['used_by'] used_by.append(vm_name) return dev
def create(self, vm_name, params): # Path will never be blank due to API.json verification. # There is no need to cover this case here. if not ('vol' in params) ^ ('path' in params): if not is_s390x(): raise InvalidParameter('KCHVMSTOR0017E') if 'dir_path' not in params: raise InvalidParameter('KCHVMSTOR0019E') dom = VMModel.get_vm(vm_name, self.conn) params['bus'] = _get_device_bus(params['type'], dom) if is_s390x() and params['type'] == 'disk' and 'dir_path' in params: if 'format' not in params: raise InvalidParameter('KCHVMSTOR0020E') size = params['size'] name = params['name'] dir_path = params.get('dir_path') params['path'] = dir_path + '/' + name if os.path.exists(params['path']): raise InvalidParameter( 'KCHVMSTOR0021E', {'disk_path': params['path']}) create_disk_image( format_type=params['format'], path=params['path'], capacity=size ) else: params['format'] = 'raw' dev_list = [ dev for dev, bus in get_vm_disks(dom).items() if bus == params['bus'] ] dev_list.sort() if len(dev_list) == 0: params['index'] = 0 else: char = dev_list.pop()[2] params['index'] = string.ascii_lowercase.index(char) + 1 if ( params['bus'] not in HOTPLUG_TYPE and DOM_STATE_MAP[dom.info()[0]] != 'shutoff' ): raise InvalidOperation('KCHVMSTOR0011E') if params.get('vol'): vol_info = self._get_vol_info(params) params['path'] = vol_info['path'] params['disk'] = vol_info['type'] params.update(self._get_available_bus_address(params['bus'], vm_name)) # Add device to VM dev, xml = get_disk_xml(params) try: dom = VMModel.get_vm(vm_name, self.conn) dom.attachDeviceFlags(xml, get_vm_config_flag(dom, 'all')) except Exception as e: raise OperationFailed('KCHVMSTOR0008E', {'error': str(e)}) # Don't put a try-block here. Let the exception be raised. If we # allow disks used_by to be out of sync, data corruption could # occur if a disk is added to two guests unknowingly. if params.get('vol'): used_by = vol_info['used_by'] used_by.append(vm_name) return dev
def create(self, vm_name, params): vol_model = None # Path will never be blank due to API.json verification. # There is no need to cover this case here. if not ('vol' in params) ^ ('path' in params): if not is_s390x(): raise InvalidParameter("KCHVMSTOR0017E") if 'dir_path' not in params: raise InvalidParameter("KCHVMSTOR0019E") dom = VMModel.get_vm(vm_name, self.conn) params['bus'] = _get_device_bus(params['type'], dom) if is_s390x() and params['type'] == 'disk' and 'dir_path' in params: if 'format' not in params: raise InvalidParameter("KCHVMSTOR0020E") size = params['size'] name = params['name'] dir_path = params.get('dir_path') params['path'] = dir_path + "/" + name if os.path.exists(params['path']): raise InvalidParameter("KCHVMSTOR0021E", {'disk_path': params['path']}) create_disk_image(format_type=params['format'], path=params['path'], capacity=size) else: params['format'] = 'raw' dev_list = [dev for dev, bus in get_vm_disks(dom).iteritems() if bus == params['bus']] dev_list.sort() if len(dev_list) == 0: params['index'] = 0 else: char = dev_list.pop()[2] params['index'] = string.ascii_lowercase.index(char) + 1 if (params['bus'] not in HOTPLUG_TYPE and DOM_STATE_MAP[dom.info()[0]] != 'shutoff'): raise InvalidOperation('KCHVMSTOR0011E') if params.get('vol'): try: pool = params['pool'] vol_model = StorageVolumeModel(conn=self.conn, objstore=self.objstore) vol_info = vol_model.lookup(pool, params['vol']) except KeyError: raise InvalidParameter("KCHVMSTOR0012E") except Exception as e: raise InvalidParameter("KCHVMSTOR0015E", {'error': e}) if len(vol_info['used_by']) != 0: raise InvalidParameter("KCHVMSTOR0016E") valid_format = { "disk": ["raw", "qcow", "qcow2", "qed", "vmdk", "vpc"], "cdrom": "iso"} if vol_info['type'] == 'file': if (params['type'] == 'disk' and vol_info['format'] in valid_format[params['type']]): params['format'] = vol_info['format'] else: raise InvalidParameter("KCHVMSTOR0018E", {"format": vol_info['format'], "type": params['type']}) if (params['format'] == 'raw' and not vol_info['isvalid']): message = 'This is not a valid RAW disk image.' raise OperationFailed('KCHVMSTOR0008E', {'error': message}) params['path'] = vol_info['path'] params['disk'] = vol_info['type'] params.update(self._get_available_bus_address(params['bus'], vm_name)) # Add device to VM dev, xml = get_disk_xml(params) try: dom = VMModel.get_vm(vm_name, self.conn) dom.attachDeviceFlags(xml, get_vm_config_flag(dom, 'all')) except Exception as e: raise OperationFailed("KCHVMSTOR0008E", {'error': e.message}) # Don't put a try-block here. Let the exception be raised. If we # allow disks used_by to be out of sync, data corruption could # occour if a disk is added to two guests unknowingly. if params.get('vol'): used_by = vol_info['used_by'] used_by.append(vm_name) return dev