Exemplo n.º 1
0
    def __init__(self):
        """Init processing"""
        self.tool = flow_common_tool()
        self.xml = xml_tool()

        self.debug_to_stdout = False
        self.default = {
            "cli_show_timeout": 300,
            "conf_commit_timeout": 300,
        }
        self.runtime = {}

        # MTS behavior compatible support
        self.get_route_instance_entry = self.fetch_route_instance_entry
        self.search_route_instance_entry = self.verify_route_instance_entry
Exemplo n.º 2
0
    def __init__(self, **kwargs):
        """Constructor method to update the instance of RUtils class."""
        for key in kwargs:
            setattr(self, key, kwargs[key])

        self.dd = lambda: defaultdict(self.dd)
        # self.tg = None
        self.dh = None
        self.xml = xml_tool()
        self.topo = self.dd()
        self.cmd = ''
        self.tg_port_pairs = []
        self.resource = None
        self.cmd_list = []
        self.ptr = {}
        self.log = utils.log
        self._chk_in_msg = {}
        self._cmd_name_tag = None
        self._cmd_mapping = None
Exemplo n.º 3
0
def get_secintel_feed_summary_specific(srx_handle, feed_category, feed_name,
                                       status_type='status', device_type='SA', logical_system=None, tenant=None):
    """
    Get SecIntel feed Summary
    :param srx_handle: SRX handle
    :param feed_category: Feed Category name
    :param feed_name: Feed name
    :param logical_system: LDOM name
    :param tenant: Tenant name
    :param status_type: (Default value: status)
           Feed summary field you want this function to return - values should be one of these:
           (status, update-status, name, version, objects, create-time, update-time, expired, options)
    :param device_type: Is it HA or SA Device (Default value: HA)
    :return: Requested value
    """
    prefix = 'show services security-intelligence category summary ' \
             '{}' \
             ''.format(feed_category)
    if logical_system is not None:
        command = prefix + ' logical-system {}'.format(logical_system)
    elif tenant is not None:
        command = prefix + ' tenant {}'.format(tenant)
    else:
        command = prefix
    response = srx_handle.cli(command=command, format="XML", channel="PYEZ").response()
    srx_handle.log(response)

    summary_dict = xml_tool().xml_obj_to_dict(response)
    srx_handle.log(summary_dict)

    dict_location = None
    if device_type is 'HA':
        dict_location = summary_dict["multi-routing-engine-results"]["multi-routing-engine-item"]["secintel-category"][
            "secintel-category-summary"]["secintel-category-summary-feed"]
    elif device_type is 'SA':
        dict_location = summary_dict["secintel-category"]["secintel-category-summary"]["secintel-category-summary-feed"]
    if str(type(dict_location)) == '<class \'jxmlease.dictnode.XMLDictNode\'>':
        return dict_location["secintel-category-summary-feed-" + status_type]
    elif str(type(dict_location)) == '<class \'jxmlease.listnode.XMLListNode\'>':
        for ind in range(len(dict_location)):
            if dict_location[ind]["secintel-category-summary-feed-name"] in feed_name:
                return dict_location[ind]["secintel-category-summary-feed-" + status_type]
Exemplo n.º 4
0
    def __init__(self):
        """Init processing"""
        super().__init__()
        self.xml = xml_tool()
        self.tool = flow_common_tool()
        self.license = system_license()

        self.default = {
            "cli_commit_timeout":       120,
            "cli_show_timeout":         300,
            "cli_reboot_timeout":       600,
            "regress_username":         credentials.Junos["USERNAME"],
            "regress_password":         credentials.Junos["PASSWORD"],
            "root_username":            credentials.Junos["SU"],
            "root_password":            credentials.Junos["SUPASSWORD"],
        }

        self.info = {
            "version_info":                 {},             # for get_version_info method
            "tnpdump_info":                 {},             # for send_vty_cmd_and_get_response
            "root_permission":              {},             # indicate device whehter work in root
        }
Exemplo n.º 5
0
    def setUp(self):
        """setup before all cases"""
        self.tool = flow_common_tool()
        self.xml = xml_tool()
        self.ins = lsys()

        self.response = {}
        self.response["SA_LSYS_MULTITENANCY"] = """
    <show-mtenancy xmlns="http://xml.juniper.net/junos/18.2I0/junos-lsys-lic">
        <mtenancy-mode-config>logical-domain</mtenancy-mode-config>
        <mtenancy-mode-running>logical-domain</mtenancy-mode-running>
    </show-mtenancy>
        """

        self.response["SA_LSYS_MULTITENANCY_IN_LSYS"] = """
    <show-mtenancy xmlns="http://xml.juniper.net/junos/18.2I0/junos-lsys-lic">
        <mtenancy-mode-config>logical-system</mtenancy-mode-config>
        <mtenancy-mode-running>logical-system</mtenancy-mode-running>
    </show-mtenancy>
        """

        self.response["HA_LSYS_MULTITENANCY"] = """
    <multi-routing-engine-results>

        <multi-routing-engine-item>

            <re-name>node1</re-name>

            <show-mtenancy xmlns="http://xml.juniper.net/junos/18.2I0/junos-lsys-lic">
                <mtenancy-mode-config>logical-domain</mtenancy-mode-config>
                <mtenancy-mode-running>logical-domain</mtenancy-mode-running>
            </show-mtenancy>
        </multi-routing-engine-item>

    </multi-routing-engine-results>
        """

        self.response["SA_LSYS_MULTITENANCY_NEED_REBOOT"] = """
Exemplo n.º 6
0
    def setUp(self):
        """setup before all cases"""
        self.tool = flow_common_tool()
        self.xml = xml_tool()
        self.ins = services_offload()

        self.response = {}
        self.response["SA_HE_FPC_PIC_STATUS_WITH_SOF"] = """
Slot 1   Online       SRX5k IOC II
  PIC 0  Online       10x 10GE SFP+- np-cache/services-offload
