Esempio n. 1
0
    def collectDiagnostics(self,
                           diagZipFilename='ixiaDiagnostics.zip',
                           localPath=None):
        """
        Description
           Collect diagnostics for debugging.

        Parameter
           diagZipFileName: <str>: The diagnostic filename to name with .zip extension.
           localPath: <str>: The local destination where you want to put the collected diag file.
        """

        try:
            self.ixNetwork.CollectLogs(
                Arg1=Files(diagZipFilename, local_file=True))
        except Exception as err:
            raise Exception("Failed Creating Diag logs {}".format(err))

        if localPath:
            try:
                self.ixNetwork.CopyFile(
                    Files(diagZipFilename, local_file=True),
                    localPath + "\\" + diagZipFilename)
            except Exception as e:
                print(e)
                self.ixNetwork.CopyFile(
                    Files(diagZipFilename, local_file=True),
                    localPath + "/" + diagZipFilename)
 def run_config(self, device, command, *argv, **kwarg):
     """
     - IxiaClient
        load_config - config_file_name
        save_config - config_file_name
     """
     ############# Implement me ################
     if not IxnetworkIxiaClientImpl.ixnet:
         return 0, "Ixia not connected"
     params = kwarg["params"]
     if not params or not params[0]:
         return 0, "Need to specify config file name"
     param = params[0]
     fname = param["config_file_name"]
     name = os.path.basename(fname)
     if command == "load_config":
         files = IxnetworkIxiaClientImpl.session.GetFileList()
         found = False
         for f in files["files"]:
             if f["name"] == name:
                 found = True
                 break
         if not found:
             out = IxnetworkIxiaClientImpl.session.UploadFile(fname, name)
         out = IxnetworkIxiaClientImpl.ixnet.LoadConfig(Files(name))
         # get the traffic items back
         IxnetworkIxiaClientImpl.tis = IxnetworkIxiaClientImpl.ixnet.Traffic.TrafficItem.find(
         )
     elif command == "save_config":
         out = IxnetworkIxiaClientImpl.ixnet.SaveConfig(Files(name))
         out += IxnetworkIxiaClientImpl.session.DownloadFile(name, fname)
     return 0, out
def test_can_import_export_json_as_file(ixnetwork):

    ixnetwork.Vport.add().add()

    ixnetwork.ResourceManager.ExportConfigFile(['/descendant-or-self::*'],
                                               False, 'json',
                                               Files('two_vports.json'))

    ixnetwork.ResourceManager.ImportConfigFile(Files('two_vports.json'), True)
    assert (len(ixnetwork.Vport.find()) == 2)
def test_can_save_ixncfg_config_from_sessions(ixnetwork, tmpdir):
    ixnetwork.Vport.add().add().add().add()
    session = ixnetwork._parent
    ixnetwork.SaveConfig(Files('sample.ixncfg'))
    session.DownloadFile('sample.ixncfg', tmpdir.join('local.ixncfg').strpath)

    assert tmpdir.join('local.ixncfg').check(file=1)
Esempio n. 5
0
    def importJsonConfigFile(self, jsonFileName, option='modify'):
        """
        Description
            To import a JSON config file to IxNetwork.
            You could state it to import as a modified config or creating a new config.

            The benefit of importing an actual JSON config file is so you could manually use
            IxNetwork Resource Manager to edit any part of the JSON config and add to the
            current configuration

        Parameters
            jsonFileName: (json object): The JSON config file. Could include absolute path also.
            option: (str): newConfig|modify
        """
        if option == 'modify':
            arg3 = False
        if option == 'newConfig':
            arg3 = True

        try:
            self.ixNetwork.ResourceManager.ImportConfigFile(
                Arg2=Files(jsonFileName), Arg3=arg3)
        except Exception as err:
            self.ixnObj.logInfo("Error with importJsonConfig {}".format(err))
            raise Exception('\nimportJsonConfigObj Error')
