Пример #1
0
def mount_fileshare(verbose=True):
    with open("mounting.yaml", 'r') as datafile:
        config = yaml.load(datafile)
        datafile.close()
    nMounts = 0
    for mnt_itm in config.values():
        # gives mounted information only, would not write anything or carry out mount action
        for triplet in mnt_itm["fileshares"]:
            output = pipe_with_output("mount",
                                      "grep {}".format(
                                          triplet["remote_mount_path"]),
                                      verbose=False)
            umounts, existmounts = [], []
            # we would have only 1 line, since we now mount at leaf-path level
            for line in output.splitlines():
                umounts, existmounts = confirm_mounted(
                    line, triplet["remote_mount_path"], umounts, existmounts,
                    verbose)
            umounts.sort()
            # Examine mount point, unmount those file shares that fails.
            for um in umounts:
                cmd = "umount -v %s" % um
                logging.debug("Mount fails, to examine mount %s " % um)
                exec_with_output(cmd, verbose=verbose)
                time.sleep(3)
            if len(existmounts) <= 0:
                nMounts += 1
                exec_with_output("mount {}:{} {} -o {} ".format(
                    mnt_itm["private_ip"], triplet["nfs_local_path"],
                    triplet["remote_mount_path"], mnt_itm["options"]),
                                 verbose=verbose)
    if nMounts > 0:
        time.sleep(1)
Пример #2
0
def mount_fileshare(verbose=True):
    with open("mounting.yaml", 'r') as datafile:
        config = yaml.load(datafile)
        datafile.close()
    nMounts = 0
    for mnt_itm in config.values():
        # to make the code backward compatible
        client_mount_key = "client_mount_root" if "fileshare_system" in mnt_itm else "remote_mount_path"
        for triplet in mnt_itm["fileshares"]:
            # gives mounted information only, would not write anything or carry out mount action
            output = pipe_with_output("mount",
                                      "grep {}".format(
                                          triplet[client_mount_key]),
                                      verbose=False)
            umounts, existmounts = [], []
            # we would have only 1 line, since we now mount at leaf-path level
            for line in output.splitlines():
                umounts, existmounts = confirm_mounted(
                    line, triplet[client_mount_key], umounts, existmounts,
                    verbose)
            umounts.sort()
            # Examine mount point, unmount those file shares that fails.
            for um in umounts:
                cmd = "umount -v %s" % um
                logging.debug("Mount fails, to examine mount %s " % um)
                exec_with_output(cmd, verbose=verbose)
                time.sleep(3)
            if len(existmounts) <= 0:
                nMounts += 1
                exec_with_output("mkdir -p {}".format(
                    triplet[client_mount_key]),
                                 verbose=verbose)
                if "fileshare_system" not in mnt_itm:
                    private_ip = mnt_itm.get("private_ip",
                                             mnt_itm["private_ip_address"])
                    mount_cmd = "mount {}:{} {} -o {} ".format(
                        private_ip, triplet["nfs_local_path"],
                        triplet["remote_mount_path"], mnt_itm["options"])
                elif mnt_itm["fileshare_system"] == "nfs":
                    mount_cmd = "mount {}:{} {} -o {} ".format(
                        mnt_itm["private_ip"], triplet["server_path"],
                        triplet["client_mount_root"], mnt_itm["options"])
                elif mnt_itm["fileshare_system"] == "lustre":
                    mount_cmd = "mount {}:{} {} -t lustre".format(
                        mnt_itm["private_ip"], triplet["server_path"],
                        triplet["client_mount_root"])
                exec_with_output(mount_cmd, verbose=verbose)
                exec_with_output("sudo chmod 777 {}".format(
                    triplet[client_mount_key]),
                                 verbose=verbose)
    if nMounts > 0:
        time.sleep(1)
Пример #3
0
def link_fileshare(verbose=True):
    with open("mounting.yaml", 'r') as datafile:
        config = yaml.load(datafile)
        datafile.close()
    (retcode, output, err) = exec_with_output("sudo mount", verbose=False)
    for mnt_itm in config.values():
        # to make the code backward compatible
        client_mount_key = "client_mount_root" if "fileshare_system" in mnt_itm else "remote_mount_path"
        local_path_key = "server_path" if "fileshare_system" in mnt_itm else "nfs_local_path"
        for triplet in mnt_itm["fileshares"]:
            if output.find(triplet[client_mount_key]) < 0:
                logging.debug(
                    "!!!Warning!!! {} has not been mounted at {} ".format(
                        triplet[local_path_key], triplet[client_mount_key]))
                logging.debug(output)
                continue
            if "fileshare_system" in mnt_itm:
                for link_itm in triplet["client_links"]:
                    if link_itm["src"][0] == '/':
                        link_src = link_itm["src"]
                    else:
                        link_src = os.path.join(triplet["client_mount_root"],
                                                link_itm["src"])
                    # abspath would also remove tailing '/' if it's in ther path string
                    # we need to get rid of tailing '/' of link_dst,
                    # otherwise the softlink itself would not be deleted
                    link_dst = os.path.abspath(link_itm["dst"])
                    link_src = os.path.abspath(link_src)
                    if os.path.exists(link_dst):
                        continue
                    exec_with_output("mkdir -p {}".format(
                        os.path.dirname(link_dst)),
                                     verbose=verbose)
                    exec_with_output("mkdir -p {}".format(link_src),
                                     verbose=verbose)
                    exec_with_output("ln -s {} {}".format(link_src, link_dst),
                                     verbose=verbose)
                    exec_with_output("chmod 777 {}".format(link_src),
                                     verbose=verbose)
            else:
                exec_wo_output(
                    "if [ ! -e {} ]; then mkdir -p {}; sudo ln -s {} {}; fi;".
                    format(triplet["remote_link_path"],
                           os.path.dirname(triplet["remote_link_path"]),
                           triplet["remote_mount_path"],
                           triplet["remote_link_path"]))
Пример #4
0
def link_fileshare():
    with open("mounting.yaml", 'r') as datafile:
        config = yaml.load(datafile)
        datafile.close()
    (retcode, output, err) = exec_with_output("sudo mount")
    for mnt_itm in config.values():
        for triplet in mnt_itm["fileshares"]:
            if output.find(triplet["remote_mount_path"]) < 0:
                logging.debug(
                    "!!!Warning!!! {} has not been mounted at {} ".format(
                        triplet["nfs_local_path"],
                        triplet["remote_mount_path"]))
                logging.debug(output)
                continue
            if not os.path.exists(triplet["remote_link_path"]):
                exec_wo_output("mkdir -p {}; sudo ln -s {} {}; ".format(
                    os.path.dirname(triplet["remote_link_path"]),
                    triplet["remote_mount_path"], triplet["remote_link_path"]))
Пример #5
0
def get_catalog_download_config(catalog_id):
    try:
        configs = load_yaml(CONFIG_DOWNLOADS_PATH)
    except:
        logger.warning(
            "No se pudo cargar el archivo de configuración 'config_downloads.yaml'."
        )
        logger.warning("Utilizando configuración default...")
        configs = {"defaults": {}}

    default_config = configs["defaults"]

    config = configs[catalog_id] if catalog_id in configs else {}
    if "catalog" not in config:
        config["catalog"] = {}
    if "sources" not in config:
        config["sources"] = {}

    for key, value in list(default_config.items()):
        for subconfig in list(config.values()):
            if key not in subconfig:
                subconfig[key] = value

    return config