示例#1
0
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        node_command_args = (ISCSI_CMD,
                             ISCSI_CMD_OPTION_MODE,
                             ISCSI_CMD_OPTION_MODE_NODE
                             )

        (node_rc, node_res) = execute_command(node_command_args)
        if node_rc != 0:
            for node_line in node_res:
                if node_line.find(ISCSI_CMD_RES_NO_NODE) != -1:
                    self.logger.info("iSCSI node not found")
                    return True

            raise KssCommandException('Failed to get iSCSI node. message=%s' % (node_res))

        self.up_progress(20)
        session_command_args = (ISCSI_CMD,
                                ISCSI_CMD_OPTION_MODE,
                                ISCSI_CMD_OPTION_MODE_SESSION
                                )

        (session_rc, session_res) = execute_command(session_command_args)
        if session_rc != 0:
            raise KssCommandException('Failed to get iSCSI session. message=%s' % (session_res))

        self.up_progress(20)
        for node_line in node_res:
            if not node_line:
                continue

            try:
                node = iscsi_parse_node(node_line)
            except:
                self.logger.warn('Failed to parse iSCSI node command response. message="%s"' % (node_line))
                continue

            is_active = 0
            for session_line in session_res:
                if not session_line:
                    continue

                if session_line.find(ISCSI_CMD_RES_NO_ACTIVE_SESSION) != -1:
                    break

                try:
                    session = iscsi_parse_session(session_line)
                except:
                    self.logger.warn('Failed to parse iSCSI session command response. message="%s"' % (session_line))
                    continue

                if iscsi_check_node_status(node, session):
                    is_active = 1
                    break

            if iscsi_check_node_autostart(node):
                autostart = 0
            else:
                autostart = 1

            if opts.iqn is None:
                self.logger.info("%s %s %s" % (iscsi_print_format_node(node), is_active, autostart))
                print >>sys.stdout, _("%s %s %s") % (iscsi_print_format_node(node), is_active, autostart)
            else:
                if opts.iqn == node['iqn']:
                    auth = iscsi_get_auth_type(node)
                    user = iscsi_get_auth_user(node)

                    self.logger.info("%s %s %s %s %s" % (iscsi_print_format_node(node), is_active, autostart, auth, user))
                    print >>sys.stdout, _("%s %s %s %s %s") % (iscsi_print_format_node(node), is_active, autostart, auth, user)
                    break

        return True
示例#2
0
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        node_command_args = (ISCSI_CMD, ISCSI_CMD_OPTION_MODE,
                             ISCSI_CMD_OPTION_MODE_NODE)

        (node_rc, node_res) = execute_command(node_command_args)
        if node_rc != 0:
            for node_line in node_res:
                if node_line.lower().find(ISCSI_CMD_RES_NO_NODE) != -1:
                    self.logger.info("iSCSI node not found")
                    return True

            raise KssCommandException('Failed to get iSCSI node. message=%s' %
                                      (node_res))

        self.up_progress(20)
        session_command_args = (ISCSI_CMD, ISCSI_CMD_OPTION_MODE,
                                ISCSI_CMD_OPTION_MODE_SESSION)

        (session_rc, session_res) = execute_command(session_command_args)
        if session_rc != 0:
            raise KssCommandException(
                'Failed to get iSCSI session. message=%s' % (session_res))

        self.up_progress(20)
        for node_line in node_res:
            if not node_line:
                continue

            try:
                node = iscsi_parse_node(node_line)
            except:
                self.logger.warn(
                    'Failed to parse iSCSI node command response. message="%s"'
                    % (node_line))
                continue

            is_active = 0
            for session_line in session_res:
                if not session_line:
                    continue

                if session_line.find(ISCSI_CMD_RES_NO_ACTIVE_SESSION) != -1:
                    break

                try:
                    session = iscsi_parse_session(session_line)
                except:
                    self.logger.warn(
                        'Failed to parse iSCSI session command response. message="%s"'
                        % (session_line))
                    continue

                if iscsi_check_node_status(node, session):
                    is_active = 1
                    break

            if iscsi_check_node_autostart(node):
                autostart = 0
            else:
                autostart = 1

            if opts.iqn is None:
                self.logger.info(
                    "%s %s %s" %
                    (iscsi_print_format_node(node), is_active, autostart))
                print >> sys.stdout, _("%s %s %s") % (
                    iscsi_print_format_node(node), is_active, autostart)
            else:
                if opts.iqn == node['iqn']:
                    auth = iscsi_get_auth_type(node)
                    user = iscsi_get_auth_user(node)

                    self.logger.info("%s %s %s %s %s" %
                                     (iscsi_print_format_node(node), is_active,
                                      autostart, auth, user))
                    print >> sys.stdout, _("%s %s %s %s %s") % (
                        iscsi_print_format_node(node), is_active, autostart,
                        auth, user)
                    break

        return True