def test_can_upload_ixncfg_config_to_session(ixnetwork):
    session = ixnetwork._parent
    file_name = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             'local.ixncfg')
    session.UploadFile(file_name)
    ixnetwork.NewConfig()
    ixnetwork.LoadConfig(Files('local.ixncfg', local_file=False))

    assert len(ixnetwork.Vport.find()) == 4
def test_can_save_ixncfg_config_from_sessions(ixnetwork, tmpdir):
    ixnetwork.Vport.add().add().add().add()
    session = ixnetwork._parent
    # saves the config on server
    ixnetwork.SaveConfig(Files('sample.ixncfg'))

    # download the remote saved configuration as some other local file
    session.DownloadFile('sample.ixncfg', tmpdir.join('local.ixncfg').strpath)
    # checking if file exist
    assert tmpdir.join('local.ixncfg').check(file=1)
def test_can_upload_ixncfg_config_to_session(ixnetwork):
    session = ixnetwork._parent
    file_name = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             'local.ixncfg')
    session.UploadFile(file_name)
    ixnetwork.NewConfig()
    ixnetwork.LoadConfig(Files('local.ixncfg', local_file=False))

    # checking if the file has been uploaded, this needs to be tested locally
    # assert any(file_name == files.get('name') for files in session.GetFileList().get('files'))

    # verify the config that has been loaded has 4 ports
    assert len(ixnetwork.Vport.find()) == 4
def test_upload_filename_with_special_chars(ixnetwork):
    session = ixnetwork._parent
    file_name = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             'local.ixncfg')
    with open(file_name, 'rb') as fp:
        contents = fp.read()
    special_file_name = 'local+-)_(.ixncfg' 
    with open(special_file_name, 'wb') as fp:
        fp.write(contents)
    ixnetwork.LoadConfig(Files(special_file_name, local_file=True))
    assert (file_exists(ixnetwork, special_file_name) is True)
    session.RemoveFile(special_file_name)
    assert (file_exists(ixnetwork, special_file_name) is False)
    session.UploadFile(special_file_name)
    assert (file_exists(ixnetwork, special_file_name) is True)
Esempio n. 10
0
def test_can_upload_ixncfg_config_to_session(ixnetwork):
    session = ixnetwork._parent
    file_name = '.\\ixnetwork_restpy\\pytest_tests\\tests\\files_tests\\local.ixncfg'
    session.UploadFile(file_name)
    file_obj = Files(file_name)
    if file_obj.is_local_file:
        ixnetwork.LoadConfig(file_obj)
    assert file_obj.file_name in file_name.split('\\')

    # checking if the file is correctly uploaded of not
    assert any(file_name == files.get('name')
               for files in session.GetFileList().get('files'))

    # since the saved config has 4 ports
    assert len(ixnetwork.Vport.find()) == 4


# todo: try with json
Esempio n. 11
0
    def loadConfigFile(self, configFile, localFile=True, portList=None):
        """
        Description
            Load a saved config file.

        Parameters
            configFile: (str): The full path including the saved config filename.
                               If the config file is in a Windows filesystem, the format is
                               c:\\path\\bgp.ixncfg
                               If you are executing the script from Linux and the config file is in
                               local Linux filesystem, the format is /path/bgp.ixncfg and
                               localFile=True.

            localFile: (bool): For Windows API server and Connection Mgr running on a Windows
            server only. Set to False if the config file is in the Windows API server filesystem.

            portList: (list): This takes the list of ports to be connected to once load config is performed
            If the value is None(default value), then chassis, slot and port under configuration file are retained.
            If not None, chassis, slot and port configurations loaded using configuration file will get replaced with
            the given parameters
            Example: [['10.39.64.197', '1', '1'],
                      ['10.39.64.197', '1', '2']]
        """

        self.ixnObj.logInfo("Loading Config File {}".format(configFile))
        try:
            self.ixNetwork.LoadConfig(Files(configFile, local_file=localFile))
            if portList is not None:
                vportList = self.ixNetwork.Vport.find()
                chassisIp = portList[0][0]
                connectedChassis = self.ixNetwork.AvailableHardware.Chassis.find(
                )
                if chassisIp != connectedChassis.Hostname:
                    self.ixNetwork.AvailableHardware.Chassis.find().remove()
                    self.ixNetwork.AvailableHardware.Chassis.add(
                        Hostname=chassisIp)
                for port, vport in zip(portList, vportList):
                    vport.update(Location=';'.join(port))

        except Exception as err:
            self.ixnObj.logInfo("Error with Load config {}".format(err))
            raise Exception(
                "Failed to load config file {} ".format(configFile))
