def loginNode(): print('=> Initializing connection to nexus device ...') nxswUrl = 'https://%s' % (host) nxsw = Node(nxswUrl) nxsw.methods.Login(username, password).POST() mit = nxsw.mit return nxsw, mit
def testDistributeConfig(): n = Node('') mit = n.mit mit.polUni().fvTenant('cisco') mit.polUni().fvTenant('insieme') mits = distributeConfig(mit) mits.should.have.length_of(2) mits[0].ReadOnlyTree = True mits[0].polUni().fvTenant('cisco').name.should.equal('cisco') mits[1].ReadOnlyTree = True mits[1].polUni().fvTenant('insieme').name.should.equal('insieme')
def testReadOnlyTree(): n = Node('') tree = n.mit #pylint: disable=pointless-statement tree.ReadOnlyTree.should.be.false with readOnlyTree(tree) as r: #pylint: disable=pointless-statement tree.ReadOnlyTree.should.be.true #pylint: disable=pointless-statement r.ReadOnlyTree.should.be.true #pylint: disable=pointless-statement tree.ReadOnlyTree.should.be.false
def testMergeRoot(): n = Node('') t1 = n.mit t1.polUni().fvTenant('cisco') t2 = n.mit t2.polUni().fvTenant('insieme') mit = n.mit mergeRoot(mit, t1) mergeRoot(mit, t2) mit.ReadOnlyTree = True mit.polUni().fvTenant('cisco').name.should.equal('cisco') mit.polUni().fvTenant('insieme').name.should.equal('insieme')
def main(host, user, password, **kwargs): print('Initializing connection to nexus device ...') nxswUrl = 'http://%s' % (host) nxsw = Node(nxswUrl) nxsw.methods.Login(user, password, autoRefresh=True).POST() print('Listening for Events ...') nxsw.startWsListener() _, subscriptionId = nxsw.methods.ResolveClass('rtctrlL2Evpn').GET( **options.subscribe & options.subtree) while (True): nxsw.waitForWsMo(subscriptionId, timeout=5) if nxsw.hasWsMo(subscriptionId): print(nxsw.popWsMo(subscriptionId).Xml) print('logging out') nxsw.methods.Logout(user)
import requests from getpass import getpass from pydme import Node, options # Optionally, insert switch credentials here #host = '192.168.1.10' #username = '******' #password = '******' host = input("Switch IP: ") username = input("Username: "******"Password: ") host_url = 'https://' + host my_switch = Node(host_url) result = my_switch.methods.Login(username, password).POST() #if result.status_code != requests.codes.ok: #break() mit = my_switch.mit lldp_neighbors = mit.GET(**options.subtreeClass('lldpAdjEp')) for lldp_neighbor in lldp_neighbors: dn = lldp_neighbor.Dn lldp_if = dn[dn.find('[') + len('['):dn.rfind(']')] sysDesc = lldp_neighbor.sysDesc if 'eth' in lldp_if: if 'Linux' in sysDesc: print('We will set ' + lldp_if + ' ' + sysDesc) mit = my_switch.mit if_status = mit.topSystem().interfaceEntity().l1PhysIf(lldp_if)