def get_filesystems():
        filesystem_info_list = []

        stdout, stderr, rc = runCmd([os.path.join(GPFS_CMD_PATH, "mmlsfs"),
                                                  "all", "-Y"],
                                                  sh=False)

        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",
                                     "mmlsfs",
                                     ["all", "-Y"],
                                     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
Exemple #2
0
    def get_state(node_names=[]):
        stdout = stderr = ""
        rc = RC_SUCCESS

        cmd = [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], cmd[1:], -1, stdout,
                                         stderr)

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Retrieving the node state failed",
                                         cmd[0], cmd[1:], 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):
        nsd_df_info_list = []

        # 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
        stdout, stderr, rc = runCmd(
            [os.path.join(GPFS_CMD_PATH, "mmdf"), filesystem_name, "-Y"],
            sh=False)

        if rc != RC_SUCCESS:
            raise SpectrumScaleException(
                "Retrieving filesystem disk space usage failed", "mmdf",
                [filesystem_name, "-Y"], 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
Exemple #4
0
    def apply_license(node_name, license):
        stdout = stderr = ""
        rc = RC_SUCCESS

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

        cmd = [
            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], cmd[1:], -1, stdout,
                                         stderr)

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

        return rc, stdout
    def create_filesystem(name, stanza_path, block_size, 
                          default_metadata_replicas,
                          default_data_replicas, num_nodes,
                          automatic_mount_option, 
                          default_mount_point):
        cmd = [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], cmd[1:],
                                         -1, stdout, stderr)

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


        return rc, stdout
Exemple #6
0
    def add_node(node_name, stanza_path):
        stdout = stderr = ""
        rc = RC_SUCCESS

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

        cmd = [
            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], cmd[1:], -1, stdout,
                                         stderr)

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

        return rc, stdout, stderr
Exemple #7
0
    def delete_nsd(nsd_list):
        nsd_names = ";".join(nsd_list)
        stdout, stderr, rc = runCmd(
            [os.path.join(GPFS_CMD_PATH, "mmdelnsd"), nsd_names])

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Deleting NSD(s) Failed", "mmdelnsd",
                                         nsd_list, rc, stdout, stderr)
Exemple #8
0
    def delete_cluster(name):
        stdout = stderr = ""
        rc = RC_SUCCESS

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

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Deleting cluster failed", cmd[0],
                                         cmd[1:], rc, stdout, stderr)
        return rc, stdout
Exemple #9
0
    def __retrieve_cluster_info(self):
        stdout = stderr = ""
        rc = RC_SUCCESS
        cmd = [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], cmd[1:], -1, stdout,
                                         stderr)
        if rc != RC_SUCCESS:
            raise SpectrumScaleException(
                "Retrieving the cluster information failed", cmd[0], cmd[1:],
                rc, stdout, stderr)

        return parse_aggregate_cmd_output(
            stdout, ["clusterSummary", "cnfsSummary", "cesSummary"])
    def unmount_filesystems(node_name, wait=True):
        cmd = [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], cmd[1:],
                                         -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], cmd[1:], rc, stdout, stderr)
        return rc, stdout 
Exemple #11
0
    def create_cluster(name, stanza_path):
        stdout = stderr = ""
        rc = RC_SUCCESS

        cmd = [
            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], cmd[1:], -1, stdout,
                                         stderr)

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

        return rc, stdout
    def delete_disk(node_name, filesystem_name, disk_names):
        """
            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']
        """
        disk_name_str = ";".join(disk_names)
        stdout, stderr, rc = runCmd([os.path.join(GPFS_CMD_PATH, "mmdeldisk"), 
                                     filesystem_name,
                                     disk_name_str, '-N', node_name])

        if rc != RC_SUCCESS:
            cmd_args = "{0} {1} {2}".format(node_name, filesystem_name, disk_name_str)
            raise SpectrumScaleException("Deleting disk(s) failed. ",
                                     "mmdeldisk ",
                                     cmd_args, 
                                     rc, stdout, stderr) 
Exemple #13
0
    def delete_node(node_name):
        stdout = stderr = ""
        rc = RC_SUCCESS

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

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

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Deleting node from cluster failed",
                                         cmd[0], cmd[1:], rc, stdout, stderr)

        return rc, stdout
Exemple #14
0
    def start_node(node_name, wait=True):
        stdout = stderr = ""
        rc = RC_SUCCESS

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

        cmd = [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], cmd[1:], -1, stdout,
                                         stderr)

        if rc != RC_SUCCESS:
            raise SpectrumScaleException("Starting node failed", cmd[0],
                                         cmd[1:], 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)
                done = all("active" in state for state in node_state.values())
                retry = retry + 1

            if not done:
                raise SpectrumScaleException(
                    "Starting node(s) timed out", cmd[0], cmd[1:], -1, ""
                    "Node state is not \"active\" after retries")
        return rc, stdout
Exemple #15
0
    def get_all_nsd_info():
        nsd_info_list = []

        stdout, stderr, rc = runCmd(
            [os.path.join(GPFS_CMD_PATH, "mmlsnsd"), "-a", "-X", "-Y"],
            sh=False)

        if rc == RC_SUCCESS:
            if "No disks were found" in stderr:
                return nsd_info_list
        else:
            raise SpectrumScaleException("Retrieving NSD information Failed",
                                         "mmlsnsd", ["-a", "-X", "-Y"], 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
Exemple #16
0
    def remove_server_access_to_nsd(nsd_to_delete, node_to_delete,
                                    nsd_attached_to_nodes):
        stdout = stderr = ""
        rc = -1

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

        try:
            stdout, stderr, rc = runCmd(
                ["/usr/lpp/mmfs/bin/mmchnsd", server_access_list], 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, "mmchnsd",
                                         [server_access_list], stdout, str(e))

        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, "mmchnsd",
                                         [server_access_list], stdout, stderr)
    def get_all_disk_info(fs_name):
        disk_info_list = []
        stdout, stderr, rc = runCmd([os.path.join(GPFS_CMD_PATH, "mmlsdisk"),
                                                  fs_name, "-Y"],
                                                  sh=False)

        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",
                                     "mmlsdisk",
                                     [fs_name, "-Y"], 
                                     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