def conf_vxlan_mcast( hostip, userid, passwd, anycast, mgrp_list, list_lo1, role='spine'): retval = True target_cmd = "conf t ; ip pim rp-address %s group-list %s/8 ; ip pim ssm range 232.0.0.0/8 ; " %(anycast, mgrp_list) if role == 'leaf': target_cmd += "fabric forwarding anycast-gateway-mac 0000.2222.3333 ; " if role == 'spine': target_cmd += "ip pim rp-candidate loopback1 group-list %s/8 ; " %(mgrp_list) for lo1 in list_lo1: target_cmd += "ip pim anycast-rp %s %s ; " %(anycast, util.get_ip_from_cidr(lo1)) target_cmd = util.remove_last_semicolon(target_cmd) print target_cmd resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json() outputs = resp['ins_api']['outputs']['output'] #print outputs for out in outputs: if not 'Success' in out['msg']: retval = False print 'do conf vxlan/nve1 on %s is %s' %(hostip, retval) return retval
conf_model = util.load_model_config( sys.argv[1]) #switch-model.yaml for h in conf_model.keys(): if conf_model[h].has_key('role') : if conf_model[h]['role'] == 'spine': host_role['spine'].append( h) else: host_role['leaf'].append( h) print host_role for host in host_role['spine']: conf_basic(host, os.environ['NEXUS_USER'], os.environ['NEXUS_PASSWD'], 'spine') conf_features( host, os.environ['NEXUS_USER'], os.environ['NEXUS_PASSWD'], FEATURES) conf_interface( host, os.environ['NEXUS_USER'], os.environ['NEXUS_PASSWD'], conf_model[host], conf_model['common']['ospf_as']) conf_vxlan_mcast( host, os.environ['NEXUS_USER'], os.environ['NEXUS_PASSWD'], util.get_ip_from_cidr(conf_model[host]['lo1']), '225.0.0.0', util.get_spine_lo0_list( conf_model), 'spine') conf_bgp(host, os.environ['NEXUS_USER'], os.environ['NEXUS_PASSWD'], conf_model['common']['bgp_as'], util.get_ip_from_cidr(conf_model[host]['lo0']), util.get_bgp_peers( host, conf_model), 'spine') for host in host_role['leaf']: conf_basic(host, os.environ['NEXUS_USER'], os.environ['NEXUS_PASSWD'], 'leaf') conf_features( host, os.environ['NEXUS_USER'], os.environ['NEXUS_PASSWD'], FEATURES) conf_interface( host, os.environ['NEXUS_USER'], os.environ['NEXUS_PASSWD'], conf_model[host], conf_model['common']['ospf_as']) conf_vxlan_mcast( host, os.environ['NEXUS_USER'], os.environ['NEXUS_PASSWD'], util.get_spine_lo1(conf_model), '225.0.0.0', util.get_spine_lo0_list( conf_model), 'leaf') conf_nve1(host, os.environ['NEXUS_USER'], os.environ['NEXUS_PASSWD']) conf_bgp(host, os.environ['NEXUS_USER'], os.environ['NEXUS_PASSWD'], conf_model['common']['bgp_as'], util.get_ip_from_cidr(conf_model[host]['lo0']),