def _check_default_pools(self): pools = {} if 'disks' not in tmpl_defaults or len( tmpl_defaults['disks'] ) == 0 or not tmpl_defaults.get('disks')[0].get('pool'): return tmpl_defaults.get('disks') default_pool = tmpl_defaults['disks'][0]['pool']['name'] default_pool = default_pool.split('/')[-1] pools[default_pool] = {} if default_pool == 'default': pools[default_pool] = {'path': '/var/lib/libvirt/images'} if config.get('kimchi', {}).get('create_iso_pool', False): 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." % kimchiPaths.sysconf_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 wok_log.error(msg % pool_name) wok_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 wok_log.error(msg % pool_name) wok_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
def _check_default_pools(self): pools = {} if 'disks' not in tmpl_defaults or len(tmpl_defaults['disks']) == 0 or not tmpl_defaults.get('disks')[0].get('pool'): return tmpl_defaults.get('disks') default_pool = tmpl_defaults['disks'][0]['pool']['name'] default_pool = default_pool.split('/')[-1] pools[default_pool] = {} if default_pool == 'default': pools[default_pool] = {'path': '/var/lib/libvirt/images'} if config.get('kimchi', {}).get('create_iso_pool', False): 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." % kimchiPaths.sysconf_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 wok_log.error(msg % pool_name) wok_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 wok_log.error(msg % pool_name) wok_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
def _check_default_networks(self): networks = list(set(tmpl_defaults.get('networks', []))) conn = self.conn.get() for net_name in networks: error_msg = ("Network %s does not exist or is not " "active. Please, check the configuration in " "%s/template.conf to ensure it lists only valid " "networks." % (net_name, kimchiPaths.sysconf_dir)) try: net = conn.networkLookupByName(net_name) except libvirt.libvirtError, e: msg = "Fatal: Unable to find network %s." wok_log.error(msg, net_name) wok_log.error("Details: %s", e.message) raise Exception(error_msg) if net.isActive() == 0: try: net.create() except libvirt.libvirtError as e: msg = "Fatal: Unable to activate network %s." wok_log.error(msg, net_name) wok_log.error("Details: %s", e.message) raise Exception(error_msg)
def _check_default_networks(self): networks = list(set(tmpl_defaults.get('networks', []))) conn = self.conn.get() for net_name in networks: error_msg = ('Network %s does not exist or is not ' 'active. Please, check the configuration in ' '%s/template.conf to ensure it lists only valid ' 'networks.' % (net_name, kimchiPaths.sysconf_dir)) try: net = conn.networkLookupByName(net_name) except libvirt.libvirtError as e: wok_log.error(f'Fatal: Unable to find network {net_name}.') wok_log.error(f'Details: {str(e)}') raise Exception(error_msg) if net.isActive() == 0: try: net.create() except libvirt.libvirtError as e: wok_log.error( f'Fatal: Unable to activate network {net_name}.') wok_log.error(f'Details: {str(e)}') raise Exception(error_msg)
def _check_default_networks(self): networks = list(set(tmpl_defaults.get('networks', []))) conn = self.conn.get() for net_name in networks: error_msg = ( 'Network %s does not exist or is not ' 'active. Please, check the configuration in ' '%s/template.conf to ensure it lists only valid ' 'networks.' % (net_name, kimchiPaths.sysconf_dir) ) try: net = conn.networkLookupByName(net_name) except libvirt.libvirtError as e: wok_log.error(f'Fatal: Unable to find network {net_name}.') wok_log.error(f'Details: {str(e)}') raise Exception(error_msg) if net.isActive() == 0: try: net.create() except libvirt.libvirtError as e: wok_log.error( f'Fatal: Unable to activate network {net_name}.') wok_log.error(f'Details: {str(e)}') raise Exception(error_msg)