예제 #1
0
def add_devices(deviceList, snmp, username, password):
    #print (snmp,username, password)
    deviceList = [d.rstrip() for d in deviceList]
    payload = {
        "ipAddress": deviceList,
        "type": "NETWORK_DEVICE",
        "computeDevice": "false",
        "snmpVersion": "v2",
        "snmpROCommunity": snmp,
        "snmpRWCommunity": "",
        "snmpRetry": "3",
        "snmpTimeout": "5",
        "cliTransport": "ssh",
        "userName": username,
        "password": password,
        "enablePassword": ""
    }
    response = post_and_wait("dna/intent/api/v1/network-device", data=payload)
    task = response['id']
    time.sleep(5)
    tree = get_url("dna/intent/api/v1/task/{}/tree".format(task))
    #print(json.dumps(tree,indent=2))

    for t in tree['response']:
        if 'failureReason' in t:
            print(t['failureReason'])
        else:
            progress = json.loads(t['progress'])
            print(" ".join(
                ['{}:{}'.format(k, progress[k]) for k in progress.keys()]))
예제 #2
0
def activate(imageUuid, *deviceIdList):

    url = 'image/activation/device'
    for deviceId in deviceIdList:
        body = []
        body.append({
        "activateLowerImageVersion": True,
        "deviceUpgradeMode": "currentlyExists",
        "deviceUuid": deviceId,
        "distributeIfNeeded": False,
        "imageUuidList": [
            imageUuid
        ],
        "smuImageUuidList": [

        ]
        })

        print("=== Upgrading ",deviceId)
        print(body)
        response = post_and_wait(url, body)

        print(response)
        taskId = response['id']
        detail = get_url('task?parentId={0}'.format(taskId))
        print (json.dumps(detail, indent=2))
    else:
        print("=== Upgrade finished! ===")
예제 #3
0
def assign_tag(tag, device):
    deviceId = device2id(device)
    payload = {
        "resourceId": deviceId,
        "resourceType": "network-device",
        "tag": tag
    }
    response = post_and_wait('tag/association', payload)
    print(response, '\n')
예제 #4
0
def assign_tag(tag_id, devicelist):
    # should refactor this to provide a list of devices
    deviceIds = list(map(device2id,devicelist))

    # this is a list of deviceIds
    payload = {
	"networkdevice" :deviceIds}

    print(payload)
    response = post_and_wait('dna/intent/api/v1/tag/{}/member'.format(tag_id), payload)
    print(response['progress'])
예제 #5
0
def distribute(imageUuid, *deviceIdList):

    body = []
    for deviceId in deviceIdList:
        body.append({"deviceUuid": deviceId, "imageUuid": imageUuid})

    url = 'image/distribution'
    response = post_and_wait(url, body)
    print(response)
    taskId = response['id']
    detail = get_url('image/task?taskUuid={0}'.format(taskId))
    print(json.dumps(detail, indent=2))
def create_path_trace(args):
    data = {
        "sourceIP" : args.srcip,
        "destIP" : args.dstip,
        "periodicRefresh" : False
    }
    if  args.srcport is not None:
        data["sourcePort"] =  args.srcport
    if  args.dstport is not None:
        data["destPort"] =  args.dstport

    if args.stats:
        data["inclusions"]  = ["INTERFACE-STATS","DEVICE-STATS"]
    print(data)
    result = post_and_wait("flow-analysis", data)
    return result['progress']
예제 #7
0
def update_template(template, template_name, new_body):
    '''
    takes an existing template and updates it with  a new body.  Does a save and commit
    :param template:
    :param template_name:
    :param new_body:
    :return:
    '''
    # need to be careful here with params and how they are handled....
    print("Updating template:{} to {}".format(template_name, new_body))
    print(json.dumps(template))
    template['templateContent'] = new_body

    # need to change the template ID to the parent
    template_id = template['parentTemplateId']
    template['id'] = template_id

    # need to find a way to get the variables from the new template... addition/subtraction
    response = put_and_wait("template-programmer/template", template)
    print("Saving:{}".format(response['progress']))

    body = {"comments": "", "templateId": template_id}
    response = post_and_wait("template-programmer/template/version", body)
    print("Commit:{}".format(response['progress']))
예제 #8
0
def create_tag(tag):
    print ("Creating tag: {0}".format(tag))
    payload = { "name" : tag }
    response = post_and_wait('dna/intent/api/v1/tag', payload)
    print (response['progress'])
예제 #9
0
def create_tag(tag):
    print("Creating tag: {0}".format(tag))
    payload = {"tag": tag}
    response = post_and_wait('tag', payload)
    print(response)