def deploy(): headers = {'x-auth-token': token, 'content-type': 'application/json'} # create a url for this API call url = create_url('/v1/template-programmer/template/deploy') body = { "templateId": "967c8430-96cd-4445-8fc4-72543b624d9f", "targetInfo": [{ "id": "10.10.22.70", "type": "MANAGED_DEVICE_IP", "params": { "description": "changed by DNAC", "interface": "TenGigabitEthernet1/0/24" } }] } # make the REST request response = requests.post(url, headers=headers, data=json.dumps(body), verify=False) response.raise_for_status() deploymentId = response.json()['deploymentId'] # now look for the status url = create_url( '/v1/template-programmer/template/deploy/status/{}'.format( deploymentId)) response = requests.get(url, headers=headers, verify=False) response.raise_for_status() print(json.dumps(response.json(), indent=2))
def deploy(): headers = {'x-auth-token': token, 'content-type': 'application/json'} # create a url for this API call url = create_url('/v1/template-programmer/template/deploy') body = { "templateId": "d1b4c4b4-31b9-4419-b7ed-a5ce2bf7eb83", "targetInfo": [ { "id": "10.10.22.70", "type": "MANAGED_DEVICE_IP", "params": {"description": "changed by DNA Center", "interface": "TenGigabitEthernet1/1/1"} } ] } # make the REST request response = requests.post(url, headers=headers, data=json.dumps(body), verify=False) response.raise_for_status() deploymentId = response.json()['deploymentId'] # clean response to grab DeploymentID deploymentId = deploymentId.split(':') deploymentId = deploymentId[-1] print("deploymentID -->", deploymentId) # now look for the status url = create_url('/v1/template-programmer/template/deploy/status/{}'.format(deploymentId)) response = requests.get(url, headers=headers, verify=False) response.raise_for_status() print(json.dumps(response.json(), indent=2))
def deploy(): headers = {'x-auth-token': token, 'content-type': 'application/json'} # create a url for this API call url = create_url('/v1/template-programmer/template/deploy') body = { "templateId": "af2c57dc-769f-47af-9f36-96a12746286a", "targetInfo": [{ "id": "10.10.20.82", "type": "MANAGED_DEVICE_IP", "params": { "description": "changed by DNA Center {}".format(time.time()), "interface": "TenGigabitEthernet1/1/1" } }] } # make the REST request response = requests.post(url, headers=headers, data=json.dumps(body), verify=False) response.raise_for_status() deploymentId = response.json()['deploymentId'] # clean response to grab DeploymentID deploymentId = deploymentId.split(':') deploymentId = deploymentId[-1] deploymentId = deploymentId.replace(" ", "") print("deploymentID -->", deploymentId) time.sleep(5) # now look for the status url = create_url( '/v1/template-programmer/template/deploy/status/{}'.format( deploymentId)) response = requests.get(url, headers=headers, verify=False) response.raise_for_status() print(json.dumps(response.json(), indent=2))
def download_results(token, results_fileId): ''' obtains the result file by it's UUID from DNAC :param token: obtained earlier via authentication to dnac :param results_fileId: the fileId of the results file :return: the contents of the file as json. NOTE: This is really text, but gets converted to json by requests ''' headers = {'x-auth-token': token} url = create_url('/v1/file/{}'.format(results_fileId)) response = requests.get(url, headers=headers, verify=False) return response.json()
def get_deviceIdList(token, *deviceIps): ''' converts a list of device IP adddreses into device UUID :param token: obtained earlier via authentication to dnac :param deviceIps: a list of deviceIps :return: a list of UUID ''' headers = {'x-auth-token': token} deviceIdList = [] for deviceIp in deviceIps: url = create_url("/v1/network-device/ip-address/{}".format(deviceIp)) response = requests.get(url, headers=headers, verify=False) response.raise_for_status() deviceIdList.append(response.json()['response']['id']) return deviceIdList
def execute_commands(token, deviceIdList, commandList): ''' runs the list of commands on the list of devices :param token: obtained earlier via authentication to dnac :param deviceIdList: a list of device UUID to run the commands on :param commandList: a list of IOS commands (exec-only, no config) to run on the deviceList :return: a fileId containing the output of the commands ''' url = create_url('/v1/network-device-poller/cli/read-request') headers = {'x-auth-token': token, 'content-type': 'application/json'} payload = { "name": "my commands", "commands": commandList, "deviceUuids": deviceIdList } task_result = post_and_wait(token, url, payload) print("task complete") # the value of "progress" is a string, but needs to be interprettd as json. return ast.literal_eval(task_result['progress'])['fileId']
#!/usr/bin/env python from __future__ import print_function from dnac_utils import dnac_token, create_url import requests import json # Entry point for program. if __name__ == '__main__': # get an authentication token. The username and password is obtained from an environment file token = dnac_token() headers = {'x-auth-token' : token} # create a url for this API call url = create_url('/v1/template-programmer/project') # make the REST request response = requests.get(url, headers=headers, verify=False) response.raise_for_status() # now print the templates for project in response.json(): if project['templates'] <> []: print('Project:{}'.format(project['name'])) for template in project['templates']: print ('\t{}:{}'.format(template['name'], template['id']))
#!/usr/bin/env python from __future__ import print_function from dnac_utils import dnac_token, create_url import requests import json # Entry point for program. if __name__ == '__main__': # get an authentication token. The username and password is obtained from an environment file token = dnac_token() headers = {'x-auth-token' : token} # create a url for this API call url = create_url('/v1/network-device-poller/cli/legit-reads') # make the REST request response = requests.get(url, headers=headers, verify=False) response.raise_for_status() # now show the commands supported. Note there are no "configuration" commands print("Exec commands supported:") print(json.dumps(response.json()['response'], indent=4))
import requests import time import json # Entry point for program. if __name__ == '__main__': # get an authentication token. The username and password is obtained from an environment file token = dnac_token() headers = {'x-auth-token': token} # Input this value with a valid template id for your environment templateid = input( "Please enter a valid template ID, which can be obtained with the get_templates.py script: " ) # create a url for this API call url = create_url( '/v1/template-programmer/template/version/{}'.format(templateid)) # make the REST request response = requests.get(url, headers=headers, verify=False) response.raise_for_status() template = response.json()[0] #build a dict with version as key print('Project:{} Template:{}'.format(template['projectName'], template['name'])) versions = {} for version in template['versionsInfo']: if 'version' in version: versions[version['version']] = '{} {} {}'.format( version['id'],