Slot 3   Online       SPC3
  PIC 0  Online       SPU Cp-Flow
  PIC 1  Online       SPU Flow
        """

        self.response["SA_HE_FPC_PIC_STATUS_WITHOUT_SOF"] = """
Slot 1   Online       SRX5k IOC II
  PIC 0  Online       10x 10GE SFP+-
Slot 3   Online       SPC3
  PIC 0  Online       SPU Cp-Flow
  PIC 1  Online       SPU Flow
        """

        self.response["SA_HE_SHOW_INTERFACE"] = """
Exemplo n.º 7
0
    def __init__(self):
        """INIT"""
        self.tool = flow_common_tool()
        self.xml = xml_tool()

        self.default = {
            "CLI_SHOW_TIMEOUT": 300,
            "CLI_COMMIT_TIMEOUT": 300,
        }

        self.debug_to_stdout = False
        self.runtime = {}

        # MTS compatible keywords
        self.get_address_book = self.fetch_address_book
        self.get_appfw_profile = self.fetch_appfw_profile
        self.get_appfw_rule = self.fetch_appfw_rule
        self.get_appfw_rule_set = self.fetch_appfw_rule_set
        self.get_auth_entry = self.fetch_auth_entry
        self.get_flow_gate = self.fetch_flow_gate
        self.get_flow_session = self.fetch_flow_session
        self.get_dslite_softwire_initiator = self.fetch_dslite_softwire_initiator
        self.get_nat_cone_binding = self.fetch_nat_cone_binding
        self.get_nat_destination_pool = self.fetch_nat_destination_pool
        self.get_nat_destination_rule = self.fetch_nat_destination_rule
        self.get_nat_interface_port_ol = self.fetch_nat_interface_port_ol
        self.get_nat_nopat_address = self.fetch_nat_nopat_address
        self.get_nat_pat_address = self.fetch_nat_pat_address
        self.get_nat_pat_portnum = self.fetch_nat_pat_portnum
        self.get_nat_port_ol_ipnumber = self.fetch_nat_port_ol_ipnumber
        self.get_nat_rule_referenced_prefix = self.fetch_nat_rule_referenced_prefix
        self.get_nat_source_pool = self.fetch_nat_source_pool
        self.get_nat_source_rule = self.fetch_nat_source_rule
        self.get_nat_static_rule = self.fetch_nat_static_rule
        self.get_policy = self.fetch_policy
        self.get_policy_with_count = self.fetch_policy_with_count
        self.get_scheduler = self.fetch_scheduler
        self.get_security_log_stream_number = self.fetch_security_log_stream_number
        self.get_zone = self.fetch_zone
        self.search_address_book = self.verify_address_book
        self.search_appfw_profile = self.verify_appfw_profile
        self.search_appfw_rule = self.verify_appfw_rule
        self.search_appfw_rule_set = self.verify_appfw_rule_set
        self.search_auth_entry = self.verify_auth_entry
        self.search_dslite_softwire_initiator = self.verify_dslite_softwire_initiator
        self.search_flow_gate = self.verify_flow_gate
        self.search_flow_session = self.verify_flow_session
        self.search_nat_cone_binding = self.verify_nat_cone_binding
        self.search_nat_destination_pool = self.verify_nat_destination_pool
        self.search_nat_destination_rule = self.verify_nat_destination_rule
        self.search_nat_interface_port_ol = self.verify_nat_interface_port_ol
        self.search_nat_nopat_address = self.verify_nat_nopat_address
        self.search_nat_pat_address = self.verify_nat_pat_address
        self.search_nat_pat_portnum = self.verify_nat_pat_portnum
        self.search_nat_port_ol_ipnumber = self.verify_nat_port_ol_ipnumber
        self.search_nat_rule_referenced_prefix = self.verify_nat_rule_referenced_prefix
        self.search_nat_source_pool = self.verify_nat_source_pool
        self.search_nat_source_rule = self.verify_nat_source_rule
        self.search_nat_static_rule = self.verify_nat_static_rule
        self.search_policy = self.verify_policy
        self.search_policy_with_count = self.verify_policy_with_count
        self.search_scheduler = self.verify_scheduler
        self.search_security_log_stream_number = self.verify_security_log_stream_number
        self.search_zone = self.verify_zone
