Esempio n. 1
0
    def get_current_config(self):
        """get current configuration"""

        flags = list()
        exp = "| ignore-case section include bgp %s" % self.bgp_instance
        flags.append(exp)
        return get_config(self.module, flags)
Esempio n. 2
0
    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_netstream_config(self):
        """get current netstream configuration"""

        flags = list()
        exp = " | inc ^netstream export"
        flags.append(exp)
        return get_config(self.module, flags)
Esempio n. 4
0
    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_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)
Esempio n. 6
0
    def get_netstream_config(self):
        """get current netstream configuration"""

        flags = list()
        exp = " | inc ^netstream export"
        flags.append(exp)
        return get_config(self.module, flags)
Esempio n. 7
0
    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)
Esempio n. 8
0
    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)
Esempio n. 9
0
    def cli_get_config(self, regular):
        """ Cli method to get config """

        flags = list()
        flags.append(regular)
        tmp_cfg = get_config(self.module, flags)

        return tmp_cfg
Esempio n. 10
0
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)
Esempio n. 11
0
    def cli_get_config(self, regular):
        """ Cli method to get config """

        flags = list()
        flags.append(regular)
        tmp_cfg = get_config(self.module, flags)

        return tmp_cfg
Esempio n. 12
0
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)
Esempio n. 13
0
    def cli_get_config(self):
        """ Get configure through cli """

        regular = "| include snmp | include trap"
        flags = list()
        flags.append(regular)
        tmp_cfg = get_config(self.module, flags)

        return tmp_cfg
Esempio n. 14
0
    def cli_get_connect_port(self):
        """ Get connect port by cli """

        regular = "| include snmp | include snmp-agent udp-port"
        flags = list()
        flags.append(regular)
        tmp_cfg = get_config(self.module, flags)

        return tmp_cfg
Esempio n. 15
0
    def cli_get_connect_port(self):
        """ Get connect port by cli """

        regular = "| include snmp | include snmp-agent udp-port"
        flags = list()
        flags.append(regular)
        tmp_cfg = get_config(self.module, flags)

        return tmp_cfg
Esempio n. 16
0
    def cli_get_config(self):
        """ Get configure through cli """

        regular = "| include snmp | include trap"
        flags = list()
        flags.append(regular)
        tmp_cfg = get_config(self.module, flags)

        return tmp_cfg
Esempio n. 17
0
    def cli_get_config(self):
        """ Get config by cli """

        regular = "| include snmp | include location"
        flags = list()
        flags.append(regular)
        tmp_cfg = get_config(self.module, flags)

        return tmp_cfg
Esempio n. 18
0
    def cli_get_config(self):
        """ Get config by cli """

        regular = "| include snmp | include location"
        flags = list()
        flags.append(regular)
        tmp_cfg = get_config(self.module, flags)

        return tmp_cfg