def ixia_qos(result, packetcount, option):
    # connect to a test platform, create a session and get the root IxNetwork object
    test_platform = TestPlatform('127.0.0.1', rest_port=63061)
    forceTakePortOwnership = True
    test_platform.Trace = 'none'
    sessions = test_platform.Sessions.add()
    ixChassisIpList = ['10.244.9.24']
    ixnetwork = sessions.Ixnetwork
    #test_platform.Trace = 'request_response'
    ixnetwork.NewConfig()

    #create the logical ports for Ixia

    vport1 = ixnetwork.Vport.add(Name='Port1')
    vport2 = ixnetwork.Vport.add(Name='Port2')

    vportList = [vport.href for vport in ixnetwork.Vport.find()]

    portList = [[ixChassisIpList[0], 2, 4]]

    #### load the saved IxNetwork configuration
    ixnetwork.LoadConfig(Files(result, local_file=True))
    testPorts = []
    for port in portList:
        print("Chassis IP address is {}".format(port[0]))
        testPorts.append(dict(Arg1=port[0], Arg2=port[1], Arg3=port[2]))

    forceTakePortOwnership = True

    #Assign the ports to the configuration

    ixnetwork.AssignPorts(testPorts, [], vportList, forceTakePortOwnership)

    ##Start all protocols

    print("*******************Starting Protocols************************")

    ixnetwork.StartAllProtocols(Arg1='sync')
    time.sleep(20)

    print("*******************Creating Traffic Items************************")

    #Define traffic items with specific trafic types.
    traffic_item1 = ixnetwork.Traffic.TrafficItem.find(TrafficType='ipv4')
    traffic_item2 = ixnetwork.Traffic.TrafficItem.find(TrafficType='ipv6')

    print(traffic_item1)
    #print(traffic_item2)

    ### Define the framecount that you want to send through the Ixia port.

    print(
        "*******************Define the number of packets you want to send************************"
    )

    configElement = traffic_item1.ConfigElement.find()
    transmissioncontrol = configElement.TransmissionControl
    transmissioncontrol.update(FrameCount=packetcount)
    test_platform.info(transmissioncontrol.FrameCount)
    #print(configElement)

    #print("Choose the type of traffic you want to send:")

    print("\n")

    #a = int(input("Enter 1. IPv4 or 2. IPv6 or 3. Both: "))

    i = 0

    ###Run the traffic IPv4 traffic if the user enters 1 as an option.

    if option == 1:

        #####Only enable IPv4 traffic as defined in the test case.

        #traffic_item1.update(Enabled=True)
        traffic_item1.find()[1].update(Enabled=False)
        traffic_item1.find()[3].update(Enabled=False)

        time.sleep(5)
        traffic_item1.Generate()
        time.sleep(5)
        ixnetwork.Traffic.Apply()
        time.sleep(5)

        ixnetwork.StartCapture()
        time.sleep(5)
        ixnetwork.Traffic.Start()
        time.sleep(10)

        ixnetwork.StopCapture()
        ixnetwork.SaveCapture("C:\Python27\Programs", '_QoS')

        pcapFile = "EGRESS - NETWORK TRUNK_HW_QoS.cap"
        #####Parse through the Wireshark file to check each packet for a COS value ==5. Print a statement if the value is not equal to 5"
        for packet in rdpcap(pcapFile):
            #ixnetwork.info('\nPacket: {}:\n'.format(index))
            #print("here")
            try:
                dot1q = packet['Dot1Q']
                #priority = dot1q[prio]
                if (packet.prio) == 5:
                    print("cos == 5")
                    i = i + 1
                    continue
                else:
                    print("Packet does not have priorty set to 5")
            except:
                pass
        print("Total IPv4 packets checked {}".format(i))
        #	time.sleep(10)
        #ixnetwork.Traffic.Stop()

    ###Run the traffic IPv6 traffic if the user enters 2 as an option.

    elif option == 2:

        #####Only enable IPv6 traffic as defined in the test case.

        #traffic_item1.update(Enabled=True)
        traffic_item1.find()[0].update(Enabled=False)
        traffic_item1.find()[2].update(Enabled=False)

        print(configElement)
        time.sleep(5)
        traffic_item1.Generate()
        time.sleep(5)
        ixnetwork.Traffic.Apply()
        time.sleep(5)

        ixnetwork.StartCapture()
        time.sleep(5)
        ixnetwork.Traffic.Start()
        time.sleep(10)

        ixnetwork.StopCapture()
        ixnetwork.SaveCapture("C:\Python27\Programs", '_QoS')

        pcapFile = "EGRESS - NETWORK TRUNK_HW_QoS.cap"
        ####Parse through the Wireshark file to check each packet for a COS value ==5. Print a statement if the value is not equal to 5"
        for packet in rdpcap(pcapFile):
            #ixnetwork.info('\nPacket: {}:\n'.format(index))
            #print("here")
            try:
                dot1q = packet['Dot1Q']
                #priority = dot1q[prio]
                if (packet.prio) == 5:
                    print("cos == 5")
                    i = i + 1
                    continue
                else:
                    print("Packet does not have priorty set to 5")
            except:
                pass
        print("Total IPv6 packets checked {}".format(i))

        #	time.sleep(10)
        #ixnetwork.Traffic.Stop()

    else:

        time.sleep(5)
        traffic_item1.Generate()
        time.sleep(5)
        ixnetwork.Traffic.Apply()
        time.sleep(5)

        ixnetwork.StartCapture()
        time.sleep(5)
        ixnetwork.Traffic.Start()
        time.sleep(10)

        ixnetwork.StopCapture()
        ixnetwork.SaveCapture("C:\Python27\Programs", 'cap')

        pcapFile = "EGRESS - NETWORK TRUNK_HWcap.cap"

        #####Parse through the Wireshark file to check each packet for a COS value ==5. Print a statement if the value is not equal to 5"
        for packet in rdpcap(pcapFile):
            #ixnetwork.info('\nPacket: {}:\n'.format(index))
            #print("here")
            try:
                dot1q = packet['Dot1Q']
                #priority = dot1q[prio]
                if (packet.prio) == 5:
                    print("cos == 5")
                    i = i + 1
                    continue
                else:
                    print("Packet does not have priorty set to 5")
            except:
                pass
        print("Total IPv4 & IPv6 packets checked {}".format(i))
