def load_config(session, file=''): try: ixnetwork = session.Ixnetwork if file == '': file = sys.argv[0].split('/')[-1].split('.')[0] + '.ixncfg' ixnetwork.LoadConfig(Files(file, local_file=True)) #ixNetwork.ResourceManager.ImportConfigFile(Files(jsonConfigFile, local_file=True), Arg3=True) except Exception as err: logger.error(err) logger_msg(u'加载配置文件失败,请检查配置', 'ERROR')
except: isLayer3 = False print('\n\nTopology isLayer3: False\n') return isLayer3 try: # LogLevel: none, info, warning, request, request_response, all session = SessionAssistant(IpAddress=apiServerIp, RestPort=None, UserName='******', Password='******', SessionName=None, SessionId=None, ApiKey=None, ApplicationType=applicationType, ClearConfig=True, LogLevel='all', LogFilename='restpy.log') ixNetwork = session.Ixnetwork ixNetwork.LoadConfig(Files(configFile, local_file=True)) # Assign ports portMap = session.PortMapAssistant() vport = dict() for index,port in enumerate(portList): # For the port name, get the loaded configuration's port name portName = ixNetwork.Vport.find()[index].Name portMap.Map(IpAddress=port[0], CardId=port[1], PortId=port[2], Name=portName) portMap.Connect(forceTakePortOwnership) for vport in ixNetwork.Vport.find(): if vport.Type == 'novusTenGigLan': vport.L1Config.NovusTenGigLan.Media = portMedia
# LogLevel: none, info, warning, request, request_response, all session = SessionAssistant(IpAddress='192.168.70.3', RestPort=None, UserName='******', Password='******', SessionName=None, SessionId=None, ApiKey=None, ClearConfig=True, LogLevel='info', LogFilename='restpy.log') ixNetwork = session.Ixnetwork ixNetwork.info('Loading config file: bgp_ngpf_8.30.ixncfg') ixNetwork.LoadConfig(Files('bgp_ngpf_8.30.ixncfg', local_file=True)) # Assign ports. Map physical ports to the configured vports. portMap = session.PortMapAssistant() # For the portName, get it from the loaded configuration portMap.Map(IpAddress='192.168.70.128', CardId=1, PortId=1, Name=ixNetwork.Vport.find()[0].Name) portMap.Map(IpAddress='192.168.70.128', CardId=2, PortId=1, Name=ixNetwork.Vport.find()[1].Name) portMap.Connect(ForceOwnership=True) ixNetwork.info('Starting NGPF protocols')
try: session = SessionAssistant(IpAddress=apiServerIp, RestPort=None, UserName='******', Password='******', SessionName=None, SessionId=None, ApiKey=None, ClearConfig=True, LogLevel='all', LogFilename='restpy.log') ixNetwork = session.Ixnetwork ixNetwork.info('\nLoading JSON config file: {0}'.format(jsonConfigFile)) ixNetwork.ResourceManager.ImportConfigFile(Files(jsonConfigFile, local_file=True), Arg3=True) # Assign ports. portMap = session.PortMapAssistant() vport = dict() for index, port in enumerate(portList): portName = ixNetwork.Vport.find()[index].Name portMap.Map(IpAddress=port[0], CardId=port[1], PortId=port[2], Name=portName) portMap.Connect(forceTakePortOwnership) # Example on how to change the media port type: copper|fiber
"""Demonstrates collecting diagnostic logs """ from ixnetwork_restpy import SessionAssistant, Files session_assistant = SessionAssistant(IpAddress='127.0.0.1', UserName='******', Password='******', LogLevel=SessionAssistant.LOGLEVEL_INFO, ClearConfig=True) ixnetwork = session_assistant.Ixnetwork ixnetwork.CollectLogs(Arg1=Files('diagnostic_logs'), Arg2='currentInstance') session_assistant.Session.DownloadFile('diagnostic_logs.zip')
""" from ixnetwork_restpy import SessionAssistant, Files session_assistant = SessionAssistant(IpAddress='127.0.0.1', UserName='******', Password='******', LogLevel=SessionAssistant.LOGLEVEL_INFO, ClearConfig=True) ixnetwork = session_assistant.Ixnetwork # 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(session_assistant.Session.GetFileList()) # download the remote saved configuration as some other local file session_assistant.Session.DownloadFile('sample.ixncfg', 'local.ixncfg') # upload the local file print(session_assistant.Session.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)
ixnetwork = session_assistant.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)