def netid_to_serialnum(net_id):
    query = 'http://localhost:8080/web/provisioning/getNetElementById.do?netElementId=%s' % mac
    client = RestClient(query, 'GET')
    if client.connect():
        dev_info = json.loads(client.getResponse())
        return dev_info['serialNumber']
    return None
def rest_getBundleApplied(imageNames):
    for imageBundle in imageNames:
        client = RestClient(
            cvpserver + rest_getAssignedBundle + imageNames[imageBundle] +
            '&queryparam=' + undefinedContainerName, 'GET')
        if client.connect():
            # Parses configlet data into JSON.
            imageBundles = json.loads(client.getResponse())
            if imageBundles['total'] == 1:
                return imageBundle
Esempio n. 3
0
def check_configlet_exists(configlet_name):
    client = RestClient(
        cvpserver + rest_get_configlet_by_name + configlet_name, 'GET')
    if client.connect():
        output = json.loads(client.getResponse())
        if 'errorCode' in output:
            if output['errorCode'] == '132801':
                print 'Configlet ' + configlet_name + ' not found. Adding.'
                return False
        else:
            print 'Configlet ' + configlet_name + ' found.'
            configlet_key = output['key']
            return configlet_key
def get_undefined_image():
    imageNames = {}
    client = RestClient(cvpserver + rest_getImageBundles, 'GET')
    if client.connect():
        # Parses configlet data into JSON.
        imageBundles = json.loads(client.getResponse())['data']
        for image in imageBundles:
            imageNames.update({image['key']: image['name']})
        undefinedVersion = rest_getBundleApplied(imageNames)
        for image in imageBundles:
            if image['key'] == undefinedVersion:
                imageList = image['imageIds']
        for image in imageList:
            if image.lower().endswith('.swi'):
                finalImage = image
    return finalImage
Esempio n. 5
0
def add_configlet(configlet_data, configlet_name):
    data = {"config": configlet_data, "name": configlet_name}
    client = RestClient(cvpserver + rest_add_configlet, 'POST')
    client.setRawData(json.dumps(data))
    if client.connect():
        output = json.loads(client.getResponse())
        print 'Added configlet ' + configlet_name
def query(postfix, http_type='GET', data=None):
    response = False
    query_string = 'https://localhost/cvpservice/' + postfix
    client = RestClient(query_string, http_type)
    if http_type == 'POST':
        client.setRawData(json.dumps(data))
    if client.connect():
        response = json.loads(client.getResponse())
    return response
def add_configlet(configlet_data, configlet_name):
    data = {"config": configlet_data, "name": configlet_name}
    client = RestClient(cvpserver + rest_add_configlet, 'POST')
    client.setRawData(json.dumps(data))
    if client.connect():
        output = json.loads(client.getResponse())
        if 'errorCode' in output:
            if output['errorCode'] == '132518':
                if overwrite_configlets:
                    print 'error 132518'
            if not overwrite_configlets:
                print 'Failure - configlet overwriting disabled.'
        print 'Configlet Added.'
def update_configlet(configlet_data, configlet_name, configlet_key):
    data = {
        "config": configlet_data,
        "key": configlet_key,
        "name": configlet_name,
        "waitForTaskIds": False,
        "reconciled": False
    }
    if not overwrite_configlets:
        print 'Failure - configlet overwriting disabled.'
        return
    client = RestClient(cvpserver + rest_update_configlet, 'POST')
    client.setRawData(json.dumps(data))
    if client.connect():
        output = json.loads(client.getResponse())
        print output
Esempio n. 9
0
def update_configlet(configlet_data, configlet_name, configlet_key):
    data = {
        "config": configlet_data,
        "key": configlet_key,
        "name": configlet_name,
        "waitForTaskIds": False,
        "reconciled": False
    }
    if overwrite_configlets:
        client = RestClient(cvpserver + rest_update_configlet, 'POST')
        client.setRawData(json.dumps(data))
        if client.connect():
            output = json.loads(client.getResponse())
            print 'Updated configlet ' + configlet_name
    else:
        print 'Configlet ' + configlet_name + ' already exists. Skipping due to overwrite_configlets being disabled.'
        raise 'Error - Configlet overwrite disabled'
def get_net_element(system_mac):
  url='http://localhost:8080/cvpservice/provisioning/getNetElementById.do?netElementId={0}'.format(system_mac)
  client = RestClient(url, 'GET')
  client.connect()
  node_info = json.loads(client.getResponse())
  return node_info
Esempio n. 11
0
rest_get_configlet_by_name = '/cvpservice/configlet/getConfigletByName.do?name='

### YAML Locationrest_get_configlet_by_name = '/cvpservice/configlet/getConfigletByName.do?name='

# YAML can either be stored in CVP directly or off-box on an http url.
yaml_location = 'cvp'  # 'http' | 'cvp'

## http storage. Define the full requests url.
if yaml_location == 'http':
    yaml_http = requests.get(
        'http://gitlab.example.com/root/YamlBuilder/raw/master/example.yaml')
    yamlfile = yaml_http.text
## CVP Storage - define yaml_configlet as the name of the configlet.
if yaml_location == 'cvp':
    yaml_configlet = 'example.yaml'
    client = RestClient(
        cvpserver + rest_get_configlet_by_name + yaml_configlet, 'GET')
    if client.connect():
        # Parses configlet data into JSON.
        yamlfile = json.loads(client.getResponse())['config']

### Device Roles
evpn_roles = ['Spine', 'Compute Leaf', 'Service Leaf', 'Storage Leaf']

bgp_only = ['Border Leaf']

### Device Templates

## MLAG Template
mlagconfig = Template("""\
vlan {{ vlanid }}
   name MLAG