Esempio n. 13
0
    testPlatform = TestPlatform(apiServerIp,
                                rest_port=apiServerPort,
                                platform=osPlatform,
                                log_file_name='restpy.log')

    # Console output verbosity: None|request|'request response'
    testPlatform.Trace = 'request_response'

    testPlatform.Authenticate(username, password)
    session = testPlatform.Sessions.add()

    ixNetwork = session.Ixnetwork
    ixNetwork.NewConfig()

    ixNetwork.info('Loading config file: {0}'.format(configFile))
    ixNetwork.LoadConfig(Files(configFile, local_file=True))

    ixNetwork.Globals.Licensing.LicensingServers = licenseServerIp
    ixNetwork.Globals.Licensing.Mode = licenseMode
    ixNetwork.Globals.Licensing.Tier = licenseTier

    # Assign ports
    testPorts = []
    vportList = [vport.href for vport in ixNetwork.Vport.find()]
    for port in portList:
        testPorts.append(dict(Arg1=port[0], Arg2=port[1], Arg3=port[2]))

    ixNetwork.AssignPorts(testPorts, [], vportList, forceTakePortOwnership)

    ixNetwork.StartAllProtocols(Arg1='sync')
Esempio n. 14
0
from ixnetwork_restpy.files import Files

# connect to a test platform, create a session and get the root IxNetwork object
test_platform = TestPlatform('127.0.0.1', rest_port=11009)
test_platform.Trace = 'request_response'
sessions = test_platform.Sessions.find(Id=1)
ixnetwork = sessions.Ixnetwork

