Best Python code snippet using localstack_python
startup_script.py
Source:startup_script.py
1# list of packages that should be imported for this code to work23import cobra.mit.access4import cobra.mit.request5import cobra.mit.session6import cobra.model.fv7import cobra.model.ip8import cobra.model.vz9import cobra.model.pol10import cobra.model.vpc11import cobra.model.fvns12import cobra.model.lacp13import cobra.model.phys14import cobra.model.infra15import cobra.model.l3ext16import cobra.model.fabric17from cobra.internal.codec.xmlcodec import toXMLStr181920# log into an APIC and create a directory object21ls = cobra.mit.session.LoginSession('https://apic', 'admin', 'password')22md = cobra.mit.access.MoDirectory(ls)23md.login()2425# the top level object on which operations will be made26topMo = md.lookupByDn("uni/controller/nodeidentpol")2728# build the request using cobra syntax29leaf1 = cobra.model.fabric.NodeIdentP(topMo, serial=u'TEP-1-101', nodeId=u'101', name=u'leaf-1')30leaf2 = cobra.model.fabric.NodeIdentP(topMo, serial=u'TEP-1-102', nodeId=u'102', name=u'leaf-2')31spine1 = cobra.model.fabric.NodeIdentP(topMo, serial=u'TEP-1-103', nodeId=u'201', name=u'spine-1')3233# commit fabric initialization34c = cobra.mit.request.ConfigRequest()35c.addMo(topMo)36md.commit(c)37383940# the top level object on which operations will be made41polUni = cobra.model.pol.Uni('')42infraInfra = cobra.model.infra.Infra(polUni)4344# build the vlan pools45snv_pool = cobra.model.fvns.VlanInstP(infraInfra, name=u'SnV_general_pool', allocMode=u'static')46snv_range = cobra.model.fvns.EncapBlk(snv_pool, to=u'vlan-199', from_=u'vlan-100')4748heroes_pool = cobra.model.fvns.VlanInstP(infraInfra, name=u'Heroes_general_pool', allocMode=u'static')49heroes_range = cobra.model.fvns.EncapBlk(heroes_pool, to=u'vlan-299', from_=u'vlan-200')5051# build the phys domain52snv_phys_domain = cobra.model.phys.DomP(polUni, name=u'SnV_phys')53infraRsVlanNs = cobra.model.infra.RsVlanNs(snv_phys_domain, tDn=u'uni/infra/vlanns-[SnV_general_pool]-static')5455heroes_phys_domain = cobra.model.phys.DomP(polUni, name=u'Heroes_phys')56infraRsVlanNs = cobra.model.infra.RsVlanNs(heroes_phys_domain, tDn=u'uni/infra/vlanns-[Heroes_general_pool]-static')5758# build the l3ext domain59snv_l3ext_domain = cobra.model.l3ext.DomP(polUni, name=u'SnV_external_corporate')6061heroes_l3ext_domain = cobra.model.l3ext.DomP(polUni, name=u'Heroes_external_corporate')6263# build phys aaep64snv_aaep_phys = cobra.model.infra.AttEntityP(infraInfra, name=u'SnV_phys')65snv_aaep_phys_domain = cobra.model.infra.RsDomP(snv_aaep_phys, tDn=u'uni/phys-SnV_phys')66snv_aaep_phys_infra = cobra.model.infra.FuncP(infraInfra)6768heroes_aaep_phys = cobra.model.infra.AttEntityP(infraInfra, name=u'Heroes_phys')69heroes_aaep_phys_domain = cobra.model.infra.RsDomP(heroes_aaep_phys, tDn=u'uni/phys-Heroes_phys')70heroes_aaep_phys_infra = cobra.model.infra.FuncP(infraInfra)7172# build l3ext aaep73snv_aaep_l3ext = cobra.model.infra.AttEntityP(infraInfra, name=u'SnV_corporate_external')74snv_aaep_l3ext_domain = cobra.model.infra.RsDomP(snv_aaep_l3ext, tDn=u'uni/l3dom-SnV_external_corporate')75snv_aaep_l3ext_infra = cobra.model.infra.FuncP(infraInfra)7677heroes_aaep_l3ext = cobra.model.infra.AttEntityP(infraInfra, name=u'Heroes_corporate_external')78heroes_aaep_l3ext_domain = cobra.model.infra.RsDomP(heroes_aaep_l3ext, tDn=u'uni/l3dom-Heroes_external_corporate')79heroes_aaep_l3ext_infra = cobra.model.infra.FuncP(infraInfra)8081# build the lacp active policy82lacpLagPol = cobra.model.lacp.LagPol(infraInfra, name=u'lacp_active', ctrl=u'fast-sel-hot-stdby,graceful-conv,susp-individual', mode=u'active')8384# build the interface policy groups85infraFuncP = cobra.model.infra.FuncP(infraInfra)8687snv_standard_pg = cobra.model.infra.AccPortGrp(infraFuncP, name=u'SnV_standard_access')88snv_standard_aaep = cobra.model.infra.RsAttEntP(snv_standard_pg, tDn=u'uni/infra/attentp-SnV_phys')8990heroes_standard_pg = cobra.model.infra.AccPortGrp(infraFuncP, name=u'Heroes_standard_access')91heroes_standard_aaep = cobra.model.infra.RsAttEntP(heroes_standard_pg, tDn=u'uni/infra/attentp-Heroes_phys')9293snv_corp_ext_pg = cobra.model.infra.AccPortGrp(infraFuncP, name=u'SnV_corporate_external')94snv_corp_ext_aaep = cobra.model.infra.RsAttEntP(snv_corp_ext_pg, tDn=u'uni/infra/attentp-SnV_corporate_external')9596heroes_corp_ext_pg = cobra.model.infra.AccPortGrp(infraFuncP, name=u'Heroes_corporate_external')97heroes_corp_ext_aaep = cobra.model.infra.RsAttEntP(heroes_corp_ext_pg, tDn=u'uni/infra/attentp-Heroes_corporate_external')9899fi1a_bundle = cobra.model.infra.AccBndlGrp(infraFuncP, lagT=u'node', name=u'SnV_FI-1A')100fi1a_aaep = cobra.model.infra.RsAttEntP(fi1a_bundle, tDn=u'uni/infra/attentp-SnV_phys')101fi1a_lacp = cobra.model.infra.RsLacpPol(fi1a_bundle, tnLacpLagPolName=u'lacp_active')102103fi1b_bundle = cobra.model.infra.AccBndlGrp(infraFuncP, lagT=u'node', name=u'SnV_FI-1B')104fi1b_aaep = cobra.model.infra.RsAttEntP(fi1b_bundle, tDn=u'uni/infra/attentp-SnV_phys')105fi1b_lacp = cobra.model.infra.RsLacpPol(fi1b_bundle, tnLacpLagPolName=u'lacp_active')106107fi2a_bundle = cobra.model.infra.AccBndlGrp(infraFuncP, lagT=u'node', name=u'Heroes_FI-2A')108fi2a_aaep = cobra.model.infra.RsAttEntP(fi2a_bundle, tDn=u'uni/infra/attentp-Heroes_phys')109fi2a_lacp = cobra.model.infra.RsLacpPol(fi2a_bundle, tnLacpLagPolName=u'lacp_active')110111fi2b_bundle = cobra.model.infra.AccBndlGrp(infraFuncP, lagT=u'node', name=u'Heroes_FI-2B')112fi2b_aaep = cobra.model.infra.RsAttEntP(fi2b_bundle, tDn=u'uni/infra/attentp-Heroes_phys')113fi2b_lacp = cobra.model.infra.RsLacpPol(fi2b_bundle, tnLacpLagPolName=u'lacp_active')114115# build the interface profiles116snv_corp_ext_acc = cobra.model.infra.AccPortP(infraInfra, name=u'SnV_corporate_external')117snv_corp_ext_phys_port = cobra.model.infra.HPortS(snv_corp_ext_acc, name=u'ethernet1_48', type='range')118snv_corp_ext_port_range = cobra.model.infra.PortBlk(snv_corp_ext_phys_port, name=u'block2', fromPort=u'48', toPort=u'48')119snv_corp_ext_config = cobra.model.infra.RsAccBaseGrp(snv_corp_ext_phys_port, tDn=u'uni/infra/funcprof/accportgrp-SnV_corporate_external')120121heroes_corp_ext_acc = cobra.model.infra.AccPortP(infraInfra, name=u'Heroes_corporate_external')122heroes_corp_ext_phys_port = cobra.model.infra.HPortS(heroes_corp_ext_acc, name=u'ethernet1_47', type='range')123heroes_corp_ext_port_range = cobra.model.infra.PortBlk(heroes_corp_ext_phys_port, name=u'block2', fromPort=u'47', toPort=u'47')124heroes_corp_ext_config = cobra.model.infra.RsAccBaseGrp(heroes_corp_ext_phys_port, tDn=u'uni/infra/funcprof/accportgrp-Heroes_corporate_external')125126snv_server1_acc = cobra.model.infra.AccPortP(infraInfra, name=u'SnV_server1')127snv_server1_phys_port = cobra.model.infra.HPortS(snv_server1_acc, name=u'ethernet1_1', type='range')128snv_server1_port_range = cobra.model.infra.PortBlk(snv_server1_phys_port, name=u'block2', fromPort=u'1', toPort=u'1')129snv_server1_config = cobra.model.infra.RsAccBaseGrp(snv_server1_phys_port, tDn=u'uni/infra/funcprof/accportgrp-SnV_standard_access')130131snv_server2_acc = cobra.model.infra.AccPortP(infraInfra, name=u'SnV_server2')132snv_server2_phys_port = cobra.model.infra.HPortS(snv_server2_acc, name=u'ethernet1_1', type='range')133snv_server2_port_range = cobra.model.infra.PortBlk(snv_server2_phys_port, name=u'block2', fromPort=u'1', toPort=u'1')134snv_server2_config = cobra.model.infra.RsAccBaseGrp(snv_server2_phys_port, tDn=u'uni/infra/funcprof/accportgrp-SnV_standard_access')135136snv_act_pass_acc = cobra.model.infra.AccPortP(infraInfra, name=u'SnV_phys_act_pass')137snv_act_pass_phys_ports = cobra.model.infra.HPortS(snv_act_pass_acc, name=u'ethernet1_2-4', type='range')138snv_act_pass_port_range = cobra.model.infra.PortBlk(snv_act_pass_phys_ports, name=u'block2', fromPort=u'2', toPort=u'4')139snv_act_pass_config = cobra.model.infra.RsAccBaseGrp(snv_act_pass_phys_ports, tDn=u'uni/infra/funcprof/accportgrp-SnV_standard_access')140141heroes_server1_acc = cobra.model.infra.AccPortP(infraInfra, name=u'Heroes_server1')142heroes_server1_phys_port = cobra.model.infra.HPortS(heroes_server1_acc, name=u'ethernet1_21', type='range')143heroes_server1_port_range = cobra.model.infra.PortBlk(heroes_server1_phys_port, name=u'block2', fromPort=u'21', toPort=u'21')144heroes_server1_config = cobra.model.infra.RsAccBaseGrp(heroes_server1_phys_port, tDn=u'uni/infra/funcprof/accportgrp-Heroes_standard_access')145146heroes_server2_acc = cobra.model.infra.AccPortP(infraInfra, name=u'Heroes_server2')147heroes_server2_phys_port = cobra.model.infra.HPortS(heroes_server2_acc, name=u'ethernet1_21', type='range')148heroes_server2_port_range = cobra.model.infra.PortBlk(heroes_server2_phys_port, name=u'block2', fromPort=u'21', toPort=u'21')149heroes_server2_config = cobra.model.infra.RsAccBaseGrp(heroes_server2_phys_port, tDn=u'uni/infra/funcprof/accportgrp-Heroes_standard_access')150151heroes_act_pass_acc = cobra.model.infra.AccPortP(infraInfra, name=u'Heroes_phys_act_pass')152heroes_act_pass_phys_ports = cobra.model.infra.HPortS(heroes_act_pass_acc, name=u'ethernet1_22-24', type='range')153heroes_act_pass_port_range = cobra.model.infra.PortBlk(heroes_act_pass_phys_ports, name=u'block2', fromPort=u'22', toPort=u'24')154heroes_act_pass_config = cobra.model.infra.RsAccBaseGrp(heroes_act_pass_phys_ports, tDn=u'uni/infra/funcprof/accportgrp-Heroes_standard_access')155156fi1a_acc = cobra.model.infra.AccPortP(infraInfra, name=u'SnV_FI-1A')157fi1a_phys_ports = cobra.model.infra.HPortS(fi1a_acc, name=u'ethernet1_5-8', type='range')158fi1a_port_range = cobra.model.infra.PortBlk(fi1a_phys_ports, name=u'block2', fromPort=u'5', toPort=u'8')159fi1a_config = cobra.model.infra.RsAccBaseGrp(fi1a_phys_ports, tDn=u'uni/infra/funcprof/accbundle-SnV_FI-1A')160161fi1b_acc = cobra.model.infra.AccPortP(infraInfra, name=u'SnV_FI-1B')162fi1b_phys_ports = cobra.model.infra.HPortS(fi1b_acc, name=u'ethernet1_9-12', type='range')163fi1b_port_range = cobra.model.infra.PortBlk(fi1b_phys_ports, name=u'block2', fromPort=u'9', toPort=u'12')164fi1b_confige = cobra.model.infra.RsAccBaseGrp(fi1b_phys_ports, tDn=u'uni/infra/funcprof/accbundle-SnV_FI-1B')165166fi2a_acc = cobra.model.infra.AccPortP(infraInfra, name=u'Heroes_FI-2A')167fi2a_phys_ports = cobra.model.infra.HPortS(fi2a_acc, name=u'ethernet1_13-16', type='range')168fi2a_port_range = cobra.model.infra.PortBlk(fi2a_phys_ports, name=u'block2', fromPort=u'13', toPort=u'16')169fi2a_config = cobra.model.infra.RsAccBaseGrp(fi2a_phys_ports, tDn=u'uni/infra/funcprof/accbundle-Heroes_FI-2A')170171fi2b_acc = cobra.model.infra.AccPortP(infraInfra, name=u'Heroes_FI-2B')172fi2b_phys_ports = cobra.model.infra.HPortS(fi2b_acc, name=u'ethernet1_17-20', type='range')173fi2b_port_range = cobra.model.infra.PortBlk(fi2b_phys_ports, name=u'block2', fromPort=u'17', toPort=u'20')174fi2b_confige = cobra.model.infra.RsAccBaseGrp(fi2b_phys_ports, tDn=u'uni/infra/funcprof/accbundle-Heroes_FI-2B')175176# build the switch profiles and attach interfaces177leaf1 = cobra.model.infra.NodeP(infraInfra, name=u'leaf_1')178leaf1_name = cobra.model.infra.LeafS(leaf1, type=u'range', name=u'leaf_1')179leaf1_range = cobra.model.infra.NodeBlk(leaf1_name, to_=u'101', from_=u'101', name=u'b235d75799f7d020')180leaf1_intfc1 = cobra.model.infra.RsAccPortP(leaf1, tDn=u'uni/infra/accportprof-SnV_server1')181leaf1_intfc2 = cobra.model.infra.RsAccPortP(leaf1, tDn=u'uni/infra/accportprof-Heroes_server1')182183leaf2 = cobra.model.infra.NodeP(infraInfra, name=u'leaf_2')184leaf2_name = cobra.model.infra.LeafS(leaf2, type=u'range', name=u'leaf_2')185leaf2_range = cobra.model.infra.NodeBlk(leaf2_name, to_=u'102', from_=u'102', name=u'9ebfdd3979c07bcf')186leaf2_intfc1 = cobra.model.infra.RsAccPortP(leaf2, tDn=u'uni/infra/accportprof-SnV_server2')187leaf2_intfc2 = cobra.model.infra.RsAccPortP(leaf2, tDn=u'uni/infra/accportprof-Heroes_server2')188189leafs12 = cobra.model.infra.NodeP(infraInfra, name=u'leafs_1-2')190leafs12_name = cobra.model.infra.LeafS(leafs12, type=u'range', name=u'leafs_1-2')191leafs12_range = cobra.model.infra.NodeBlk(leafs12_name, to_=u'102', from_=u'101', name=u'50b60d7cf265710f')192leafs12_intfc1 = cobra.model.infra.RsAccPortP(leafs12, tDn=u'uni/infra/accportprof-SnV_FI-1A')193leafs12_intfc2 = cobra.model.infra.RsAccPortP(leafs12, tDn=u'uni/infra/accportprof-SnV_FI-1B')194leafs12_intfc3 = cobra.model.infra.RsAccPortP(leafs12, tDn=u'uni/infra/accportprof-SnV_corporate_external')195leafs12_intfc4 = cobra.model.infra.RsAccPortP(leafs12, tDn=u'uni/infra/accportprof-SnV_phys_act_pass')196leafs12_intfc5 = cobra.model.infra.RsAccPortP(leafs12, tDn=u'uni/infra/accportprof-Heroes_FI-2A')197leafs12_intfc6 = cobra.model.infra.RsAccPortP(leafs12, tDn=u'uni/infra/accportprof-Heroes_FI-2B')198leafs12_intfc7 = cobra.model.infra.RsAccPortP(leafs12, tDn=u'uni/infra/accportprof-Heroes_corporate_external')199leafs12_intfc8 = cobra.model.infra.RsAccPortP(leafs12, tDn=u'uni/infra/accportprof-Heroes_phys_act_pass')200201# setup the vpc202fabricInst = cobra.model.fabric.Inst(polUni)203vpcInstPol = cobra.model.vpc.InstPol(fabricInst, name=u'leafs_1-2')204205# build the vpc domain206fabricProtPol = cobra.model.fabric.ProtPol(fabricInst)207fabricExplicitGEp = cobra.model.fabric.ExplicitGEp(fabricProtPol, name=u'leafs_1-2', id=u'12')208fabricNodePEp = cobra.model.fabric.NodePEp(fabricExplicitGEp, id=u'101')209fabricNodePEp2 = cobra.model.fabric.NodePEp(fabricExplicitGEp, id=u'102')210fabricRsVpcInstPol = cobra.model.fabric.RsVpcInstPol(fabricExplicitGEp, tnVpcInstPolName=u'leafs_1-2')211212213214# commit infraInfra215c = cobra.mit.request.ConfigRequest()216#c.addMo(polUni)217c.addMo(infraInfra)218md.commit(c)219220# commit snv phys domain221c = cobra.mit.request.ConfigRequest()222c.addMo(snv_phys_domain)223md.commit(c)224225# commit heroes phys domain226c = cobra.mit.request.ConfigRequest()227c.addMo(heroes_phys_domain)228md.commit(c)229230# commit snv l3ext domain231c = cobra.mit.request.ConfigRequest()232c.addMo(snv_l3ext_domain)233md.commit(c)234235# commit heroes l3ext domain236c = cobra.mit.request.ConfigRequest()237c.addMo(heroes_l3ext_domain)238md.commit(c)239240# commit the vpc configs241c = cobra.mit.request.ConfigRequest()242c.addMo(fabricProtPol)243c.addMo(vpcInstPol)244md.commit(c)245246247248# build the contracts and filters in common249common_tenant = cobra.model.fv.Tenant(polUni, ownerKey=u'', name=u'common', descr=u'', ownerTag=u'')250251vzFilter = cobra.model.vz.Filter(common_tenant, ownerKey=u'', name=u'power_up', descr=u'', ownerTag=u'')252vzEntry = cobra.model.vz.Entry(vzFilter, tcpRules=u'', arpOpc=u'unspecified', applyToFrag=u'no', dToPort=u'9002', descr=u'', prot=u'tcp', icmpv4T=u'unspecified', sFromPort=u'unspecified', stateful=u'no', icmpv6T=u'unspecified', sToPort=u'unspecified', etherT=u'ip', dFromPort=u'9001', name=u'tcp_9001-9002')253vzFilter2 = cobra.model.vz.Filter(common_tenant, ownerKey=u'', name=u'http', descr=u'', ownerTag=u'')254vzEntry2 = cobra.model.vz.Entry(vzFilter2, tcpRules=u'', arpOpc=u'unspecified', applyToFrag=u'no', dToPort=u'http', descr=u'', prot=u'tcp', icmpv4T=u'unspecified', sFromPort=u'unspecified', stateful=u'no', icmpv6T=u'unspecified', sToPort=u'unspecified', etherT=u'ip', dFromPort=u'http', name=u'tcp-80')255vzFilter3 = cobra.model.vz.Filter(common_tenant, ownerKey=u'', name=u'https', descr=u'', ownerTag=u'')256vzEntry3 = cobra.model.vz.Entry(vzFilter3, tcpRules=u'', arpOpc=u'unspecified', applyToFrag=u'no', dToPort=u'https', descr=u'', prot=u'tcp', icmpv4T=u'unspecified', sFromPort=u'unspecified', stateful=u'no', icmpv6T=u'unspecified', sToPort=u'unspecified', etherT=u'ip', dFromPort=u'https', name=u'tcp-443')257vzFilter4 = cobra.model.vz.Filter(common_tenant, ownerKey=u'', name=u'sql_browser', descr=u'', ownerTag=u'')258vzEntry4 = cobra.model.vz.Entry(vzFilter4, tcpRules=u'', arpOpc=u'unspecified', applyToFrag=u'no', dToPort=u'1434', descr=u'', prot=u'udp', icmpv4T=u'unspecified', sFromPort=u'unspecified', stateful=u'no', icmpv6T=u'unspecified', sToPort=u'unspecified', etherT=u'ip', dFromPort=u'1434', name=u'udp-1434')259vzFilter5 = cobra.model.vz.Filter(common_tenant, ownerKey=u'', name=u'sql_server', descr=u'', ownerTag=u'')260vzEntry5 = cobra.model.vz.Entry(vzFilter5, tcpRules=u'', arpOpc=u'unspecified', applyToFrag=u'no', dToPort=u'1433', descr=u'', prot=u'tcp', icmpv4T=u'unspecified', sFromPort=u'unspecified', stateful=u'no', icmpv6T=u'unspecified', sToPort=u'unspecified', etherT=u'ip', dFromPort=u'1433', name=u'tcp-1433')261262vzBrCP = cobra.model.vz.BrCP(common_tenant, ownerKey=u'', name=u'web', prio=u'unspecified', ownerTag=u'', descr=u'')263vzSubj = cobra.model.vz.Subj(vzBrCP, revFltPorts=u'yes', name=u'http', prio=u'unspecified', descr=u'', consMatchT=u'AtleastOne', provMatchT=u'AtleastOne')264vzRsSubjFiltAtt = cobra.model.vz.RsSubjFiltAtt(vzSubj, tnVzFilterName=u'http')265vzSubj2 = cobra.model.vz.Subj(vzBrCP, revFltPorts=u'yes', name=u'https', prio=u'unspecified', descr=u'', consMatchT=u'AtleastOne', provMatchT=u'AtleastOne')266vzRsSubjFiltAtt2 = cobra.model.vz.RsSubjFiltAtt(vzSubj2, tnVzFilterName=u'https')267vzBrCP2 = cobra.model.vz.BrCP(common_tenant, ownerKey=u'', name=u'power_up', prio=u'unspecified', ownerTag=u'', descr=u'')268vzSubj3 = cobra.model.vz.Subj(vzBrCP2, revFltPorts=u'yes', name=u'app_ports', prio=u'unspecified', descr=u'', consMatchT=u'AtleastOne', provMatchT=u'AtleastOne')269vzRsSubjFiltAtt3 = cobra.model.vz.RsSubjFiltAtt(vzSubj3, tnVzFilterName=u'power_up')270vzBrCP3 = cobra.model.vz.BrCP(common_tenant, ownerKey=u'', name=u'sql', prio=u'unspecified', ownerTag=u'', descr=u'', scope=u'application-profile')271vzSubj4 = cobra.model.vz.Subj(vzBrCP3, revFltPorts=u'yes', name=u'sql-server', prio=u'unspecified', descr=u'', consMatchT=u'AtleastOne', provMatchT=u'AtleastOne')272vzRsSubjFiltAtt4 = cobra.model.vz.RsSubjFiltAtt(vzSubj4, tnVzFilterName=u'sql_server')273vzSubj5 = cobra.model.vz.Subj(vzBrCP3, revFltPorts=u'yes', name=u'sql-browser', prio=u'unspecified', descr=u'', consMatchT=u'AtleastOne', provMatchT=u'AtleastOne')274vzRsSubjFiltAtt5 = cobra.model.vz.RsSubjFiltAtt(vzSubj5, tnVzFilterName=u'sql_browser')275276# build the heroes tenant277fvTenant = cobra.model.fv.Tenant(polUni, ownerKey=u'', name=u'Heroes', descr=u'', ownerTag=u'')278fvCtx = cobra.model.fv.Ctx(fvTenant, ownerKey=u'', name=u'Heroes_Only', descr=u'', knwMcastAct=u'permit', pcEnfDir=u'ingress', ownerTag=u'', pcEnfPref=u'enforced')279fvRsCtxToExtRouteTagPol = cobra.model.fv.RsCtxToExtRouteTagPol(fvCtx, tnL3extRouteTagPolName=u'')280fvRsBgpCtxPol = cobra.model.fv.RsBgpCtxPol(fvCtx, tnBgpCtxPolName=u'')281vzAny = cobra.model.vz.Any(fvCtx, matchT=u'AtleastOne', name=u'', descr=u'')282fvRsOspfCtxPol = cobra.model.fv.RsOspfCtxPol(fvCtx, tnOspfCtxPolName=u'')283fvRsCtxToEpRet = cobra.model.fv.RsCtxToEpRet(fvCtx, tnFvEpRetPolName=u'')284fvBD = cobra.model.fv.BD(fvTenant, ownerKey=u'', vmac=u'not-applicable', name=u'Hero_Land', descr=u'', unkMacUcastAct=u'proxy', arpFlood=u'no', limitIpLearnToSubnets=u'yes', llAddr=u'::', mac=u'00:22:BD:F8:19:FF', epMoveDetectMode=u'', unicastRoute=u'yes', ownerTag=u'', multiDstPktAct=u'bd-flood', unkMcastAct=u'flood')285fvRsBDToNdP = cobra.model.fv.RsBDToNdP(fvBD, tnNdIfPolName=u'')286fvRsCtx = cobra.model.fv.RsCtx(fvBD, tnFvCtxName=u'Heroes_Only')287fvRsIgmpsn = cobra.model.fv.RsIgmpsn(fvBD, tnIgmpSnoopPolName=u'')288fvSubnet = cobra.model.fv.Subnet(fvBD, name=u'', descr=u'', ctrl=u'', ip=u'10.1.120.1/22', preferred=u'no', virtual=u'no', scope=u'public')289fvSubnet2 = cobra.model.fv.Subnet(fvBD, name=u'', descr=u'', ctrl=u'', ip=u'192.168.120.1/22', preferred=u'no', virtual=u'no')290fvRsBdToEpRet = cobra.model.fv.RsBdToEpRet(fvBD, resolveAct=u'resolve', tnFvEpRetPolName=u'')291fvRsTenantMonPol = cobra.model.fv.RsTenantMonPol(fvTenant, tnMonEPGPolName=u'')292fvAp = cobra.model.fv.Ap(fvTenant, ownerKey=u'', prio=u'unspecified', name=u'Save_The_Planet', descr=u'', ownerTag=u'')293fvAEPg1 = cobra.model.fv.AEPg(fvAp, isAttrBasedEPg=u'no', matchT=u'AtleastOne', prio=u'unspecified', name=u'web', descr=u'')294fvRsProv1 = cobra.model.fv.RsProv(fvAEPg1, tnVzBrCPName=u'web', matchT=u'AtleastOne', prio=u'unspecified')295fvRsCons1 = cobra.model.fv.RsCons(fvAEPg1, tnVzBrCPName=u'sql', prio=u'unspecified')296fvRsPathAtt1 = cobra.model.fv.RsPathAtt(fvAEPg1, tDn=u'topology/pod-1/protpaths-101-102/pathep-[Heroes_FI-2B]', instrImedcy=u'lazy', encap=u'vlan-200', descr=u'', mode=u'regular')297fvRsPathAtt4 = cobra.model.fv.RsPathAtt(fvAEPg1, tDn=u'topology/pod-1/protpaths-101-102/pathep-[Heroes_FI-2A]', instrImedcy=u'lazy', encap=u'vlan-200', descr=u'', mode=u'regular')298fvRsDomAtt1 = cobra.model.fv.RsDomAtt(fvAEPg1, instrImedcy=u'lazy', resImedcy=u'lazy', encap=u'unknown', tDn=u'uni/phys-Heroes_phys')299fvAEPg2 = cobra.model.fv.AEPg(fvAp, isAttrBasedEPg=u'no', matchT=u'AtleastOne', prio=u'unspecified', name=u'app', descr=u'')300fvRsProv2 = cobra.model.fv.RsProv(fvAEPg2, tnVzBrCPName=u'power_up', matchT=u'AtleastOne', prio=u'unspecified')301fvRsCons2 = cobra.model.fv.RsCons(fvAEPg2, tnVzBrCPName=u'sql', prio=u'unspecified')302fvRsPathAtt5 = cobra.model.fv.RsPathAtt(fvAEPg2, tDn=u'topology/pod-1/protpaths-101-102/pathep-[Heroes_FI-2B]', instrImedcy=u'lazy', encap=u'vlan-201', descr=u'', mode=u'regular')303fvRsPathAtt6 = cobra.model.fv.RsPathAtt(fvAEPg2, tDn=u'topology/pod-1/protpaths-101-102/pathep-[Heroes_FI-2A]', instrImedcy=u'lazy', encap=u'vlan-201', descr=u'', mode=u'regular')304fvRsDomAtt2 = cobra.model.fv.RsDomAtt(fvAEPg2, instrImedcy=u'lazy', resImedcy=u'lazy', encap=u'unknown', tDn=u'uni/phys-Heroes_phys')305fvAEPg3 = cobra.model.fv.AEPg(fvAp, isAttrBasedEPg=u'no', matchT=u'AtleastOne', prio=u'unspecified', name=u'db', descr=u'')306fvRsProv3 = cobra.model.fv.RsProv(fvAEPg3, tnVzBrCPName=u'sql', matchT=u'AtleastOne', prio=u'unspecified')307fvRsPathAtt5 = cobra.model.fv.RsPathAtt(fvAEPg3, tDn=u'topology/pod-1/protpaths-101-102/pathep-[Heroes_FI-2B]', instrImedcy=u'lazy', encap=u'vlan-202', descr=u'', mode=u'regular')308fvRsPathAtt6 = cobra.model.fv.RsPathAtt(fvAEPg3, tDn=u'topology/pod-1/protpaths-101-102/pathep-[Heroes_FI-2A]', instrImedcy=u'lazy', encap=u'vlan-202', descr=u'', mode=u'regular')309fvRsDomAtt3 = cobra.model.fv.RsDomAtt(fvAEPg3, instrImedcy=u'lazy', resImedcy=u'lazy', encap=u'unknown', tDn=u'uni/phys-Heroes_phys')310fvRsCustQosPol1 = cobra.model.fv.RsCustQosPol(fvAEPg1, tnQosCustomPolName=u'')311fvRsBd1 = cobra.model.fv.RsBd(fvAEPg1, tnFvBDName=u'Hero_Land')312fvRsCustQosPol2 = cobra.model.fv.RsCustQosPol(fvAEPg2, tnQosCustomPolName=u'')313fvRsBd2 = cobra.model.fv.RsBd(fvAEPg2, tnFvBDName=u'Hero_Land')314fvRsCustQosPol3 = cobra.model.fv.RsCustQosPol(fvAEPg3, tnQosCustomPolName=u'')315fvRsBd3 = cobra.model.fv.RsBd(fvAEPg3, tnFvBDName=u'Hero_Land')316l3extOut = cobra.model.l3ext.Out(fvTenant, ownerKey=u'', name=u'Heroes_external_corporate', descr=u'', targetDscp=u'unspecified', enforceRtctrl=u'export', ownerTag=u'')317l3extRsEctx = cobra.model.l3ext.RsEctx(l3extOut, tnFvCtxName=u'Heroes_Only')318l3extLNodeP = cobra.model.l3ext.LNodeP(l3extOut, ownerKey=u'', name=u'borderleaf_2_corporate', descr=u'', targetDscp=u'unspecified', tag=u'yellow-green', ownerTag=u'')319l3extRsNodeL3OutAtt = cobra.model.l3ext.RsNodeL3OutAtt(l3extLNodeP, rtrIdLoopBack=u'yes', rtrId=u'10.1.100.2', tDn=u'topology/pod-1/node-102')320ipRouteP = cobra.model.ip.RouteP(l3extRsNodeL3OutAtt, aggregate=u'no', ip=u'0.0.0.0/0', pref=u'1', name=u'', descr=u'')321ipNexthopP = cobra.model.ip.NexthopP(ipRouteP, nhAddr=u'10.1.2.2', pref=u'unspecified', name=u'', descr=u'')322l3extLIfP = cobra.model.l3ext.LIfP(l3extLNodeP, ownerKey=u'', tag=u'yellow-green', name=u'borderleaf_2', descr=u'', ownerTag=u'')323l3extRsNdIfPol = cobra.model.l3ext.RsNdIfPol(l3extLIfP, tnNdIfPolName=u'')324l3extRsPathL3OutAtt = cobra.model.l3ext.RsPathL3OutAtt(l3extLIfP, addr=u'10.1.200.3/31', descr=u'', encapScope=u'local', targetDscp=u'unspecified', llAddr=u'::', mac=u'00:22:BD:F8:19:FF', mode=u'regular', encap=u'unknown', ifInstT=u'l3-port', mtu=u'inherit', tDn=u'topology/pod-1/paths-102/pathep-[eth1/47]')325l3extLNodeP2 = cobra.model.l3ext.LNodeP(l3extOut, ownerKey=u'', name=u'borderleaf_1_corporate', descr=u'', targetDscp=u'unspecified', tag=u'yellow-green', ownerTag=u'')326l3extRsNodeL3OutAtt2 = cobra.model.l3ext.RsNodeL3OutAtt(l3extLNodeP2, rtrIdLoopBack=u'yes', rtrId=u'10.1.100.1', tDn=u'topology/pod-1/node-101')327ipRouteP2 = cobra.model.ip.RouteP(l3extRsNodeL3OutAtt2, aggregate=u'no', ip=u'0.0.0.0/0', pref=u'1', name=u'', descr=u'')328ipNexthopP2 = cobra.model.ip.NexthopP(ipRouteP2, nhAddr=u'10.1.200.0', pref=u'unspecified', name=u'', descr=u'')329l3extLIfP2 = cobra.model.l3ext.LIfP(l3extLNodeP2, ownerKey=u'', tag=u'yellow-green', name=u'borderleaf_1', descr=u'', ownerTag=u'')330l3extRsNdIfPol2 = cobra.model.l3ext.RsNdIfPol(l3extLIfP2, tnNdIfPolName=u'')331l3extRsPathL3OutAtt2 = cobra.model.l3ext.RsPathL3OutAtt(l3extLIfP2, addr=u'10.1.200.1/31', descr=u'', encapScope=u'local', targetDscp=u'unspecified', llAddr=u'::', mac=u'00:22:BD:F8:19:FF', mode=u'regular', encap=u'unknown', ifInstT=u'l3-port', mtu=u'inherit', tDn=u'topology/pod-1/paths-101/pathep-[eth1/47]')332l3extRsL3DomAtt = cobra.model.l3ext.RsL3DomAtt(l3extOut, tDn=u'uni/l3dom-Heroes_external_corporate')333l3extInstP = cobra.model.l3ext.InstP(l3extOut, prio=u'unspecified', matchT=u'AtleastOne', name=u'Heroes_default', descr=u'', targetDscp=u'unspecified')334fvRsCons4 = cobra.model.fv.RsCons(l3extInstP, tnVzBrCPName=u'power_up', prio=u'unspecified')335fvRsCons5 = cobra.model.fv.RsCons(l3extInstP, tnVzBrCPName=u'web', prio=u'unspecified')336l3extSubnet = cobra.model.l3ext.Subnet(l3extInstP, aggregate=u'', ip=u'0.0.0.0/0', name=u'', descr=u'')337fvRsCustQosPol5 = cobra.model.fv.RsCustQosPol(l3extInstP, tnQosCustomPolName=u'')338339340# commit the generated code to APIC341c = cobra.mit.request.ConfigRequest()342c.addMo(common_tenant)343md.commit(c)344345c = cobra.mit.request.ConfigRequest()346c.addMo(fvTenant)
...
params.py
Source:params.py
1"""2Licensed to the Apache Software Foundation (ASF) under one3or more contributor license agreements. See the NOTICE file4distributed with this work for additional information5regarding copyright ownership. The ASF licenses this file6to you under the Apache License, Version 2.0 (the7"License"); you may not use this file except in compliance8with the License. You may obtain a copy of the License at9 http://www.apache.org/licenses/LICENSE-2.010Unless required by applicable law or agreed to in writing, software11distributed under the License is distributed on an "AS IS" BASIS,12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13See the License for the specific language governing permissions and14limitations under the License.15"""16from ambari_commons.constants import AMBARI_SUDO_BINARY17from resource_management.libraries.functions.default import default18from resource_management.libraries.functions.format import format19from resource_management.libraries.functions.is_empty import is_empty20from resource_management.libraries.script.script import Script21import os22import status_params23def get_port_from_url(address):24 if not is_empty(address):25 return address.split(':')[-1]26 else:27 return address28# config object that holds the configurations declared in the -site.xml file29config = Script.get_config()30tmp_dir = Script.get_tmp_dir()31stack_version = default("/commandParams/version", None)32sudo = AMBARI_SUDO_BINARY33security_enabled = status_params.security_enabled34infra_solr_conf = "/etc/ambari-infra-solr/conf"35infra_solr_port = status_params.infra_solr_port36infra_solr_piddir = status_params.infra_solr_piddir37infra_solr_pidfile = status_params.infra_solr_pidfile38user_group = config['configurations']['cluster-env']['user_group']39fetch_nonlocal_groups = config['configurations']['cluster-env']["fetch_nonlocal_groups"]40# shared configs41java64_home = config['hostLevelParams']['java_home']42zookeeper_hosts_list = config['clusterHostInfo']['zookeeper_hosts']43zookeeper_hosts_list.sort()44# get comma separated list of zookeeper hosts from clusterHostInfo45zookeeper_hosts = ",".join(zookeeper_hosts_list)46#####################################47# Solr configs48#####################################49# Only supporting SolrCloud mode - so hardcode those options50solr_cloudmode = 'true'51solr_dir = '/usr/lib/ambari-infra-solr'52solr_client_dir = '/usr/lib/ambari-infra-solr-client'53solr_bindir = solr_dir + '/bin'54cloud_scripts = solr_dir + '/server/scripts/cloud-scripts'55if "infra-solr-env" in config['configurations']:56 infra_solr_hosts = config['clusterHostInfo']['infra_solr_hosts']57 infra_solr_znode = config['configurations']['infra-solr-env']['infra_solr_znode']58 infra_solr_min_mem = format(config['configurations']['infra-solr-env']['infra_solr_minmem'])59 infra_solr_max_mem = format(config['configurations']['infra-solr-env']['infra_solr_maxmem'])60 infra_solr_instance_count = len(config['clusterHostInfo']['infra_solr_hosts'])61 infra_solr_datadir = format(config['configurations']['infra-solr-env']['infra_solr_datadir'])62 infra_solr_data_resources_dir = os.path.join(infra_solr_datadir, 'resources')63 infra_solr_jmx_port = config['configurations']['infra-solr-env']['infra_solr_jmx_port']64 infra_solr_ssl_enabled = default('configurations/infra-solr-env/infra_solr_ssl_enabled', False)65 infra_solr_keystore_location = config['configurations']['infra-solr-env']['infra_solr_keystore_location']66 infra_solr_keystore_password = config['configurations']['infra-solr-env']['infra_solr_keystore_password']67 infra_solr_keystore_type = config['configurations']['infra-solr-env']['infra_solr_keystore_type']68 infra_solr_truststore_location = config['configurations']['infra-solr-env']['infra_solr_truststore_location']69 infra_solr_truststore_password = config['configurations']['infra-solr-env']['infra_solr_truststore_password']70 infra_solr_truststore_type = config['configurations']['infra-solr-env']['infra_solr_truststore_type']71 infra_solr_user = config['configurations']['infra-solr-env']['infra_solr_user']72 infra_solr_log_dir = config['configurations']['infra-solr-env']['infra_solr_log_dir']73 infra_solr_log = format("{infra_solr_log_dir}/solr-install.log")74 solr_env_content = config['configurations']['infra-solr-env']['content']75zookeeper_port = default('/configurations/zoo.cfg/clientPort', None)76# get comma separated list of zookeeper hosts from clusterHostInfo77index = 078zookeeper_quorum = ""79for host in config['clusterHostInfo']['zookeeper_hosts']:80 zookeeper_quorum += host + ":" + str(zookeeper_port)81 index += 182 if index < len(config['clusterHostInfo']['zookeeper_hosts']):83 zookeeper_quorum += ","84if security_enabled:85 kinit_path_local = status_params.kinit_path_local86 _hostname_lowercase = config['hostname'].lower()87 infra_solr_jaas_file = infra_solr_conf + '/infra_solr_jaas.conf'88 infra_solr_kerberos_keytab = config['configurations']['infra-solr-env']['infra_solr_kerberos_keytab']89 infra_solr_kerberos_principal = config['configurations']['infra-solr-env']['infra_solr_kerberos_principal'].replace('_HOST',_hostname_lowercase)90 infra_solr_web_kerberos_keytab = config['configurations']['infra-solr-env']['infra_solr_web_kerberos_keytab']91 infra_solr_web_kerberos_principal = config['configurations']['infra-solr-env']['infra_solr_web_kerberos_principal'].replace('_HOST',_hostname_lowercase)92 infra_solr_kerberos_name_rules = config['configurations']['infra-solr-env']['infra_solr_kerberos_name_rules']93solr_xml_content = default('configurations/infra-solr-xml/content', None)94solr_log4j_content = default('configurations/infra-solr-log4j/content', None)95solr_client_custom_log4j = "infra-solr-client-log4j" in config['configurations']96smokeuser = config['configurations']['cluster-env']['smokeuser']97smoke_user_keytab = config['configurations']['cluster-env']['smokeuser_keytab']...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!