Esempio n. 19
0
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', choices=['line', 'strict', 'exact', 'none']),
        replace=dict(default='line', choices=['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(ce_argument_spec)

    mutually_exclusive = [('lines', 'src'),
                          ('parents', 'src')]

    required_if = [('match', 'strict', ['lines']),
                   ('match', 'exact', ['lines']),
                   ('replace', '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)
Esempio n. 20
0
    def get_jumboframe_config(self):
        """ get_jumboframe_config"""

        flags = list()
        exp = " all | section inc %s$" % self.interface.upper()
        flags.append(exp)
        output = get_config(self.module, flags)
        output = output.replace('*', '')

        return self.prase_jumboframe_para(output)
Esempio n. 21
0
    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'
Esempio n. 22
0
    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'
Esempio n. 23
0
    def get_jumboframe_config(self):
        """ get_jumboframe_config"""

        flags = list()
        exp = " all | section inc %s$" % self.interface.upper()
        flags.append(exp)
        output = get_config(self.module, flags)
        output = output.replace('*', '')

        return self.prase_jumboframe_para(output)
Esempio n. 24
0
    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)
Esempio n. 25
0
    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 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)
Esempio n. 27
0
    def get_current_config(self):
        """get current configuration"""

        flags = list()
        exp = " | ignore-case section include dfs-group"
        if self.vpn_instance:
            exp += "|^ip vpn-instance %s$" % self.vpn_instance
        if self.vbdif_name:
            exp += "|^interface %s$" % self.vbdif_name
        flags.append(exp)
        return get_config(self.module, flags)
Esempio n. 28
0
    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_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["interface"] = "all"
        self.end_state["sampler"].append(sampler_tmp)
        if self.interface != "all":
            flags = list()
            exp = " | ignore-case  section include ^interface %s$" \
                  " | include netstream sampler random-packets" % self.interface
            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["interface"] = self.interface
                    self.end_state["sampler"].append(sampler_tmp1)
Esempio n. 30
0
def main():
    """ main entry point for module execution
    """
    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', choices=['line', 'strict', 'exact', 'none']),
        replace=dict(default='line', choices=['line', 'block']),
        config=dict(),
        defaults=dict(type='bool', default=False),

        backup=dict(type='bool', default=False),
        save=dict(type='bool', default=False),
    )

    argument_spec.update(ce_argument_spec)

    mutually_exclusive = [('lines', 'src'),
                          ('parents', 'src')]

    required_if = [('match', 'strict', ['lines']),
                   ('match', 'exact', ['lines']),
                   ('replace', '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)
Esempio n. 31
0
    def get_snmp_local_engine(self, **kwargs):
        """ Get snmp local engine operation """

        module = kwargs["module"]

        regular = "| include snmp | include local-engineid"
        flags = list()
        flags.append(regular)
        tmp_cfg = get_config(module, flags)

        if tmp_cfg:
            tmp_data = tmp_cfg.split(r"snmp-agent local-engineid ")
            self.local_engine_id = tmp_data[1]
Esempio n. 32
0
    def get_snmp_local_engine(self, **kwargs):
        """ Get snmp local engine operation """

        module = kwargs["module"]

        regular = "| include snmp | include local-engineid"
        flags = list()
        flags.append(regular)
        tmp_cfg = get_config(module, flags)

        if tmp_cfg:
            tmp_data = tmp_cfg.split(r"snmp-agent local-engineid ")
            self.local_engine_id = tmp_data[1]
Esempio n. 33
0
    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 += "|^interface %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
Esempio n. 34
0
    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 += "|^interface %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])
Esempio n. 36
0
    def get_config_in_bgp_view(self):
        """Get configuration in BGP view"""

        flags = list()
        exp = " | section include"
        if self.as_number:
            if self.bgp_instance:
                exp += " bgp %s instance %s" % (self.as_number,
                                                self.bgp_instance)
            else:
                exp += " bgp %s" % self.as_number

        flags.append(exp)
        config = get_config(self.module, flags)

        return config
Esempio n. 37
0
    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["interface"] = self.interface
        statistic_tmp1["statistics_record"] = list()
        statistic_tmp1["interface"] = self.interface
        flags = list()
        exp = " | ignore-case  section include ^interface %s$" \
              " | include netstream record"\
              % (self.interface)
        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)
Esempio n. 38
0
    def cli_get_interface_stp_config(self):
        """ Cli get interface's stp configuration """

        if self.interface:
            regular = "| ignore-case section include ^interface %s$" % self.interface
            flags = list()
            flags.append(regular)
            tmp_cfg = get_config(self.module, flags)

            if not tmp_cfg:
                self.module.fail_json(
                    msg='Error: The interface %s is not exist.' % self.interface)

            if "undo portswitch" in tmp_cfg:
                self.module.fail_json(
                    msg='Error: The interface %s is not switch mode.' % self.interface)

            self.interface_stp_cfg = tmp_cfg
    def get_config_in_bgp_view(self):
        """Get configuration in BGP view"""

        flags = list()
        exp = " | section include"
        if self.as_number:
            if self.bgp_instance:
                exp += " bgp %s instance %s" % (self.as_number,
                                                self.bgp_instance)
            else:
                exp += " bgp %s" % self.as_number

        flags.append(exp)
        config = get_config(self.module, flags)
        cmd = 'display current-configuration ' + exp
        config = config.strip() if config else ""
        if cmd == config:
            return ''

        return config
Esempio n. 40
0
    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)
    def get_end_interface_statistic(self):
        """get end netstream interface statistic parameters"""

        statistic_tmp1 = dict()
        statistic_tmp1["statistics_direction"] = list()
        flags = list()
        exp = " | ignore-case  section include ^interface %s$" \
              " | include netstream inbound|outbound"\
              % self.interface
        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["interface"] = self.interface
        self.end_state["statistic"].append(statistic_tmp1)