if __name__ == '__main__': # connection to NETCONF servers session_1 = NetconfSSHSession(host_1, port, username, password) session_2 = NetconfSSHSession(host_2, port, username, password) # create operations print(create_config(session_1, create_1)) time.sleep(ts) print(create_config(session_2, create_1)) time.sleep(td) # get operations print(get_config(session_1)) time.sleep(ts) print(get_config(session_2)) time.sleep(td) # merge oeprations print(merge_config(session_1, merge_1)) time.sleep(ts) print(merge_config(session_2, merge_1)) time.sleep(td) # delete operations print(delete_config(session_1, delete)) time.sleep(ts) print(delete_config(session_2, delete)) session_1.close() session_2.close()
from netconf.client import NetconfSSHSession from lxml import etree session = NetconfSSHSession("localhost", "8300", "admin", "admin") config = session.get() # TODO: Catch the RPCerror exception. print(type(config)) print(etree.tostring(config, pretty_print=True)) session.close()
def main(args): if not args: return #print(type(args)) #return #TODO: check if args is a valid IP nsmap_add("sys", "urn:ietf:params:xml:ns:yang:ietf-system") MODEL_NS = "urn:my-urn:my-model" nsmap_add('pfx', MODEL_NS) keyFileToSend = "python/cwCA/intermediate/certs/www.ap.controlware.com.cert.pem" privateKeyFile = "/usr/src/app/python/vendorCA/intermediate/private/www.ownership.vendor1.com.key.pem" fileString = getCertStringfromFile(keyFileToSend) sign = signString(privateKeyFile, b"password", fileString.encode('ascii'), "sha256") #Encode signature so it can be send as a string sign_base64 = base64.b64encode(sign) utf8Signature = sign_base64.decode('utf-8') ownershipRPC = util.elm("ownership") cert = OpenSSL.crypto.load_certificate( OpenSSL.crypto.FILETYPE_PEM, getCertStringfromFile( '/usr/src/app/python/vendorCA/intermediate/certs/www.ownership.vendor1.com.cert.pem' )) #if verifyString(cert, sign, fileString.encode('ascii'),"sha256"): if verifyString( '/usr/src/app/python/vendorCA/intermediate/certs/www.ownership.vendor1.com.cert.pem', sign, fileString.encode('ascii'), "sha256"): ownerCertificate = util.subelm(ownershipRPC, "ownerCertificate") ownerCertificate.append(util.leaf_elm("certificate", fileString)) #ownerCertificate.append(util.leaf_elm("certificateSignature", sign_base64)) ownerCertificate.append( util.leaf_elm("certificateSignature", utf8Signature)) bootstrapRPC = util.elm("bootstrap") bootInfo = util.subelm(bootstrapRPC, "bootInfo") #bootInfo_base64 = base64.b64encode(asnString) bytebootstrapArtifact = buildbootstrapArtifact() bootInfo_base64 = base64.b64encode(bytebootstrapArtifact) utf8BootInfo = bootInfo_base64.decode('utf-8') privateKeyFile = "/usr/src/app/python/cwCA/intermediate/private/www.ap.controlware.com.key.pem" sign = signString(privateKeyFile, b"password", utf8BootInfo.encode('ascii'), "sha256") sign_base64 = base64.b64encode(sign) utf8Signature = sign_base64.decode('utf-8') bootInfo.append(util.leaf_elm("bootInfoASN", utf8BootInfo)) if verifyString( '/usr/src/app/python/cwCA/intermediate/certs/www.ap.controlware.com.cert.pem', sign, utf8BootInfo.encode('ascii'), "sha256"): bootInfo.append(util.leaf_elm("bootInfoSignature", utf8Signature)) #TODO: not hardcode session = NetconfSSHSession(args, "8300", "admin", "admin", debug=True) root, reply, replystring = session.send_rpc(ownershipRPC) root, reply, replystring = session.send_rpc(bootstrapRPC) session.close() dataElem = reply.find("nc:data", namespaces=NSMAP) x = dataElem.find("nc:result", namespaces=NSMAP) if x is not None: print(x.text) else: print("not found")