# create an empty configuration on the server
ixnetwork.NewConfig()

# add 4 vport objects
ixnetwork.Vport.add().add().add().add()

# save the configuration on the server
ixnetwork.SaveConfig(Files('sample.ixncfg'))

# get a list of remote files
print(sessions.GetFileList())

# download the remote saved configuration as some other local file
sessions.DownloadFile('sample.ixncfg', 'local.ixncfg')

# upload the local file
print(sessions.UploadFile('local.ixncfg'))

# load the remote local configuration
print(ixnetwork.LoadConfig(Files('local.ixncfg')))

# verify that the vport objects exist
assert (len(ixnetwork.Vport.find()) == 4)
Esempio n. 15
0
    sessions = test_platform.Sessions.add()
    print(sessions)

    ixnetwork = sessions.Ixnetwork
    print(ixnetwork)

    views = ixnetwork.Statistics.View.find()
    print(views)

    try:
        ixnetwork.LoadConfig('c:/temp/ipv4_traffic.ixncfg')
        assert ('Type checking failed')
    except TypeError as e:
        print(e)
    ixnetwork.LoadConfig(
        Files('c:/users/anbalogh/downloads/ipv4_traffic.ixncfg',
              local_file=True))

    print(ixnetwork.Globals)
    print(ixnetwork.AvailableHardware)
    print(ixnetwork.Traffic)
    print(ixnetwork.Statistics)
    print(ixnetwork.ResourceManager)

    assert (len(ixnetwork.Vport.find()) == 0)
    assert (len(ixnetwork.Topology.find()) == 0)
    assert (len(ixnetwork.AvailableHardware.Chassis.find()) == 0)
    assert (len(ixnetwork.Statistics.View.find()) == 0)
    assert (len(ixnetwork.Traffic.TrafficItem.find()) == 0)

    vport_name = 'Abstract Port 1'
    vports = ixnetwork.Vport.add(Name=vport_name, Type='pos')
Esempio n. 16
0
from ixnetwork_restpy.testplatform.testplatform import TestPlatform
from ixnetwork_restpy.files import Files


# connect to a test platform, create a session and get the root IxNetwork object
test_platform = TestPlatform('127.0.0.1', rest_port=11009)
test_platform.Trace = 'request_response'
sessions = test_platform.Sessions.find(Id=1)
ixnetwork = sessions.Ixnetwork

# create an empty configuration on the server
ixnetwork.NewConfig()

# add 4 vport objects
ixnetwork.Vport.add().add().add().add()

# save the configuration on the server
ixnetwork.SaveConfig(Files('sample.ixncfg'))

# create an empty configuration
ixnetwork.NewConfig()
assert(len(ixnetwork.Vport.find()) == 0)

# load the saved configuration
ixnetwork.LoadConfig(Files('sample.ixncfg'))

# verify that the vport objects exist
assert(len(ixnetwork.Vport.find()) == 4)


