def get_IxnHttp_instance(use_gui=None, ip_address=None, rest_port=None, username=None, password=None):
        """Get an instance of an IxnHttp class using the static class variables
        
        :param use_gui: override the static class USE_IXNETWORK_GUI

        :param ip_address: override the static class HOST_IP_ADDRESS

        :param rest_port: override the static class HOST_REST_PORT

        :returns: an instance of the IxnHttp class
        """
        if use_gui is not None:
            Config.USE_IXNETWORK_GUI = use_gui
        if ip_address is not None:
            Config.HOST_IP_ADDRESS = ip_address
        if rest_port is not None:
            Config.HOST_REST_PORT = rest_port
        ixnhttp = IxnHttp(Config.HOST_IP_ADDRESS, rest_port=Config.HOST_REST_PORT)
        if Config.USE_IXNETWORK_GUI:
            ixnhttp.current_session = ixnhttp.sessions()[0]
        else:
            ixnhttp.auth(username, password)
            ixnhttp.create_session()
        ixnhttp.trace = Config.TRACE_REST_CALLS
        return ixnhttp
示例#2
0
import sys
import os
path = os.path.realpath(__file__)
sys.path.insert(0, path[0: path.rfind('ixnetwork')])

from ixnetwork.samples.Config import Config
from ixnetwork.IxnHttp import IxnHttp


# this sample demonstrates how to reconnect to an existing session if one exists
ixnhttp = IxnHttp(Config.HOST_IP_ADDRESS, rest_port=Config.HOST_REST_PORT)
sessions = ixnhttp.sessions()
for session in sessions:
    session.dump()
if len(sessions) > 0:
    ixnhttp.current_session = sessions[0]


"""
import sys
import os
path = os.path.realpath(__file__)
sys.path.insert(0, path[0:path.rfind('ixnetwork')])

from ixnetwork.IxnHttp import IxnHttp
from ixnetwork.IxnConfigManagement import IxnConfigManagement
from ixnetwork.IxnEmulationHosts import IxnEthernetEmulation, IxnIpv4Emulation, IxnIgmpHostEmulation

use_gui = False

if use_gui:
    ixnhttp = IxnHttp('10.200.22.48', rest_port=12345)
    ixnhttp.current_session = ixnhttp.sessions()[0]
else:
    ixnhttp = IxnHttp('10.200.23.60', rest_port=443)
    ixnhttp.trace = True
    ixnhttp.auth('admin', 'admin')
    ixnhttp.create_session()

# load a binary configuration
config_mgmt = IxnConfigManagement(ixnhttp)
config_filename = '%s/emulation-host-demo.ixncfg' % os.path.dirname(
    os.path.realpath(__file__))
config_mgmt.load_config(config_filename, upload=True, remove_chassis=True)

# find ethernet emulation host session(s) by vport_name or parent
eth = IxnEthernetEmulation(ixnhttp)
eth.find(vport_name='PE2-6/8')
from ixnetwork.IxnHttp import IxnHttp
from ixnetwork.IxnConfigManagement import IxnConfigManagement
import json

# Standalone IxNetwork GUI
# connect to a session with ReST port 12345
ixnetwork_gui = IxnHttp('10.200.22.48', 12345)
ixnetwork_gui.current_session = ixnetwork_gui.sessions()[0]

# management objects
config_mgmt = IxnConfigManagement(ixnetwork_gui)

# clear the current configuration
config_mgmt.new_config()

# export the default configuration
json_config = config_mgmt.export_config()

# modify part of the configuration
json_config['globals']['preferences']['rebootPortsOnConnect'] = True

# configure using the modified configuration fragment
config_mgmt.configure(json_config['globals']['preferences'])

# configure using a fragment
# if there are not 4 vports then they will be created
config_mgmt.configure({'xpath': '/vport[4]'})

# configure the first vport
config_mgmt.configure({'xpath': '/vport[1]', 'name': 'My Virtual Port', 'type': 'ethernetvm'})
import sys
import os
path = os.path.realpath(__file__)
sys.path.insert(0, path[0:path.rfind('ixnetwork')])

from ixnetwork.samples.Config import Config
from ixnetwork.IxnHttp import IxnHttp

# This sample demonstrates how to connect to a running standalone IxNetwork GUI session

# specify the connection parameters of the target host
# the ReST port is specified in the IxNetwork GUI command line as -restport <tcp port number>
# and can also be found in the log view window under the RestAPIService tab as the first entry
ixnetwork_gui = IxnHttp(Config.HOST_IP_ADDRESS,
                        rest_port=Config.HOST_REST_PORT)

# get a list of sessions on that ipaddress and rest port
# since this is an IxNetwork GUI there will be only one session
sessions = ixnetwork_gui.sessions()

# print out the details of each session
# there should only be one session
for session in sessions:
    session.dump()

# set the current session to be the one and only session
ixnetwork_gui.current_session = sessions[0]