def __init__(self, **kargs): self.conn = kargs['conn'] self.objstore = kargs['objstore'] self.scanner = Scanner(self._clean_scan) self.scanner.delete() self.caps = CapabilitiesModel(**kargs) self.device = DeviceModel(**kargs)
class StoragePoolsModel(object): def __init__(self, **kargs): self.conn = kargs['conn'] self.objstore = kargs['objstore'] self.scanner = Scanner(self._clean_scan) self.scanner.delete() def get_list(self): try: conn = self.conn.get() names = conn.listStoragePools() names += conn.listDefinedStoragePools() return sorted(map(lambda x: x.decode('utf-8'), names)) except libvirt.libvirtError as e: raise OperationFailed("KCHPOOL0006E", {'err': e.get_error_message()}) def create(self, params): task_id = None conn = self.conn.get() try: name = params['name'] if name in (ISO_POOL_NAME, ): raise InvalidOperation("KCHPOOL0001E", {'name': name}) if params['type'] == 'kimchi-iso': task_id = self._do_deep_scan(params) poolDef = StoragePoolDef.create(params) poolDef.prepare(conn) xml = poolDef.xml.encode("utf-8") except KeyError, item: raise MissingParameter("KCHPOOL0004E", {'item': item, 'name': name}) if name in self.get_list(): raise InvalidOperation("KCHPOOL0001E", {'name': name}) try: if task_id: # Create transient pool for deep scan conn.storagePoolCreateXML(xml, 0) return name pool = conn.storagePoolDefineXML(xml, 0) if params['type'] in ['logical', 'dir', 'netfs']: pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW) # autostart dir and logical storage pool created from kimchi pool.setAutostart(1) else: # disable autostart for others pool.setAutostart(0) except libvirt.libvirtError as e: kimchi_log.error("Problem creating Storage Pool: %s", e) raise OperationFailed("KCHPOOL0007E", {'name': name, 'err': e.get_error_message()}) return name
def __init__(self, **kargs): self.conn = kargs['conn'] self.objstore = kargs['objstore'] self.scanner = Scanner(self._clean_scan) self.scanner.delete() self.caps = CapabilitiesModel(**kargs) self.device = DeviceModel(**kargs) if self.conn.isQemuURI(): self._check_default_pools()
class StoragePoolsModel(object): def __init__(self, **kargs): self.conn = kargs['conn'] self.objstore = kargs['objstore'] self.scanner = Scanner(self._clean_scan) self.scanner.delete() def get_list(self): try: conn = self.conn.get() names = conn.listStoragePools() names += conn.listDefinedStoragePools() return sorted(names) except libvirt.libvirtError as e: raise OperationFailed(e.get_error_message()) def create(self, params): task_id = None conn = self.conn.get() try: name = params['name'] if name in (ISO_POOL_NAME, ): raise InvalidOperation("StoragePool already exists") if params['type'] == 'kimchi-iso': task_id = self._do_deep_scan(params) poolDef = StoragePoolDef.create(params) poolDef.prepare(conn) xml = poolDef.xml except KeyError, key: raise MissingParameter(key) if name in self.get_list(): err = "The name %s has been used by a pool" raise InvalidOperation(err % name) try: if task_id: # Create transient pool for deep scan conn.storagePoolCreateXML(xml, 0) return name pool = conn.storagePoolDefineXML(xml, 0) if params['type'] in ['logical', 'dir', 'netfs']: pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW) # autostart dir and logical storage pool created from kimchi pool.setAutostart(1) else: # disable autostart for others pool.setAutostart(0) except libvirt.libvirtError as e: msg = "Problem creating Storage Pool: %s" kimchi_log.error(msg, e) raise OperationFailed(e.get_error_message()) return name
def __init__(self, **kargs): self.conn = kargs['conn'] self.objstore = kargs['objstore'] self.scanner = Scanner(self._clean_scan) self.scanner.delete() self.caps = CapabilitiesModel() self.device = DeviceModel(**kargs)
class StoragePoolsModel(object): def __init__(self, **kargs): self.conn = kargs['conn'] self.objstore = kargs['objstore'] self.scanner = Scanner(self._clean_scan) self.scanner.delete() self.caps = CapabilitiesModel() self.device = DeviceModel(**kargs) def get_list(self): try: conn = self.conn.get() names = conn.listStoragePools() names += conn.listDefinedStoragePools() return sorted(map(lambda x: x.decode('utf-8'), names)) except libvirt.libvirtError as e: raise OperationFailed("KCHPOOL0006E", {'err': e.get_error_message()}) def create(self, params): task_id = None conn = self.conn.get() try: name = params['name'] if name == ISO_POOL_NAME: raise InvalidOperation("KCHPOOL0031E") # The user may want to create a logical pool with the same name # used before but a volume group will already exist with this name # So check the volume group does not exist to create the pool if params['type'] == 'logical': vgdisplay_cmd = ['vgdisplay', name] output, error, returncode = run_command(vgdisplay_cmd) # From vgdisplay error codes: # 1 error reading VGDA # 2 volume group doesn't exist # 3 not all physical volumes of volume group online # 4 volume group not found # 5 no volume groups found at all # 6 error reading VGDA from lvmtab if returncode not in [2, 4, 5]: raise InvalidOperation("KCHPOOL0036E", {'name': name}) if params['type'] == 'kimchi-iso': task_id = self._do_deep_scan(params) if params['type'] == 'scsi': adapter_name = params['source']['adapter_name'] extra_params = self.device.lookup(adapter_name) # Adds name, adapter_type, wwpn and wwnn to source information params['source'].update(extra_params) params['fc_host_support'] = self.caps.fc_host_support poolDef = StoragePoolDef.create(params) poolDef.prepare(conn) xml = poolDef.xml.encode("utf-8") except KeyError, item: raise MissingParameter("KCHPOOL0004E", {'item': str(item), 'name': name}) if name in self.get_list(): raise InvalidOperation("KCHPOOL0001E", {'name': name}) try: if task_id: # Create transient pool for deep scan conn.storagePoolCreateXML(xml, 0) return name pool = conn.storagePoolDefineXML(xml, 0) if params['type'] in ['logical', 'dir', 'netfs', 'scsi']: pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW) # autostart dir, logical, netfs and scsi storage pools created # from kimchi pool.setAutostart(1) else: # disable autostart for others pool.setAutostart(0) except libvirt.libvirtError as e: kimchi_log.error("Problem creating Storage Pool: %s", e) raise OperationFailed("KCHPOOL0007E", {'name': name, 'err': e.get_error_message()}) if params['type'] == 'netfs': output, error, returncode = run_command(['setsebool', '-P', 'virt_use_nfs=1']) if error or returncode: kimchi_log.error("Unable to set virt_use_nfs=1. If you use " "SELinux, this may prevent NFS pools from " "being used.") return name
def __init__(self, **kargs): self.conn = kargs['conn'] self.objstore = kargs['objstore'] self.scanner = Scanner(self._clean_scan) self.scanner.delete()
class StoragePoolsModel(object): def __init__(self, **kargs): self.conn = kargs['conn'] self.objstore = kargs['objstore'] self.scanner = Scanner(self._clean_scan) self.scanner.delete() self.caps = CapabilitiesModel(**kargs) self.device = DeviceModel(**kargs) if self.conn.isQemuURI(): self._check_default_pools() def _check_default_pools(self): pools = {} default_pool = tmpl_defaults['storagepool'] default_pool = default_pool.split('/')[2] pools[default_pool] = {} if default_pool == 'default': pools[default_pool] = {'path': '/var/lib/libvirt/images'} if config.get("server", "create_iso_pool") == "true": pools['ISO'] = {'path': '/var/lib/kimchi/isos'} error_msg = ("Please, check the configuration in %s/template.conf to " "ensure it has a valid storage pool." % paths.conf_dir) conn = self.conn.get() for pool_name in pools: try: pool = conn.storagePoolLookupByName(pool_name) except libvirt.libvirtError, e: pool_path = pools[pool_name].get('path') if pool_path is None: msg = "Fatal: Unable to find storage pool %s. " + error_msg kimchi_log.error(msg % pool_name) kimchi_log.error("Details: %s", e.message) sys.exit(1) # Try to create the pool pool = E.pool(E.name(pool_name), type='dir') pool.append(E.target(E.path(pool_path))) xml = ET.tostring(pool) try: pool = conn.storagePoolDefineXML(xml, 0) # Add build step to make sure target directory created pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW) pool.setAutostart(1) except libvirt.libvirtError, e: msg = "Fatal: Unable to create storage pool %s. " msg += error_msg kimchi_log.error(msg % pool_name) kimchi_log.error("Details: %s", e.message) sys.exit(1) if pool.isActive() == 0: try: pool.create(0) except libvirt.libvirtError, e: msg = "Fatal: Unable to craete storage pool %s. " msg += error_msg kimchi_log.error(msg % pool_name) kimchi_log.error("Details: %s", e.message) sys.exit(1)
class StoragePoolsModel(object): def __init__(self, **kargs): self.conn = kargs['conn'] self.objstore = kargs['objstore'] self.scanner = Scanner(self._clean_scan) self.scanner.delete() self.caps = CapabilitiesModel(**kargs) self.device = DeviceModel(**kargs) if self.conn.isQemuURI(): self._check_default_pools() def _check_default_pools(self): pools = {} default_pool = tmpl_defaults['storagepool'] default_pool = default_pool.split('/')[2] pools[default_pool] = {} if default_pool == 'default': pools[default_pool] = {'path': '/var/lib/libvirt/images'} if config.get("server", "create_iso_pool") == "true": pools['ISO'] = {'path': '/var/lib/kimchi/isos'} error_msg = ("Please, check the configuration in %s/template.conf to " "ensure it has a valid storage pool." % paths.conf_dir) conn = self.conn.get() for pool_name in pools: try: pool = conn.storagePoolLookupByName(pool_name) except libvirt.libvirtError, e: pool_path = pools[pool_name].get('path') if pool_path is None: msg = "Fatal: Unable to find storage pool %s. " + error_msg kimchi_log.error(msg % pool_name) kimchi_log.error("Details: %s", e.message) sys.exit(1) # Try to create the pool pool = E.pool(E.name(pool_name), type='dir') pool.append(E.target(E.path(pool_path))) xml = ET.tostring(pool) try: pool = conn.storagePoolDefineXML(xml, 0) except libvirt.libvirtError, e: msg = "Fatal: Unable to create storage pool %s. " msg += error_msg kimchi_log.error(msg % pool_name) kimchi_log.error("Details: %s", e.message) sys.exit(1) # Build and set autostart value to pool # Ignore error as the pool was already successfully created try: # Add build step to make sure target directory created # The build process may fail when the pool directory # already exists on system pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW) pool.setAutostart(1) except: pass if pool.isActive() == 0: try: pool.create(0) except libvirt.libvirtError, e: msg = "Fatal: Unable to craete storage pool %s. " msg += error_msg kimchi_log.error(msg % pool_name) kimchi_log.error("Details: %s", e.message) sys.exit(1)
class StoragePoolsModel(object): def __init__(self, **kargs): self.conn = kargs['conn'] self.objstore = kargs['objstore'] self.scanner = Scanner(self._clean_scan) self.scanner.delete() self.caps = CapabilitiesModel(**kargs) self.device = DeviceModel(**kargs) def get_list(self): try: conn = self.conn.get() names = conn.listStoragePools() names += conn.listDefinedStoragePools() return sorted(map(lambda x: x.decode('utf-8'), names)) except libvirt.libvirtError as e: raise OperationFailed("KCHPOOL0006E", {'err': e.get_error_message()}) def create(self, params): task_id = None conn = self.conn.get() try: name = params['name'] if name == ISO_POOL_NAME: raise InvalidOperation("KCHPOOL0031E") # The user may want to create a logical pool with the same name # used before but a volume group will already exist with this name # So check the volume group does not exist to create the pool if params['type'] == 'logical': vgdisplay_cmd = ['vgdisplay', name.encode('utf-8')] output, error, returncode = run_command(vgdisplay_cmd) # From vgdisplay error codes: # 1 error reading VGDA # 2 volume group doesn't exist # 3 not all physical volumes of volume group online # 4 volume group not found # 5 no volume groups found at all # 6 error reading VGDA from lvmtab if returncode not in [2, 4, 5]: raise InvalidOperation("KCHPOOL0036E", {'name': name}) if params['type'] == 'kimchi-iso': task_id = self._do_deep_scan(params) if params['type'] == 'scsi': adapter_name = params['source']['adapter_name'] extra_params = self.device.lookup(adapter_name) # Adds name, adapter_type, wwpn and wwnn to source information params['source'].update(extra_params) params['fc_host_support'] = self.caps.fc_host_support poolDef = StoragePoolDef.create(params) poolDef.prepare(conn) xml = poolDef.xml.encode("utf-8") except KeyError, item: raise MissingParameter("KCHPOOL0004E", { 'item': str(item), 'name': name }) if name in self.get_list(): raise InvalidOperation("KCHPOOL0001E", {'name': name}) try: if task_id: # Create transient pool for deep scan conn.storagePoolCreateXML(xml, 0) return name pool = conn.storagePoolDefineXML(xml, 0) if params['type'] in ['logical', 'dir', 'netfs', 'scsi']: pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW) # autostart dir, logical, netfs and scsi storage pools created # from kimchi pool.setAutostart(1) else: # disable autostart for others pool.setAutostart(0) except libvirt.libvirtError as e: kimchi_log.error("Problem creating Storage Pool: %s", e) raise OperationFailed("KCHPOOL0007E", { 'name': name, 'err': e.get_error_message() }) if params['type'] == 'netfs': output, error, returncode = run_command( ['setsebool', '-P', 'virt_use_nfs=1']) if error or returncode: kimchi_log.error("Unable to set virt_use_nfs=1. If you use " "SELinux, this may prevent NFS pools from " "being used.") return name
class StoragePoolsModel(object): def __init__(self, **kargs): self.conn = kargs['conn'] self.objstore = kargs['objstore'] self.scanner = Scanner(self._clean_scan) self.scanner.delete() self.caps = CapabilitiesModel() self.device = DeviceModel(**kargs) def get_list(self): try: conn = self.conn.get() names = conn.listStoragePools() names += conn.listDefinedStoragePools() return sorted(map(lambda x: x.decode('utf-8'), names)) except libvirt.libvirtError as e: raise OperationFailed("KCHPOOL0006E", {'err': e.get_error_message()}) def create(self, params): task_id = None conn = self.conn.get() try: name = params['name'] if name == ISO_POOL_NAME: raise InvalidOperation("KCHPOOL0031E") if params['type'] == 'kimchi-iso': task_id = self._do_deep_scan(params) if params['type'] == 'scsi': adapter_name = params['source']['adapter_name'] extra_params = self.device.lookup(adapter_name) # Adds name, adapter_type, wwpn and wwnn to source information params['source'].update(extra_params) params['fc_host_support'] = self.caps.fc_host_support poolDef = StoragePoolDef.create(params) poolDef.prepare(conn) xml = poolDef.xml.encode("utf-8") except KeyError, item: raise MissingParameter("KCHPOOL0004E", {'item': str(item), 'name': name}) if name in self.get_list(): raise InvalidOperation("KCHPOOL0001E", {'name': name}) try: if task_id: # Create transient pool for deep scan conn.storagePoolCreateXML(xml, 0) return name pool = conn.storagePoolDefineXML(xml, 0) if params['type'] in ['logical', 'dir', 'netfs', 'scsi']: pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW) # autostart dir, logical, netfs and scsi storage pools created # from kimchi pool.setAutostart(1) else: # disable autostart for others pool.setAutostart(0) except libvirt.libvirtError as e: kimchi_log.error("Problem creating Storage Pool: %s", e) raise OperationFailed("KCHPOOL0007E", {'name': name, 'err': e.get_error_message()}) return name
class StoragePoolsModel(object): def __init__(self, **kargs): self.conn = kargs['conn'] self.objstore = kargs['objstore'] self.scanner = Scanner(self._clean_scan) self.scanner.delete() self.caps = CapabilitiesModel() self.device = DeviceModel(**kargs) def get_list(self): try: conn = self.conn.get() names = conn.listStoragePools() names += conn.listDefinedStoragePools() return sorted(map(lambda x: x.decode('utf-8'), names)) except libvirt.libvirtError as e: raise OperationFailed("KCHPOOL0006E", {'err': e.get_error_message()}) def create(self, params): task_id = None conn = self.conn.get() try: name = params['name'] if name == ISO_POOL_NAME: raise InvalidOperation("KCHPOOL0031E") if params['type'] == 'kimchi-iso': task_id = self._do_deep_scan(params) if params['type'] == 'scsi': adapter_name = params['source']['adapter_name'] extra_params = self.device.lookup(adapter_name) # Adds name, adapter_type, wwpn and wwnn to source information params['source'].update(extra_params) params['fc_host_support'] = self.caps.fc_host_support poolDef = StoragePoolDef.create(params) poolDef.prepare(conn) xml = poolDef.xml.encode("utf-8") except KeyError, item: raise MissingParameter("KCHPOOL0004E", { 'item': str(item), 'name': name }) if name in self.get_list(): raise InvalidOperation("KCHPOOL0001E", {'name': name}) try: if task_id: # Create transient pool for deep scan conn.storagePoolCreateXML(xml, 0) return name pool = conn.storagePoolDefineXML(xml, 0) if params['type'] in ['logical', 'dir', 'netfs', 'scsi']: pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW) # autostart dir, logical, netfs and scsi storage pools created # from kimchi pool.setAutostart(1) else: # disable autostart for others pool.setAutostart(0) except libvirt.libvirtError as e: kimchi_log.error("Problem creating Storage Pool: %s", e) raise OperationFailed("KCHPOOL0007E", { 'name': name, 'err': e.get_error_message() }) return name