Exemplo n.º 8
0
    def setUp(self):
        """setup before all cases"""
        self.tool = flow_common_tool()
        self.xml = xml_tool()
        self.ins = system_license()

        self.response = {}
        self.response["MULTI_LICENSE"] = """
    <license-usage-summary xmlns="http://xml.juniper.net/junos/15.1I0/junos-license">
        <features-used/>
        <feature-summary>
            <name>idp-sig</name>
            <description>IDP Signature</description>
            <licensed>1</licensed>
            <used-licensed>0</used-licensed>
            <needed>0</needed>
            <end-date junos:seconds="1545696000">2018-12-25</end-date>
        </feature-summary>
        <feature-summary>
            <name>appid-sig</name>
            <description>APPID Signature</description>
            <licensed>1</licensed>
            <used-licensed>0</used-licensed>
            <needed>0</needed>
            <end-date junos:seconds="1545696000">2018-12-25</end-date>
        </feature-summary>
        <feature-summary>
            <name>logical-system</name>
            <description>Logical System Capacity</description>
            <licensed>1</licensed>
            <used-licensed>1</used-licensed>
            <used-given>0</used-given>
            <needed>0</needed>
            <validity-type>permanent</validity-type>
        </feature-summary>
        <feature-summary>
            <name>remote-access-ipsec-vpn-client</name>
            <description>remote-access-ipsec-vpn-client</description>
            <licensed>2</licensed>
            <used-licensed>0</used-licensed>
            <needed>0</needed>
            <validity-type>permanent</validity-type>
        </feature-summary>
        <feature-summary>
            <name>Virtual Appliance</name>
            <description>Virtual Appliance</description>
            <licensed>1</licensed>
            <used-licensed>1</used-licensed>
            <needed>0</needed>
            <remaining-time>
                <remaining-validity-value junos:seconds="2572880">29 days</remaining-validity-value>
            </remaining-time>
        </feature-summary>
    </license-usage-summary>
        """

        self.response["SINGLE_PERMANENT_LICENSE"] = """
    <license-usage-summary xmlns="http://xml.juniper.net/junos/15.1I0/junos-license">
        <feature-summary>
            <name>logical-system</name>
            <description>Logical System Capacity</description>
            <licensed>1</licensed>
            <used-licensed>1</used-licensed>
            <used-given>0</used-given>
            <needed>0</needed>
            <validity-type>permanent</validity-type>
        </feature-summary>
    </license-usage-summary>
        """

        self.response["SINGLE_END_DATE_LICENSE"] = """
    <license-usage-summary xmlns="http://xml.juniper.net/junos/15.1I0/junos-license">
        <feature-summary>
            <name>idp-sig</name>
            <description>IDP Signature</description>
            <licensed>1</licensed>
            <used-licensed>0</used-licensed>
            <needed>0</needed>
            <end-date junos:seconds="1545696000">2018-12-25</end-date>
        </feature-summary>
    </license-usage-summary>
        """

        self.response["SINGLE_REMAINING_TIME_LICENSE"] = """
Exemplo n.º 9
0
def ensure_usf_mode(device_handle):
    """ Enable USF mode and reboot devices in parallel. Skips rebooting if usf mode is already enabled.
        :param device_handle list device_handle:
            **MANDATORY**  pass single or list of device handles
        :return: True if enabling usf mode is successfull
        :rtype: bool

        Example::
            Python:
                ensure_usf_mode(r0) # r0 is device handle
                ensure_usf_mode([r0, r1]) # r0, r1 are device handles

            Robot:
                ${r0} =  Get Handle   resource=device0    controller=re0
                ${r1} =  Get Handle   resource=device0    controller=re1
                @{device_list} =  Create List    ${r0}   ${r1}
                Ensure Usf Mode    device_handle=${device_list}
    """
    if isinstance(device_handle, (list, tuple)):
        dev_list = device_handle
    else:
        dev_list = (device_handle, )
    xpath = 'unified-services-status-information/unified-services-status'
    reboot_list = []
    for dev in dev_list:
        output = dev.cli(command='show system unified-services status',
                         timeout=120,
                         format='xml').response()
        xml_handle = xml_tool()
        xml_tree = xml_handle.xml_string_to_dict(xml_str=output)
        xml_tree = xml_tree['rpc-reply']
        for path in xpath.split('/'):
            xml_tree = xml_tree[path]
        if xml_tree != 'Unified Services : Enabled':
            dev.config(
                command_list=['load override /var/tmp/baseline-config.conf'
                              ]).status()
            dev.commit()
            dev.cli(command='request system enable unified-services',
                    pattern='.*').response()
            dev.cli(command='yes').response()
            reboot_list.append(dev)
        else:
            print("USF Mode is Enabled Already....So Skipping .....!!")
    if reboot_list:
        reboot_router = dut_tool()
        reboot_router.reboot(device=reboot_list,
                             wait=30,
                             timeout=480,
                             mode='cli',
                             check_interval=30,
                             on_parallel=True)
        for dev1 in dev_list:
            status = dev1.cli(command='show system unified-services status',
                              timeout=120,
                              format='xml').response()
            xml_new = xml_handle.xml_string_to_dict(xml_str=status)
            xml_new = xml_new['rpc-reply']
            for new_path in xpath.split('/'):
                xml_new = xml_new[new_path]
            if xml_new == 'Unified Services : Enabled':
                print("USF Mode is enabled !!")
            else:
                raise TobyException('USF is still not enabled')
    return True
Exemplo n.º 10
0
    def setUp(self):
        self.pcp = pcp(dh=None)
        self.xml = xml_tool()
        self.pcp.log = MagicMock()
        self.pcp.config = MagicMock()
        self.pcp.config.return_value = True
        self.pcp.cmd_add = MagicMock()
        self.pcp.config = MagicMock()
        self.pcp.dh = MagicMock()
        self.pcp.dh.cli = MagicMock()
        self.pcp.dh.cli = MagicMock()
        self.pcp.fn_checkin = MagicMock()
        self.pcp.fn_checkout = MagicMock()
        self.pcp.fn_checkout.return_value = True

        dd = {}
        dd = lambda: defaultdict(dd)
        self.pcp.dd = MagicMock()
        self.pcp.dd.return_value = dd()

        self.pcp.r_if = {'ss1'}
        self.pcp.resource = 'esst480p'
        #self.pcp.topo = {'intf' : {'ms-5/0/0' : { 'path' : 'r0r1'}}, 'path_res' : { 'esst480p' : { 'r0r1' : ['intf1']}}}
        self.pcp.topo = {
            'intf': {
                '1/1': {
                    'path': 'r0r1'
                }
            },
            'path_res': {
                'esst480p': {
                    'r0r1': ['intf1']
                }
            }
        }
        builtins.t = {
            'resources': {
                'esst480p': {
                    'interfaces': {
                        'intf1': {
                            'pic': 'ms-5/0/0'
                        }
                    }
                }
            }
        }
        self.pcp.intf_ss = {'ms-5/0/0': 'ss1'}
        self.pcp.sset = {'ss1': {'spic': 'ms-5/0/0', 'nat_rules': ['nr1']}}
        #self.pcp.nat_rule = {'nr1': {'src_pool': 'np1'}}
        #self.pcp.nat_rule = {'nr1': {'src_pool': 'np1', 'trans_type': 'dnat','trans_eim': 1,'trans_eif': 1}}
        self.pcp.nat_rule = {
            'nr1': {
                'src_pool': 'np1',
                'trans_type': 'napt',
                'trans_eim': 1,
                'trans_eif': 1
            }
        }
        self.pcp.nat_pool = {
            'np1': {
                'trans_type': 'napt',
                'addr': '112.1.1.0/24',
                'nat_port': '1024-3456'
            },
            'np2': {
                'trans_type': 'dynamic',
                'addr': '120.1.1.0/24'
            }
        }
        #self.pcp.tg_sess = {'ms-5/0/0': {'sess_list': [{'src_ip': '11.1.1.2','src_port': '5060'},{'src_ip': '11.1.1.2','src_port': '5060'},{'src_ip': '11.1.1.2','src_port': '5060'}]}}
        self.pcp.tg_sess = {
            '1/1': {
                'total':
                10,
                'src_ips_list': ['11.1.1.2', '11.1.1.3'],
                'dst_ips_list': ['60.1.1.2', '60.1.1.3'],
                'sess_list': [{
                    'src_ip': '11.1.1.2',
                    'src_port': '5060'
                }, {
                    'src_ip': '11.1.1.2',
                    'src_port': '5060'
                }, {
                    'src_ip': '11.1.1.2',
                    'src_port': '5060'
                }]
            },
            'total': 10
        }
        self.pcp.tg_cfg_map = {
            '1/1': {
                'spic': 'ms-5/0/0',
                'sset': 'ss1',
                'nat_rule': 'nr1',
                'nat_pool': 'np1',
                'nat_ip': '112.1.1.0/24',
                'nat_port': '1024-3456',
                'nat_port_low': '1024',
                'nat_port_high': '3456',
                'tot_sess': 1,
                'rand_sess_idx_list': [0]
            }
        }
        #self.pcp.tg_sess_cnt_pcp = {'1/1':10, 'total': 10}
        self.pcp.pool_map = {'np1': {'tot_sess': 10}, 'np2': {'tot_sess': 10}}
        self.pcp.MissingMandatoryArgument = MissingMandatoryArgument
Exemplo n.º 11
0
    def setUp(self):
        """setup before all case"""
        self.tool = flow_common_tool()
        self.xml = xml_tool()
        self.ins = route()

        self.response = {}
        self.response["HA_SINGLE_INSTANCE"] = """
    <instance-information xmlns="http://xml.juniper.net/junos/18.1I0/junos-routing" junos:style="terse">
        <instance-core>
            <instance-name>master</instance-name>
            <instance-type>forwarding</instance-type>
            <instance-rib>
                <irib-name>inet.0</irib-name>
                <irib-active-count>22</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet6.0</irib-name>
                <irib-active-count>7</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
        </instance-core>
    </instance-information>
        """

        self.response["HA_MULTI_INSTANCE"] = """
    <instance-information xmlns="http://xml.juniper.net/junos/18.1I0/junos-routing" junos:style="terse">
        <instance-core>
            <instance-name>master</instance-name>
            <instance-type>forwarding</instance-type>
            <instance-rib>
                <irib-name>inet.0</irib-name>
                <irib-active-count>22</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet6.0</irib-name>
                <irib-active-count>7</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
        </instance-core>
        <instance-core>
            <instance-name>__juniper_private1__</instance-name>
            <instance-type>forwarding</instance-type>
            <instance-rib>
                <irib-name>__juniper_private1__.inet.0</irib-name>
                <irib-active-count>12</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
        </instance-core>
        <instance-core>
            <instance-name>__juniper_private2__</instance-name>
            <instance-type>forwarding</instance-type>
            <instance-rib>
                <irib-name>__juniper_private2__.inet.0</irib-name>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>1</irib-hidden-count>
            </instance-rib>
        </instance-core>
        <instance-core>
            <instance-name>__juniper_private3__</instance-name>
            <instance-type>forwarding</instance-type>
        </instance-core>
        <instance-core>
            <instance-name>__juniper_private4__</instance-name>
            <instance-type>forwarding</instance-type>
            <instance-rib>
                <irib-name>__juniper_private4__.inet.0</irib-name>
                <irib-active-count>2</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
        </instance-core>
        <instance-core>
            <instance-name>__master.anon__</instance-name>
            <instance-type>forwarding</instance-type>
        </instance-core>
        <instance-core>
            <instance-name>mgmt_junos</instance-name>
            <instance-type>forwarding</instance-type>
        </instance-core>
    </instance-information>
        """

        self.response["HA_SINGLE_INSTANCE_BRIEF"] = """
    <instance-information xmlns="http://xml.juniper.net/junos/18.1I0/junos-routing" junos:style="terse">
        <instance-core>
            <instance-name>master</instance-name>
            <instance-type>forwarding</instance-type>
            <instance-rib>
                <irib-name>inet.0</irib-name>
                <irib-active-count>18</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet6.0</irib-name>
                <irib-active-count>1</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
        </instance-core>
    </instance-information>
        """

        self.response["HA_SINGLE_INSTANCE_DETAIL"] = """
    <instance-information xmlns="http://xml.juniper.net/junos/18.1I0/junos-routing" junos:style="detail">
        <instance-core>
            <instance-name>master</instance-name>
            <router-id>10.208.133.147</router-id>
            <instance-type>forwarding</instance-type>
            <instance-state>Active</instance-state>
            <instance-rib>
                <irib-name>inet.0</irib-name>
                <irib-route-count>18</irib-route-count>
                <irib-active-count>18</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet6.0</irib-name>
                <irib-route-count>1</irib-route-count>
                <irib-active-count>1</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
        </instance-core>
    </instance-information>
        """

        self.response["HA_SINGLE_INSTANCE_EXTENSIVE"] = """
    <instance-information xmlns="http://xml.juniper.net/junos/18.1I0/junos-routing" junos:style="detail">
        <instance-core>
            <instance-name>master</instance-name>
            <router-id>10.208.133.147</router-id>
            <instance-type>forwarding</instance-type>
            <instance-state>Active</instance-state>
            <instance-rib>
                <irib-name>inet.0</irib-name>
                <irib-route-count>20</irib-route-count>
                <irib-active-count>20</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet.1</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet.2</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet.3</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>iso.0</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>mpls.0</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>__mpls-oam__.mpls.0</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet6.0</irib-name>
                <irib-route-count>5</irib-route-count>
                <irib-active-count>5</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet6.1</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet6.2</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet6.3</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>l2circuit.0</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>mdt.0</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>l2protection.0</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>lsdist.0</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>lsdist.1</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inetcolor.0</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet6color.0</irib-name>
                <irib-route-count>0</irib-route-count>
                <irib-active-count>0</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
        </instance-core>
    </instance-information>
        """

        self.response["HA_SINGLE_INSTANCE_SUMMARY"] = """
    <instance-information xmlns="http://xml.juniper.net/junos/18.1I0/junos-routing" junos:style="terse">
        <instance-core>
            <instance-name>master</instance-name>
            <instance-type>forwarding</instance-type>
            <instance-rib>
                <irib-name>inet.0</irib-name>
                <irib-active-count>22</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
            <instance-rib>
                <irib-name>inet6.0</irib-name>
                <irib-active-count>5</irib-active-count>
                <irib-holddown-count>0</irib-holddown-count>
                <irib-hidden-count>0</irib-hidden-count>
            </instance-rib>
        </instance-core>
    </instance-information>
        """

        self.response["SA_INSTANCE_TEXT"] = """