Esempio n. 17
0
    # ixNetwork is the root object to the IxNetwork API hierarchical tree.
    ixNetwork = session.Ixnetwork

    # Instantiate the helper class objects
    statObj = Statistics(ixNetwork)
    portObj = Ports(ixNetwork)

    if osPlatform == 'windows':
        ixNetwork.NewConfig()

    ixNetwork.Globals.Licensing.LicensingServers = licenseServerIp
    ixNetwork.Globals.Licensing.Mode = licenseMode

    print('\nLoading JSON config file: {0}'.format(jsonConfigFile))
    ixNetwork.ResourceManager.ImportConfigFile(Files(jsonConfigFile,
                                                     local_file=True),
                                               Arg3=True)

    # Assigning ports after loading a saved config is optional because you could use the ports that
    # are saved in the config file. Optionally, reassign ports to use other chassis/ports on different testbeds.
    # getVportList=True because vports are already configured in the config file.
    portObj.assignPorts(portList, forceTakePortOwnership, getVportList=True)

    # Example: How to modify a loaded json config using XPATH
    # Arg3:  True=To create a new config. False=To modify an existing config.
    data = json.dumps([{
        "xpath": "/traffic/trafficItem[1]",
        "name": 'Modified Traffic'
    }])
    ixNetwork.ResourceManager.ImportConfig(Arg2=data, Arg3=False)
Esempio n. 18
0
# create a configuration fragment of two virtual ports
vports = [
    {
        'xpath': '/vport[1]',
        'name': 'vport 1'
    },
    {
        'xpath': '/vport[2]',
        'name': 'vport 2'
    }
]

# import the configuration fragment as a string
ixnetwork.ResourceManager.ImportConfig(json.dumps(vports), True)
assert(len(ixnetwork.Vport.find()) == 2)

# export the entire configuration as a string
config = ixnetwork.ResourceManager.ExportConfig(['/descendant-or-self::*'], False, 'json')

# import the entire configuration as a string
ixnetwork.ResourceManager.ImportConfig(config, True)
assert(len(ixnetwork.Vport.find()) == 2)

# export the entire configuration as a file
ixnetwork.ResourceManager.ExportConfigFile(['/descendant-or-self::*'], False, 'json', Files('two_vports.json'))

# import then entire configuration from a file
ixnetwork.ResourceManager.ImportConfigFile(Files('two_vports.json'), True)
assert(len(ixnetwork.Vport.find()) == 2)
    def getCapFile(self,
                   port,
                   typeOfCapture='data',
                   saveToTempLocation='c:\\Temp',
                   localLinuxLocation='.',
                   appendToSavedCapturedFile=None):
        """
        Get the latest captured .cap file from ReST API server to local Linux drive.

        Parameters
            port: Format:[IxiaIpAddress, slotNumber, cardNumber]
                  Example: [ixChassisIp, '2', '1']

            typeOfCapture: data|control

            saveToTempLocation: For Windows:
                                    Where to temporary save the .cap file on the ReST API server:
                                    Provide any path with double backslashes: C:\\Temp.
                                    The folder will be created if it doesn't exists.

                                For Linux, value= 'linux'.

            localLinuxLocation: Where to save the .cap file on the local Linux machine.

            appendToSavedCapturedFile: Add a text string to the captured file.

        Example:
            captureObj.getCapFile([ixChassisIp, '2', '1'], 'control', 'c:\\Temp', '/home/hgee/test')

        Syntaxes:

               DATA: {"arg1": "packetCaptureFolder"}  <-- This could be any name.
                                                Just a temporary folder to store the captured file.

               Wait for the /operations/savecapturefiles/<id> to complete.
                            May take up to a minute or more.

               For Windows API server:

                  DATA: {"arg1": "c:\\Results\\port2_HW.cap",
                         "arg2": "/api/v1/sessions/1/ixnetwork/files/port2_HW.cap"}

               For Linux API server:

                  DATA: {"arg1": "captures/packetCaptureFolder/port2_HW.cap",
                         "arg2": "/api/v1/sessions/<id>/ixnetwork/files/port2_HW.cap"}

        """

        vport = self.portMgmtObj.getVports([port])[0]
        vportName = vport.Name

        if appendToSavedCapturedFile is not None:
            self.ixNetwork.SaveCaptureFiles(Arg1=saveToTempLocation,
                                            Arg2=appendToSavedCapturedFile)
        else:
            self.ixNetwork.SaveCaptureFiles(Arg1=saveToTempLocation)

        # example capfilePathName: 'c:\\Results\\1-7-2_HW.cap'
        if typeOfCapture == 'control':
            if self.ixnObj.serverOs in ['windows', 'windowsConnectionMgr']:
                capFileToGet = saveToTempLocation + "\\" + vportName + "_SW.cap"
                filename = vportName + "_HW.cap"
            else:
                capFileToGet = saveToTempLocation + "/" + vportName + "_SW.cap"
                filename = vportName + "_HW.cap"

        if typeOfCapture == 'data':
            if self.ixnObj.serverOs in ['windows', 'windowsConnectionMgr']:
                capFileToGet = saveToTempLocation + "\\" + vportName + "_HW.cap"
                filename = vportName + "_HW.cap"
            else:
                capFileToGet = saveToTempLocation + "/" + vportName + "_HW.cap"
                filename = vportName + "_HW.cap"

        try:
            self.ixNetwork.CopyFile(
                Files(capFileToGet, local_file=False),
                localLinuxLocation + "\\" + filename + ".cap")
        except Exception as err:
            self.ixnObj.logInfo("Error {} ".format(err))
            self.ixNetwork.CopyFile(
                Files(capFileToGet, local_file=False),
                localLinuxLocation + "/" + filename + ".cap")
