leaf_ip = '{0}.{1}.{2}.{3}'.format(octect[0], octect[1], octect[2], fourth)
      neighbors[device][intf]['leaf_ip'] = leaf_ip
    
  routed_info = list()
  for device in neighbors.keys():
    for intf in neighbors[device].keys():
      if 'spine_mac' != intf:
        leaf_if = neighbors[device][intf]['leaf_if']
        leaf_ip = neighbors[device][intf]['leaf_ip']
        spine_ip = neighbors[device][intf]['spine_ip']
        routed_info.append((leaf_if, device, intf.replace('/','_'), leaf_ip, spine_ip))

  return routed_info

### Start of Script
mgmt_ip = Form.getFieldById('mgmt_ip').getValue()
bgp_as = Form.getFieldById('bgp_as').getValue()
loop_1 = Form.getFieldById('loop_1').getValue()
routed_ints = ['Ethernet2', 'Ethernet3']
snmp_info = Form.getFieldById('snmp_info').getValue()

# Build Managemennt Configuration
mgmt_lookup = socket.gethostbyaddr(mgmt_ip)
hostname = mgmt_lookup[0].split('.')[0]
mgmt_config = '''
hostname {0}

vrf definition mgmt
ip routing vrf mgmt
ip route vrf mgmt 0.0.0.0/0 192.168.1.1
Example #2
0
from jsonrpclib import Server
from cvplibrary import Form
from cvplibrary import CVPGlobalVariables, GlobalVariableNames
import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context
#
# Get all data from Form
spine1_port_num = Form.getFieldById('spine1_port_num').getValue()
spine2_port_num = Form.getFieldById('spine2_port_num').getValue()
spine3_port_num = Form.getFieldById('spine3_port_num').getValue()

ip = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_IP)
myCVPuser = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_USERNAME)
myCVPpasswd = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_PASSWORD)

#
# Username/password/protocol for eAPI access to switches
#

EAPI_USERNAME = myCVPuser
EAPI_PASSWORD = myCVPpasswd
EAPI_METHOD = 'https'
Example #3
0
from cvplibrary import Form
from jsonrpclib import Server
from cvplibrary import CVPGlobalVariables, GlobalVariableNames

#fetching the management ip of the current device
device_ip = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_IP)
#fetching the username for the current device
username = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_USERNAME)
#fetching the password for the current device
password = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_PASSWORD)

#fetching the variables from the form
intvlan_var = Form.getFieldById("field_1").getValue()
vrf_var = Form.getFieldById("field_2").getValue()
ipaddrv = Form.getFieldById("field_3").getValue()

print "vrf definition " + vrf_var

print "vlan " + intvlan_var
print "interface vlan " + intvlan_var
print "mtu 9000"
print "no autostate"
print "vrf forwarding " + vrf_var
print "ip address virtual " + ipaddrv + "/24"

print "interface Vxlan1"
print "vxlan vlan " + intvlan_var + " vni " + intvlan_var

#connecting to the switch
switch = Server('https://%s:%s@%s/command-api' %
                (username, password, device_ip))
Example #4
0
# Getting the Ingest Key
# Note: Changing the ingest key requires restarting CVP for the builder to take it.
ingest_key = os.environ.get('AERIS_INGEST_KEY', '')

# Smash tables to exclude
smash_exclude_list = ['ale',
                      'flexCounter',
                      'hardware',
                      'kni',
                      'pulse',
                      'strata']
smash_exclude = ','.join(smash_exclude_list)

# Paths to exclude from the ingest stream
ingest_exclude_list = ['/Sysdb/cell/1/agent',
                       '/Sysdb/cell/2/agent']
ingest_exclude = ','.join(ingest_exclude_list)

# Get Management VRF (allow blank form for default vrf)
ingest_vrf = Form.getFieldById( 'vrf' ).getValue()
if not ingest_vrf:
   ingest_vrf = 'default'

# Print the config
print 'daemon TerminAttr'
print '  exec /usr/bin/TerminAttr -ingestgrpcurl=%s -taillogs ' \
      '-ingestauth=key,%s -smashexcludes=%s -ingestexclude=%s' \
      % (ingest_grpc, ingest_key, smash_exclude, ingest_exclude) \
      + ((' -ingestvrf=%s' % ingest_vrf) if (ingest_vrf != 'default') else '')
print '  no shutdown'
Example #5
0
import cvp
from cvplibrary import Form
from cvplibrary import CVPGlobalVariables, GlobalVariableNames
import re

# Login to CVP API
username = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_USERNAME)
password = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_PASSWORD)
server = cvp.Cvp("localhost")
server.authenticate(username, password)

# Retrieve Form Data
vlan = Form.getFieldById("vlan").getValue()
name = Form.getFieldById("name").getValue()
vrf = Form.getFieldById("vrf").getValue()
gateway = Form.getFieldById("gateway").getValue()
mask = Form.getFieldById("mask").getValue()
jumbo = Form.getFieldById("jumbo").getValue()

# Generate Vlan Config Data
new_vlan_config = "vlan %s\n   name %s\n" % (vlan, name)

# If L3 Required, generate SVI Config
if gateway != None:
    new_svi_config = "interface Vlan%s\n" % (vlan)
    new_svi_config += "   description %s\n" % (name)
    if jumbo == "Yes":
        new_svi_config += "   mtu 9164\n"
    new_svi_config += "   vrf %s\n" % (vrf)
    new_svi_config += "   ip address virtual %s/%s\n" % (gateway, mask)
else:
Example #6
0
import cvp
from cvplibrary import Form
from cvplibrary import CVPGlobalVariables, GlobalVariableNames
from jinja2 import Template
import re

# Login to CVP API
username = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_USERNAME)
password = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_PASSWORD)
server = cvp.Cvp("localhost")
server.authenticate(username, password)

# Retrieve Form Data
vlan = Form.getFieldById("vlan").getValue()
name = Form.getFieldById("name").getValue()
tenant = Form.getFieldById("tenant").getValue()
gateway = Form.getFieldById("gateway").getValue()
mask = Form.getFieldById("mask").getValue()

# Pull in relavent Jinja2 Tempaltes via CVP API
# Templates are stored as normal static configlets
try:
    vlan_template_configlet = server.cvpService.getConfigletByName(
        "L3LS-v Vlan Template")
    vlan_template = Template(vlan_template_configlet["config"])
except cvp.cvpServices.CvpError as e:
    if str(e).startswith("132801"):
        print "L3LS-v Vlan Template configlet does not exist.  Exiting..."

# Render Vlan Template for Config Application
# Create dictionary based on Field inputs for feeding purposes
Example #7
0
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#import pyexcel to read excel sheets
import pyexcel
from cvplibrary import Form
from cvplibrary import CVPGlobalVariables, GlobalVariableNames

#build dictionary of excel sheet
my_dict = pyexcel.get_dict(file_name="/opt/CVPfiles/cutsheet.xlsx")

#define variables from keys of dictionary
systemId = my_dict['systemId']
ip_address = my_dict['ipAddress']
hostname = my_dict['hostname']
netmask = my_dict['Netmask']
gateway = my_dict['defaultGateway']
print

#get user input from form
user_input = Form.getFieldById('systemId').getValue()

device_index = systemId.index(user_input)

print 'hostname %s' % (hostname[device_index])
print "!"
print "interface management 1"
print " ip address %s/%s" % (ip_address[device_index], netmask[device_index])
print "!"
print "ip route 0.0.0.0/0 %s" % gateway[device_index]
            if acl_to_delete:
                configlet_content = buildACLConfiglet(configlet_details_dict)
                if preview_or_apply == "Apply":
                    #Delete ACL Configlet
                    server.updateConfiglet(configlet["key"], configlet["name"], configlet_content)
                    print "Deleted ACL {} from {} configlet".format(acl_name , "{}-ACLs".format(switch["hostname"]))
                print "-"*30
                print configlet_content
                print "-"*30
            else:
                print "ACL {} doesn't exist in {} configlet".format(acl_name , "{}-ACLs".format(switch["hostname"]))
        else:
            print "Configlet does not exist for {} ".format(switch["hostname"])


acl_option = Form.getFieldById('acl_option').value

show_details_acl_name = Form.getFieldById('show_details_acl_name').value

modify_acl_name = Form.getFieldById('modify_acl_name').value

#acl_name will be name of acl we are working with
if show_details_acl_name is not None:
  acl_name = show_details_acl_name
elif modify_acl_name is not None:
  acl_name = modify_acl_name
else:
  acl_name = None

modify_action = Form.getFieldById('modify_action').value
import cvp
from cvplibrary import Form
from cvplibrary import CVPGlobalVariables, GlobalVariableNames
import re
import sys

# Login to CVP API
username = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_USERNAME)
password = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_PASSWORD)
server = cvp.Cvp("localhost")
server.authenticate(username, password)

# Retrieve Form Data
int_type = Form.getFieldById("int_type").getValue()
single_switch = Form.getFieldById("single_switch").getValue()
single_int = Form.getFieldById("single_int").getValue()
pair = Form.getFieldById("pair").getValue()
mlag_id = Form.getFieldById("mlag_id").getValue()
mlag_int = Form.getFieldById("mlag_int").getValue()
desc = Form.getFieldById("desc").getValue()
mode = Form.getFieldById("mode").getValue()
access_vlan = Form.getFieldById("access_vlan").getValue()
trunk_vlans = Form.getFieldById("trunk_vlans").getValue()
native_vlan = Form.getFieldById("native_vlan").getValue()

# Pull in corresponding port configlets for concatenation and collision checks
if int_type == "Stand-alone":
    try:
        pair = single_switch[:-1] + "A / B"
        mlag_configlet = server.cvpService.getConfigletByName(pair + " MLAGs")
        old_mlag_config = mlag_configlet["config"]
Example #10
0
import cvp
from cvplibrary import Form
from cvplibrary import CVPGlobalVariables, GlobalVariableNames
from jinja2 import Template
import re

# Login to CVP API
username = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_USERNAME)
password = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_PASSWORD)
server = cvp.Cvp("localhost")
server.authenticate(username, password)

# Retrieve Form Data
tenant_id = Form.getFieldById("tenant_id").getValue()
fw_vlan_id = Form.getFieldById("fw_vlan_id").getValue()
fw_gateway = Form.getFieldById("fw_gateway").getValue()

# Pull in relavent Jinja2 Tempaltes via CVP API
# Templates are stored as normal static configlets
try:
    tenant_template_configlet = server.cvpService.getConfigletByName(
        "L3LS-v Tenant Template")
    tenant_template = Template(tenant_template_configlet["config"])
except cvp.cvpServices.CvpError as e:
    if str(e).startswith("132801"):
        print "L3LS-v Tenant Template configlet does not exist.  Exiting..."
try:
    fw_template_configlet = server.cvpService.getConfigletByName(
        "L3LS-v FW Template")
    fw_template = Template(fw_template_configlet["config"])
except cvp.cvpServices.CvpError as e:
Example #11
0
from cvplibrary import Form
from cvplibrary import CVPGlobalVariables, GlobalVariableNames

hostname = Form.getFieldById('HOSTNAME').getValue()
ip = Form.getFieldById('IP').getValue()

print 'hostname ' + hostname
print '!'
print 'vrf instance management'
print '!'
print 'interface Management1'
print '   vrf management'
print '   ip address ' + ip + '/25'
print '   no lldp transmit'
print '   no lldp receive'
print '!'
print 'ip route vrf management 0.0.0.0/0 10.2.244.1'
print '!'
print 'no ip routing vrf management'
print '!'
print 'management api http-commands'
print '   no shutdown'
print '   !'
print '   vrf management'
print '      no shutdown'
from cvplibrary import CVPGlobalVariables as cvp_vars
from cvplibrary import GlobalVariableNames as cvp_names
from cvplibrary import RestClient
from cvplibrary import Form

import netaddr
import jsonrpclib
import json
import requests

# Set Form Variables and static
lo0 = Form.getFieldById('lo0').getValue()
lo0 = netaddr.IPNetwork('%s/32' % lo0)
lo1 = Form.getFieldById('lo1').getValue()
lo1 = netaddr.IPNetwork('%s/32' % lo1)
lo1_sec = Form.getFieldById('lo1_sec').getValue()
lo1_sec = netaddr.IPNetwork('%s/32' % lo1_sec)
mlag_subnet = Form.getFieldById('mlag_subnet').getValue()
mlag_subnet = netaddr.IPNetwork(mlag_subnet)
leaf_asn = Form.getFieldById('leaf_asn').getValue()
spine_asn = Form.getFieldById('spine_asn').getValue()
mac = cvp_vars.getValue(cvp_names.CVP_MAC)
routed_ints = list()
routed_ints.append('Ethernet2')
routed_ints.append('Ethernet3')
mlag_peer_ints = list()
mlag_peer_ints.append('Ethernet1')
mlag_ints = list()
mlag_ints.append('Ethernet4')

from cvplibrary import CVPGlobalVariables as cvp_vars
from cvplibrary import GlobalVariableNames as cvp_names
from cvplibrary import RestClient
from cvplibrary import Form

import netaddr
import jsonrpclib
import json

# Set Variables based on Form and static
base_net = Form.getFieldById('supernet').getValue()
base_net = netaddr.IPNetwork(base_net)
lo0 = Form.getFieldById('lo0').getValue()
lo0 = netaddr.IPNetwork('%s/32' % lo0)
asn = Form.getFieldById('asn').getValue().upper()
leaf_asn = Form.getFieldById('leaf_asn').getValue()
start = int(leaf_asn.split('-')[0])
end = int(leaf_asn.split('-')[-1])
leaf_asn = range(start, end + 1)
mac = cvp_vars.getValue(cvp_names.CVP_MAC)

# Can be changed to fit environment
p2p_cidr = 31


# Functions
def get_credentials(ztp=cvp_vars.getValue(cvp_names.ZTP_STATE)):
    if ztp == 'true':
        user = cvp_vars.getValue(cvp_names.ZTP_USERNAME)
        pwd = cvp_vars.getValue(cvp_names.ZTP_PASSWORD)
    else:
Example #14
0
import cvp
from cvplibrary import Form
from cvplibrary import CVPGlobalVariables, GlobalVariableNames

# Login to CVP API
username = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_USERNAME)
password = CVPGlobalVariables.getValue(GlobalVariableNames.CVP_PASSWORD)
server = cvp.Cvp("localhost")
server.authenticate(username, password)

# Retrieve Form Data
vlan = Form.getFieldById("vlan").getValue()
name = Form.getFieldById("name").getValue()
rtr = Form.getFieldById("rtr").getValue()
iface = Form.getFieldById("iface").getValue()

# Convert rtr variable to list
rtr_list = rtr.split(",")

# Generate NNI Config Data
new_nni_config = '''vlan {vlan}
   name {name}
!
interface {iface}
   description NNI {name}
   switchport trunk allowed vlan {vlan}
   switchport mode trunk
!
router bgp 11111
   !
   vlan {vlan}