exportJsonConfigFile = 'bgp_ngpf_hw_8.40.json'

try:
    restObj = Connect(apiServerIp='192.168.70.3', serverIpPort='11009')
    fileMgmtObj = FileMgmt(restObj)

    # How to export a configuration into a JSON format file.
    #    This will export your current configuration into a specified json filename.
    fileMgmtObj.exportJsonConfigFile(jsonFileName=exportJsonConfigFile)

    # How to load a complete json config file
    fileMgmtObj.importJsonConfigFile(jsonConfigFile, option='newConfig')

    # Read a JSON config file and store all the datas into an object.
    # Use the jsonData object to make your modifications.
    jsonData = fileMgmtObj.jsonReadConfig(exportJsonConfigFile)


    # How to use XPATH to modify IxNetwork configurations.
    xpathObj = [{"xpath": "/multivalue[@source = '/topology[1]/deviceGroup[1]/ethernet[1]/ipv4[1]/bgpIpv4Peer[1] flap']/singleValue",
                 "value": "true"},
               {"xpath": "/multivalue[@source = '/topology[1]/deviceGroup[1]/ethernet[1]/ipv4[1]/bgpIpv4Peer[1] uptimeInSec']/singleValue",
                 "value": "28"},
               {"xpath": "/multivalue[@source = '/topology[1]/deviceGroup[1]/ethernet[1]/ipv4[1]/bgpIpv4Peer[1] downtimeInSec']/singleValue",
                 "value": "68"}
             ]
    fileMgmtObj.importJsonConfigObj(dataObj=xpathObj, option='modify')


    # How to add a new Traffic Item without touching the JSON config file.
    #     Assuming that there are two Traffic Items already.
Ejemplo n.º 2
0
        if forceTakePortOwnership == True:
            portObj.releasePorts(portList)
            portObj.clearPortOwnership(portList)
        else:
            raise IxNetRestApiException(
                '\nPorts are owned by another user and forceTakePortOwnership is set to False. Exiting test.'
            )

    # Optional: Uncomment if required.
    # Configuring license requires releasing all ports even for ports that is not used for this test.
    portObj.releaseAllPorts()
    mainObj.configLicenseServerDetails([licenseServerIp], licenseModel,
                                       licenseTier)

    fileMgmtObj = FileMgmt(mainObj)
    jsonData = fileMgmtObj.jsonReadConfig(jsonConfigFile)

    # 8.40: Takes 5 minutes to load/assignPorts on OVA/VE Linux.
    fileMgmtObj.importJsonConfigFile(jsonConfigFile, type='newConfig')
    fileMgmtObj.jsonAssignPorts(jsonData, portList, timeout=300)
    portObj.verifyPortState()

    # Example: How to modify
    #    Mofify the BGP configuration using JSON XPATH. XPATH are obtained from a JSON exported config file.
    #       1> Export the JSON configuration to a file.
    #       2> Get the XPATH to where you want to modify the configuraiton.
    #       3> Import the modified JSON to IxNetwork
    xpathObj = [{
        "xpath":
        "/multivalue[@source = '/topology[1]/deviceGroup[1]/ethernet[1]/ipv4[1]/bgpIpv4Peer[1] flap']/singleValue",
        "value": "true"