def load_package_list(self, options_file): json_wrapper_option_list = JsonWrapper(options_file) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() self.package_menu_items = [] base_path = os.path.dirname(options_file) package_list = [] default_selected = 0 visible_options_cnt = 0 for install_option in options_sorted: if install_option[1]["visible"] == True: package_list = PackageSelector.get_packages_to_install(options_sorted, install_option[0], base_path) additional_files = PackageSelector.get_additional_files_to_copy_in_iso( options_sorted, base_path, install_option[0]) self.package_menu_items.append((install_option[1]["title"], self.exit_function, [install_option[0], package_list, additional_files])) if install_option[0] == 'minimal': default_selected = visible_options_cnt visible_options_cnt = visible_options_cnt + 1 self.package_menu = Menu(self.menu_starty, self.maxx, self.package_menu_items, default_selected=default_selected, tab_enable=False)
def load_package_list(self): json_wrapper_package_list = JsonWrapper("packages_full.json"); package_list_json = json_wrapper_package_list.read() for package in package_list_json["packages"]: self.menu_items.append((package, self.exit_function)) self.package_menu = Menu(self.menu_starty, self.maxx, self.menu_items, height = 18, selector_menu = True)
def main(): usage = os.path.basename(__file__) + "--input-type=[json/pkg/who-needs] --pkg=[pkg_name] --file=<JSON_FILE_NAME> --disp=[tree/list/json]" parser = OptionParser(usage) parser.add_option("-i", "--input-type", dest="input_type", default=DEFAULT_INPUT_TYPE) parser.add_option("-p", "--pkg", dest="pkg") parser.add_option("-f", "--file", dest="json_file", default="packages_minimal.json") parser.add_option("-d", "--disp", dest="display_option", default=DEFAULT_DISPLAY_OPTION) parser.add_option("-s", "--spec-dir", dest="spec_dir", default=SPEC_FILE_DIR) parser.add_option("-t", "--stage-dir", dest="stage_dir", default="../../stage") parser.add_option("-a", "--input-data-dir", dest="input_data_dir", default="../../common/data/") (options, args) = parser.parse_args() if(False == options.input_data_dir.endswith('/')): options.input_data_dir += '/' specDeps = SerializedSpecObjects(options.input_data_dir, options.stage_dir) displayOption = options.display_option abs_path = os.path.abspath(__file__) dir_name = os.path.dirname(abs_path) os.chdir(dir_name) if(options.input_type == "pkg" or options.input_type == "who-needs"): # To display/print package dependencies on console targetName = options.pkg specDeps.readSpecsAndConvertToSerializableObjects(options.spec_dir, options.input_type, targetName, displayOption) elif(options.input_type == "json"):# Generate the expanded package dependencies json file based on package_list_file json_wrapper_option_list = JsonWrapper(options.json_file) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() for install_option in options_sorted: if displayOption == "tree" and install_option[1]["title"] == "ISO Packages": continue specDeps.readSpecsAndConvertToSerializableObjects(options.spec_dir, options.input_type, install_option[1]["file"], displayOption) sys.exit(0)
def main(): usage = "Usage: %prog [options]" parser = ArgumentParser(usage) parser.add_argument("-i", "--input-type", dest="input_type", default=DEFAULT_INPUT_TYPE) parser.add_argument("-p", "--pkg", dest="pkg") parser.add_argument("-f", "--file", dest="json_file", default="packages_minimal.json") parser.add_argument("-d", "--disp", dest="display_option", default=DEFAULT_DISPLAY_OPTION) parser.add_argument("-s", "--spec-dir", dest="spec_dir", default=SPEC_FILE_DIR) parser.add_argument("-l", "--log-dir", dest="log_dir", default=LOG_FILE_DIR) parser.add_argument("-t", "--stage-dir", dest="stage_dir", default="../../stage") parser.add_argument("-a", "--input-data-dir", dest="input_data_dir", default="../../common/data/") parser.add_argument("-o", "--output-dir", dest="output_dir", default="../../stage/common/data") options = parser.parse_args() constants.setSpecPath(options.spec_dir) constants.setLogPath(options.log_dir) constants.initialize() cmdUtils = CommandUtils() if not os.path.isdir(options.output_dir): cmdUtils.runCommandInShell2("mkdir -p "+options.output_dir) if not options.input_data_dir.endswith('/'): options.input_data_dir += '/' try: specDeps = SpecDependencyGenerator() # To display/print package dependencies on console if (options.input_type == "pkg" or options.input_type == "who-needs" or options.input_type == "who-needs-build"): specDeps.process(options.input_type, options.pkg, options.display_option) elif options.input_type == "json": list_json_files = options.json_file.split("\n") # Generate the expanded package dependencies json file based on package_list_file for json_file in list_json_files: shutil.copy2(json_file, options.output_dir) json_wrapper_option_list = JsonWrapper(json_file) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() for install_option in options_sorted: output_file = None input_value = os.path.join(os.path.dirname(json_file), install_option[1]["file"]) if options.display_option == "tree" and install_option[1]["title"] == "ISO Packages": continue if options.display_option == "json": output_file = os.path.join(options.output_dir, install_option[1]["file"]) print ("Generating the install time dependency list for " + json_file) specDeps.process(options.input_type, input_value, options.display_option, output_file) except Exception as e: traceback.print_exc() sys.stderr.write(str(e)) sys.stderr.write("Failed to generate dependency lists from spec files\n") sys.exit(1) sys.stderr.write("Successfully generated dependency lists from spec files\n") sys.exit(0)
def exit_function(self, selected_indexes): json_wrapper_package_list = JsonWrapper("packages_minimal.json"); package_list_json = json_wrapper_package_list.read() selected_items = [] for index in selected_indexes: selected_items.append(self.menu_items[index][0]) self.install_config['packages'] = package_list_json["packages"] + selected_items return ActionResult(True, None)
def create_additional_file_list_to_copy_in_iso(base_path, build_install_option): json_wrapper_option_list = JsonWrapper(build_install_option) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() file_list = [] for install_option in options_sorted: if install_option[1].has_key("additional-files"): file_list = file_list + map(lambda filename: os.path.join(base_path, filename), install_option[1].get("additional-files")) return file_list
def get_packages_to_install(options, config_type): package_list = [] install_option = options[config_type] for include_type in install_option["include"]: package_list = package_list + get_packages_to_install(options, include_type) json_wrapper_package_list = JsonWrapper(install_option["file"]) package_list_json = json_wrapper_package_list.read() package_list = package_list + package_list_json["packages"] return package_list
def get_live_cd_status_string(build_install_option): json_wrapper_option_list = JsonWrapper(build_install_option) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() file_list = [] for install_option in options_sorted: if install_option[1].has_key("live-cd"): if install_option[1].get("live-cd") == True: return "true" return "false"
def load_package_list(self): json_wrapper_package_list = JsonWrapper("package_list.json"); self.package_list_json = json_wrapper_package_list.read() self.package_menu_items = [ ('1. Photon OS (Micro)', self.exit_function, ['micro', self.package_list_json["micro_packages"]]), ('2. Photon Container OS (Minimal)', self.exit_function, ['minimal', self.package_list_json["minimal_packages"]]), ('3. Photon Full OS (All)', self.exit_function, ['full', self.package_list_json["minimal_packages"] + self.package_list_json["optional_packages"]]), ('4. Photon Custom OS', self.custom_packages, ['custom', None]) ] self.package_menu = Menu(self.menu_starty, self.maxx, self.package_menu_items)
def get_packages_to_install(options, config_type, output_data_path): package_list = [] for install_option in options: if install_option[0] == config_type: for include_type in install_option[1]["include"]: package_list = package_list + PackageSelector.get_packages_to_install(options, include_type, output_data_path) json_wrapper_package_list = JsonWrapper(os.path.join(output_data_path, install_option[1]["file"])) package_list_json = json_wrapper_package_list.read() package_list = package_list + package_list_json["packages"] break return package_list
def create_rpm_list_to_copy_in_iso(build_install_option): base_path = os.path.dirname(build_install_option) json_wrapper_option_list = JsonWrapper(build_install_option) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() packages = [] for install_option in options_sorted: file_path = os.path.join(base_path, install_option[1]["file"]) json_wrapper_package_list = JsonWrapper(file_path) package_list_json = json_wrapper_package_list.read() packages = packages + package_list_json["packages"] return packages
def get_packages_to_install(options, base_path, config_type): package_list = [] for install_option in options: if install_option[0] == config_type: if install_option[1]["include"] != "none": for include_type in install_option[1]["include"].split(','): package_list = package_list + PackageSelector.get_packages_to_install(options, base_path, include_type) json_wrapper_package_list = JsonWrapper(os.path.join(base_path, install_option[1]["file"])) package_list_json = json_wrapper_package_list.read() package_list = package_list + package_list_json["packages"] break return package_list
def create_pkg_list_to_copy_to_iso(build_install_option, output_data_path): json_wrapper_option_list = JsonWrapper(build_install_option) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() packages = [] for install_option in options_sorted: if install_option[0] != "iso": file_path = os.path.join(output_data_path, install_option[1]["file"]) json_wrapper_package_list = JsonWrapper(file_path) package_list_json = json_wrapper_package_list.read() packages = packages + package_list_json["packages"] return packages
def load_package_list(self, options_file): json_wrapper_option_list = JsonWrapper(options_file) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() self.package_menu_items = [] base_path = os.path.dirname(options_file) package_list = [] for install_option in options_sorted: if install_option[1]["visible"] == True: package_list = PackageSelector.get_packages_to_install(options_sorted, base_path, install_option[0]) self.package_menu_items.append((install_option[1]["title"], self.exit_function, [install_option[0], package_list] )) self.package_menu = Menu(self.menu_starty, self.maxx, self.package_menu_items)
def get_config(self, path): if path.startswith("http://"): # Do 5 trials to get the kick start # TODO: make sure the installer run after network is up wait = 1 for x in range(0, 5): err_msg = "" try: response = requests.get(path, timeout=3) if response.ok: return json.loads(response.text) err_msg = response.text except Exception as e: err_msg = e modules.commons.log( modules.commons.LOG_ERROR, "Failed to get the kickstart file at {0}, error msg: {1}". format(path, err_msg)) print "Failed to get the kickstart file at {0}, retry in a second".format( path) time.sleep(wait) wait = wait * 2 # Something went wrong print "Failed to get the kickstart file at {0}, exiting the installer, check the logs for more details".format( path) raise Exception(err_msg) else: if path.startswith("cdrom:/"): self.mount_RPMS_cd() path = os.path.join(self.cd_path, path.replace("cdrom:/", "", 1)) return (JsonWrapper(path)).read()
async def handle(self, websocket, path): data = await websocket.recv() print(f"Client < \t {data}") data = json.loads(data) action = data["Message"] if (action == "!join"): username = new_user(JsonWrapper(data)) data_to_send = join_user(username) elif (action == "!gather"): data_to_send = gather(JsonWrapper(data)) elif (action == "!inventory"): data_to_send = get_user_inventory(JsonWrapper(data)) elif (action == "!ship"): data_to_send = buy_ship(JsonWrapper(data)) elif (action == "!upgrade"): data_to_send = buy_upgrade(JsonWrapper(data)) elif (action == "!deposit"): data_to_send = deposit(JsonWrapper(data)) elif (action == "!login"): data_to_send = login(JsonWrapper(data)) # elif(action == "!move"): # data_to_send = move(JsonWrapper(data)) else: await websocket.send( "Failed, the server did not understand the Message content: " + json.dumps(data)) return (False) print(f"Server > \t {data_to_send} \n") await websocket.send(json.dumps(data_to_send)) return (True)
def copy_rpms(self): # prepare the RPMs list json_pkg_to_rpm_map = JsonWrapper(self.install_config["pkg_to_rpm_map_file"]) pkg_to_rpm_map = json_pkg_to_rpm_map.read() self.rpms_tobeinstalled = [] selected_packages = self.install_config['packages'] for pkg in selected_packages: if pkg in pkg_to_rpm_map: if not pkg_to_rpm_map[pkg]['rpm'] is None: name = pkg_to_rpm_map[pkg]['rpm'] basename = os.path.basename(name) self.rpms_tobeinstalled.append({'filename': basename, 'path': name, 'package' : pkg}) # Copy the rpms for rpm in self.rpms_tobeinstalled: shutil.copy(rpm['path'], self.photon_root + '/RPMS/')
def get_packages_to_install(option, output_data_path): if 'packagelist_file' in option: json_wrapper_package_list = JsonWrapper( os.path.join(output_data_path, option['packagelist_file'])) package_list_json = json_wrapper_package_list.read() platform_packages = "packages_" + platform.machine() if platform_packages in package_list_json: return package_list_json["packages"] + package_list_json[ platform_packages] return package_list_json["packages"] elif 'packages' in option: return option["packages"] else: raise Exception( "Install option '" + option['title'] + "' must have 'packagelist_file' or 'packages' property")
def ks_config(self, options_file, ks_config): """Load configuration from file""" del options_file install_config = ks_config install_config['iso_system'] = False if self.is_vmware_virtualization() and 'install_linux_esx' not in install_config: install_config['install_linux_esx'] = True json_wrapper_option_list = JsonWrapper("build_install_options_all.json") option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() base_path = os.path.dirname("build_install_options_all.json") package_list = [] package_list = PackageSelector.get_packages_to_install(options_sorted, install_config['type'], base_path) if 'additional_packages' in install_config: package_list.extend(install_config['additional_packages']) install_config['packages'] = package_list if 'partitions' in install_config: partitions = install_config['partitions'] else: partitions = modules.commons.default_partitions install_config['disk'] = modules.commons.partition_disk(install_config['disk'], partitions) if "hostname" in install_config: evalhostname = os.popen('printf ' + install_config["hostname"].strip(" ")).readlines() install_config['hostname'] = evalhostname[0] if "hostname" not in install_config or install_config['hostname'] == "": install_config['hostname'] = "photon-" + self.random_id.strip() # crypt the password if needed if install_config['password']['crypted']: install_config['password'] = install_config['password']['text'] else: install_config['password'] = crypt.crypt( install_config['password']['text'], "$6$" + "".join([random.choice( string.ascii_letters + string.digits) for _ in range(16)])) return install_config
def get_packages_to_install(options, config_type, output_data_path): package_list = [] for install_option in options: if install_option[0] == config_type: for include_type in install_option[1]["include"]: package_list = ( package_list + PackageSelector.get_packages_to_install( options, include_type, output_data_path)) json_wrapper_package_list = JsonWrapper( os.path.join(output_data_path, install_option[1]["file"])) package_list_json = json_wrapper_package_list.read() package_list = package_list + package_list_json["packages"] if "remove" in install_option[1]: for package in install_option[1]["remove"]: package_list.remove(package) break return package_list
def create_rpm_list_to_be_copied_to_iso(pkg_to_rpm_map_file, build_install_option, copy_flags, output_data_path): packages = [] if build_install_option is None: packages = [] else: packages = create_pkg_list_to_copy_to_iso(build_install_option, output_data_path) rpm_list = [] json_pkg_to_rpm_map = JsonWrapper(pkg_to_rpm_map_file) pkg_to_rpm_map = json_pkg_to_rpm_map.read() for k in pkg_to_rpm_map: if build_install_option is None or k in packages: if not pkg_to_rpm_map[k]['rpm'] is None and bool(copy_flags & 1): filename = pkg_to_rpm_map[k]['rpm'] rpm_list.append(get_file_name_with_last_folder(filename)) if not pkg_to_rpm_map[k]['debugrpm'] is None and bool(copy_flags & 2): filename = pkg_to_rpm_map[k]['debugrpm'] rpm_list.append(pkg_to_rpm_map[k]['debugrpm']) if not pkg_to_rpm_map[k]['sourcerpm'] is None and bool(copy_flags & 4): rpm_list.append(pkg_to_rpm_map[k]['sourcerpm']) return rpm_list
def execute(name, ks_config, config, root): if ks_config: options = JsonWrapper("build_install_options_all.json").read() packages = get_packages_to_install(options, ks_config['type']) if 'additional_packages' in ks_config: packages.extend(ks_config['additional_packages']) config['type'] = ks_config['type'] config["packages"] = packages
def _copy_rpms(self): """ Prepare RPM list and copy rpms """ # prepare the RPMs list json_pkg_to_rpm_map = JsonWrapper(self.install_config["pkg_to_rpm_map_file"]) pkg_to_rpm_map = json_pkg_to_rpm_map.read() self.rpms_tobeinstalled = [] selected_packages = self.install_config['packages'] for pkg in selected_packages: if pkg in pkg_to_rpm_map: if pkg_to_rpm_map[pkg]['rpm'] is not None: name = pkg_to_rpm_map[pkg]['rpm'] basename = os.path.basename(name) self.rpms_tobeinstalled.append({'filename': basename, 'path': name, 'package' : pkg}) # Copy the rpms for rpm in self.rpms_tobeinstalled: shutil.copy(rpm['path'], self.photon_root + '/RPMS/')
def _create_installrpms_list(self): """ Prepare RPM list and copy rpms """ # prepare the RPMs list json_pkg_to_rpm_map = JsonWrapper(self.install_config["pkg_to_rpm_map_file"]) pkg_to_rpm_map = json_pkg_to_rpm_map.read() self.rpms_tobeinstalled = [] selected_packages = self.install_config['packages'] for pkg in selected_packages: versionindex = pkg.rfind("-") if versionindex == -1: raise Exception("Invalid pkg name: " + pkg) package = pkg[:versionindex] if pkg in pkg_to_rpm_map: if pkg_to_rpm_map[pkg]['rpm'] is not None: name = pkg_to_rpm_map[pkg]['rpm'] basename = os.path.basename(name) self.rpms_tobeinstalled.append({'filename': basename, 'path': name, 'package' : package})
def load_package_list(self, options_file): json_wrapper_option_list = JsonWrapper(options_file) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() self.package_menu_items = [] base_path = os.path.dirname(options_file) package_list = [] default_selected = 0 visible_options_cnt = 0 for install_option in options_sorted: if install_option[1]["visible"] == True: package_list = PackageSelector.get_packages_to_install(options_sorted, install_option[0], base_path) additional_files = PackageSelector.get_additional_files_to_copy_in_iso(options_sorted, base_path, install_option[0]) self.package_menu_items.append((install_option[1]["title"], self.exit_function, [install_option[0], package_list, additional_files] )) if install_option[0] == 'minimal': default_selected = visible_options_cnt visible_options_cnt = visible_options_cnt + 1 self.package_menu = Menu(self.menu_starty, self.maxx, self.package_menu_items, default_selected = default_selected, tab_enable=False)
def ks_config(self, options_file, ks_config): install_config = ks_config install_config['iso_system'] = False if self.is_vmware_virtualization() and 'install_linux_esx' not in install_config: install_config['install_linux_esx'] = True json_wrapper_option_list = JsonWrapper("build_install_options_all.json") option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() base_path = os.path.dirname("build_install_options_all.json") package_list = [] package_list = PackageSelector.get_packages_to_install(options_sorted, install_config['type'], base_path) if 'additional_packages' in install_config: package_list.extend(install_config['additional_packages']) install_config['packages'] = package_list if 'partitions' in install_config: partitions = install_config['partitions'] else: partitions = modules.commons.default_partitions install_config['disk'] = modules.commons.partition_disk(install_config['disk'], partitions) if "hostname" in install_config: evalhostname = os.popen('printf ' + install_config["hostname"].strip(" ")).readlines() install_config['hostname'] = evalhostname[0] if "hostname" not in install_config or install_config['hostname'] == "": random_id = '%12x' % random.randrange(16**12) install_config['hostname'] = "photon-" + random_id.strip() # crypt the password if needed if install_config['password']['crypted']: install_config['password'] = install_config['password']['text'] else: install_config['password'] = crypt.crypt(install_config['password']['text'], "$6$" + "".join([random.choice(string.ascii_letters + string.digits) for _ in range(16)])) return install_config
def load_package_list(self, options_file): json_wrapper_option_list = JsonWrapper(options_file) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() self.package_menu_items = [] base_path = os.path.dirname(options_file) package_list = [] if len(options_sorted) == 1: self.inactive_screen = True list(options_sorted)[0][1]['visible'] = True if platform.machine() == "aarch64" and 'realtime' in dict( options_sorted): dict(options_sorted)['realtime']['visible'] = False default_selected = 0 visible_options_cnt = 0 for install_option in options_sorted: if install_option[1]["visible"] == True: package_list = PackageSelector.get_packages_to_install( install_option[1], base_path) self.package_menu_items.append( (install_option[1]["title"], self.exit_function, [install_option[0], package_list])) if install_option[0] == 'minimal': default_selected = visible_options_cnt visible_options_cnt = visible_options_cnt + 1 if self.inactive_screen: self.exit_function(self.package_menu_items[0][2]) else: self.package_menu = Menu(self.menu_starty, self.maxx, self.package_menu_items, default_selected=default_selected, tab_enable=False)
def __init__(self, options): install_config=None self.media_mount_path = None photon_media = None ks_path = options.install_config_file # Path to RPMS repository: local media or remote URL # If --repo-path= provided - use it, # if not provided - use kernel repo= parameter, # if not provided - use /RPMS path from photon_media, # exit otherwise. repo_path = options.repo_path with open('/proc/cmdline', 'r') as f: kernel_params = shlex.split(f.read().replace('\n', '')) for arg in kernel_params: if arg.startswith("ks="): if not ks_path: ks_path = arg[len("ks="):] elif arg.startswith("repo="): if not repo_path: repo_path = arg[len("repo="):] elif arg.startswith("photon.media="): photon_media = arg[len("photon.media="):] if photon_media: self.mount_media(photon_media) if not repo_path: if self.media_mount_path: repo_path = self.media_mount_path + "/RPMS" else: print("Please specify RPM repo path.") return if ks_path: install_config=self._load_ks_config(ks_path) if options.ui_config_file: ui_config = (JsonWrapper(options.ui_config_file)).read() else: ui_config={} ui_config['options_file'] = options.options_file # Run installer installer = Installer(rpm_path=repo_path, log_path="/var/log") installer.configure(install_config, ui_config) installer.execute()
def execute(name, ks_config, config, root): if ks_config: package_list = JsonWrapper("package_list.json").read() if ks_config['type'] == 'micro': packages = package_list["micro_packages"] elif ks_config['type'] == 'minimal': packages = package_list["minimal_packages"] elif ks_config['type'] == 'full': packages = package_list["minimal_packages"] + package_list["optional_packages"] else: #TODO: error packages = [] config['type'] = ks_config['type'] config["packages"] = packages
def create_rpm_list_to_copy_in_iso(build_install_option, output_data_path): json_wrapper_option_list = JsonWrapper(build_install_option) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() packages = [] for install_option in options_sorted: if install_option[0] != "iso": file_path = os.path.join(output_data_path, install_option[1]["file"]) json_wrapper_package_list = JsonWrapper(file_path) package_list_json = json_wrapper_package_list.read() packages = packages + package_list_json["packages"] return packages
def _load_ks_config(self, path): """kick start configuration""" if path.startswith("http://") and not self.insecure_installation: raise Exception( "Refusing to download kick start configuration from non-https URLs. \ \nPass insecure_installation=1 as a parameter when giving http url in ks." ) if path.startswith("https://") or path.startswith("http://"): # Do 5 trials to get the kick start # TODO: make sure the installer run after network is up ks_file_error = "Failed to get the kickstart file at {0}".format( path) wait = 1 for _ in range(0, 5): err_msg = "" try: if self.insecure_installation: response = requests.get(path, timeout=3, verify=False) else: response = requests.get(path, timeout=3, verify=True) except Exception as e: err_msg = e else: return json.loads(response.text) print("error msg: {0} Retry after {1} seconds".format( err_msg, wait)) time.sleep(wait) wait = wait * 2 # Something went wrong print(ks_file_error) raise Exception(err_msg) else: if path.startswith("cdrom:/"): if self.media_mount_path is None: raise Exception( "cannot read ks config from cdrom, no cdrom specified") path = os.path.join(self.media_mount_path, path.replace("cdrom:/", "", 1)) elif not path.startswith("/"): path = os.path.join(os.getcwd(), path) return (JsonWrapper(path)).read()
def __init__(self, options): install_config = None self.cd_mount_path = None cd_search = None ks_path = options.install_config_file repo_path = options.repo_path with open('/proc/cmdline', 'r') as f: kernel_params = shlex.split(f.read().replace('\n', '')) for arg in kernel_params: if arg.startswith("ks="): if not ks_path: ks_path = arg[len("ks="):] elif arg.startswith("repo="): if not repo_path: repo_path = arg[len("repo="):] elif arg.startswith("photon.media="): cd_search = arg[len("photon.media="):] if not repo_path: print("Please specify RPM repo path.") return if cd_search: self.mount_cd(cd_search) if ks_path: install_config = self._load_ks_config(ks_path) if options.ui_config_file: ui_config = (JsonWrapper(options.ui_config_file)).read() else: ui_config = {} ui_config['options_file'] = options.options_file # Run installer installer = Installer(rpm_path=repo_path, log_path="/var/log") installer.configure(install_config, ui_config) installer.execute()
def get_config(self, path): """kick start configuration""" if path.startswith("http://"): # Do 5 trials to get the kick start # TODO: make sure the installer run after network is up ks_file_error = "Failed to get the kickstart file at {0}".format( path) wait = 1 for _ in range(0, 5): err_msg = "" try: response = requests.get(path, timeout=3) if response.ok: return json.loads(response.text) err_msg = response.text except Exception as e: err_msg = e modules.commons.log(modules.commons.LOG_ERROR, ks_file_error) modules.commons.log(modules.commons.LOG_ERROR, "error msg: {0}".format(err_msg)) print(ks_file_error) print("retry in a second") time.sleep(wait) wait = wait * 2 # Something went wrong print(ks_file_error) print("exiting the installer, check the logs for more details") raise Exception(err_msg) else: if path.startswith("cdrom:/"): if self.cd_mount_path is None: raise Exception( "cannot read ks config from cdrom, no cdrom specified") path = os.path.join(self.cd_mount_path, path.replace("cdrom:/", "", 1)) return (JsonWrapper(path)).read()
def prepare_files_rpms_list(self): self.total_size = 0 self.install_factor = 3 tools_list = (JsonWrapper("tools_list.json")).read() tools = tools_list['base_tools'] # Add the additional iso tools. if self.install_config['iso_system']: tools = tools + tools_list['iso_tools'] self.files_tobecopied = [] for item in tools: src = os.path.join(self.scripts_working_directory, item) if os.path.isfile(src): if item != '.hidden': size = os.path.getsize(src) self.total_size += size self.files_tobecopied.append({ 'name': item, 'path': src, 'size': size }) continue for root, dirs, files in os.walk(src): for name in files: file = os.path.join(root, name) size = os.path.getsize(file) self.total_size += size relative = None if name.endswith(".rpm"): relative = os.path.relpath(file, self.rpm_path) relative = os.path.join("RPMS", relative) self.files_tobecopied.append({ 'name': name, 'path': file, 'relative_path': relative, 'size': size }) # prepare the RPMs # TODO: mbassiouny, do not copy the rpms twice rpms = [] for root, dirs, files in os.walk( os.path.join(self.scripts_working_directory, self.rpm_path)): for name in files: file = os.path.join(root, name) size = os.path.getsize(file) relative = os.path.relpath(file, self.rpm_path) relative = os.path.join("RPMS", relative) rpms.append({ 'name': name, 'path': file, 'relative_path': relative, 'size': size }) self.rpms_tobeinstalled = [] # prepare the RPMs list selected_packages = self.install_config['packages'] for package in selected_packages: pattern = package + '-[0-9]*.rpm' for rpm in rpms: if fnmatch.fnmatch(rpm['name'], pattern): rpm['package'] = package self.rpms_tobeinstalled.append(rpm) self.total_size += rpm[ 'size'] + rpm['size'] * self.install_factor break
def main(): usage = ( os.path.basename(__file__) + "--input-type=[json/pkg/who-needs/who-needs-build] " + "--pkg=[pkg_name] --file=<JSON_FILE_NAME> --disp=[tree/list/json]") parser = OptionParser(usage) parser.add_option("-i", "--input-type", dest="input_type", default=DEFAULT_INPUT_TYPE) parser.add_option("-p", "--pkg", dest="pkg") parser.add_option("-f", "--file", dest="json_file", default="packages_minimal.json") parser.add_option("-d", "--disp", dest="display_option", default=DEFAULT_DISPLAY_OPTION) parser.add_option("-s", "--spec-dir", dest="spec_dir", default=SPEC_FILE_DIR) parser.add_option("-t", "--stage-dir", dest="stage_dir", default="../../stage") parser.add_option("-a", "--input-data-dir", dest="input_data_dir", default="../../common/data/") (options, args) = parser.parse_args() if not options.input_data_dir.endswith('/'): options.input_data_dir += '/' try: specDeps = SerializedSpecObjects(options.input_data_dir, options.stage_dir) displayOption = options.display_option abs_path = os.path.abspath(__file__) dir_name = os.path.dirname(abs_path) os.chdir(dir_name) # To display/print package dependencies on console if (options.input_type == "pkg" or options.input_type == "who-needs" or options.input_type == "who-needs-build"): targetName = options.pkg specDeps.readSpecsAndConvertToSerializableObjects( options.spec_dir, options.input_type, targetName, displayOption) elif (options.input_type == "json"): # Generate the expanded package dependencies json file based on package_list_file json_wrapper_option_list = JsonWrapper(options.json_file) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() for install_option in options_sorted: if displayOption == "tree" and install_option[1][ "title"] == "ISO Packages": continue specDeps.readSpecsAndConvertToSerializableObjects( options.spec_dir, options.input_type, install_option[1]["file"], displayOption) except Exception as error: sys.stderr.write( "Failed to generate dependency lists from spec files\n") sys.exit(1) sys.stderr.write( "Successfully generated dependency lists from spec files\n") sys.exit(0)
def __init__(self, options): install_config=None self.media_mount_path = None photon_media = None ks_path = options.install_config_file # Path to RPMS repository: local media or remote URL # If --repo-path= provided - use it, # if not provided - use kernel repo= parameter, # if not provided - use /RPMS path from photon_media, # exit otherwise. repo_path = options.repo_path self.insecure_installation = None with open('/proc/cmdline', 'r') as f: kernel_params = shlex.split(f.read().replace('\n', '')) for arg in kernel_params: if arg.startswith("ks="): if not ks_path: ks_path = arg[len("ks="):] elif arg.startswith("repo="): if not repo_path: repo_path = arg[len("repo="):] elif arg.startswith("photon.media="): photon_media = arg[len("photon.media="):] elif arg.startswith("insecure_installation="): self.insecure_installation = bool(int(arg[len("insecure_installation="):])) if photon_media: self.mount_media(photon_media) if not repo_path: if self.media_mount_path: repo_path = self.media_mount_path + "/RPMS" else: print("Please specify RPM repo path.") return if ks_path: install_config = self._load_ks_config(ks_path) # insecure_installation flag added through commandline overrides that of ks_config if self.insecure_installation: if not install_config: install_config = {} install_config['insecure_installation'] = self.insecure_installation if not install_config: install_config = {} install_config['photon_release_version'] = options.photon_release_version if options.ui_config_file: ui_config = (JsonWrapper(options.ui_config_file)).read() else: ui_config={} ui_config['options_file'] = options.options_file #initializing eula file path ui_config['eula_file_path'] = options.eula_file_path #initializing license display text ui_config['license_display_title'] = options.license_display_title # Run installer installer = Installer(rpm_path=repo_path, log_path="/var/log") installer.configure(install_config, ui_config) installer.execute()
def __init__(self, stdscreen, argv): self.screen = stdscreen if len(argv) == 2: local_install = True else: local_install = False # Init the colors curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE) curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_GREEN) curses.init_pair(4, curses.COLOR_RED, curses.COLOR_WHITE) self.screen.bkgd(' ', curses.color_pair(1)) self.maxy, self.maxx = self.screen.getmaxyx() self.screen.addstr(self.maxy - 1, 0, '<Tab> moves; <Space> selects; <Enter> forward') curses.curs_set(0) self.install_config = {} license_agreement = License(self.maxy, self.maxx) # skip the disk selection and partitioning if we are running with conf file in test environment. if local_install == True: # Read the conf file self.install_config = (JsonWrapper(argv[1])).read() self.install_config['iso_system'] = False else: self.install_config['iso_system'] = False disk_partitioner = DiskPartitioner(self.maxy, self.maxx) select_disk = SelectDisk(self.maxy, self.maxx, self.install_config) package_selector = PackageSelector(self.maxy, self.maxx, self.install_config) custom_package_selector = CustomPackageSelector( self.maxy, self.maxx, self.install_config) hostname_reader = WindowStringReader( self.maxy, self.maxx, 10, 70, False, 'Choose the hostname for your system', 'Hostname:', 2, self.install_config) root_password_reader = WindowStringReader(self.maxy, self.maxx, 10, 70, True, 'Set up root password', 'Root password:', 2, self.install_config) installer = Installer(self.install_config, self.maxy, self.maxx, True, local_install, tools_path="/usr/src/photon", rpm_path="/usr/src/photon/RPMS", log_path="/var/log") # This represents the installer screen, the bool indicated if I can go back to this window or not items = [(package_selector.display, True), (custom_package_selector.display, False), (hostname_reader.get_user_string, True), (root_password_reader.get_user_string, True), (installer.install, False)] # Include disk selection and partitioning in state machine when there is no extra param. if local_install == False: items = [ #(disk_partitioner.display, True), (select_disk.display, True) ] + items items = [(license_agreement.display, False)] + items index = 0 params = None while True: result = items[index][0](params) if result.success: index += 1 params = result.result if index == len(items): break else: index -= 1 while index >= 0 and items[index][1] == False: index -= 1 if index < 0: index = 0
def get_packages_to_install(packagelist_file, output_data_path): json_wrapper_package_list = JsonWrapper( os.path.join(output_data_path, packagelist_file)) package_list_json = json_wrapper_package_list.read() return package_list_json["packages"]
# Read the conf file config = (JsonWrapper(options.configfile)).read() config['iso_system'] = False config['vmdk_install'] = False config["pkg_to_rpm_map_file"] = options.pkg_to_rpm_map_file if 'password' in config: # crypt the password if needed if config['password']['crypted']: config['password'] = config['password']['text'] else: config['password'] = crypt.crypt(config['password']['text'], "$6$" + "".join([random.choice(string.ascii_letters + string.digits) for _ in range(16)])) # Check the installation type json_wrapper_option_list = JsonWrapper(options.package_list_file) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() packages = [] packages = PackageSelector.get_packages_to_install(options_sorted, config['type'], options.output_data_path) config['packages'] = packages if (os.path.isdir(options.working_directory)): process = subprocess.Popen(['rm', '-rf', options.working_directory]) retval = process.wait() process = subprocess.Popen(['mkdir', '-p', os.path.join(options.working_directory, "photon-chroot")]) retval = process.wait()
(options, args) = parser.parse_args() if options.iso_path: # Check the arguments if (len(args)) != 0: parser.error("Incorrect arguments") config = {} config['iso_system'] = True elif options.vmdk_path: # Check the arguments if (len(args)) != 1: parser.error("Incorrect arguments") # Read the conf file config = (JsonWrapper(args[0])).read() config['disk'], success = create_vmdk_and_partition( config, options.vmdk_path) if not success: print "Unexpected failure, please check the logs" sys.exit(1) config['iso_system'] = False config['vmdk_install'] = True else: # Check the arguments if (len(args)) != 1: parser.error("Incorrect arguments") # Read the conf file
if options.iso_path: # Check the arguments if options.configfile: parser.error("Incorrect arguments") config = {} config['iso_system'] = True config['vmdk_install'] = False config['type'] = 'iso' elif options.vmdk_path: # Check the arguments if not options.configfile: parser.error("Incorrect arguments") # Read the conf file config = (JsonWrapper(options.configfile)).read() config['disk'], success = create_vmdk_and_partition( config, options.vmdk_path) if not success: print "Unexpected failure, please check the logs" sys.exit(1) config['iso_system'] = False config['vmdk_install'] = True else: # Check the arguments if not options.configfile: parser.error("Incorrect arguments") # Read the conf file
(options, args) = parser.parse_args() if options.iso_path or options.src_iso_path: # Check the arguments if (len(args)) != 0: parser.error("Incorrect arguments") config = {} config['iso_system'] = True config['vmdk_install'] = False elif options.vmdk_path: # Check the arguments if (len(args)) != 1: parser.error("Incorrect arguments") # Read the conf file config = (JsonWrapper(args[0])).read() config['disk'], success = create_vmdk_and_partition(config, options.vmdk_path) if not success: print "Unexpected failure, please check the logs" sys.exit(1) config['initrd_dir'] = "/boot" config['iso_system'] = False config['vmdk_install'] = True else: # Check the arguments if (len(args)) != 1: parser.error("Incorrect arguments")
parser.error("Incorrect arguments") # Read the conf file config = (JsonWrapper(args[0])).read() config['iso_system'] = False if 'password' in config: # crypt the password if needed if config['password']['crypted']: config['password'] = config['password']['text'] else: config['password'] = crypt.crypt(config['password']['text'], "$6$" + "".join([random.choice(string.ascii_letters + string.digits) for _ in range(16)])) # Check the installation type json_wrapper_option_list = JsonWrapper(options.package_list_file) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() base_path = os.path.dirname(options.package_list_file) packages = [] if config['iso_system'] == True: for install_option in options_sorted: if install_option[0] == "iso": json_wrapper_package_list = JsonWrapper(os.path.join(base_path, install_option[1]["file"])) package_list_json = json_wrapper_package_list.read() packages = package_list_json["packages"] else: packages = PackageSelector.get_packages_to_install(options_sorted, base_path, config['type']) config['packages'] = packages
def main(): usage = "Usage: %prog [options]" parser = ArgumentParser(usage) parser.add_argument("-i", "--input-type", dest="input_type", default=DEFAULT_INPUT_TYPE) parser.add_argument("-p", "--pkg", dest="pkg") parser.add_argument("-f", "--file", dest="json_file", default="packages_minimal.json") parser.add_argument("-d", "--display-option", dest="display_option", default=DEFAULT_DISPLAY_OPTION) parser.add_argument("-s", "--spec-path", dest="spec_path", default=SPEC_FILE_DIR) parser.add_argument("-l", "--log-path", dest="log_path", default=LOG_FILE_DIR) parser.add_argument("-y", "--log-level", dest="log_level", default="info") parser.add_argument("-t", "--stage-dir", dest="stage_dir", default="../../stage") parser.add_argument("-a", "--input-data-dir", dest="input_data_dir", default="../../common/data/") parser.add_argument("-o", "--output-dir", dest="output_dir", default="../../stage/common/data") options = parser.parse_args() constants.setSpecPath(options.spec_path) constants.setLogPath(options.log_path) constants.setLogLevel(options.log_level) constants.initialize() cmdUtils = CommandUtils() logger = Logger.getLogger("SpecDeps", options.log_path, options.log_level) if not os.path.isdir(options.output_dir): cmdUtils.runCommandInShell2("mkdir -p "+options.output_dir) if not options.input_data_dir.endswith('/'): options.input_data_dir += '/' try: specDeps = SpecDependencyGenerator(options.log_path, options.log_level) if options.input_type == "remove-upward-deps": whoNeedsList = specDeps.process("get-upward-deps", options.pkg, options.display_option) logger.info("Removing upward dependencies: " + str(whoNeedsList)) for pkg in whoNeedsList: package, version = StringUtils.splitPackageNameAndVersion(pkg) release = SPECS.getData().getRelease(package, version) for p in SPECS.getData().getPackages(package,version): buildarch=SPECS.getData().getBuildArch(p, version) rpmFile = "stage/RPMS/" + buildarch + "/" + p + "-" + version + "-" + release + ".*" + buildarch+".rpm" cmdUtils.runCommandInShell2("rm -f "+rpmFile) elif options.input_type == "print-upward-deps": whoNeedsList = specDeps.process("get-upward-deps", options.pkg, options.display_option) logger.info("Upward dependencies: " + str(whoNeedsList)) # To display/print package dependencies on console elif (options.input_type == "pkg" or options.input_type == "who-needs"): specDeps.process(options.input_type, options.pkg, options.display_option) elif options.input_type == "json": list_json_files = options.json_file.split("\n") # Generate the expanded package dependencies json file based on package_list_file logger.info("Generating the install time dependency list for all json files") for json_file in list_json_files: shutil.copy2(json_file, options.output_dir) json_wrapper_option_list = JsonWrapper(json_file) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() for install_option in options_sorted: output_file = None input_value = os.path.join(os.path.dirname(json_file), install_option[1]["file"]) if options.display_option == "tree" and install_option[1]["title"] == "ISO Packages": continue if options.display_option == "json": output_file = os.path.join(options.output_dir, install_option[1]["file"]) specDeps.process(options.input_type, input_value, options.display_option, output_file) except Exception as e: traceback.print_exc() sys.stderr.write(str(e)) sys.stderr.write("Failed to generate dependency lists from spec files\n") sys.exit(1) sys.exit(0)
def main(): usage = "Usage: %prog [options]" parser = ArgumentParser(usage) parser.add_argument("-i", "--input-type", dest="input_type", default=DEFAULT_INPUT_TYPE) parser.add_argument("-p", "--pkg", dest="pkg") parser.add_argument("-f", "--file", dest="json_file", default="packages_minimal.json") parser.add_argument("-d", "--disp", dest="display_option", default=DEFAULT_DISPLAY_OPTION) parser.add_argument("-s", "--spec-dir", dest="spec_dir", default=SPEC_FILE_DIR) parser.add_argument("-l", "--log-dir", dest="log_dir", default=LOG_FILE_DIR) parser.add_argument("-t", "--stage-dir", dest="stage_dir", default="../../stage") parser.add_argument("-a", "--input-data-dir", dest="input_data_dir", default="../../common/data/") parser.add_argument("-o", "--output-dir", dest="output_dir", default="../../stage/common/data") options = parser.parse_args() constants.setSpecPath(options.spec_dir) constants.setLogPath(options.log_dir) constants.initialize() cmdUtils = CommandUtils() if not os.path.isdir(options.output_dir): cmdUtils.runCommandInShell2("mkdir -p " + options.output_dir) if not options.input_data_dir.endswith('/'): options.input_data_dir += '/' try: specDeps = SpecDependencyGenerator() # To display/print package dependencies on console if (options.input_type == "pkg" or options.input_type == "who-needs" or options.input_type == "who-needs-build"): specDeps.process(options.input_type, options.pkg, options.display_option) elif options.input_type == "json": list_json_files = options.json_file.split("\n") # Generate the expanded package dependencies json file based on package_list_file for json_file in list_json_files: shutil.copy2(json_file, options.output_dir) json_wrapper_option_list = JsonWrapper(json_file) option_list_json = json_wrapper_option_list.read() options_sorted = option_list_json.items() for install_option in options_sorted: output_file = None input_value = os.path.join(os.path.dirname(json_file), install_option[1]["file"]) if options.display_option == "tree" and install_option[1][ "title"] == "ISO Packages": continue if options.display_option == "json": output_file = os.path.join(options.output_dir, install_option[1]["file"]) print("Generating the install time dependency list for " + json_file) specDeps.process(options.input_type, input_value, options.display_option, output_file) except Exception as e: traceback.print_exc() sys.stderr.write(str(e)) sys.stderr.write( "Failed to generate dependency lists from spec files\n") sys.exit(1) sys.stderr.write( "Successfully generated dependency lists from spec files\n") sys.exit(0)