def ui_command_create(self, ip_address=None, ip_port=None): ''' Creates a Network Portal with specified I{ip_address} and I{ip_port}. If I{ip_port} is omitted, the default port for the target fabric will be used. If I{ip_address} is omitted, the first IP address found matching the local hostname will be used. SEE ALSO ======== B{delete} ''' self.assert_root() # FIXME: Add a specfile parameter to determine default port ip_port = self.ui_eval_param(ip_port, 'number', 3260) ip_address = self.ui_eval_param(ip_address, 'string', "0.0.0.0") if ip_address not in utils.list_eth_ips() and ip_address != "0.0.0.0": raise ExecutionError("Cannot bind to address: %s" % ip_address) if ip_port == 3260: self.shell.log.info("Using default IP port %d" % ip_port) if ip_address == "0.0.0.0": self.shell.log.info("Binding to INADDR_ANY (0.0.0.0)") portal = NetworkPortal(self.tpg, ip_address, ip_port, mode='create') self.shell.log.info("Created network portal %s:%d." % (ip_address, ip_port)) ui_portal = UIPortal(portal, self) return self.new_node(ui_portal)
def ui_command_create(self, ip_address=None, ip_port=None): ''' Creates a Network Portal with specified I{ip_address} and I{ip_port}. If I{ip_port} is omitted, the default port for the target fabric will be used. If I{ip_address} is omitted, the first IP address found matching the local hostname will be used. SEE ALSO ======== B{delete} ''' self.assert_root() try: listen_all = int(ip_address.replace(".", "")) == 0 except: listen_all = False if listen_all: ip_address = "0.0.0.0" if ip_port is None: # FIXME: Add a specfile parameter to determine that ip_port = 3260 self.shell.log.info("Using default IP port %d" % ip_port) if ip_address is None: if not ip_address: ip_address = utils.get_main_ip() if ip_address: self.shell.log.info( "Automatically selected IP address %s." % ip_address) else: self.shell.log.error( "Cannot find a usable IP address to " + "create the Network Portal.") return elif ip_address not in utils.list_eth_ips() and not listen_all: self.shell.log.error("IP address does not exist: %s" % ip_address) return try: ip_port = int(ip_port) except ValueError: self.shell.log.error("The ip_port must be an integer value.") return portal = NetworkPortal(self.tpg, ip_address, ip_port, mode='create') self.shell.log.info("Created network portal %s:%d." % (ip_address, ip_port)) ui_portal = UIPortal(portal, self) return self.new_node(ui_portal)
def ui_command_create(self, ip_address=None, ip_port=None): ''' Creates a Network Portal with specified I{ip_address} and I{ip_port}. If I{ip_port} is omitted, the default port for the target fabric will be used. If I{ip_address} is omitted, the first IP address found matching the local hostname will be used. SEE ALSO ======== B{delete} ''' self.assert_root() try: listen_all = int(ip_address.replace(".", "")) == 0 except: listen_all = False if listen_all: ip_address = "0.0.0.0" if ip_port is None: # FIXME: Add a specfile parameter to determine that ip_port = 3260 self.shell.log.info("Using default IP port %d" % ip_port) if ip_address is None: if not ip_address: ip_address = utils.get_main_ip() if ip_address: self.shell.log.info("Automatically selected IP address %s." % ip_address) else: self.shell.log.error("Cannot find a usable IP address to " + "create the Network Portal.") return elif ip_address not in utils.list_eth_ips() and not listen_all: self.shell.log.error("IP address does not exist: %s" % ip_address) return try: ip_port = int(ip_port) except ValueError: self.shell.log.error("The ip_port must be an integer value.") return portal = NetworkPortal(self.tpg, ip_address, ip_port, mode='create') self.shell.log.info("Created network portal %s:%d." % (ip_address, ip_port)) ui_portal = UIPortal(portal, self) return self.new_node(ui_portal)
def ui_complete_create(self, parameters, text, current_param): ''' Parameter auto-completion method for user command create. @param parameters: Parameters on the command line. @type parameters: dict @param text: Current text of parameter being typed by the user. @type text: str @param current_param: Name of parameter to complete. @type current_param: str @return: Possible completions @rtype: list of str ''' if current_param == 'ip_address': completions = [addr for addr in utils.list_eth_ips() if addr.startswith(text)] else: completions = [] if len(completions) == 1: return [completions[0] + ' '] else: return completions
def ui_complete_create(self, parameters, text, current_param): ''' Parameter auto-completion method for user command create. @param parameters: Parameters on the command line. @type parameters: dict @param text: Current text of parameter being typed by the user. @type text: str @param current_param: Name of parameter to complete. @type current_param: str @return: Possible completions @rtype: list of str ''' if current_param == 'ip_address': completions = [ addr for addr in utils.list_eth_ips() if addr.startswith(text) ] else: completions = [] if len(completions) == 1: return [completions[0] + ' '] else: return completions
def validate_val(self, value, val_type, parent=None): valid_value = None log.debug("validate_val(%s, %s)" % (value, val_type)) if value == NO_VALUE: return None if val_type == "bool": if value.lower() in ["yes", "true", "1", "enable"]: valid_value = "yes" elif value.lower() in ["no", "false", "0", "disable"]: valid_value = "no" elif val_type == "bytes": match = re.match(r"(\d+(\.\d*)?)([kKMGT]?B?$)", value) if match: qty = str(float(match.group(1))) unit = match.group(3).upper() if not unit.endswith("B"): unit += "B" valid_value = "%s%s" % (qty, unit) elif val_type == "int": try: valid_value = str(int(value)) except: pass elif val_type == "ipport": (addr, _, port) = value.rpartition(":") try: str(int(port)) except: pass else: try: listen_all = int(addr.replace(".", "")) == 0 except: listen_all = False if listen_all: valid_value = "0.0.0.0:%s" % port elif addr in list_eth_ips(): valid_value = value elif val_type == "posint": try: val = int(value) except: pass else: if val > 0: valid_value = value elif val_type == "str": valid_value = str(value) forbidden = "*?[]" for char in forbidden: if char in valid_value: valid_value = None break elif val_type == "erl": if value in ["0", "1", "2"]: valid_value = value elif val_type == "iqn": if is_valid_wwn("iqn", value): valid_value = value elif val_type == "naa": if is_valid_wwn("naa", value): valid_value = value elif val_type == "backend": if is_valid_backend(value, parent): valid_value = value else: raise ConfigError("Unknown value type '%s' when validating %s" % (val_type, value)) log.debug("validate_val(%s) is a valid %s: %s" % (value, val_type, valid_value)) return valid_value
def validate_val(self, value, val_type, parent=None): valid_value = None log.debug("validate_val(%s, %s)" % (value, val_type)) if value == NO_VALUE: return None if val_type == 'bool': if value.lower() in ['yes', 'true', '1', 'enable']: valid_value = 'yes' elif value.lower() in ['no', 'false', '0', 'disable']: valid_value = 'no' elif val_type == 'bytes': match = re.match(r'(\d+(\.\d*)?)([kKMGT]?B?$)', value) if match: qty = str(float(match.group(1))) unit = match.group(3).upper() if not unit.endswith('B'): unit += 'B' valid_value = "%s%s" % (qty, unit) elif val_type == 'int': try: valid_value = str(int(value)) except: pass elif val_type == 'ipport': (addr, _, port) = value.rpartition(":") try: str(int(port)) except: pass else: try: listen_all = int(addr.replace(".", "")) == 0 except: listen_all = False if listen_all: valid_value = "0.0.0.0:%s" % port elif addr in list_eth_ips(): valid_value = value elif val_type == 'posint': try: val = int(value) except: pass else: if val > 0: valid_value = value elif val_type == 'str': valid_value = str(value) forbidden = "*?[]" for char in forbidden: if char in valid_value: valid_value = None break elif val_type == 'erl': if value in ["0", "1", "2"]: valid_value = value elif val_type == 'iqn': if is_valid_wwn('iqn', value): valid_value = value elif val_type == 'naa': if is_valid_wwn('naa', value): valid_value = value elif val_type == 'backend': if is_valid_backend(value, parent): valid_value = value else: raise ConfigError("Unknown value type '%s' when validating %s" % (val_type, value)) log.debug("validate_val(%s) is a valid %s: %s" % (value, val_type, valid_value)) return valid_value