示例#1
0
    def unmount_filesystems(node_name, wait=True, admin_ip=None):
        stdout = stderr = ""
        rc = RC_SUCCESS

        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        cmd.extend(
            [os.path.join(GPFS_CMD_PATH, "mmumount"), "all", "-N", node_name])
        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)

        if rc != RC_SUCCESS:
            if 'mmumount: No file systems were found' in stdout or \
                    'mmumount: No file systems were found' in stderr:
                # We can claim success on umount if there are no filesystems
                return RC_SUCCESS

            raise SpectrumScaleException(
                "Unmounting filesystems on node failed", cmd[0:mmcmd_idx],
                cmd[mmcmd_idx:], rc, stdout, stderr)
        return rc, stdout
    def remove_server_access_to_nsd(nsd_to_delete,
                                    node_to_delete,
                                    nsd_attached_to_nodes,
                                    admin_ip=None):
        stdout = stderr = ""
        rc = RC_SUCCESS

        # mmchnsd "nsd1:node1.domain.com"
        server_access_list = ','.join(map(str, nsd_attached_to_nodes))
        server_access_list = nsd_to_delete + ":" + server_access_list

        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        cmd.extend(
            [os.path.join(GPFS_CMD_PATH, "mmchnsd"), server_access_list])

        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            e_msg = ("Exception encountered during execution of modifying NSD "
                     "server access list for NSD={0} on Node={1}. Exception "
                     "Message={2)".format(nsd_to_delete, node_to_delete, e))
            raise SpectrumScaleException(e_msg, cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], rc, stdout, stderr)

        if rc != RC_SUCCESS:
            e_msg = ("Failed to modify NSD server access list for NSD={0} on "
                     "Node={1}".format(nsd_to_delete, node_to_delete))
            raise SpectrumScaleException(e_msg, cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], rc, stdout, stderr)
    def delete_disk(node_name, filesystem_name, disk_names, admin_ip=None):
        """
            This function performs "mmdeldisk".
            Args:
                node_name (str): Node for which disk needs to be deleted.
                filesystems_name (str): Filesystem name associated with the disks.
                disk_names (list): Disk name to be deleted.
                                  Ex: ['gpfs1nsd', 'gpfs2nsd', 'gpfs3nsd']
        """
        stdout = stderr = ""
        rc = RC_SUCCESS

        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        disk_name_str = ";".join(disk_names)

        cmd.extend([
            os.path.join(GPFS_CMD_PATH, "mmdeldisk"), filesystem_name,
            disk_name_str, '-N', node_name
        ])

        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Deleting disk(s) failed. ",
                                         cmd[0:mmcmd_idx], cmd[mmcmd_idx:], rc,
                                         stdout, stderr)
    def apply_license(node_name, license, admin_ip=None):
        stdout = stderr = ""
        rc = RC_SUCCESS

        if isinstance(node_name, str):
            node_name_str = node_name
        else:
            node_name_str = ' '.join(node_name)

        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        cmd.extend([
            os.path.join(GPFS_CMD_PATH, "mmchlicense"), license, "--accept",
            "-N", node_name_str
        ])

        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Changing license on  node failed",
                                         cmd[0:mmcmd_idx], cmd[mmcmd_idx:], rc,
                                         stdout, stderr)

        return rc, stdout
    def create_cluster(name, stanza_path, admin_ip=None):
        stdout = stderr = ""
        rc = RC_SUCCESS

        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        cmd.extend([
            os.path.join(GPFS_CMD_PATH, "mmcrcluster"), "-N", stanza_path,
            "-C", name
        ])
        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Creating cluster failed",
                                         cmd[0:mmcmd_idx], cmd[mmcmd_idx:], rc,
                                         stdout, stderr)

        return rc, stdout
    def add_node(node_name, stanza_path, admin_ip=None):
        stdout = stderr = ""
        rc = RC_SUCCESS

        if isinstance(node_name, str):
            node_name_str = node_name
        else:
            node_name_str = ' '.join(node_name)

        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        cmd.extend([
            os.path.join(GPFS_CMD_PATH, "mmaddnode"), "-N", stanza_path,
            "--accept"
        ])
        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Adding node to cluster failed",
                                         cmd[0:mmcmd_idx], cmd[mmcmd_idx:], rc,
                                         stdout, stderr)

        return rc, stdout, stderr
    def start_node(node_name, wait=True, admin_ip=None):
        stdout = stderr = ""
        rc = RC_SUCCESS
        cmd = []
        mmcmd_idx = 1

        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        if isinstance(node_name, str):
            node_name_str = node_name
            node_name_list = [node_name]
        else:
            node_name_str = ' '.join(node_name)
            node_name_list = node_name

        cmd.extend(
            [os.path.join(GPFS_CMD_PATH, "mmstartup"), "-N", node_name_str])
        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Starting node failed",
                                         cmd[0:mmcmd_idx], cmd[mmcmd_idx:], rc,
                                         stdout, stderr)

        if wait:
            # Wait for a maximum of 36 * 5 = 180 seconds (3 minutes)
            MAX_RETRY = 36
            retry = 0
            done = False
            while (not done and retry < MAX_RETRY):
                time.sleep(5)
                node_state = SpectrumScaleNode.get_state(
                    node_name_list, admin_ip)
                done = all("active" in state
                           for state in list(node_state.values()))
                retry = retry + 1

            if not done:
                raise SpectrumScaleException(
                    "Starting node(s) timed out", cmd[0:mmcmd_idx],
                    cmd[mmcmd_idx:], -1, "",
                    "Node state is not \"active\" after retries")
        return rc, stdout
    def get_state(node_names=[], admin_ip=None):
        stdout = stderr = ""
        rc = RC_SUCCESS
        cmd = []
        mmcmd_idx = 1

        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        cmd.extend([os.path.join(GPFS_CMD_PATH, "mmgetstate")])

        if len(node_names) == 0:
            cmd.append("-a")
        else:
            # If a set of node names have ben provided, use that instead
            node_name_str = ','.join(node_names)
            cmd.append("-N")
            cmd.append(node_name_str)

        cmd.append("-Y")

        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Retrieving the node state failed",
                                         cmd[0:mmcmd_idx], cmd[mmcmd_idx:], rc,
                                         stdout, stderr)

        node_state_dict = parse_unique_records(stdout)
        node_state_list = node_state_dict["mmgetstate"]

        node_state = {}
        for node in node_state_list:
            node_state[node["nodeName"]] = node["state"]

        return node_state
    def get_df_info(filesystem_name, admin_ip=None):
        nsd_df_info_list = []

        stdout = stderr = ""
        rc = RC_SUCCESS

        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        # TODO
        # The original code executed the command "/usr/lpp/mmfs/bin/mmdf <fs_name> -d -Y"
        # but this did not work if there were multiple Pools with a separate System Pool.
        # Therefore the "-d" flag has been removed. Check to see why the "-d" flag was
        # was used in the first place
        cmd.extend([os.path.join(GPFS_CMD_PATH, "mmdf"), filesystem_name, "-Y"])

        try: 
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx], cmd[mmcmd_idx:],
                                         -1, stdout, stderr)

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Retrieving filesystem disk space usage failed",
                                         cmd[0:mmcmd_idx], cmd[mmcmd_idx:], rc,
                                         stdout, stderr)

        df_dict = parse_aggregate_cmd_output(stdout, ["poolTotal", "data", 
                                                      "metadata", "fsTotal", 
                                                      "inode"])

        nsd_df_list = df_dict["nsd"]

        for nsd_df in nsd_df_list:
            nsd_df_instance = SpectrumScaleDf(nsd_df)
            nsd_df_info_list.append(nsd_df_instance)

        return nsd_df_info_list
