Example #1
0
   - IxOS and IxNetwork PIT installer for HLTAPI packages. 

Supports Python 2 and Python 3

"""

from __future__ import absolute_import, print_function
import sys, os
import time, re

from ixiatcl import IxiaTcl
from ixiahlt import IxiaHlt
from ixiangpf import IxiaNgpf
from ixiaerror import IxiaError

ixia_tcl = IxiaTcl()
ixia_hlt = IxiaHlt(ixia_tcl)
ixia_ngpf = IxiaNgpf(ixia_hlt)
ixNet = ixia_ngpf.ixnet
# For low level Python API commands

ixChassisIp = '192.168.70.128'
ixNetworkTclServer = '192.168.70.12'
# The Linux API server IP
licenseServerIp = '192.168.70.3'
licenseMode = 'subscription'
portList = '1/1 1/2'


def VerifyProtocolSessionStatusUpNgpfHlPy(protocolHandle, totalTime=60):
    '''
from pprint import pprint
import os, sys
import time

# Append paths to python APIs

# sys.path.append('/path/to/hltapi/library/common/ixiangpf/python')
# sys.path.append('/path/to/ixnetwork/api/python')

from ixiatcl import IxiaTcl
from ixiahlt import IxiaHlt
from ixiangpf import IxiaNgpf
from ixiaerror import IxiaError

ixiatcl = IxiaTcl()
ixiahlt = IxiaHlt(ixiatcl)
ixiangpf = IxiaNgpf(ixiahlt)

dirname, filename = os.path.split(os.path.abspath(__file__))
chassis_ip = "ixro-hlt-xm2-09"
tcl_server = "ixro-hlt-xm2-09"
ixnetwork_tcl_server = 'localhost'
port_list_str = "2/1 2/2"
port_list = port_list_str.split()
cfgErrors = 0
file_param = os.path.join(dirname, 'file_params.csv')

print "Printing connection variables ... "
print "test_name = %s" % filename
print 'chassis_ip =  %s' % chassis_ip
Example #3
0
# IxNetwork version: 8.10.1046.6
# time of scriptgen: 11/8/2016, 10:02 AM
import sys, os
import time, re
# sys.path.append('/path/to/hltapi/library/common/ixiangpf/python')
# sys.path.append('/path/to/ixnetwork/api/python')

from ixiatcl import IxiaTcl
from ixiahlt import IxiaHlt
from ixiangpf import IxiaNgpf
from ixiaerror import IxiaError

if os.name == 'nt':
	ixiatcl = IxiaTcl()
else:
	# unix dependencies
	tcl_dependencies = [
		'/home/user/ixia/ixos/lib',
		'/home/user/ixia/ixnet/IxTclProtocol',
		'/home/user/ixia/ixnet/IxTclNetwork'
	]
	ixiatcl = IxiaTcl(tcl_autopath=tcl_dependencies)

ixiahlt = IxiaHlt(ixiatcl)
ixiangpf = IxiaNgpf(ixiahlt)
			
def ixnHLT_endpointMatch(ixnHLT, ixnpattern_list, handle_type='HANDLE'):
	traffic_ep_ignore_list = [
		'^::ixNet::OBJ-/vport:\d+/protocols/mld/host:\d+$',
		'^::ixNet::OBJ-/vport:\d+/protocolStack/ethernet:[^/]+/ipEndpoint:[^/]+/range:[^/]+/ptpRangeOverIp:1$'
	]
Example #4
0
from pprint import pprint
import sys, os
import time, re

# Append paths to python APIs (Linux and Windows)

# sys.path.append('/path/to/hltapi/library/common/ixiangpf/python')
# sys.path.append('/path/to/ixnetwork/api/python')

from ixiatcl import IxiaTcl
from ixiahlt import IxiaHlt
from ixiangpf import IxiaNgpf
from ixiaerror import IxiaError

ixiatcl = IxiaTcl()
ixiahlt = IxiaHlt(ixiatcl)
ixiangpf = IxiaNgpf(ixiahlt)
            
try:
    ErrorHandler('', {})
except (NameError,):
    def ErrorHandler(cmd, retval):
        global ixiatcl
        err = ixiatcl.tcl_error_info()
        log = retval['log']
        additional_info = '> command: %s\n> tcl errorInfo: %s\n> log: %s' % (cmd, err, log)
        raise IxiaError(IxiaError.COMMAND_FAIL, additional_info)

################################################################################
# Connection to the chassis, IxNetwork Tcl Server                              #
Example #5
0
    def __init__(self, system_data=None, chassis=None, appserver=None, license_server=None, ixia_lib_path=None):
        """
        IXIA abstraction layer for HLTAPI

        -- Workflow 1 --
        :param  system_data  *MANDATORY* Dictionary of IXIA information
          Example:
          system_data =
            system:
              primary:
                appserver: wf-appserver2.englab.juniper.net
                controllers:
                  unknown:
                    domain: englab.juniper.net
                    hostname: wf-ixchassis2
                    mgt-intf-name: mgt0
                    mgt-ip: 10.9.1.107
                    osname: IxOS
                license_server: sv8-pod1-ixlic1.englab.juniper.net
                make: ixia
                model: xgs12
                name: wf-ixchassis2
                osname: IxOS

        -- Workflow 2 --
        :param  chassis  *MANDATORY* Name of chassis
        :param  appserver  *MANDATORY* Name of tcl server
        :param  license_server  *MANDATORY* Name of chassis

        :return: ixia object
        """
        self.virtual = False
        self.port_list = None
        self.session_info = None
        self.handle_to_port_map = None
        self.port_to_handle_map = None
        self.intf_to_port_map = None
        self.major_minor_version = None
        self.physical_port_type = 'fiber'
        self.user_functions = dict()
        self.connect_args = dict()
        self.cleanup_session_args = None
        self.port_order = None
        self.interfaces = None
        self.port = 8009
        self.connect_to_current_session = False
        self.connect_to_current_session_args = dict() # args just for connecting to current session
        atexit.register(self.cleanup)
        self.min_version = None
        self.username, self.password = credentials.get_credentials(os='Ixia')
        self.port_type = dict()
        # Ixia API handles
        self._ixiangpf = None
        self._ixiaixnet = None

        if ixia_lib_path:
            self.lib_path = ixia_lib_path
        else:
            environment = yaml.safe_load(open(os.path.join(os.path.dirname(credentials.__file__), "environment.yaml")))
            self.lib_path = environment['ixia-lib-path']
        if system_data:
            sys_pri = system_data['system']['primary']
            controller_key = list(sys_pri['controllers'].keys())[0]
            self.chassis = sys_pri['controllers'][controller_key]['mgt-ip']

            # Instantiate host object for logging
            host_args = dict()
            if 'name' in sys_pri:
                host_args['host'] = sys_pri['name']
            else:
                raise TobyIxiaException("Missing 'name' from 'primary' system stanza")
            if 'osname' in sys_pri['controllers'][controller_key]:
                host_args['os'] = sys_pri['controllers'][controller_key]['osname']
            else:
                raise TobyIxiaException("Missing 'osname' from controller " + controller_key + " stanza")
            super(Ixia, self).__init__(**host_args)


            # connect user fv- knob information and materialize kwargs for Ixia connect() call
            if 'appserver' in sys_pri:
                self.connect_args['ixnetwork_tcl_server'] = sys_pri['appserver']
            if 'appserver-port' in sys_pri:
                self.connect_args['ixnetwork_tcl_server'] = sys_pri['appserver'] + ':' + str(sys_pri['appserver-port'])
                self.port = sys_pri['appserver-port']
            if 'appserver-username' in sys_pri:
                self.connect_args['user_name'] = sys_pri['appserver-username']
            if 'appserver-password' in sys_pri:
                self.connect_args['user_password'] = sys_pri['appserver-password']
            if 'return-detailed-handles' in sys_pri:
                if sys_pri['return-detailed-handles'] == 'disable':
                    self.connect_args['return_detailed_handles'] = 0
            if 'config-file' in sys_pri:
                self.connect_args['config_file'] = sys_pri['config-file']
            else:
                self.connect_args['reset'] = 1
            if sys_pri['model'].lower().startswith('ixvm') or sys_pri['model'].lower().startswith('vixia'):
                self.virtual = True
                self.model = sys_pri['model'].lower()
                self.log(level='INFO', message="IXIA Type= Virtual")
                if 'license_server' in sys_pri:
                    self.connect_args['ixnetwork_license_servers'] = sys_pri['license_server']
                if 'license_type' in sys_pri:
                    if sys_pri['license_type'].startswith('tier'):
                        self.connect_args['ixnetwork_license_type'] = 'mixed_' + sys_pri['license_type']
                    else:
                        self.connect_args['ixnetwork_license_type'] = sys_pri['license_type']
            else:
                self.log(level='INFO', message="IXIA Type= Physical")

            if 'connect-args' in sys_pri and type(sys_pri['connect-args']) is dict:
                self.connect_args.update(sys_pri['connect-args'])
            if 'cleanup-session-args' in sys_pri and type(sys_pri['cleanup-session-args']) is dict:
                self.cleanup_session_args = sys_pri['cleanup-session-args']
            if 'port-order' in sys_pri:
                self.port_order = sys_pri['port-order']
            if 'connect-to-current-session' in sys_pri and sys_pri['connect-to-current-session'] == 'enable':
                self.connect_to_current_session = True
                self.connect_to_current_session_args['ixnetwork_tcl_server'] = self.connect_args['ixnetwork_tcl_server']
                # adding only connect-args for current session (no other arguments so can preserve session)
                if 'connect-args' in sys_pri and type(sys_pri['connect-args']) is dict:
                    self.connect_to_current_session_args.update(sys_pri['connect-args'])

            if 'min-version' in sys_pri and type(sys_pri['min-version']) is str:
                self.min_version = sys_pri['min-version']
                self.log(level='info', message="Ixia Minimum Chassis Version is set to: "+ sys_pri['min-version'])

            # Ensure mandatory connect() args are satisfied
            if 'ixnetwork_tcl_server' not in self.connect_args:
                raise TobyIxiaException("Missing appserver information (ixnetwork_tcl_server).  This may be provided via 'fv-ixia-appserver'"
                                    "knob, or via 'fv-ixia-connect-args'.", host_obj=self)
            if sys_pri['model'].lower().startswith('ixvm') or sys_pri['model'].lower().startswith('vixia'):
                if 'ixnetwork_license_servers' not in self.connect_args:
                    raise TobyIxiaException("Missing VM licensing information (ixnetwork_license_servers)." + \
                                        "This may be provided via 'fv-ixia-license-server' knob, or via 'fv-ixia-connect-args'.",
                                        host_obj=self)
                if 'ixnetwork_license_type' not in self.connect_args:
                    self.connect_args['ixnetwork_license_type'] = 'mixed_tier1'


        elif chassis and appserver:
            self.chassis = chassis
            self.appserver = appserver
            if license_server:
                self.license_server = license_server
        else:
            raise TobyIxiaException("Missing either system_data (Workflow 1) or chassis/appserver"
                                "/license_server (Workflow 2) parameters", host_obj=self)

        self.intf_status = None
        self.log(level='info', message="CHASSIS= " + self.chassis)
        self.log(level='info', message="APPSERVER= " + self.connect_args['ixnetwork_tcl_server'])

        self.wait = 1
        self.telnet_handle = None
        self.version = self._get_version()
        if self.min_version:
            if(float(self.version) < float(self.min_version)):
                raise TobyIxiaChassisConnectException("Ixia Minimum Chassis Version Check Failed", host_obj=self)
        if self.virtual:
            result = self._configure_promiscuous()
            if not result:
                self.log(level='WARN', message="Unable to set Promiscuous mode on IXIA virtual chassis")
            else:
                self.log(level='info', message="Successfully set Promiscuous mode on IXIA virtual chassis")
            if self.chassis_type is not None:
               if self.model.startswith('vixia') and re.search('Virtual Load Module', self.chassis_type, re.I):  
                   self.log(level='WARN', message="Virtual ixia chassis type is not correct as virtual modeli defined in params")
        self.ixia_lib_version = self._get_lib_version()
        self._set_envs()
        # Import core modules for native IXIA APIs
        # disable import-error because dynamic ENV changes based on IXIA version make it possible to import ok
        from ixiatcl import IxiaTcl # pylint: disable=import-error
        from ixiahlt import IxiaHlt # pylint: disable=import-error
        from ixiangpf import IxiaNgpf # pylint: disable=import-error
#        from ixiaerror import IxiaError # pylint: disable=import-error

        self.ixiatcl = IxiaTcl()
        self.ixiahlt = IxiaHlt(self.ixiatcl)
        self._ixiangpf = IxiaNgpf(self.ixiahlt)

        # Import extended ixia modules with functions
        # from jnpr/toby/trafficgen/ixia
        current_dir = os.path.dirname(os.path.abspath(
            inspect.getfile(inspect.currentframe())))
        user_module_dir = re.sub(r"jnpr\/toby.*", "jnpr/toby/trafficgen/ixia", current_dir)
        sys.path.append(user_module_dir)
        file_list = list(filter(lambda x: os.path.isfile(os.path.join(user_module_dir, x)), os.listdir(user_module_dir)))
        for file_name in file_list:
            if file_name.endswith('.py') and not file_name.startswith('__'):
                module = re.sub(r"\.py$", "", file_name)
                obj = __import__(module)
                function_list = [o for o in inspect.getmembers(obj)
                                 if inspect.isfunction(o[1])]
                for function_tuple in function_list:
                    function_name, function = function_tuple
                    if function_name in self.user_functions:
                        raise TobyIxiaException("Duplicate functions in user contributed modules", host_obj=self)
                    self.user_functions[function_name] = function
Example #6
0
################################################################################

from pprint import pprint
import os, sys
import time
import pdb

# sys.path.append('/path/to/hltapi/library/common/ixiangpf/python')
# sys.path.append('/path/to/ixnetwork/api/python')

from ixiatcl import IxiaTcl
from ixiahlt import IxiaHlt
from ixiangpf import IxiaNgpf
from ixiaerror import IxiaError

ixiatcl = IxiaTcl()
ixiahlt = IxiaHlt(ixiatcl)
ixiangpf = IxiaNgpf(ixiahlt)

dirname, filename = os.path.split(os.path.abspath(__file__))
print dirname
print filename
logname = dirname + '\\log.log'

chassis_ip = ['master_chassis', 'slave_1', 'slave_2', 'slave_3']
tcl_server = "localhost"
ixnetwork_tcl_server = 'localhost'
port_list = [['4/1'], [], ['4/1'], []]
master_chassis = ['none', 'master_chassis', 'master_chassis', 'master_chassis']
chain_cables_length = [0, 3, 6, 6]
chain_type = 'star'