def _get_iscsi_config(node): path = iscsi_get_config_path_node(node) parser = iscsidParser() dop = DictOp() dop.addconf(MODULE, parser.read_conf(path)) return dop
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
def process(self): (opts, args) = getopts() chkopts(opts) self.up_progress(10) config_path = iscsi_get_config_path(opts.host, opts.iqn, opts.port, opts.tpgt) parser = iscsidParser() dop = DictOp() dop.addconf("new", parser.read_conf(config_path)) 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_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) self.up_progress(10) parser.write_conf(dop.getconf("new"), config_path) self.up_progress(30) self.logger.info("Updated iSCSI node. - host=%s iqn=%s" % (opts.host, opts.iqn)) print >> sys.stdout, _("Updated iSCSI node. - host=%s iqn=%s") % ( opts.host, opts.iqn) return True
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
def process(self): (opts, args) = getopts() chkopts(opts) self.up_progress(10) config_path = iscsi_get_config_path(opts.host, opts.iqn, opts.port, opts.tpgt) parser = iscsidParser() dop = DictOp() dop.addconf("new", parser.read_conf(config_path)) 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_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) self.up_progress(10) parser.write_conf(dop.getconf("new"), config_path) self.up_progress(30) self.logger.info("Updated iSCSI node. - host=%s iqn=%s" % (opts.host, opts.iqn)) print >>sys.stdout, _("Updated iSCSI node. - host=%s iqn=%s") % (opts.host, opts.iqn) return True