示例#10
0
    def get_filesystems(admin_ip=None):
        filesystem_info_list = []

        stdout = stderr = ""
        rc = RC_SUCCESS

        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        cmd.extend([os.path.join(GPFS_CMD_PATH, "mmlsfs"), "all", "-Y"])

        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)

        if rc != RC_SUCCESS:
            if 'mmlsfs: No file systems were found.' in stdout or \
                    'mmlsfs: No file systems were found.' in stderr:
                return filesystem_info_list

            raise SpectrumScaleException(
                "Retrieving filesystem information failed", cmd[0:mmcmd_idx],
                cmd[mmcmd_idx:], rc, stdout, stderr)

        filesystem_dict = parse_simple_cmd_output(stdout, "deviceName",
                                                  "properties", "filesystems")
        filesystem_list = filesystem_dict["filesystems"]

        for filesystem in filesystem_list:
            device_name = filesystem["deviceName"]
            fs_properties = filesystem["properties"]
            filesystem_instance = SpectrumScaleFS(device_name, fs_properties)
            filesystem_info_list.append(filesystem_instance)

        return filesystem_info_list
    def __retrieve_cluster_info(self, admin_ip):
        stdout = stderr = ""
        rc = RC_SUCCESS
        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        cmd.extend([os.path.join(GPFS_CMD_PATH, "mmlscluster"), "-Y"])
        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)
        if rc != RC_SUCCESS:
            raise SpectrumScaleException(
                "Retrieving the cluster information failed", cmd[0:mmcmd_idx],
                cmd[mmcmd_idx:], rc, stdout, stderr)

        return parse_aggregate_cmd_output(
            stdout, ["clusterSummary", "cnfsSummary", "cesSummary"])
