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 = {} # Don't create default pool if it's not # explicitly specified in template.conf if is_s390x() and 'pool' not in tmpl_defaults['disks'][0]: return 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'} conn = self.conn.get() for pool_name in pools: error_msg = ("Storage pool %s does not exist or is not " "active. Please, check the configuration in " "%s/template.conf to ensure it lists only valid " "storage." % (pool_name, kimchiPaths.sysconf_dir)) 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. " wok_log.error(msg % pool_name) wok_log.error("Details: %s", e.message) raise Exception(error_msg) # 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. " wok_log.error(msg % pool_name) wok_log.error("Details: %s", e.message) raise Exception(error_msg) # 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 _listen(self, guest, console): """Accepts client connections. Each connection is directly linked to the desired guest console. Thus any data received from the client can be send to the guest console as well as any response from the guest console can be send back to the client console. """ client, client_addr = self._socket.accept() client.settimeout(config.get('kimchi', {}). get('SERIAL_CONSOLE_TIMEOUT', 120)) wok_log.info('[%s] Client connected to %s', self.name, self._guest_name) # register the callback to receive any data from the console console.eventAddCallback(libvirt.VIR_STREAM_EVENT_READABLE, self._send_to_client, client) # start the libvirt event loop in a python thread libvirt_loop = threading.Thread(target=self.libvirt_event_loop, args=(guest, client)) libvirt_loop.start() while True: data = '' try: data = client.recv(1024) except Exception as e: wok_log.info('[%s] Client disconnected from %s: %s', self.name, self._guest_name, e.message) break if not data or data == CTRL_Q: break # if the console can no longer be accessed, close everything # and quits try: console.send(data) except: wok_log.info('[%s] Console of %s is not accessible', self.name, self._guest_name) break # clear used resources when the connection is closed and, if possible, # tell the client the connection was lost. try: client.send('\r\n\r\nClient disconnected\r\n') except: pass
def __init__(self, **kargs): # check federation feature is enabled on Kimchi server if not config.get("kimchi", {}).get("federation", False): return # register server on openslp hostname = socket.getfqdn(wok_config.get("server", "host")) port = wok_config.get("server", "ssl_port") self.url = hostname + ":" + port cmd = ["slptool", "register", "service:wokd://%s" % self.url] out, error, ret = run_command(cmd) if out and len(out) != 0: wok_log.error("Unable to register server on openSLP." " Details: %s" % out) cherrypy.engine.subscribe("exit", self._peer_deregister)
def __init__(self, **kargs): # check federation feature is enabled on Kimchi server if not config.get('kimchi', {}).get('federation', False): return # register server on openslp hostname = socket.getfqdn() port = wok_config.get("server", "proxy_port") self.url = hostname + ":" + port cmd = ["slptool", "register", "service:wokd://%s" % self.url] out, error, ret = run_command(cmd) if out and len(out) != 0: wok_log.error("Unable to register server on openSLP." " Details: %s" % out) cherrypy.engine.subscribe('exit', self._peer_deregister)
def get_list(self): # check federation feature is enabled on Kimchi server if not config.get("kimchi", {}).get("federation", False): return [] cmd = ["slptool", "findsrvs", "service:wokd"] out, error, ret = run_command(cmd) if ret != 0: return [] peers = [] for server in out.strip().split("\n"): match = re.match("service:wokd://(.*?),.*", server) peer = match.group(1) if peer != self.url: peers.append("https://" + peer) return peers
def get_list(self): # check federation feature is enabled on Kimchi server if not config.get('kimchi', {}).get('federation', False): return [] cmd = ["slptool", "findsrvs", "service:wokd"] out, error, ret = run_command(cmd) if ret != 0: return [] peers = [] for server in out.strip().split("\n"): match = re.match("service:wokd://(.*?),.*", server) peer = match.group(1) if peer != self.url: peers.append("https://" + peer) return peers
def lookup(self, name): kconfig = config.get('kimchi', {}) return { 'federation': kconfig.get('federation', False), 'version': get_kimchi_version() }
def lookup(self, name): kconfig = config.get('kimchi', {}) return {'federation': kconfig.get('federation', False), 'version': get_kimchi_version()}
def lookup(self, name): kconfig = config.get("kimchi", {}) return {"federation": kconfig.get("federation", False), "version": get_kimchi_version()}