Ejemplo 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
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')
print(eth.session_ids)

ipv4 = IxnIpv4Emulation(ixnhttp)
ipv4.find(emulation_host=eth)
Ejemplo n.º 3
0
    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,
              license_tier)
        query_license.globals.licensing.attributes.licensingServers.value = [
            license_server_ip
        ]
        query_license.globals.licensing.attributes.mode.value = license_mode
        query_license.globals.licensing.attributes.tier.value = license_tier