Esempio n. 1
0
def force_sync(deviceIds):

    payload = deviceIds
    url = 'network-device/sync?forceSync=true'

    response = put_and_wait(url, payload)
    print(response)
def delete_file(file, deviceIds):

    payload = deviceIds
    url = 'network-device/sync?forceSync=true'

    response = put_and_wait(url, payload)
    print(response)
Esempio n. 3
0
def update_device(ip, role):

    #print(json.dumps(payload,indent=2))
    #return
    print('Changing role of device IP {} to {}: '.format(ip, role), end='')
    response = get_url(
        "dna/intent/api/v1/network-device/ip-address/{}".format(ip))
    try:
        deviceid = response['response']['id']
        oldrole = response['response']['role']
    except ValueError as e:
        print(e)
        return
    if oldrole == role:
        print("Oldrole {} same as newrole {}, skipping".format(oldrole, role))
        return
    payload = {"id": deviceid, "role": role, "roleSource": "MANUAL"}
    logging.debug(json.dumps(payload))
    response = put_and_wait("dna/intent/api/v1/network-device/brief",
                            data=payload)
    task = response['id']
    time.sleep(2)
    tree = get_url("dna/intent/api/v1/task/{}/tree".format(task))
    logging.debug(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()]))
            print(t['progress'])
Esempio n. 4
0
def forcesync(devicelist):
    deviceList = [d.rstrip() for d in devicelist]
    logging.debug("SYNC:{}".format(str(deviceList)))
    payload = list(map(device2id, deviceList))
    logging.debug(payload)
    response = put_and_wait('dna/intent/api/v1/network-device/sync', payload)
    print(response)
Esempio n. 5
0
def assign_tag_OLD(tag_id, device):
    # this will remove all existing tags..
    deviceId = device2id(device)
    payload = {
        "memberType":"networkdevice",
        "memberToTags":{deviceId:[tag_id]}}
    print(payload)
    response = put_and_wait('dna/intent/api/v1/tag/member', payload)
    print(response['progress'])
def update_device(oldip, newip):

    payload = {
        "type":
        "NETWORK_DEVICE",
        "computeDevice":
        False,
        "snmpVersion":
        "NODATACHANGE",
        "snmpROCommunity":
        "NO!$DATA!$",
        "snmpRWCommunity":
        "NO!$DATA!$",
        "snmpRetry":
        "-1",
        "snmpTimeout":
        "-1",
        "cliTransport":
        "NO!$DATA!$",
        "userName":
        "******",
        "password":
        "******",
        "enablePassword":
        "******",
        "netconfPort":
        "-1",
        "ipAddress": [oldip],
        "updateMgmtIPaddressList": [{
            "newMgmtIpAddress": newip,
            "existMgmtIpAddress": oldip
        }]
    }
    #print(json.dumps(payload,indent=2))
    #return

    response = put_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))
    logging.debug(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()]))
            print(t['progress'])
Esempio n. 7
0
def update_devices(deviceList, snmpauth, snmppriv, snmpuser, username,
                   password, enable):
    #print (snmp,username, password)
    deviceList = [d.rstrip() for d in deviceList]
    payload = {
        "ipAddress": deviceList,
        "type": "NETWORK_DEVICE",
        "computeDevice": "false",
        "snmpVersion": "v3",
        "snmpMode": "AUTHPRIV",
        "snmpAuthProtocol": "SHA",
        "snmpAuthPassphrase": snmpauth,
        "snmpPrivProtocol": "AES128",
        "snmpPrivPassphrase": snmppriv,
        "snmpUserName": snmpuser,
        "snmpRetry": "3",
        "snmpTimeout": "5",
        "cliTransport": "ssh",
        "userName": username,
        "password": password,
        "enablePassword": enable
    }
    #print(json.dumps(payload,indent=2))
    #return

    response = put_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))
    logging.debug(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()]))
            print(t['progress'])
Esempio n. 8
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']))