diff --git a/Postman/Cisco-AlwaysOn-SD-WAN-Env.postman_environment.json b/Postman/Cisco-AlwaysOn-SD-WAN-Env.postman_environment.json new file mode 100644 index 0000000..2b06045 --- /dev/null +++ b/Postman/Cisco-AlwaysOn-SD-WAN-Env.postman_environment.json @@ -0,0 +1,34 @@ +{ + "id": "1bd29ba3-2f5b-45fc-8ae7-b5d352e44ccb", + "name": "Cisco-AlwaysOn-SD-WAN-Environment", + "values": [ + { + "key": "vmanage", + "value": "sandbox-sdwan-1.cisco.com", + "enabled": true + }, + { + "key": "j_username", + "value": "devnetuser", + "enabled": true + }, + { + "key": "j_password", + "value": "RG!_Yw919_83", + "enabled": true + }, + { + "key": "port", + "value": "443", + "enabled": true + }, + { + "key": "X-XSRF-TOKEN", + "value": "", + "enabled": true + } + ], + "_postman_variable_scope": "environment", + "_postman_exported_at": "2020-05-07T01:44:29.596Z", + "_postman_exported_using": "Postman/7.23.0" +} \ No newline at end of file diff --git a/Postman/Cisco-AlwaysOn-SD-WAN.postman_collection.json b/Postman/Cisco-AlwaysOn-SD-WAN.postman_collection.json new file mode 100644 index 0000000..9c0c274 --- /dev/null +++ b/Postman/Cisco-AlwaysOn-SD-WAN.postman_collection.json @@ -0,0 +1,315 @@ +{ + "info": { + "_postman_id": "6b9300d8-c5fb-48d7-85fd-57d4353cd903", + "name": "Cisco-SD-WAN-AlwaysOn", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "1.Authentication", + "item": [ + { + "name": "Authentication", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "j_username", + "value": "{{j_username}}", + "type": "text" + }, + { + "key": "j_password", + "value": "{{j_password}}", + "type": "text" + } + ] + }, + "url": { + "raw": "https://{{vmanage}}:{{port}}/j_security_check", + "protocol": "https", + "host": [ + "{{vmanage}}" + ], + "port": "{{port}}", + "path": [ + "j_security_check" + ] + } + }, + "response": [] + }, + { + "name": "Token", + "event": [ + { + "listen": "test", + "script": { + "id": "92af74e2-ccda-4a82-912a-7554abf16ea9", + "exec": [ + "var XSRFToken = pm.response.text()", + "pm.environment.set(\"X-XSRF-TOKEN\", XSRFToken);", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://{{vmanage}}:{{port}}/dataservice/client/token", + "protocol": "https", + "host": [ + "{{vmanage}}" + ], + "port": "{{port}}", + "path": [ + "dataservice", + "client", + "token" + ] + } + }, + "response": [] + } + ], + "protocolProfileBehavior": {} + }, + { + "name": "2. SD-WAN Fabric Devices", + "item": [ + { + "name": "Fabric Devices", + "request": { + "method": "GET", + "header": [ + { + "key": "X-XSRF-TOKEN", + "value": "{{X-XSRF-TOKEN}}", + "type": "text" + } + ], + "url": { + "raw": "https://{{vmanage}}:{{port}}/dataservice/device", + "protocol": "https", + "host": [ + "{{vmanage}}" + ], + "port": "{{port}}", + "path": [ + "dataservice", + "device" + ] + } + }, + "response": [] + }, + { + "name": "Devices Status", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://{{vmanage}}:{{port}}/dataservice/device/monitor", + "protocol": "https", + "host": [ + "{{vmanage}}" + ], + "port": "{{port}}", + "path": [ + "dataservice", + "device", + "monitor" + ] + } + }, + "response": [] + }, + { + "name": "Device Counters", + "request": { + "method": "GET", + "header": [ + { + "key": "X-XSRF-TOKEN", + "value": "{{X-XSRF-TOKEN}}", + "type": "text" + } + ], + "url": { + "raw": "https://{{vmanage}}:{{port}}/dataservice/device/counters", + "protocol": "https", + "host": [ + "{{vmanage}}" + ], + "port": "{{port}}", + "path": [ + "dataservice", + "device", + "counters" + ] + } + }, + "response": [] + }, + { + "name": "Interface statistics", + "request": { + "method": "GET", + "header": [ + { + "key": "X-XSRF-TOKEN", + "value": "{{X-XSRF-TOKEN}}", + "type": "text" + } + ], + "url": { + "raw": "https://{{vmanage}}:{{port}}/dataservice/statistics/interface", + "protocol": "https", + "host": [ + "{{vmanage}}" + ], + "port": "{{port}}", + "path": [ + "dataservice", + "statistics", + "interface" + ] + } + }, + "response": [] + } + ], + "protocolProfileBehavior": {} + }, + { + "name": "3. SD-WAN Device Template", + "item": [ + { + "name": "Template Feature", + "request": { + "method": "GET", + "header": [ + { + "key": "X-XSRF-TOKEN", + "value": "{{X-XSRF-TOKEN}}", + "type": "text" + } + ], + "url": { + "raw": "https://{{vmanage}}:{{port}}/dataservice/template/feature", + "protocol": "https", + "host": [ + "{{vmanage}}" + ], + "port": "{{port}}", + "path": [ + "dataservice", + "template", + "feature" + ] + } + }, + "response": [] + }, + { + "name": "Template Feature Type", + "request": { + "method": "GET", + "header": [ + { + "key": "X-XSRF-TOKEN", + "value": "{{X-XSRF-TOKEN}}", + "type": "text" + } + ], + "url": { + "raw": "https://{{vmanage}}:{{port}}/dataservice/template/feature/types", + "protocol": "https", + "host": [ + "{{vmanage}}" + ], + "port": "{{port}}", + "path": [ + "dataservice", + "template", + "feature", + "types" + ] + } + }, + "response": [] + } + ], + "protocolProfileBehavior": {} + }, + { + "name": "4. SD-WAN Device Policy", + "item": [ + { + "name": "vEdge Template Policy", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://{{vmanage}}:{{port}}/dataservice/template/policy/vedge/devices", + "protocol": "https", + "host": [ + "{{vmanage}}" + ], + "port": "{{port}}", + "path": [ + "dataservice", + "template", + "policy", + "vedge", + "devices" + ] + } + }, + "response": [] + }, + { + "name": "Policy List", + "request": { + "method": "GET", + "header": [ + { + "key": "X-XSRF-TOKEN", + "value": "{{X-XSRF-TOKEN}}", + "type": "text" + } + ], + "url": { + "raw": "https://{{vmanage}}:{{port}}/dataservice/template/policy/list", + "protocol": "https", + "host": [ + "{{vmanage}}" + ], + "port": "{{port}}", + "path": [ + "dataservice", + "template", + "policy", + "list" + ] + } + }, + "response": [] + } + ], + "protocolProfileBehavior": {} + } + ], + "protocolProfileBehavior": {} +} \ No newline at end of file diff --git a/Postman/Cisco-SD-WAN-Environment.postman_environment.json b/Postman/Cisco-SD-WAN-Environment.postman_environment.json deleted file mode 100644 index d837398..0000000 --- a/Postman/Cisco-SD-WAN-Environment.postman_environment.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "id": "bff3364e-598f-4890-8e64-c8e93afb2345", - "name": "Cisco-SD-WAN-Environment", - "values": [ - { - "key": "vmanage", - "value": "sandboxsdwan.cisco.com", - "description": "", - "enabled": true - }, - { - "key": "j_username", - "value": "devnetuser", - "description": "", - "enabled": true - }, - { - "key": "j_password", - "value": "Cisco123!", - "description": "", - "enabled": true - }, - { - "key": "port", - "value": "8443", - "type": "text", - "description": "", - "enabled": true - } - ], - "_postman_variable_scope": "environment", - "_postman_exported_at": "2018-10-07T04:09:04.277Z", - "_postman_exported_using": "Postman/6.3.0" -} \ No newline at end of file diff --git a/Postman/Cisco-SD-WAN.postman_collection.json b/Postman/Cisco-SD-WAN.postman_collection.json deleted file mode 100644 index d8d68e8..0000000 --- a/Postman/Cisco-SD-WAN.postman_collection.json +++ /dev/null @@ -1,145 +0,0 @@ -{ - "info": { - "_postman_id": "f3596695-561c-4159-a998-5eca1f85e0cb", - "name": "Cisco-SD-WAN", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" - }, - "item": [ - { - "name": "1.Authentication", - "item": [ - { - "name": "Authentication", - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/x-www-form-urlencoded" - } - ], - "body": { - "mode": "urlencoded", - "urlencoded": [ - { - "key": "j_username", - "value": "{{j_username}}", - "type": "text" - }, - { - "key": "j_password", - "value": "{{j_password}}", - "type": "text" - } - ] - }, - "url": { - "raw": "https://{{vmanage}}:{{port}}/j_security_check", - "protocol": "https", - "host": [ - "{{vmanage}}" - ], - "port": "{{port}}", - "path": [ - "j_security_check" - ] - } - }, - "response": [] - } - ] - }, - { - "name": "2. SD-WAN Fabric Devices", - "item": [ - { - "name": "Fabric Devices", - "request": { - "method": "GET", - "header": [], - "body": {}, - "url": { - "raw": "https://{{vmanage}}:{{port}}/dataservice/device", - "protocol": "https", - "host": [ - "{{vmanage}}" - ], - "port": "{{port}}", - "path": [ - "dataservice", - "device" - ] - } - }, - "response": [] - }, - { - "name": "Devices Status", - "request": { - "method": "GET", - "header": [], - "body": {}, - "url": { - "raw": "https://{{vmanage}}:{{port}}/dataservice/device/monitor", - "protocol": "https", - "host": [ - "{{vmanage}}" - ], - "port": "{{port}}", - "path": [ - "dataservice", - "device", - "monitor" - ] - } - }, - "response": [] - }, - { - "name": "Device Counters", - "request": { - "method": "GET", - "header": [], - "body": {}, - "url": { - "raw": "https://{{vmanage}}:{{port}}/dataservice/device/counters", - "protocol": "https", - "host": [ - "{{vmanage}}" - ], - "port": "{{port}}", - "path": [ - "dataservice", - "device", - "counters" - ] - } - }, - "response": [] - }, - { - "name": "Interface statistics", - "request": { - "method": "GET", - "header": [], - "body": {}, - "url": { - "raw": "https://{{vmanage}}:{{port}}/dataservice/statistics/interface", - "protocol": "https", - "host": [ - "{{vmanage}}" - ], - "port": "{{port}}", - "path": [ - "dataservice", - "statistics", - "interface" - ] - } - }, - "response": [] - } - ] - } - ] -} \ No newline at end of file diff --git a/get_request.py b/get_request.py index 3bc7f6d..d8cd5ba 100644 --- a/get_request.py +++ b/get_request.py @@ -2,7 +2,7 @@ def get_request(vmanage_ip, mount_point): """GET request""" - url = "https://%s:8443/dataservice/%s"%(vmanage_ip, mount_point) + url = "https://%s/dataservice/%s"%(vmanage_ip, mount_point) response = requests.request("GET", url, verify=False) data = response.content diff --git a/login.py b/login.py index 2df4cdd..411b495 100644 --- a/login.py +++ b/login.py @@ -3,7 +3,7 @@ def login(vmanage_ip, username, password): """Login to vmanage""" - base_url_str = 'https://%s:8443/'%vmanage_ip + base_url_str = 'https://%s/'%vmanage_ip login_action = '/j_security_check' @@ -19,4 +19,22 @@ def login(vmanage_ip, username, password): if b'' in login_response.content: print ("Login Failed") - sys.exit(0) \ No newline at end of file + sys.exit(0) + + token_url = 'https://%s/'%vmanage_ip + + token_action = '/dataservice/client/token' + + token = sess.get(url=token_url) + # print(token) + headers = {'X-XSRF-TOKEN':token} + + if token.status_code != 200: + if b'' in token_url.content: + print(token_url) + print ("Login Token Failed") + exit(0) + else: + print("Token Success") + + token = token.text diff --git a/post_request.py b/post_request.py index 1322791..6f8a249 100644 --- a/post_request.py +++ b/post_request.py @@ -2,7 +2,7 @@ def post_request(vmanage_ip, mount_point, payload, headers={'Content-Type': 'application/json'}): """POST request""" - url = "https://%s:8443/dataservice/%s"%(vmanage_ip, mount_point) + url = "https://%s/dataservice/%s"%(vmanage_ip, mount_point) payload = json.dumps(payload) response = requests.request("POST", url, data=payload, headers=headers, verify=False) diff --git a/rest_api_lib.py b/rest_api_lib.py index f234bd1..aa1671a 100644 --- a/rest_api_lib.py +++ b/rest_api_lib.py @@ -10,7 +10,7 @@ def __init__(self, vmanage_ip, username, password): def login(self, vmanage_ip, username, password): """Login to vmanage""" - base_url_str = 'https://%s:8443/'%vmanage_ip + base_url_str = 'https://%s/'%vmanage_ip login_action = '/j_security_check' @@ -32,9 +32,29 @@ def login(self, vmanage_ip, username, password): self.session[vmanage_ip] = sess + + + token_url = ''https://%s/'%vmanage_ip' + + token_action = '/dataservice/client/token' + + token = sess.get(url=token_url) + # print(token) + headers = {'X-XSRF-TOKEN':token} + + if token.status_code != 200: + if b'' in token_url.content: + print(token_url) + print ("Login Token Failed") + exit(0) + else: + print("Token Success") + + token = token.text + def get_request(self, mount_point): """GET request""" - url = "https://%s:8443/dataservice/%s"%(self.vmanage_ip, mount_point) + url = "https://%s/dataservice/%s"%(self.vmanage_ip, mount_point) #print url response = self.session[self.vmanage_ip].get(url, verify=False) data = response.content @@ -42,7 +62,7 @@ def get_request(self, mount_point): def post_request(self, mount_point, payload, headers={'Content-Type': 'application/json'}): """POST request""" - url = "https://%s:8443/dataservice/%s"%(self.vmanage_ip, mount_point) + url = "https://%s/dataservice/%s"%(self.vmanage_ip, mount_point) payload = json.dumps(payload) print (payload) diff --git a/sdwan.py b/sdwan.py index 6354bd3..f78ce97 100755 --- a/sdwan.py +++ b/sdwan.py @@ -26,7 +26,7 @@ if SDWAN_IP is None or SDWAN_USERNAME is None or SDWAN_PASSWORD is None: print("CISCO SDWAN details must be set via environment variables before running.") - print(" export SDWAN_IP=10.10.30.190") + print(" export SDWAN_IP=10.10.20.90") print(" export SDWAN_USERNAME=admin") print(" export SDWAN_PASSWORD=admin") print("") @@ -40,7 +40,7 @@ def __init__(self, vmanage_ip, username, password): def login(self, vmanage_ip, username, password): """Login to vmanage""" - base_url_str = 'https://%s:8443/'%vmanage_ip + base_url_str = 'https://%s/'%vmanage_ip login_action = '/j_security_check' @@ -62,9 +62,27 @@ def login(self, vmanage_ip, username, password): self.session[vmanage_ip] = sess + token_url = 'https://%s/'%vmanage_ip + + token_action = '/dataservice/client/token' + + token = sess.get(url=token_url) + # print(token) + headers = {'X-XSRF-TOKEN':token} + + if token.status_code != 200: + if b'' in token_url.content: + print(token_url) + print ("Login Token Failed") + exit(0) + else: + print("Token Success") + + token = token.text + def get_request(self, mount_point): """GET request""" - url = "https://%s:8443/dataservice/%s"%(self.vmanage_ip, mount_point) + url = "https://%s/dataservice/%s"%(self.vmanage_ip, mount_point) #print url response = self.session[self.vmanage_ip].get(url, verify=False) data = response.content @@ -72,7 +90,7 @@ def get_request(self, mount_point): def post_request(self, mount_point, payload, headers={'Content-Type': 'application/json'}): """POST request""" - url = "https://%s:8443/dataservice/%s"%(self.vmanage_ip, mount_point) + url = "https://%s/dataservice/%s"%(self.vmanage_ip, mount_point) payload = json.dumps(payload) print (payload) @@ -174,11 +192,12 @@ def attached_devices(template): @click.option("--target", help="Hostname of target network device.") @click.option("--hostname", help="Hostname you wish the target has") @click.option("--sysip", help="System IP you wish the target has") -@click.option("--loopip", help="Loopback interface IP address") +# @click.option("--loopip", help="Loopback interface IP address") @click.option("--geip", help="Gigabit0/0 interface IP address") @click.option("--siteid", help="Site ID") #@click.argument("parameters", nargs=-1) -def attach(template, target, hostname, sysip, loopip, geip, siteid): +# def attach(template, target, hostname, sysip, loopip, geip, siteid): +def attach(template, target, hostname, sysip, geip, siteid): """Attach a template with Cisco SDWAN. Provide all template parameters and their values as arguments. @@ -186,7 +205,7 @@ def attach(template, target, hostname, sysip, loopip, geip, siteid): Example command: ./sdwan.py attach --template TemplateID --target TargetID --hostname devnet01.cisco.com - --sysip 1.1.1.1 --loopip 2.2.2.2/24 --geip 3.3.3.3/24 --siteid 999 + --sysip 1.1.1.1 --geip 3.3.3.3/24 --siteid 999 """ click.secho("Attempting to attach template.") @@ -200,7 +219,6 @@ def attach(template, target, hostname, sysip, loopip, geip, siteid): "csv-deviceId":str(target), "csv-deviceIP":str(sysip), "csv-host-name":str(hostname), - "/1/loopback1/interface/ip/address":str(loopip), "/0/ge0/0/interface/ip/address":str(geip), "//system/host-name":str(hostname), "//system/system-ip":str(sysip),