示例#3
0
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        original_parser = iscsidParser()
        new_parser = iscsidParser()
        dop = DictOp()

        dop.addconf("original", original_parser.read_conf())
        dop.addconf("new", new_parser.read_conf())

        self.up_progress(10)

        dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_METHOD, opts.auth)
        if opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP:
            password = ""
            if opts.password is not None:
                password = opts.password
            elif opts.password_file is not None and is_readable(opts.password_file):
                try:
                    fp = open(opts.password_file, "r")
                    try:
                        fcntl.lockf(fp.fileno(), fcntl.LOCK_SH)
                        try:
                            password = fp.readline().strip("\n")
                        finally:
                            fcntl.lockf(fp.fileno(), fcntl.LOCK_UN)

                        self.up_progress(10)
                    finally:
                        fp.close()

                except:
                    raise KssCommandException('Failed to read file. - target host=%s password_file=%s' \
                                                  % (opts.host,opts.password_file))

                try:
                    os.remove(opts.password_file)
                except:
                    raise KssCommandException('Failed to remove file. - target host=%s password_file=%s' \
                                                  % (opts.host,opts.password_file))

            dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_METHOD, opts.auth)
            dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_USER, opts.user)
            dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD, password)
        else:
            dop.comment("new", ISCSI_CONFIG_KEY_AUTH_USER)
            dop.comment("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD)

        self.up_progress(10)
        if opts.autostart:
            dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP, ISCSI_CONFIG_VALUE_SATRTUP_ON)
        else:
            dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP, ISCSI_CONFIG_VALUE_SATRTUP_OFF)

        new_parser.write_conf(dop.getconf("new"))
        self.up_progress(10)

        discovery_command_args = (ISCSI_CMD,
                                  ISCSI_CMD_OPTION_MODE,
                                  ISCSI_CMD_OPTION_MODE_DISCOVERY,
                                  ISCSI_CMD_OPTION_TYPE,
                                  ISCSI_CMD_OPTION_TYPE_SENDTARGETS,
                                  ISCSI_CMD_OPTION_PORTAL,
                                  opts.host
                                  )

        (discovery_rc,discovery_res) = execute_command(discovery_command_args)
        self.up_progress(10)

        original_parser.write_conf(dop.getconf("original"))
        self.up_progress(10)

        if discovery_rc != 0:
            raise KssCommandException('Failed to add iSCSI. - host=%s message=%s' % (opts.host, discovery_res))

        if discovery_res == []:
            raise KssCommandException('Failed to add iSCSI. - host=%s message=No exist permit iSCSI disk for target.' % (opts.host))

        for node_line in discovery_res:
            if not node_line:
                continue

            try:
                node = iscsi_parse_node(node_line)
            except:
                self.logger.warn('Failed to parse iSCSI discovery command response. message="%s"' % (node_line))
                continue

            self.logger.info("%s" % (iscsi_print_format_node(node)))
            print >>sys.stdout, _("%s") % (iscsi_print_format_node(node))

        return True
示例#4
0
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        original_parser = iscsidParser()
        new_parser = iscsidParser()
        dop = DictOp()

        dop.addconf("original", original_parser.read_conf())
        dop.addconf("new", new_parser.read_conf())

        self.up_progress(10)

        dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_METHOD, opts.auth)
        if opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP:
            password = ""
            if opts.password is not None:
                password = opts.password
            elif opts.password_file is not None and is_readable(
                    opts.password_file):
                try:
                    fp = open(opts.password_file, "r")
                    try:
                        fcntl.lockf(fp.fileno(), fcntl.LOCK_SH)
                        try:
                            password = fp.readline().strip("\n")
                        finally:
                            fcntl.lockf(fp.fileno(), fcntl.LOCK_UN)

                        self.up_progress(10)
                    finally:
                        fp.close()

                except:
                    raise KssCommandException('Failed to read file. - target host=%s password_file=%s' \
                                                  % (opts.host,opts.password_file))

                try:
                    os.remove(opts.password_file)
                except:
                    raise KssCommandException('Failed to remove file. - target host=%s password_file=%s' \
                                                  % (opts.host,opts.password_file))

            dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_METHOD, opts.auth)
            dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_USER, opts.user)
            dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD, password)
        else:
            dop.comment("new", ISCSI_CONFIG_KEY_AUTH_USER)
            dop.comment("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD)

        self.up_progress(10)
        if opts.autostart:
            dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP,
                        ISCSI_CONFIG_VALUE_SATRTUP_ON)
        else:
            dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP,
                        ISCSI_CONFIG_VALUE_SATRTUP_OFF)

        new_parser.write_conf(dop.getconf("new"))
        self.up_progress(10)

        discovery_command_args = (ISCSI_CMD, ISCSI_CMD_OPTION_MODE,
                                  ISCSI_CMD_OPTION_MODE_DISCOVERY,
                                  ISCSI_CMD_OPTION_TYPE,
                                  ISCSI_CMD_OPTION_TYPE_SENDTARGETS,
                                  ISCSI_CMD_OPTION_PORTAL, opts.host)

        (discovery_rc, discovery_res) = execute_command(discovery_command_args)
        self.up_progress(10)

        original_parser.write_conf(dop.getconf("original"))
        self.up_progress(10)

        if discovery_rc != 0:
            raise KssCommandException(
                'Failed to add iSCSI. - host=%s message=%s' %
                (opts.host, discovery_res))

        if discovery_res == []:
            raise KssCommandException(
                'Failed to add iSCSI. - host=%s message=No exist permit iSCSI disk for target.'
                % (opts.host))

        for node_line in discovery_res:
            if not node_line:
                continue

            try:
                node = iscsi_parse_node(node_line)
            except:
                self.logger.warn(
                    'Failed to parse iSCSI discovery command response. message="%s"'
                    % (node_line))
                continue

            self.logger.info("%s" % (iscsi_print_format_node(node)))
            print >> sys.stdout, _("%s") % (iscsi_print_format_node(node))

        return True