示例#12
0
    def create_filesystem(name,
                          stanza_path,
                          block_size,
                          default_metadata_replicas,
                          default_data_replicas,
                          num_nodes,
                          automatic_mount_option,
                          default_mount_point,
                          admin_ip=None):
        stdout = stderr = ""
        rc = RC_SUCCESS

        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        cmd.extend([
            os.path.join(GPFS_CMD_PATH,
                         "mmcrfs"), name, "-F", stanza_path, "-B", block_size,
            "-m", default_metadata_replicas, "-r", default_data_replicas, "-n",
            num_nodes, "-A", automatic_mount_option, "-T", default_mount_point
        ])
        # TODO: Make this idempotent
        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Create filesystems on node failed",
                                         cmd[0:mmcmd_idx], cmd[mmcmd_idx:], rc,
                                         stdout, stderr)

        return rc, stdout
    def get_all_nsd_info(admin_ip=None):
        nsd_info_list = []

        stdout = stderr = ""
        rc = RC_SUCCESS

        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        cmd.extend([os.path.join(GPFS_CMD_PATH, "mmlsnsd"), "-a", "-X", "-Y"])

        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)

        if rc == RC_SUCCESS:
            if "No disks were found" in stderr:
                return nsd_info_list
        else:
            raise SpectrumScaleException("Retrieving NSD information Failed",
                                         cmd[0:mmcmd_idx], cmd[mmcmd_idx:], rc,
                                         stdout, stderr)

        nsd_dict = parse_unique_records(stdout)
        nsd_list = nsd_dict["nsd"]

        for nsd in nsd_list:
            nsd_instance = SpectrumScaleNSD(nsd)
            nsd_info_list.append(nsd_instance)

        return nsd_info_list
    def delete_nsd(nsd_list, admin_ip=None):
        nsd_names = ";".join(nsd_list)

        stdout = stderr = ""
        rc = RC_SUCCESS

        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        cmd.extend([os.path.join(GPFS_CMD_PATH, "mmdelnsd"), nsd_names])

        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Deleting NSD(s) Failed",
                                         cmd[0:mmcmd_idx], cmd[mmcmd_idx:], rc,
                                         stdout, stderr)
    def get_all_disk_info(fs_name, admin_ip=None):
        disk_info_list = []
        stdout = stderr = ""
        rc = RC_SUCCESS

        cmd = []
        mmcmd_idx = 1
        if admin_ip:
            cmd.extend(["ssh", admin_ip])
            mmcmd_idx = len(cmd) + 1

        cmd.extend([os.path.join(GPFS_CMD_PATH, "mmlsdisk"), fs_name, "-Y"])

        try:
            stdout, stderr, rc = runCmd(cmd, sh=False)
        except Exception as e:
            raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx],
                                         cmd[mmcmd_idx:], -1, stdout, stderr)

        if rc == RC_SUCCESS:
            # TODO: Check the return codes and examine other possibility and verify below
            if "No disks were found" in stderr:
                return nsd_info_list
        else:
            raise SpectrumScaleException("Retrieving disk information failed",
                                         cmd[0:mmcmd_idx], cmd[mmcmd_idx:], rc,
                                         stdout, stderr)

        disk_dict = parse_unique_records(stdout)
        disk_list = disk_dict["mmlsdisk"]

        for disk in disk_list:
            disk_instance = SpectrumScaleDisk(disk, fs_name)
            disk_info_list.append(disk_instance)

        return disk_info_list
def get_zimon_collectors():
    """
        This function returns zimon collector node ip's.
    """
    stdout = stderr = ""
    rc = RC_SUCCESS

    cmd = []
    mmcmd_idx = 1
    if admin_ip:
        cmd.extend(["ssh", admin_ip])
        mmcmd_idx = len(cmd) + 1

    cmd.extend([os.path.join(GPFS_CMD_PATH, "mmperfmon"), "config", "show"])

    try:
        stdout, stderr, rc = runCmd(cmd, sh=False)
    except Exception as e:
        raise SpectrumScaleException(str(e), cmd[0:mmcmd_idx], cmd[mmcmd_idx:],
                                     -1, stdout, stderr)

    if rc != RC_SUCCESS:
        raise SpectrumScaleException("Retrieving Zimon information failed",
                                     cmd[0:mmcmd_idx], cmd[mmcmd_idx:], rc,
                                     stdout, stderr)

    output = stdout.splitlines()
    col_regex = re.compile(r'colCandidates\s=\s(?P<collectors>.*)')
    for cmd_line in output:
        if col_regex.match(cmd_line):
            collectors = col_regex.match(cmd_line).group('collectors')

    collectors = collectors.replace("\"", '').replace(" ", '')
    collectors = collectors.split(',')

    return collectors