Esempio n. 1
0
    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
Esempio n. 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]


Load a configuration and find specific sessions for different protocol emulations

"""
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)
Esempio n. 4
0
        if child.name in ['port', 'item', 'connector', 'tag'
                          ] or hasattr(query_result, child.name) is False:
            continue
        attr = getattr(query_result, child.name)
        if isinstance(attr, list) is True:
            if len(attr) == 0:
                continue
            else:
                attr = attr[0]
        href = query_result.href
        metadata = ixnhttp.help('%s/%s' % (href, child.name))
        process_node(ixnhttp, href, metadata, classes)
        process_query_result(ixnhttp, attr, classes)


ixnhttp = IxnHttp('10.200.22.48', 12345)
sessions = ixnhttp.sessions()
ixnhttp.current_session = sessions[0]

classes = {}
class_paths = [
    '/topology/deviceGroup/ethernet',
    '/topology/deviceGroup/ethernet/ipv4/pimV4Interface',
    '/topology/deviceGroup/ethernet/ipv4/igmpHost',
    '/topology/deviceGroup/ethernet/ipv4/bgpIpv4Peer',
    '/topology/deviceGroup/ethernet/ipv4/ospfv2',
    '/topology/deviceGroup/ethernet/ipv4/bfdv4Interface',
    '/topology/deviceGroup/ethernet/ipv6/mldHost',
    '/topology/deviceGroup/ethernet/ipv6/bgpIpv6Peer',
    '/topology/deviceGroup/ethernet/ipv6/ospfV3',
    '/topology/deviceGroup/ethernet/ipv6/bfdv6Interface',
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.IxnPortManagement import IxnPortManagement
from ixnetwork.IxnStatManagement import IxnStatManagement
from ixnetwork.IxnEmulationHosts import IxnIgmpHostEmulation, IxnIpv4Emulation
import os
import time
import json


# connect to an existing session
ixnhttp = IxnHttp('10.200.22.48', rest_port=12345)
ixnhttp.current_session = ixnhttp.sessions()[0]


# print system information
print(ixnhttp.system_info)


# 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)


# get a list of vports and change the type to ethernet
query_result = ixnhttp.root.query \
Esempio n. 6
0
            'connector', 'item', 'port', 'tlvProfile', 'learnedInfo',
            'genericProtocol', 'packetInList'
    ]:
        return
    try:
        metadata = ixnhttp.help(path)
        class_name = 'Ixn%s%sEmulation' % (metadata.custom.name[0].upper(),
                                           metadata.custom.name[1:])
        process_node(metadata, class_name)
        for child in metadata.custom.children:
            process_class(child.path, child.name)
    except:
        print('skipping %s' % name)


ixnhttp = IxnHttp('10.200.22.48', 12345)
sessions = ixnhttp.sessions()
ixnhttp.current_session = sessions[0]

classes = {}
process_class('/topology', 'topology')

filename = '%s/../ixnetwork/IxnEmulationHosts.py' % os.path.dirname(
    os.path.realpath(__file__))
with open(filename, 'w') as fid:
    fid.write('from ixnetwork.IxnEmulationHost import IxnEmulationHost\n\n')
    keys = classes.keys()
    keys.sort()
    for key in keys:
        fid.write(classes[key])
    fid.flush()
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 create a session on the session managed host

# IxNetwork API Server
# create a session using username and password
ixnhttp = IxnHttp(Config.HOST_IP_ADDRESS, rest_port=Config.HOST_REST_PORT)
ixnhttp.auth('admin', 'admin')
session = ixnhttp.create_session()
session.dump()
Esempio n. 9
0
#-------------- User Preferences Ends ----------------#


def release_ports(ixnhttp):
    query_vport = IxnQuery(ixnhttp, '/').node('vport',
                                              properties=['name']).go()
    for vport in query_vport.vport:
        vport_name = vport.attributes.name.value
        print('\nReleasing port name:', vport_name)
        print('\t', vport.href)
        vport.operations.releaseport({'arg1': [vport.href]})


try:
    if api_server_type in ['windows', 'windowsConnectionMgr']:
        ixnhttp = IxnHttp(api_server_ip, api_server_rest_port, secure=False)
        sessions = ixnhttp.sessions()
        ixnhttp.current_session = sessions[0]

    if api_server_type == 'linux':
        ixnhttp = IxnHttp(api_server_ip, api_server_rest_port, secure=True)
        ixnhttp.auth(username, password)
        ixnhttp.create_session()

        # CONFIG LICENSE SERVER
        #    New session needs to know where the license server is located.
        query_license = IxnQuery(ixnhttp, '/') \
            .node('globals') \
            .node('licensing', properties=['licensingServers', 'tier', 'mode']) \
            .go()
        print('\nConfigure license server:', license_server_ip, license_mode,
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 delete all the sessions on a session managed host

# delete all sessions on the managed host
ixnhttp = IxnHttp(Config.HOST_IP_ADDRESS, rest_port=Config.HOST_REST_PORT)
for session in ixnhttp.sessions():
    ixnhttp.current_session = session
    ixnhttp.delete_session()
Esempio n. 11
0
import sys
import os
path = os.path.realpath(__file__)
sys.path.insert(0, path[0:path.rfind('ixnetwork')])

from ixnetwork.IxnHttp import IxnHttp, IxnQuery

# run multiple gets and try for connection refused

# ixnhttp = IxnHttp('10.36.79.30', rest_port=443)
# ixnhttp.auth('admin', 'admin')
# ixnhttp.current_session = ixnhttp.create_session()
ixnhttp = IxnHttp('127.0.0.1', rest_port=11009)
ixnhttp.current_session = ixnhttp.sessions()[0]
for i in range(0, 100000):
    state = ixnhttp.get('/traffic').state
    # result = IxnQuery(ixnhttp, '/').node('traffic').go()
    print('%s %s' % (i, state))
ixnhttp.delete_session()
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]
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 create a session on the session managed host

# IxNetwork API Server
# create a session using username and password
ixnhttp = IxnHttp(Config.HOST_IP_ADDRESS, rest_port=Config.HOST_REST_PORT)
session = ixnhttp.create_session(username='******', password='******')
session.dump()