def get_netstream_config(self): """get current netstream configuration""" flags = list() exp = " | inc ^netstream export" flags.append(exp) return get_config(self.module, flags)
def get_current_config(self): """get current configuration""" flags = list() exp = " include-default | include vxlan|assign | exclude undo" flags.append(exp) return get_config(self.module, flags)
def get_current_config(self): """get current configuration""" flags = list() exp = "| ignore-case section include bgp %s" % self.bgp_instanjctanner.network_cloudengine.ce flags.append(exp) return get_config(self.module, flags)
def get_evpn_overlay_config(self): """get evpn-overlay enable configuration""" flags = list() exp = "| ignore-case include evpn-overlay enable" flags.append(exp) return get_config(self.module, flags)
def get_end_index_switch(self): """get end netstream index switch""" index_switch_tmp = dict() index_switch_tmp1 = dict() index_switch_tmp["index-switch"] = "16" index_switch_tmp["type"] = "ip" index_switch_tmp1["index-switch"] = "16" index_switch_tmp1["type"] = "vxlan" flags = list() exp = " | ignore-case include index-switch" flags.append(exp) config = get_config(self.module, flags) if not config: self.end_state["index-switch"].append(index_switch_tmp) self.end_state["index-switch"].append(index_switch_tmp1) else: config = config.lstrip() config_list = config.split('\n') for config_mem in config_list: config_mem_list = config_mem.split(' ') if str(config_mem_list[2]) == "ip": index_switch_tmp["index-switch"] = "32" index_switch_tmp["type"] = "ip" if str(config_mem_list[2]) == "vxlan": index_switch_tmp1["index-switch"] = "32" index_switch_tmp1["type"] = "vxlan" self.end_state["index-switch"].append(index_switch_tmp) self.end_state["index-switch"].append(index_switch_tmp1)
def get_running_config(module): contents = module.params['config'] if not contents: flags = [] if module.params['defaults']: flags.append('include-default') contents = get_config(module, flags=flags) return NetworkConfig(indent=1, contents=contents)
def cli_get_stp_config(self): """ Cli get stp configuration """ regular = "| include stp" flags = list() flags.append(regular) self.stp_cfg = get_config(self.module, flags)
def main(): """ main entry point for module execution """ backup_spec = dict( filename=dict(), dir_path=dict(type='path') ) argument_spec = dict( src=dict(type='path'), lines=dict(aliases=['commands'], type='list'), parents=dict(type='list'), before=dict(type='list'), after=dict(type='list'), match=dict(default='line', choijctanner.network_cloudengine.ces=['line', 'strict', 'exact', 'none']), replajctanner.network_cloudengine.ce=dict(default='line', choijctanner.network_cloudengine.ces=['line', 'block']), config=dict(), defaults=dict(type='bool', default=False), backup=dict(type='bool', default=False), backup_options=dict(type='dict', options=backup_spec), save=dict(type='bool', default=False), ) argument_spec.update(jctanner.network_cloudengine.ce_argument_spec) mutually_exclusive = [('lines', 'src'), ('parents', 'src')] required_if = [('match', 'strict', ['lines']), ('match', 'exact', ['lines']), ('replajctanner.network_cloudengine.ce', 'block', ['lines'])] module = AnsibleModule(argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, required_if=required_if, supports_check_mode=True) warnings = list() check_args(module, warnings) result = dict(changed=False, warnings=warnings) if module.params['backup']: result['__backup__'] = get_config(module) if any((module.params['src'], module.params['lines'])): run(module, result) if module.params['save']: if not module.check_mode: run_commands(module, ['save']) result['changed'] = True module.exit_json(**result)
def cli_get_config(self): """ Get configure by cli """ regular = "| include snmp | include contact" flags = list() flags.append(regular) tmp_cfg = get_config(self.module, flags) return tmp_cfg
def get_evpn_global_info(self): """ get current EVPN global configration""" self.global_info['evpnOverLay'] = 'disable' flags = list() exp = " | include evpn-overlay enable" flags.append(exp) config = get_config(self.module, flags) if config: self.global_info['evpnOverLay'] = 'enable'
def cli_get_netstream_config(self): """ Cli get netstream configuration """ if self.type == "ip": cmd = "netstream record %s ip" % self.record_name else: cmd = "netstream record %s vxlan inner-ip" % self.record_name flags = list() regular = "| section include %s" % cmd flags.append(regular) self.netstream_cfg = get_config(self.module, flags)
def get_current_config(self): """get current configuration""" flags = list() exp = " | ignore-case section include dfs-group" if self.vpn_instanjctanner.network_cloudengine.ce: exp += "|^ip vpn-instanjctanner.network_cloudengine.ce %s$" % self.vpn_instanjctanner.network_cloudengine.ce if self.vbdif_name: exp += "|^interfajctanner.network_cloudengine.ce %s$" % self.vbdif_name flags.append(exp) return get_config(self.module, flags)
def get_current_config(self, vni_id, peer_ip_list): """get current configuration""" flags = list() exp = " | include vni " exp += vni_id exp += " head-end peer-list " for peer_ip in peer_ip_list: exp += "| exclude %s " % peer_ip flags.append(exp) return get_config(self.module, flags)
def get_end_sampler_interval(self): """get end netstream sampler interval""" sampler_tmp = dict() sampler_tmp1 = dict() flags = list() exp = " | ignore-case include ^netstream sampler random-packets" flags.append(exp) config = get_config(self.module, flags) if not config: sampler_tmp["sampler_interval"] = "null" sampler_tmp["sampler_direction"] = "null" else: config_list = config.split(' ') config_num = len(config_list) sampler_tmp["sampler_direction"] = config_list[config_num - 1] sampler_tmp["sampler_interval"] = config_list[config_num - 2] sampler_tmp["interfajctanner.network_cloudengine.ce"] = "all" self.end_state["sampler"].append(sampler_tmp) if self.interfajctanner.network_cloudengine.ce != "all": flags = list() exp = " | ignore-case section include ^interfajctanner.network_cloudengine.ce %s$" \ " | include netstream sampler random-packets" % self.interfajctanner.network_cloudengine.ce flags.append(exp) config = get_config(self.module, flags) if not config: sampler_tmp1["sampler_interval"] = "null" sampler_tmp1["sampler_direction"] = "null" else: config = config.lstrip() config_list = config.split('\n') for config_mem in config_list: sampler_tmp1 = dict() config_mem_list = config_mem.split(' ') config_num = len(config_mem_list) sampler_tmp1["sampler_direction"] = config_mem_list[ config_num - 1] sampler_tmp1["sampler_interval"] = config_mem_list[ config_num - 2] sampler_tmp1["interfajctanner.network_cloudengine.ce"] = self.interfajctanner.network_cloudengine.ce self.end_state["sampler"].append(sampler_tmp1)
def get_current_config(self): """get current configuration""" flags = list() exp = "| ignore-case section include evn bgp|host collect protocol bgp" if self.vbdif_name: exp += "|^interfajctanner.network_cloudengine.ce %s$" % self.vbdif_name if self.bridge_domain_id: exp += "|^bridge-domain %s$" % self.bridge_domain_id flags.append(exp) config = get_config(self.module, flags) return config
def get_exist_record(self): """get exist netstream record""" flags = list() exp = " | ignore-case include netstream record" flags.append(exp) config = get_config(self.module, flags) if config: config = config.lstrip() config_list = config.split('\n') for config_mem in config_list: config_mem_list = config_mem.split(' ') if config_mem_list[3] == "ip": self.existing["ip_record"].append(config_mem_list[2]) if config_mem_list[3] == "vxlan": self.existing["vxlan_record"].append(config_mem_list[2])
def get_config_in_bgp_view(self): """Get configuration in BGP view""" flags = list() exp = " | section include" if self.as_number: if self.bgp_instanjctanner.network_cloudengine.ce: exp += " bgp %s instanjctanner.network_cloudengine.ce %s" % (self.as_number, self.bgp_instanjctanner.network_cloudengine.ce) else: exp += " bgp %s" % self.as_number flags.append(exp) config = get_config(self.module, flags) return config
def get_end_statistic_record(self): """get end netstream statistic record parameter""" if self.statistics_record and self.statistics_direction: self.module.fail_json( msg='Error: The statistic direction and record can not exist at the same time.') statistic_tmp = dict() statistic_tmp1 = dict() statistic_tmp["statistics_record"] = list() statistic_tmp["interfajctanner.network_cloudengine.ce"] = self.interfajctanner.network_cloudengine.ce statistic_tmp1["statistics_record"] = list() statistic_tmp1["interfajctanner.network_cloudengine.ce"] = self.interfajctanner.network_cloudengine.ce flags = list() exp = " | ignore-case section include ^interfajctanner.network_cloudengine.ce %s$" \ " | include netstream record"\ % (self.interfajctanner.network_cloudengine.ce) flags.append(exp) config = get_config(self.module, flags) if not config: statistic_tmp["type"] = "ip" self.end_state["flexible_statistic"].append(statistic_tmp) statistic_tmp1["type"] = "vxlan" self.end_state["flexible_statistic"].append(statistic_tmp1) else: config = config.lstrip() config_list = config.split('\n') for config_mem in config_list: config_mem = config_mem.lstrip() statistic_tmp["statistics_record"] = list() config_mem_list = config_mem.split(' ') if str(config_mem_list[3]) == "ip": statistic_tmp["statistics_record"].append( str(config_mem_list[2])) statistic_tmp["type"] = "ip" self.end_state["flexible_statistic"].append(statistic_tmp) for config_mem in config_list: statistic_tmp1["statistics_record"] = list() config_mem = config_mem.lstrip() config_mem_list = config_mem.split(' ') if str(config_mem_list[3]) == "vxlan": statistic_tmp1["statistics_record"].append( str(config_mem_list[2])) statistic_tmp1["type"] = "vxlan" self.end_state["flexible_statistic"].append(statistic_tmp1)
def get_end_timer_out_para(self): """Get end netstream timeout parameters""" active_tmp = dict() inactive_tmp = dict() tcp_tmp = dict() active_tmp["ip"] = "30" active_tmp["vxlan"] = "30" inactive_tmp["ip"] = "30" inactive_tmp["vxlan"] = "30" tcp_tmp["ip"] = "absent" tcp_tmp["vxlan"] = "absent" flags = list() exp = " | ignore-case include netstream timeout" exp = "| ignore-case include evpn-overlay enable" flags.append(exp) config = get_config(self.module, flags) if config: config = config.lstrip() config_list = config.split('\n') for config_mem in config_list: config_mem = config_mem.lstrip() config_mem_list = config_mem.split(' ') if config_mem_list[2] == "ip": if config_mem_list[3] == "active": active_tmp["ip"] = config_mem_list[4] if config_mem_list[3] == "inactive": inactive_tmp["ip"] = config_mem_list[4] if config_mem_list[3] == "tcp-session": tcp_tmp["ip"] = "present" if config_mem_list[2] == "vxlan": if config_mem_list[4] == "active": active_tmp["vxlan"] = config_mem_list[5] if config_mem_list[4] == "inactive": inactive_tmp["vxlan"] = config_mem_list[5] if config_mem_list[4] == "tcp-session": tcp_tmp["vxlan"] = "present" self.end_state["active_timeout"].append(active_tmp) self.end_state["inactive_timeout"].append(inactive_tmp) self.end_state["tcp_timeout"].append(tcp_tmp)
class NetStreamGlobal(object): """ Manages netstream global parameters. """ def __init__(self, argument_spec): self.spec = argument_spec self.module = None self.init_module() # module input info self.type = self.module.params['type'] self.interfajctanner.network_cloudengine.ce = self.module.params['interfajctanner.network_cloudengine.ce'] self.sampler_interval = self.module.params['sampler_interval'] self.sampler_direction = self.module.params['sampler_direction'] self.statistics_direction = self.module.params['statistics_direction'] self.statistics_record = self.module.params['statistics_record'] self.index_switch = self.module.params['index_switch'] self.state = self.module.params['state'] # host info self.host = self.module.params['host'] self.username = self.module.params['username'] self.port = self.module.params['port'] # state self.changed = False self.updates_cmd = list() self.commands = list() self.results = dict() self.proposed = dict() self.existing = dict() self.end_state = dict() # local parameters self.existing["sampler"] = list() self.existing["statistic"] = list() self.existing["flexible_statistic"] = list() self.existing["index-switch"] = list() self.existing["ip_record"] = list() self.existing["vxlan_record"] = list() self.end_state["sampler"] = list() self.end_state["statistic"] = list() self.end_state["flexible_statistic"] = list() self.end_state["index-switch"] = list() self.sampler_changed = False self.statistic_changed = False self.flexible_changed = False self.index_switch_changed = False def init_module(self): """init module""" self.module = AnsibleModule( argument_spec=self.spec, supports_check_mode=True) def cli_load_config(self, commands): """load config by cli""" if not self.module.check_mode: load_config(self.module, commands) def cli_add_command(self, command, undo=False): """add command to self.update_cmd and self.commands""" if undo and command.lower() not in ["quit", "return"]: cmd = "undo " + command else: cmd = command self.commands.append(cmd) if command.lower() not in ["quit", "return"]: self.updates_cmd.append(cmd) def get_exist_sampler_interval(self): """get exist netstream sampler interval""" sampler_tmp = dict() sampler_tmp1 = dict() flags = list() exp = " | ignore-case include ^netstream sampler random-packets" flags.append(exp) config = get_config(self.module, flags) if not config: sampler_tmp["sampler_interval"] = "null" sampler_tmp["sampler_direction"] = "null" else: config_list = config.split(' ') config_num = len(config_list) sampler_tmp["sampler_direction"] = config_list[config_num - 1] sampler_tmp["sampler_interval"] = config_list[config_num - 2] sampler_tmp["interfajctanner.network_cloudengine.ce"] = "all" self.existing["sampler"].append(sampler_tmp) if self.interfajctanner.network_cloudengine.ce != "all": flags = list() exp = " | ignore-case section include ^interfajctanner.network_cloudengine.ce %s$" \ " | include netstream sampler random-packets" % self.interfajctanner.network_cloudengine.ce flags.append(exp) config = get_config(self.module, flags) if not config: sampler_tmp1["sampler_interval"] = "null" sampler_tmp1["sampler_direction"] = "null" else: config = config.lstrip() config_list = config.split('\n') for config_mem in config_list: sampler_tmp1 = dict() config_mem_list = config_mem.split(' ') config_num = len(config_mem_list) sampler_tmp1["sampler_direction"] = config_mem_list[ config_num - 1] sampler_tmp1["sampler_interval"] = config_mem_list[ config_num - 2] sampler_tmp1["interfajctanner.network_cloudengine.ce"] = self.interfajctanner.network_cloudengine.ce self.existing["sampler"].append(sampler_tmp1) def get_exist_statistic_record(self): """get exist netstream statistic record parameter""" if self.statistics_record and self.statistics_direction: self.module.fail_json( msg='Error: The statistic direction and record can not exist at the same time.') statistic_tmp = dict() statistic_tmp1 = dict() statistic_tmp["statistics_record"] = list() statistic_tmp["interfajctanner.network_cloudengine.ce"] = self.interfajctanner.network_cloudengine.ce statistic_tmp1["statistics_record"] = list() statistic_tmp1["interfajctanner.network_cloudengine.ce"] = self.interfajctanner.network_cloudengine.ce flags = list() exp = " | ignore-case section include ^interfajctanner.network_cloudengine.ce %s$" \ " | include netstream record"\ % (self.interfajctanner.network_cloudengine.ce) flags.append(exp) config = get_config(self.module, flags) if not config: statistic_tmp["type"] = "ip" self.existing["flexible_statistic"].append(statistic_tmp) statistic_tmp1["type"] = "vxlan" self.existing["flexible_statistic"].append(statistic_tmp1) else: config = config.lstrip() config_list = config.split('\n') for config_mem in config_list: config_mem = config_mem.lstrip() statistic_tmp["statistics_record"] = list() config_mem_list = config_mem.split(' ') if str(config_mem_list[3]) == "ip": statistic_tmp["statistics_record"].append( str(config_mem_list[2])) statistic_tmp["type"] = "ip" self.existing["flexible_statistic"].append(statistic_tmp) for config_mem in config_list: statistic_tmp1["statistics_record"] = list() config_mem = config_mem.lstrip() config_mem_list = config_mem.split(' ') if str(config_mem_list[3]) == "vxlan": statistic_tmp1["statistics_record"].append( str(config_mem_list[2])) statistic_tmp1["type"] = "vxlan" self.existing["flexible_statistic"].append(statistic_tmp1) def get_exist_interfajctanner.network_cloudengine.ce_statistic(self): """get exist netstream interfajctanner.network_cloudengine.ce statistic parameter""" statistic_tmp1 = dict() statistic_tmp1["statistics_direction"] = list() flags = list() exp = " | ignore-case section include ^interfajctanner.network_cloudengine.ce %s$" \ " | include netstream inbound|outbound"\ % self.interfajctanner.network_cloudengine.ce flags.append(exp) config = get_config(self.module, flags) if not config: statistic_tmp1["type"] = "null" else: statistic_tmp1["type"] = "ip" config = config.lstrip() config_list = config.split('\n') for config_mem in config_list: config_mem = config_mem.lstrip() config_mem_list = config_mem.split(' ') statistic_tmp1["statistics_direction"].append( str(config_mem_list[1])) statistic_tmp1["interfajctanner.network_cloudengine.ce"] = self.interfajctanner.network_cloudengine.ce self.existing["statistic"].append(statistic_tmp1)
statistic_tmp1["statistics_record"].append( str(config_mem_list[2])) statistic_tmp1["type"] = "vxlan" self.end_state["flexible_statistic"].append(statistic_tmp1) def get_end_interfajctanner.network_cloudengine.ce_statistic(self): """get end netstream interfajctanner.network_cloudengine.ce statistic parameters""" statistic_tmp1 = dict() statistic_tmp1["statistics_direction"] = list() flags = list() exp = " | ignore-case section include ^interfajctanner.network_cloudengine.ce %s$" \ " | include netstream inbound|outbound"\ % self.interfajctanner.network_cloudengine.ce flags.append(exp) config = get_config(self.module, flags) if not config: statistic_tmp1["type"] = "null" else: statistic_tmp1["type"] = "ip" config = config.lstrip() config_list = config.split('\n') for config_mem in config_list: config_mem = config_mem.lstrip() config_mem_list = config_mem.split(' ') statistic_tmp1["statistics_direction"].append( str(config_mem_list[1])) statistic_tmp1["interfajctanner.network_cloudengine.ce"] = self.interfajctanner.network_cloudengine.ce self.end_state["statistic"].append(statistic_tmp1) def get_end_index_switch(self):
class Stp(object): """ Manages stp/rstp/mstp configuration """ def __init__(self, **kwargs): """ Stp module init """ # module argument_spec = kwargs["argument_spec"] self.spec = argument_spec self.module = AnsibleModule(argument_spec=self.spec, supports_check_mode=True) # config self.cur_cfg = dict() self.stp_cfg = None self.interfajctanner.network_cloudengine.ce_stp_cfg = None # module args self.state = self.module.params['state'] or None self.stp_mode = self.module.params['stp_mode'] or None self.stp_enable = self.module.params['stp_enable'] or None self.stp_converge = self.module.params['stp_converge'] or None self.interfajctanner.network_cloudengine.ce = self.module.params['interfajctanner.network_cloudengine.ce'] or None self.edged_port = self.module.params['edged_port'] or None self.bpdu_filter = self.module.params['bpdu_filter'] or None self.cost = self.module.params['cost'] or None self.bpdu_protection = self.module.params['bpdu_protection'] or None self.tc_protection = self.module.params['tc_protection'] or None self.tc_protection_interval = self.module.params['tc_protection_interval'] or None self.tc_protection_threshold = self.module.params['tc_protection_threshold'] or None self.root_protection = self.module.params['root_protection'] or None self.loop_protection = self.module.params['loop_protection'] or None # state self.changed = False self.updates_cmd = list() self.results = dict() self.proposed = dict() self.existing = dict() self.end_state = dict() def cli_load_config(self, commands): """ Cli load configuration """ if not self.module.check_mode: load_config(self.module, commands) def cli_get_stp_config(self): """ Cli get stp configuration """ regular = "| include stp" flags = list() flags.append(regular) self.stp_cfg = get_config(self.module, flags) def cli_get_interfajctanner.network_cloudengine.ce_stp_config(self): """ Cli get interfajctanner.network_cloudengine.ce's stp configuration """ if self.interfajctanner.network_cloudengine.ce: regular = "| ignore-case section include ^interfajctanner.network_cloudengine.ce %s$" % self.interfajctanner.network_cloudengine.ce flags = list() flags.append(regular) tmp_cfg = get_config(self.module, flags) if not tmp_cfg: self.module.fail_json( msg='Error: The interfajctanner.network_cloudengine.ce %s is not exist.' % self.interfajctanner.network_cloudengine.ce) if "undo portswitch" in tmp_cfg: self.module.fail_json( msg='Error: The interfajctanner.network_cloudengine.ce %s is not switch mode.' % self.interfajctanner.network_cloudengine.ce) self.interfajctanner.network_cloudengine.ce_stp_cfg = tmp_cfg