ixnetwork = sessions.Ixnetwork

# create a configuration fragment of two virtual ports
vports = [{
    'xpath': '/vport[1]',
    'name': 'vport 1'
}, {
    'xpath': '/vport[2]',
    'name': 'vport 2'
}]

# import the configuration fragment as a string
ixnetwork.ResourceManager.ImportConfig(json.dumps(vports), True)
assert (len(ixnetwork.Vport.find()) == 2)

# export the entire configuration as a string
config = ixnetwork.ResourceManager.ExportConfig(['/descendant-or-self::*'],
                                                False, 'json')

# import the entire configuration as a string
ixnetwork.ResourceManager.ImportConfig(config, True)
assert (len(ixnetwork.Vport.find()) == 2)

# export the entire configuration as a file
ixnetwork.ResourceManager.ExportConfigFile(['/descendant-or-self::*'], False,
                                           'json', Files('two_vports.json'))

# import then entire configuration from a file
ixnetwork.ResourceManager.ImportConfigFile(Files('two_vports.json'), True)
assert (len(ixnetwork.Vport.find()) == 2)
Esempio n. 21
0
    sessions = test_platform.Sessions.add()
    print(sessions)

    ixnetwork = sessions.Ixnetwork
    print(ixnetwork)

    views = ixnetwork.Statistics.View.find()
    print(views)

    try:
        ixnetwork.LoadConfig('c:/temp/ipv4_traffic.ixncfg')
        assert ('Type checking failed')
    except TypeError as e:
        print(e)
    ixnetwork.LoadConfig(Files('c:/users/anbalogh/downloads/ipv4_traffic.ixncfg', local_file=True))

    print(ixnetwork.Globals)
    print(ixnetwork.AvailableHardware)
    print(ixnetwork.Traffic)
    print(ixnetwork.Statistics)
    print(ixnetwork.ResourceManager)
    ixnetwork.NewConfig()
    
    assert(len(ixnetwork.Vport.find()) == 0)
    assert(len(ixnetwork.Topology.find()) == 0)
    assert(len(ixnetwork.AvailableHardware.Chassis.find()) == 0)
    assert(len(ixnetwork.Statistics.View.find()) == 0)
    assert(len(ixnetwork.Traffic.TrafficItem.find()) == 0)

    vport_name = 'Abstract Port 1'