Exemplo n.º 12
0
    def setUp(self):
        """
        Set up for unit testcases for usf_cgnat.py
        """
        builtins.t = MagicMock()
        builtins.t.log = MagicMock()
        self.response = {}
        self.xml = xml_tool()
        #       builtins.t = MagicMock()
        #        builtins.t.log = MagicMock()
        self.response["NAT_POOL_DETAIL"] = '''
        <rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.2I0/junos">
          <source-nat-pool-detail-information xmlns="http://xml.juniper.net/junos/18.2I0/junos-nat">
            <total-source-nat-pools>
              <total-source-pools>1</total-source-pools>
            </total-source-nat-pools>
          <source-nat-pool-info-entry>
            <interface-name>vms-0/2/0</interface-name>
            <service-set-name>snat_ss1</service-set-name>
            <pool-name>MX1_CGN4_AMS4-CONE-p1</pool-name>
            <pool-id>4</pool-id>
            <routing-instance-name>default</routing-instance-name>
            <host-address-base>0.0.0.0</host-address-base>
            <source-pool-port-translation>[1024, 63487]</source-pool-port-translation>
            <source-pool-twin-port>[63488, 65535]</source-pool-twin-port>
            <port-overloading-factor>1</port-overloading-factor>
            <source-pool-address-assignment>no-paired</source-pool-address-assignment>
            <total-pool-address>254</total-pool-address>
            <address-pool-hits>10</address-pool-hits>
            <source-pool-include-boundary-address>Disable</source-pool-include-boundary-address>
            <source-pool-eim-timeout>300</source-pool-eim-timeout>
            <source-pool-mapping-timeout>300</source-pool-mapping-timeout>
            <source-pool-eif-inbound-flows-count>0</source-pool-eif-inbound-flows-count>
            <source-pool-eif-flow-limit-exceed-drops>0</source-pool-eif-flow-limit-exceed-drops>
            <source-pool-address-range>
              <address-range-low>60.1.1.1</address-range-low>
              <address-range-high>60.1.1.254</address-range-high>
              <single-port>0</single-port>
              <twin-port>0</twin-port>
            </source-pool-address-range>
            <source-pool-address-range-sum>
              <single-port-sum>0</single-port-sum>
              <twin-port-sum>0</twin-port-sum>
            </source-pool-address-range-sum>
          </source-nat-pool-info-entry>
          </source-nat-pool-detail-information>
      <cli>
        <banner></banner>
      </cli>
    </rpc-reply>

        '''
        self.response["NAT_RULE_DETAIL"] = '''
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.2I0/junos">
    <source-nat-rule-detail-information xmlns="http://xml.juniper.net/junos/18.2I0/junos-nat">
        <source-nat-rule-entry>
            <interface-name>vms-0/2/0</interface-name>
            <service-set-name>snat_ss1</service-set-name>
            <rule-name>nr1</rule-name>
            <rule-set-name>snat_rule_set1</rule-set-name>
            <rule-id>1</rule-id>
            <rule-matching-position>1</rule-matching-position>
            <rule-from-context>zone</rule-from-context>
            <rule-from-context-name>nh-snat_ss1-ZoneIn</rule-from-context-name>
            <rule-to-context>zone</rule-to-context>
            <rule-to-context-name>nh-snat_ss1-ZoneOut</rule-to-context-name>
            <source-address-range-entry>
                <rule-source-address-low-range>20.1.1.0</rule-source-address-low-range>
                <rule-source-address-high-range>20.1.1.255</rule-source-address-high-range>
            </source-address-range-entry>
            <destination-address-range-entry>
                <rule-destination-address-low-range>30.1.1.0</rule-destination-address-low-range>
                <rule-destination-address-high-range>30.1.1.255</rule-destination-address-high-range>
            </destination-address-range-entry>
            <src-nat-app-entry>
                <src-nat-application>configured</src-nat-application>
            </src-nat-app-entry>
            <source-nat-rule-action-entry>
                <source-nat-rule-action>src_pool1</source-nat-rule-action>
                <rule-source-mapping-type>N/A</rule-source-mapping-type>
            </source-nat-rule-action-entry>
            <source-nat-rule-hits-entry>
                <rule-translation-hits>13</rule-translation-hits>
                <succ-hits>13</succ-hits>
                <failed-hits>0</failed-hits>
                <concurrent-hits>0</concurrent-hits>
            </source-nat-rule-hits-entry>
        </source-nat-rule-entry>
    </source-nat-rule-detail-information>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>
        '''
        self.response["NAT_POOL"] = """  
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.3D0/junos">
<source-nat-pool-detail-information xmlns="http://xml.juniper.net/junos/18.3D0/junos-nat">
        <source-nat-pool-info-entry>
            <interface-name>vms-2/3/0</interface-name>
            <service-set-name>snat_ss1</service-set-name>
            <pool-name>src_pool1</pool-name>
            <pool-id>4</pool-id>
            <host-address-base>0.0.0.0</host-address-base>
            <source-pool-port-translation>[1024, 65535]</source-pool-port-translation>
            <port-overloading-factor>1</port-overloading-factor>
            <source-pool-address-assignment>no-paired</source-pool-address-assignment>
            <total-pool-address>254</total-pool-address>
            <address-pool-hits>0</address-pool-hits>
            <source-pool-include-boundary-address>Disable</source-pool-include-boundary-address>
            <source-pool-eim-timeout>300</source-pool-eim-timeout>
            <source-pool-mapping-timeout>300</source-pool-mapping-timeout>
            <source-pool-eif-inbound-flows-count>0</source-pool-eif-inbound-flows-count>
            <source-pool-eif-flow-limit-exceed-drops>0</source-pool-eif-flow-limit-exceed-drops>
            <source-pool-address-range junos:style="without-twin-port">
                <address-range-low>60.1.1.1</address-range-low>
                <address-range-high>60.1.1.254</address-range-high>
                <single-port>0</single-port>
            </source-pool-address-range>
            <source-pool-address-range-sum>
                <single-port-sum>0</single-port-sum>
            </source-pool-address-range-sum>
            <source-pool-error-counters>
                <out-of-port-error>0</out-of-port-error>
                <out-of-addr-error>0</out-of-addr-error>
                <parity-port-error>0</parity-port-error>
                <preserve-range-error>0</preserve-range-error>
                <app-out-of-port-error>0</app-out-of-port-error>
                <app-exceed-port-limit-error>0</app-exceed-port-limit-error>
                <out-of-blk-error>0</out-of-blk-error>
                <blk-exceed-limit-error>0</blk-exceed-limit-error>
            </source-pool-error-counters>
        </source-nat-pool-info-entry>
    </source-nat-pool-detail-information>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>
"""
        self.response["NAT_POOL_Des"] = """
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.4D0/junos">
    <destination-nat-pool-information xmlns="http://xml.juniper.net/junos/18.4D0/junos-nat">
        <destination-nat-pool-entry>
            <interface-name>vms-2/3/0</interface-name>
            <service-set-name>dnat_ss1</service-set-name>
            <pool-name>dst_pool1</pool-name>
            <pool-id>1</pool-id>
            <routing-instance-name></routing-instance-name>
            <total-pool-address>1</total-pool-address>
            <address-pool-hits>0</address-pool-hits>
            <pool-address-range>
                <address-range-low>30.1.1.2</address-range-low>
                <address-range-high>30.1.1.2</address-range-high>
                <address-port>0</address-port>
            </pool-address-range>
        </destination-nat-pool-entry>
    </destination-nat-pool-information>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>
"""
        self.response["NAT_POOL_False"] = """ 
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.3D0/junos">
    <source-nat-pool-detail-information xmlns="http://xml.juniper.net/junos/18.3D0/junos-nat">
        <source-nat-pool-info-entry>
            <interface-name>vms-1/1/1</interface-name>
            <service-set-name>snat_ss1</service-set-name>
            <pool-name>src_pool2</pool-name>
            <pool-id>4</pool-id>
            <host-address-base>0.0.0.0</host-address-base>
            <source-pool-port-translation>[1024, 65535]</source-pool-port-translation>
            <port-overloading-factor>1</port-overloading-factor>
            <source-pool-address-assignment>no-paired</source-pool-address-assignment>
            <total-pool-address>254</total-pool-address>
            <address-pool-hits>1</address-pool-hits>
            <source-pool-include-boundary-address>Disable</source-pool-include-boundary-address>
            <source-pool-eim-timeout>300</source-pool-eim-timeout>
            <source-pool-mapping-timeout>300</source-pool-mapping-timeout>
            <source-pool-eif-inbound-flows-count>0</source-pool-eif-inbound-flows-count>
            <source-pool-eif-flow-limit-exceed-drops>0</source-pool-eif-flow-limit-exceed-drops>
            <source-pool-address-range junos:style="without-twin-port">
                <address-range-low>60.1.1.1</address-range-low>
                <address-range-high>60.1.1.254</address-range-high>
                <single-port>0</single-port>
            </source-pool-address-range>
            <source-pool-address-range-sum>
                <single-port-sum>0</single-port-sum>
            </source-pool-address-range-sum>
            <source-pool-error-counters>
                <out-of-port-error>0</out-of-port-error>
                <out-of-addr-error>0</out-of-addr-error>
                <parity-port-error>0</parity-port-error>
                <preserve-range-error>0</preserve-range-error>
                <app-out-of-port-error>0</app-out-of-port-error>
                <app-exceed-port-limit-error>0</app-exceed-port-limit-error>
                <out-of-blk-error>0</out-of-blk-error>
                <blk-exceed-limit-error>0</blk-exceed-limit-error>
            </source-pool-error-counters>
        </source-nat-pool-info-entry>
    </source-nat-pool-detail-information>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>
"""
        self.response["NAT_RULE"] = """
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.3D0/junos">
    <source-nat-rule-detail-information xmlns="http://xml.juniper.net/junos/18.3D0/junos-nat">
        <source-nat-rule-entry>
            <interface-name>vms-2/3/0</interface-name>
            <service-set-name>snat_ss1</service-set-name>
            <rule-name>nr1</rule-name>
            <rule-set-name>snat_rule_set1</rule-set-name>
            <rule-id>1</rule-id>
            <rule-matching-position>1</rule-matching-position>
            <rule-from-context>zone</rule-from-context>
            <rule-from-context-name>snat_ss1-ZoneIn</rule-from-context-name>
            <rule-to-context>zone</rule-to-context>
            <rule-to-context-name>snat_ss1-ZoneOut</rule-to-context-name>
            <source-address-range-entry>
                <rule-source-address-low-range>20.1.1.0</rule-source-address-low-range>
                <rule-source-address-high-range>20.1.1.255</rule-source-address-high-range>
                <rule-source-address>20.1.1.1</rule-source-address>
            </source-address-range-entry>
            <destination-address-range-entry>
                <rule-destination-address-low-range>30.1.1.0</rule-destination-address-low-range>
                <rule-destination-address-high-range>30.1.1.255</rule-destination-address-high-range>
                <rule-destination-address>30.1.1.1</rule-destination-address>
            </destination-address-range-entry>
            <src-nat-app-entry>
                <src-nat-application>configured</src-nat-application>
            </src-nat-app-entry>
            <source-nat-rule-action-entry>
                <source-nat-rule-action>src_pool1</source-nat-rule-action>
                <rule-source-mapping-type>N/A</rule-source-mapping-type>
            </source-nat-rule-action-entry>
            <source-nat-rule-hits-entry>
                <rule-translation-hits>0</rule-translation-hits>
                <succ-hits>0</succ-hits>
                <failed-hits>0</failed-hits>
                <concurrent-hits>0</concurrent-hits>
            </source-nat-rule-hits-entry>
        </source-nat-rule-entry>
    </source-nat-rule-detail-information>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>
"""
        self.response["NAT_RULE_False"] = """
   <rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.3D0/junos">
    <source-nat-rule-detail-information xmlns="http://xml.juniper.net/junos/18.3D0/junos-nat">
        <source-nat-rule-entry>
            <interface-name>vms-1/1/1</interface-name>
            <service-set-name>snat_ss2</service-set-name>
            <rule-name>nr1</rule-name>
            <rule-set-name>snat_rule_set1</rule-set-name>
            <rule-id>1</rule-id>
            <rule-matching-position>1</rule-matching-position>
            <rule-from-context>zone</rule-from-context>
            <rule-from-context-name>snat_ss1-ZoneIn</rule-from-context-name>
            <rule-to-context>zone</rule-to-context>
            <rule-to-context-name>snat_ss1-ZoneOut</rule-to-context-name>
            <source-address-range-entry>
                <rule-source-address-low-range>20.1.1.0</rule-source-address-low-range>
                <rule-source-address-high-range>20.1.1.255</rule-source-address-high-range>
                <rule-source-address>20.1.1.1</rule-source-address>
            </source-address-range-entry>
            <destination-address-range-entry>
                <rule-destination-address-low-range>30.1.1.0</rule-destination-address-low-range>
                <rule-destination-address-high-range>30.1.1.255</rule-destination-address-high-range>
                <rule-destination-address>30.1.1.1</rule-destination-address>
           </destination-address-range-entry>
            <src-nat-app-entry>
                <src-nat-application>configured</src-nat-application>
            </src-nat-app-entry>
            <source-nat-rule-action-entry>
                <source-nat-rule-action>src_pool1</source-nat-rule-action>
                <rule-source-mapping-type>N/A</rule-source-mapping-type>
            </source-nat-rule-action-entry>
            <source-nat-rule-hits-entry>
                <rule-translation-hits>1</rule-translation-hits>
                <succ-hits>1</succ-hits>
                <failed-hits>1</failed-hits>
                <concurrent-hits>0</concurrent-hits>
            </source-nat-rule-hits-entry>
        </source-nat-rule-entry>
    </source-nat-rule-detail-information>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>
"""

        self.response["NAT_RULE_Des"] = """
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.3D0/junos">
    <destination-nat-rule-information xmlns="http://xml.juniper.net/junos/18.3D0/junos-nat">
        <destination-nat-rule-entry>
            <interface-name>vms-2/3/0</interface-name>
            <service-set-name>dnat_ss1</service-set-name>
            <rule-name>nr1</rule-name>
            <rule-set-name>dnat_rule_set1</rule-set-name>
            <rule-id>1</rule-id>
            <rule-matching-position>1</rule-matching-position>
            <rule-source-address-range-entry>
                <rule-source-address-low-range>20.1.1.0</rule-source-address-low-range>
                <rule-source-address-high-range>20.1.1.255</rule-source-address-high-range>
                <rule-source-address>20.1.1.1</rule-source-address>
            </rule-source-address-range-entry>
            <rule-destination-address-range-entry>
                <rule-destination-address-low-range>60.1.1.2</rule-destination-address-low-range>
                <rule-destination-address-high-range>60.1.1.2</rule-destination-address-high-range>
                <rule-destination-address>60.1.1.3</rule-destination-address>
            </rule-destination-address-range-entry>
            <destination-nat-application>configured</destination-nat-application>
            <destination-nat-rule-action>dst_pool1</destination-nat-rule-action>
            <rule-translation-hits>1</rule-translation-hits>
            <succ-hits>1</succ-hits>
            <failed-hits>1</failed-hits>
            <concurrent-hits>0</concurrent-hits>
        </destination-nat-rule-entry>
    </destination-nat-rule-information>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>
"""

        self.response["VERIFY_STATIC"] = """
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.3D0/junos">
    <configuration junos:commit-seconds="1530032367" junos:commit-localtime="2018-06-26 09:59:27 PDT" junos:commit-user="******">
            <routing-instances>
                <instance>
                    <name>server-vrf1</name>
                    <instance-type>virtual-router</instance-type>
                    <interface>
                        <name>ge-1/2/5.0</name>
                    </interface>
                    <interface>
                        <name>vms-2/3/0.2</name>
                    </interface>
                    <routing-options>
                        <static>
                            <route>
                                <name>0.0.0.0/0</name>
                                <next-hop>vms-2/3/0.2</next-hop>
                            </route>
                        </static>
                    </routing-options>
                </instance>
            </routing-instances>
    </configuration>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>
"""
        self.response["VERIFY_SESSION"] = """
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.3D0/junos">  
  <usf-session-count-information xmlns="http://xml.juniper.net/junos/18.3D0/junos-flow">
        <usf-session-count>
            <interface-name>vms-2/3/0</interface-name>
            <service-set-name>snat_ss1</service-set-name>
            <valid-session-count>0</valid-session-count>
            <pending-session-count>0</pending-session-count>
            <invalid-session-count>0</invalid-session-count>
            <other-session-count>0</other-session-count>
        </usf-session-count>
    </usf-session-count-information>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>
"""

        self.cgn = usf_cgnat(dh=None)
        self.cgn.log = MagicMock()
        self.cgn.dh = MagicMock()
        self.cgn.dh.cli = MagicMock()
        self.cgn.dh.cli = MagicMock()
        self.cgn.fn_checkin = MagicMock()
        self.cgn.fn_checkout = MagicMock()
        self.cgn.fn_checkout.return_value = True
        self.cgn.config = MagicMock()
        self.cgn.config.return_value = True
        self.cgn._get_intf_ss = MagicMock()
        self.cgn._get_tg_port_and_config_mapping = MagicMock()
        #        dd = {}
        #        dd = lambda: defaultdict(dd)
        #        self.cgn.dd = MagicMock()
        #        self.cgn.dd.return_value = dd()
        self.cgn.r_if = {'ss1'}
        self.cgn.resource = 'esst480p'
        self.cgn.topo = {
            'intf': {
                '1/1': {
                    'path': 'r0r1'
                }
            },
            'path_res': {
                'esst480p': {
                    'r0r1': ['intf1']
                }
            }
        }
        #builtins.t = {'resources' : {'esst480p' : {'interfaces' : {
        #    'intf1' : {'pic' : 'ms-5/0/0'}}}}}
        self.cgn.intf_ss = {'ms-5/0/0': 'ss1'}
        self.cgn.sset = {'ss1': {'spic': 'ms-5/0/0', 'nat_rules': ['nr1']}}
        self.cgn.nat_rule = {
            'nr1': {
                'src_pool': 'np1',
                'trans_type': 'napt',
                'trans_eim': 1,
                'trans_eif': 1
            }
        }
        self.cgn.nat_pool = {'MX1_CGN4_AMS4-CONE-p1': {'pool_type': 'source'}}
        self.cgn.tg_sess = {
            '1/1': {
                'total':
                10,
                'src_ips_list': ['11.1.1.2', '11.1.1.3'],
                'dst_ips_list': ['60.1.1.2', '60.1.1.3'],
                'sess_list': [{
                    'src_ip': '11.1.1.2',
                    'src_port': '5060'
                }, {
                    'src_ip': '11.1.1.2',
                    'src_port': '5060'
                }, {
                    'src_ip': '11.1.1.2',
                    'src_port': '5060'
                }]
            },
            'total': 10
        }
        self.cgn.tg_cfg_map = {
            '1/1': {
                'spic': 'ms-5/0/0',
                'sset': 'ss1',
                'nat_rule': 'nr1',
                'nat_pool': 'np1',
                'nat_ip': '112.1.1.0/24',
                'nat_port': '1024-3456',
                'nat_port_low': '1024',
                'nat_port_high': '3456',
                'tot_sess': 1,
                'rand_sess_idx_list': [0]
            }
        }
        self.cgn.pool_map = {'np1': {'tot_sess': 10}, 'np2': {'tot_sess': 10}}
