def initCluster(nodeAddr, quorumNodes, clustervip): postUrl = 'http://' + nodeAddr + ':9001/api/v1/cluster' # cluster json parameters jdata = json.dumps({ "kind": "Cluster", "api-version": "v1", "meta": { "name": "testCluster", }, "spec": { "auto-admit-dscs": True, "quorum-nodes": quorumNodes, "virtual-ip": clustervip } }) # Post the data. try upto 3 times since the server may not be ready.. for i in range(1, 4): try: response = http.httpPost(postUrl, jdata) except httplib.BadStatusLine: response = 'Error' print "Init cluster with " + jdata print "cluster response is: " + response if response != "Error": break time.sleep(3)
def createNet(tenantName, networkName, pktTag, encap="vxlan", subnet="", gateway=""): print "Creating network {0}:{1}".format(tenantName, networkName) # Create network postUrl = 'http://localhost:9999/api/networks/' + tenantName + ':' + networkName + '/' jdata = json.dumps({ "tenantName": tenantName, "networkName": networkName, "pktTag": pktTag, "isPublic": False, "isPrivate": True, "encap": encap, "subnet": subnet, "gateway": gateway, }) response = http.httpPost(postUrl, jdata) print "Network Create response is: " + response # Check for error if response == "Error": errorExit("Network create failure")
def createPolicy(tenantName, policyName): print "Creating policy {0}:{1}".format(tenantName, policyName) postUrl = 'http://localhost:9999/api/policys/' + tenantName + ':' + policyName + '/' jdata = json.dumps({"tenantName": tenantName, "policyName": policyName}) # Post the data response = http.httpPost(postUrl, jdata) print "Create policy response is: " + response if response == "Error": errorExit("Policy create failure")
def addRule(tenantName, policyName, ruleId, priority=1, direction='in', endpointGroup="", network="", ipAddress="", protocol="", port=0, action="allow"): print "Adding rule {2} to policy {0}:{1}".format(tenantName, policyName, ruleId) if direction == 'in': jdata = json.dumps({ "tenantName": tenantName, "policyName": policyName, "ruleId": ruleId, "priority": priority, "direction": direction, "fromEndpointGroup": endpointGroup, "fromNetwork": network, "fromIpAddress": ipAddress, "protocol": protocol, "port": port, "action": action }) else: jdata = json.dumps({ "tenantName": tenantName, "policyName": policyName, "ruleId": ruleId, "priority": priority, "direction": direction, "toEndpointGroup": endpointGroup, "toNetwork": network, "toIpAddress": ipAddress, "protocol": protocol, "port": port, "action": action }) #Post the data postUrl = 'http://localhost:9999/api/rules/' + tenantName + ':' + policyName + ':' + ruleId + '/' print "Adding rule " + jdata response = http.httpPost(postUrl, jdata) print "Rule add response is: " + response if response == "Error": errorExit("Rule add failure")
def setFabricMode(mode): postUrl = 'http://netmaster:9999/api/globals/global/' jdata = json.dumps({ "name": "global", "network-infra-type": mode, "vlans": "1-4094", "vxlans": "1-10000", }) response = http.httpPost(postUrl, jdata) # Check for error if response == "Error": print response errorExit("setFabricMode failed")
def createPolicy(tenantName, policyName): print "Creating policy {0}:{1}".format(tenantName, policyName) postUrl = 'http://localhost:9999/api/policys/' + tenantName + ':' + policyName + '/' jdata = json.dumps({ "tenantName": tenantName, "policyName": policyName }) # Post the data response = http.httpPost(postUrl, jdata) print "Create policy response is: " + response if response == "Error": errorExit("Policy create failure")
def createEpg(tenantName, networkName, groupName, policies=[]): print "Creating endpoint group {0}:{1}:{2}".format(tenantName, networkName, groupName) jdata = json.dumps({ "tenantName": tenantName, "groupName": groupName, "networkName": networkName, "policies": policies, }) # Create epg postUrl = 'http://localhost:9999/api/endpointGroups/' + tenantName + ':' + networkName + ':' + groupName + '/' response = http.httpPost(postUrl, jdata) print "Epg Create response is: " + response # Check for error if response == "Error": errorExit("Epg create failure")
def createTenant(tenantName): print "Creating tenant {0}".format(tenantName) # Create tenant postUrl = 'http://localhost:9999/api/tenants/' + tenantName + '/' jdata = json.dumps({ "key": tenantName, "tenantName": tenantName, "subnetPool": "10.1.1.1/8", "subnetLen": 24, "vlans": "100-1100", "vxlans": "1000-1100", }) response = http.httpPost(postUrl, jdata) print "Tenant Create response is: " + response # Check for error if response == "Error": errorExit("Tenant create failure")
def initCluster(nodeAddr): postUrl = 'http://' + nodeAddr + ':9001/api/v1/cluster' # cluster json parameters jdata = json.dumps({ "kind": "Cluster", "api-version": "v1", "meta": { "name": "testCluster" }, "spec": { "auto-admit-dscs": True, "quorum-nodes": quorumNames, "virtual-ip": clustervip, "ntp-servers": ["1.pool.ntp.org", "2.pool.ntp.org"] } }) # Post the data response = http.httpPost(postUrl, jdata) print "Init cluster with " + jdata print "cluster response is: " + response
def createNetwork(nodeAddr, name, subnet, gw, vlanId): postUrl = 'http://' + nodeAddr + ':' + APIGwRESTPort + '/configs/network/v1/tenant/default/networks' print "Posting to URL: " + postUrl # network json parameters jdata = json.dumps({ "kind": "Network", "meta": { "tenant": "default", "name": name }, "spec": { "ipv4-subnet": subnet, "ipv4-gateway": gw, "vlan-id": vlanId } }) # Post the data response = http.httpPost(postUrl, jdata) print "Network create response is: " + response