def create_virt_viewer_file(vm_name, graphics_info): graphics_type = graphics_info[0] graphics_port = graphics_info[2] graphics_passwd = graphics_info[3] try: host = _get_request_host() default_dir = kimchi_config.get_virtviewerfiles_path() file_path = os.path.join(default_dir, '%s-access.vv' % vm_name) file_params = { 'type': graphics_type, 'graphics_port': graphics_port, 'graphics_passwd': graphics_passwd, 'host': host, 'path': file_path } write_virt_viewer_file(file_params) return file_path except Exception as e: raise OperationFailed("KCHVM0084E", { 'name': vm_name, 'err': e.message })
def __init__(self, wok_options): make_dirs = [ os.path.dirname(os.path.abspath(config.get_object_store())), os.path.abspath(config.get_distros_store()), os.path.abspath(config.get_screenshot_path()), os.path.abspath(config.get_virtviewerfiles_path()) ] for directory in make_dirs: if not os.path.isdir(directory): os.makedirs(directory) # When running on test mode, specify the objectstore location to # remove the file on server shutting down. That way, the system will # not suffer any change while running on test mode if wok_options.test and (wok_options.test is True or wok_options.test.lower() == 'true'): self.objectstore_loc = tempfile.mktemp() self.model = mockmodel.MockModel(self.objectstore_loc) def remove_objectstore(): if os.path.exists(self.objectstore_loc): os.unlink(self.objectstore_loc) cherrypy.engine.subscribe('exit', remove_objectstore) else: self.model = kimchiModel.Model() dev_env = wok_options.environment != 'production' super(Kimchi, self).__init__(self.model, dev_env) for ident, node in sub_nodes.items(): setattr(self, ident, node(self.model)) self.api_schema = json.load( open( os.path.join(os.path.dirname(os.path.abspath(__file__)), 'API.json'))) self.paths = config.kimchiPaths self.domain = 'kimchi' self.messages = messages self.extends = { "/plugins/gingerbase": { "host-dashboard.html": "/plugins/kimchi/js/kimchi.peers.js" } } self.depends = ['gingerbase'] # Some paths or URI's present in the objectstore have changed after # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data # are necessary. if upgrade_objectstore_schema(config.get_object_store(), 'version'): upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/') upgrade_objectstore_data('storagepool', '/storagepools', '/plugins/kimchi') upgrade_objectstore_template_disks(self.model.conn) # Upgrade memory data, if necessary upgrade_objectstore_memory()
def _create_virt_viewer_tmp_file(self): path = kimchi_config.get_virtviewerfiles_path() if not os.path.isdir(path): os.makedirs(path) self.virtviewerfile_tmp = tempfile.NamedTemporaryFile(dir=path, delete=False) file_content = '[virt-viewer]\ntype=vnc\nhost=127.0.0.1\nport=5999\n' self.virtviewerfile_tmp.write(file_content.encode('utf-8')) self.virtviewerfile_tmp.close()
def _create_virt_viewer_tmp_file(self): path = kimchi_config.get_virtviewerfiles_path() if not os.path.isdir(path): os.makedirs(path) self.virtviewerfile_tmp = tempfile.NamedTemporaryFile( dir=path, delete=False) file_content = '[virt-viewer]\ntype=vnc\nhost=127.0.0.1\nport=5999\n' self.virtviewerfile_tmp.write(file_content.encode('utf-8')) self.virtviewerfile_tmp.close()
def __init__(self, wok_options): make_dirs = [ os.path.dirname(os.path.abspath(config.get_object_store())), os.path.abspath(config.get_distros_store()), os.path.abspath(config.get_screenshot_path()), os.path.abspath(config.get_virtviewerfiles_path()), ] for directory in make_dirs: if not os.path.isdir(directory): os.makedirs(directory) # When running on test mode, specify the objectstore location to # remove the file on server shutting down. That way, the system will # not suffer any change while running on test mode if wok_options.test and ( wok_options.test is True or wok_options.test.lower() == 'true' ): self.objectstore_loc = tempfile.mktemp() self.model = mockmodel.MockModel(self.objectstore_loc) def remove_objectstore(): if os.path.exists(self.objectstore_loc): os.unlink(self.objectstore_loc) cherrypy.engine.subscribe('exit', remove_objectstore) else: self.model = kimchiModel.Model() dev_env = wok_options.environment != 'production' super(Kimchi, self).__init__(self.model, dev_env) for ident, node in sub_nodes.items(): setattr(self, ident, node(self.model)) with open( os.path.join(os.path.dirname( os.path.abspath(__file__)), 'API.json') ) as fd: self.api_schema = json.load(fd) self.paths = config.kimchiPaths self.domain = 'kimchi' self.messages = messages # Some paths or URI's present in the objectstore have changed after # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data # are necessary. if upgrade_objectstore_schema(config.get_object_store(), 'version'): upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/') upgrade_objectstore_data( 'storagepool', '/storagepools', '/plugins/kimchi') upgrade_objectstore_template_disks(self.model.conn) # Upgrade memory data, if necessary upgrade_objectstore_memory()
def __init__(self, wok_options): make_dirs = [ os.path.dirname(os.path.abspath(config.get_object_store())), os.path.abspath(config.get_distros_store()), os.path.abspath(config.get_screenshot_path()), os.path.abspath(config.get_virtviewerfiles_path()) ] for directory in make_dirs: if not os.path.isdir(directory): os.makedirs(directory) if hasattr(wok_options, "model"): self.model = wok_options.model elif wok_options.test: self.model = mockmodel.MockModel() else: self.model = kimchiModel.Model() dev_env = wok_options.environment != 'production' super(Kimchi, self).__init__(self.model, dev_env) for ident, node in sub_nodes.items(): setattr(self, ident, node(self.model)) if isinstance(self.model, kimchiModel.Model): ws_proxy = websocket.new_ws_proxy() cherrypy.engine.subscribe('exit', ws_proxy.terminate) self.api_schema = json.load( open( os.path.join(os.path.dirname(os.path.abspath(__file__)), 'API.json'))) self.paths = config.kimchiPaths self.domain = 'kimchi' self.messages = messages self.extends = { "/plugins/gingerbase": { "host-dashboard.html": "/plugins/kimchi/js/kimchi.peers.js" } } # Some paths or URI's present in the objectstore have changed after # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data # are necessary. if upgrade_objectstore_schema(config.get_object_store(), 'version'): upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/') upgrade_objectstore_data('storagepool', '/storagepools', '/plugins/kimchi') upgrade_objectstore_template_disks(self.model.conn) # Upgrade memory data, if necessary upgrade_objectstore_memory()
def __init__(self, wok_options): make_dirs = [ os.path.dirname(os.path.abspath(config.get_object_store())), os.path.abspath(config.get_distros_store()), os.path.abspath(config.get_screenshot_path()), os.path.abspath(config.get_virtviewerfiles_path()) ] for directory in make_dirs: if not os.path.isdir(directory): os.makedirs(directory) if hasattr(wok_options, "model"): self.model = wok_options.model elif wok_options.test: self.model = mockmodel.MockModel() else: self.model = kimchiModel.Model() dev_env = wok_options.environment != 'production' super(Kimchi, self).__init__(self.model, dev_env) for ident, node in sub_nodes.items(): setattr(self, ident, node(self.model)) if isinstance(self.model, kimchiModel.Model): ws_proxy = websocket.new_ws_proxy() cherrypy.engine.subscribe('exit', ws_proxy.terminate) self.api_schema = json.load(open(os.path.join(os.path.dirname( os.path.abspath(__file__)), 'API.json'))) self.paths = config.kimchiPaths self.domain = 'kimchi' self.messages = messages self.extends = { "/plugins/gingerbase": { "host-dashboard.html": "/plugins/kimchi/js/kimchi.peers.js" } } # Some paths or URI's present in the objectstore have changed after # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data # are necessary. if upgrade_objectstore_schema(config.get_object_store(), 'version'): upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/') upgrade_objectstore_data('storagepool', '/storagepools', '/plugins/kimchi') upgrade_objectstore_template_disks(self.model.conn) # Upgrade memory data, if necessary upgrade_objectstore_memory()
def create_virt_viewer_file(vm_name, graphics_info): graphics_type = graphics_info[0] graphics_port = graphics_info[2] graphics_passwd = graphics_info[3] try: host = _get_request_host() default_dir = kimchi_config.get_virtviewerfiles_path() file_path = os.path.join(default_dir, f'{vm_name}-access.vv') file_params = { 'type': graphics_type, 'graphics_port': graphics_port, 'graphics_passwd': graphics_passwd, 'host': host, 'path': file_path, } write_virt_viewer_file(file_params) return file_path except Exception as e: raise OperationFailed('KCHVM0084E', {'name': vm_name, 'err': str(e)})