Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
    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/')
Ejemplo n.º 3
0
    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:
            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})

        # Copy the rpms
        for rpm in self.rpms_tobeinstalled:
            shutil.copy(rpm['path'], self.photon_root + '/RPMS/')
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
    def _load_ks_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

                print(ks_file_error)
                print("error msg: {0}".format(err_msg))
                print("retry in a second")
                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))
            return (JsonWrapper(path)).read()
Ejemplo n.º 6
0
    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(install_option[1],
                                                                       base_path)
                additional_files = PackageSelector.get_additional_files_to_copy_in_iso(
                    install_option, base_path)
                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)
Ejemplo n.º 7
0
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(get_file_name_with_last_folder(filename))
            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
Ejemplo n.º 8
0
    def get_config(self, path):
        if path.startswith("http://"):
            # Do 3 trials to get the kick start
            # TODO: make sure the installer run after network is up
            for x in range(0, 3):
                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(1)

            # 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()
Ejemplo n.º 9
0
    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:
            if 'packagelist_file' not in self.install_config:
                self.install_config['packagelist_file'] = list(
                    options_sorted)[0][1]['packagelist_file']
                list(options_sorted)[0][1]['visible'] = True

        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

        self.package_menu = Menu(self.menu_starty,
                                 self.maxx,
                                 self.package_menu_items,
                                 default_selected=default_selected,
                                 tab_enable=False)
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
 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()
         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")
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
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"
Ejemplo n.º 15
0
    def ks_install(self, options_file, rpm_path, 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)
                ]))

        installer = InstallerContainer(install_config,
                                       self.maxy,
                                       self.maxx,
                                       True,
                                       rpm_path=rpm_path,
                                       log_path="/var/log")

        installer.install(None)
Ejemplo n.º 16
0
 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
Ejemplo n.º 17
0
    def load_package_list(self):
        json_wrapper_package_list = JsonWrapper("package_list.json")
        self.package_list_json = json_wrapper_package_list.read()

        for package in self.package_list_json["optional_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)
Ejemplo n.º 18
0
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
Ejemplo n.º 19
0
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
Ejemplo n.º 20
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

        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()
Ejemplo n.º 21
0
    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)
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
    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()
Ejemplo n.º 24
0
    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()
Ejemplo n.º 25
0
    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)
Ejemplo n.º 26
0
    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:/"):
                self.mount_cd()
                path = os.path.join(self.cd_path,
                                    path.replace("cdrom:/", "", 1))
            return (JsonWrapper(path)).read()
Ejemplo n.º 27
0
    (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
Ejemplo n.º 28
0
        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
Ejemplo n.º 29
0
    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
Ejemplo n.º 30
0
    (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")