Exemplo n.º 13
0
def get_aamw_stats(srx_handle, protocol=None, action='interested', device_type='SA', logical_system=None, tenant=None):
    """
    Get SecIntel feed Summary
    :param srx_handle: SRX handle
    :param protocol: What protocol you need counters for: (http,https,smtp,smtps,imap,imaps,total)
    :param action: can be one of the following:
                   blacklist-hit-counter
                   ignored
                   interested
                   whitelist-hit-counter
                   file-fallback-blocked
                   file-fallback-permitted
                   file-ignored_by_sample_rate
                   file-submission-failure
                   file-submission-not-needed
                   file-submission-success
                   file-verdict-meets_threshold
                   file-verdict-under_threshold
                   hash-eligible
                   hash-fail
                   hash-known
                   hash-selected
                   hash-submitted
                   hash-unknown
                   hash-verdict-timeout
                   session-actives
                   session-blocked
                   session-permitted
                   email-blacklist
                   email-blocked
                   email-fallback-blocked
                   email-fallback-permitted
                   email-hit-whitelist
                   email-permitted
                   email-quarantined
                   email-scanned
                   email-tag-and-delivered
    :param device_type: Is it HA or SA Device (Default value: HA)
    :param logical_system: LDOM name
    :param tenant: Tenant name
    :return: counter value
    """
    prefix = 'show services advanced-anti-malware statistics '
    if logical_system is not None:
        command = prefix + ' logical-system {}'.format(logical_system)
    elif tenant is not None:
        command = prefix + ' tenant {}'.format(tenant)
    else:
        command = prefix
    response = srx_handle.cli(command=command, format="XML", channel="PYEZ").response()
    srx_handle.log(response)
    statistics_dict = xml_tool().xml_obj_to_dict(response)
    srx_handle.log(statistics_dict)

    dict_location = None
    if device_type is 'HA':
        dict_location = statistics_dict["multi-routing-engine-results"]["multi-routing-engine-item"][
            "aamw-statistics"]["aamw-statistics"]
    elif device_type is 'SA':
        dict_location = statistics_dict["aamw-statistics"]["aamw-statistics"]
    if protocol is None:
        return dict_location["aamw-statistics" + "-" + action]
    else:
        return dict_location["aamw-statistics-" + protocol + "-" + action]