def parse_multi_parameter_cli(self, cli): ''' Override the default implementation in case the CLI does not match asa_gen_template due to optional parameter ''' # Take care of the mandatory parameters result = SimpleType.parse_multi_parameter_cli( self, cli, alternate_asa_gen_template=self.asa_gen_template) 'Take care of the optional parameters' tokens = cli.split() # The number of mandatory parameters is 4, i.e. 'logging host management 2.2.2.2' if len(tokens) == 4: return result # no optional parameter for name in ['secure', 'protocol_port', 'emblem']: result[(Type.PARAM, name, '')] = { 'state': State.NOCHANGE, 'value': '' } option = tokens[4:] if 'secure' in option: # e.g. "logging host mgmt 2.2.2.2 secure result[Type.PARAM, 'secure', '']['value'] = 'enable' if 'emblem' in option: # e.g. "logging host mgmt 2.2.2.2 format emblem result[Type.PARAM, 'emblem', '']['value'] = 'enable' if '/' in option[0]: # e.g. "logging host mgmt 2.2.2.2 6/1471' result[Type.PARAM, 'protocol_port', '']['value'] = option[0] return result
def parse_multi_parameter_cli(self, cli): '''Override the default implementation in case the CLI does not match asa_gen_template due to optional parameter ''' 'Take care of the mandatory parameters' result = SimpleType.parse_multi_parameter_cli( self, cli, alternate_asa_gen_template= 'ipv6 route %(interface)s %(prefix)s %(gateway)s') 'Take care of the optional parameters' for name, value in self.defaults.iteritems(): result[(Type.PARAM, name, '')] = { 'state': State.NOCHANGE, 'value': value } tokens = cli.split() if len(tokens) == 5: return result #no optional parameter option = tokens[5] if option == 'tunneled': result[Type.PARAM, 'tunneled', '']['value'] = option elif option: result[Type.PARAM, 'hop_count', '']['value'] = option return result
def parse_multi_parameter_cli(self, cli): """ Override the default implementation in case the CLI does not match asa_gen_template due to optional parameter """ # Take care of the mandatory parameters result = SimpleType.parse_multi_parameter_cli(self, cli, alternate_asa_gen_template=self.asa_gen_template) "Take care of the optional parameters" tokens = cli.split() # The number of tokens must greater than 3, i.e. 'failover interface ip ...' assert len(tokens) > 3 for name in ["interface_name", "active_ip", "standby_ip"]: result[(Type.PARAM, name, "")] = {"state": State.NOCHANGE, "value": ""} option = tokens[3:] # for ipv4, option is: %(interface_name)s %(active_ip)s %(netmask)s standby %(standby_ip)s # for ipv6, option is: %(interface_name)s %(active_ip)s standby %(standby_ip)s result[Type.PARAM, "interface_name", ""]["value"] = option[0] result[Type.PARAM, "active_ip", ""]["value"] = option[1] if ":" not in option[1]: # ipv4 result[(Type.PARAM, "netmask", "")] = {"state": State.NOCHANGE, "value": ""} result[Type.PARAM, "netmask", ""]["value"] = option[2] # skip option[3], which should be the 'standby' keyword result[Type.PARAM, "standby_ip", ""]["value"] = option[4] else: # ipv6, no netmask # skip option[2], which should be the 'standby' keyword result[Type.PARAM, "standby_ip", ""]["value"] = option[3] return result
def parse_multi_parameter_cli(self, cli, alternate_asa_gen_template = None): ''' Override the default implementation in case the CLI does not match asa_gen_template due to optional parameter ''' if not cli.endswith(AdvancedThreatDetection.THREAT_DETECTION_STATISTICS_TCP_INTERCEPT): return SimpleType.parse_multi_parameter_cli(self, cli, alternate_asa_gen_template) return self.parse_intercept_cli(cli)
def parse_multi_parameter_cli(self, cli, alternate_asa_gen_template = None): ''' Override the default implementation in case the CLI does not match asa_gen_template due to optional parameter ''' # Take care of the mandatory parameters result = SimpleType.parse_multi_parameter_cli(self, cli, alternate_asa_gen_template = self.asa_gen_template) #Take care of the optional parameters tokens = cli.split() if tokens[0] == 'no': result = {(Type.PARAM, 'status', '') : {'state': State.NOCHANGE, 'value': 'disable'}} return result # The number of mandatory parameters is 3, i.e. 'threat-detection statistics host' if len(tokens) == 3: return result # no optional parameter option = tokens[3:] if 'number-of-rate' in option: pos = option.index('number-of-rate') + 1 result = {(Type.PARAM, 'number_of_rate', '') : {'state': State.NOCHANGE, 'value': option[pos]}} else: return result return result
def parse_multi_parameter_cli(self, cli): '''Override the default implementation in case the CLI does not have optional max_retries value ''' # Take care of the optional parameters tokens = cli.split() if len(tokens) < len(self.asa_gen_template.split()): cli += ' ' + MAX_RETRIES_DEFAULT return SimpleType.parse_multi_parameter_cli(self, cli, alternate_asa_gen_template = self.asa_gen_template)
def parse_multi_parameter_cli(self, cli): '''Override the default implementation in case the CLI does not have optional max_retries value ''' # Take care of the optional parameters tokens = cli.split() if len(tokens) < len(self.asa_gen_template.split()): cli += ' ' + MAX_RETRIES_DEFAULT return SimpleType.parse_multi_parameter_cli( self, cli, alternate_asa_gen_template=self.asa_gen_template)
def parse_multi_parameter_cli(self, cli): ''' Override the default implementation in case the CLI does not match asa_gen_template due to optional parameter 'reset' ''' # Take care of the mandatory parameters result = SimpleType.parse_multi_parameter_cli(self, cli, alternate_asa_gen_template = self.asa_gen_template) # Take care of the optional parameters tokens = cli.split() # The number of mandatory parameters is the same as the asa_gen_template, i.e. 'service-policy global_policy global' if (result is None) or (len(tokens) == len(self.asa_gen_template.split())): return result # doesn't match or no optional parameter if TIMEOUT_RESET_CLI in tokens[-1:]: # e.g. set connection timeout idle 2:3:4 reset result[(Type.PARAM, 'idle_reset', TIMEOUT_RESET_CLI)] = {'state': State.NOCHANGE, 'value': 'enable'} return result
def parse_multi_parameter_cli(self, cli): ''' Override the default implementation in case the CLI does not match asa_gen_template due to optional parameter ''' # Take care of the mandatory parameters result = SimpleType.parse_multi_parameter_cli(self, cli, alternate_asa_gen_template = self.asa_gen_template) 'Take care of the optional parameters' tokens = cli.split() # The number of tokens must greater than 3, i.e. 'clacp system-mac [H.H.H | auto]' assert len(tokens) > 3 option = tokens[3:] if len(option) > 0: result[(Type.PARAM, 'system-priority', '')] = {'state': State.NOCHANGE, 'value': ''} result[Type.PARAM, 'system-priority', '']['value'] = option[0] return result
def parse_multi_parameter_cli(self, cli): '''Override the default implementation in case the CLI does not match asa_gen_template due to optional parameter ''' 'Take care of the mandatory parameters' result = SimpleType.parse_multi_parameter_cli(self, cli, alternate_asa_gen_template = 'ipv6 route %(interface)s %(prefix)s %(gateway)s') 'Take care of the optional parameters' for name, value in self.defaults.iteritems(): result[(Type.PARAM, name, '')] = {'state': State.NOCHANGE, 'value': value} tokens = cli.split() if len(tokens) == 5: return result #no optional parameter option = tokens[5] if option == 'tunneled': result[Type.PARAM, 'tunneled', '']['value'] = option elif option: result[Type.PARAM, 'hop_count', '']['value'] = option return result
def parse_multi_parameter_cli(self, cli): ''' Override the default implementation in case the CLI does not match asa_gen_template due to optional parameter 'reset' ''' # Take care of the mandatory parameters result = SimpleType.parse_multi_parameter_cli( self, cli, alternate_asa_gen_template=self.asa_gen_template) # Take care of the optional parameters tokens = cli.split() # The number of mandatory parameters is the same as the asa_gen_template, i.e. 'service-policy global_policy global' if (result is None) or (len(tokens) == len( self.asa_gen_template.split())): return result # doesn't match or no optional parameter if TIMEOUT_RESET_CLI in tokens[ -1:]: # e.g. set connection timeout idle 2:3:4 reset result[(Type.PARAM, 'idle_reset', TIMEOUT_RESET_CLI)] = { 'state': State.NOCHANGE, 'value': 'enable' } return result
def parse_multi_parameter_cli(self, cli): ''' Override the default implementation in case the CLI does not match asa_gen_template due to optional parameter ''' # Take care of the mandatory parameters result = SimpleType.parse_multi_parameter_cli( self, cli, alternate_asa_gen_template=self.asa_gen_template) 'Take care of the optional parameters' tokens = cli.split() # The number of tokens must greater than 3, i.e. 'failover interface ip ...' assert len(tokens) > 3 for name in ['interface_name', 'active_ip', 'standby_ip']: result[(Type.PARAM, name, '')] = { 'state': State.NOCHANGE, 'value': '' } option = tokens[3:] # for ipv4, option is: %(interface_name)s %(active_ip)s %(netmask)s standby %(standby_ip)s # for ipv6, option is: %(interface_name)s %(active_ip)s standby %(standby_ip)s result[Type.PARAM, 'interface_name', '']['value'] = option[0] result[Type.PARAM, 'active_ip', '']['value'] = option[1] if ':' not in option[1]: # ipv4 result[(Type.PARAM, 'netmask', '')] = { 'state': State.NOCHANGE, 'value': '' } result[Type.PARAM, 'netmask', '']['value'] = option[2] # skip option[3], which should be the 'standby' keyword result[Type.PARAM, 'standby_ip', '']['value'] = option[4] else: # ipv6, no netmask # skip option[2], which should be the 'standby' keyword result[Type.PARAM, 'standby_ip', '']['value'] = option[3] return result
def parse_multi_parameter_cli(self, cli): ''' Override the default implementation in case the CLI does not match asa_gen_template due to optional parameter ''' # Take care of the mandatory parameters result = SimpleType.parse_multi_parameter_cli( self, cli, alternate_asa_gen_template=self.asa_gen_template) 'Take care of the optional parameters' tokens = cli.split() # The number of mandatory parameters is 3, i.e. 'logging message 106015' if len(tokens) == 3: return result # no optional parameter result[(Type.PARAM, 'level', '')] = { 'state': State.NOCHANGE, 'value': '' } option = tokens[3:] if 'level' in option: # e.g. "logging message 106015 level critical result[Type.PARAM, 'level', '']['value'] = option[1] return result