from functions import getRestToken, getVRF, getVRFVLAN, getNetworks from functions import DCNMPost ##### Settings from settings.ini from configparser import ConfigParser config = ConfigParser() config.read('C:/Temp/Git/Cisco/DCNM/settings.ini') dcnmuser = config.get('DCNM', 'dcnmuser') dcnmpassword = config.get('DCNM', 'dcnmpassword') dcnmserver = config.get('DCNM', 'dcnmserver') ###### # # Prüft IPAM und gibt fehlende Netze zurück # ###### # Get Token token = getRestToken(dcnmuser, dcnmpassword, dcnmserver) networks = getNetworks(dcnmserver, token) for network in networks: #print(network['networkName'], network['vrf'], network['networkTemplateConfig']['vlanId'] ) #print(network['networkTemplateConfig']) decoded = json.loads(network['networkTemplateConfig']) print(network['networkName'], network['vrf'], decoded['vlanId']) # Example #{"fabric":"MSD001","networkName":"Trans-Klett-Service","displayName":"Trans-Klett-Service","networkId":30136,"networkTemplate":"Default_Network_Universal","networkExtensionTemplate":"Default_Network_Extension_Universal","networkTemplateConfig":"{\"suppressArp\":\"false\",\"secondaryGW2\":\"\",\"secondaryGW1\":\"\",\"vlanId\":\"3047\",\"gatewayIpAddress\":\"100.64.253.76/31\",\"networkName\":\"Trans-Klett-Service\",\"vlanName\":\"Trans-Klett-Service\",\"mtu\":\"\",\"rtBothAuto\":\"false\",\"isLayer2Only\":\"false\",\"intfDescription\":\"Trans-Klett-Service\",\"segmentId\":\"30136\",\"gatewayIpV6Address\":\"2a0c:ed80:0:400::c6/127\",\"dhcpServerAddr1\":\"\",\"tag\":\"12345\",\"nveId\":\"1\",\"vrfName\":\"Service\"}","vrf":"Service","tenantName":"","serviceNetworkTemplate":null,"source":null,"interfaceGroups":null,"networkStatus":"DEPLOYED"} #
uri = "/rest/top-down/fabrics/MSD001/networks" logger = logging.getLogger() logging.basicConfig( filename="abgleich.log", filemode='a', format='%(asctime)s.%(msecs)03d %(levelname)s - %(funcName)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S') logger.setLevel(logging.DEBUG) netzliste = [] vrfliste = [] # Get Token token = getRestToken(auth.username, auth.password, auth.serverip) networks = DCNMget(uri, auth.serverip, token) uri2 = "/rest/top-down/fabrics/MSD001/vrfs" dcnmvrf = DCNMget(uri2, auth.serverip, token) empty = "" folder = os.path.join(os.environ['USERPROFILE'], "Script-Settings") from configparser import ConfigParser config = ConfigParser() folder = folder.replace("\\", "/") folder = folder + "/settings.ini" config.read(folder) ipamuser = config.get('IPAM', 'ipamuser') ipampassword = config.get('IPAM', 'ipampassword')