def main(): options = Arguments() #Authentication using rcvpapi module rcvauth = CVPCON(options.cvpserver,options.user,options.passwd) #Authentication for cvpServices module cvpsvcauth = cvpServices.CvpService(options.cvpserver, ssl=True, port=options.port) cvpsvcauth.authenticate(options.user,options.passwd) #Authentication for cvp module cvpauth = cvp.Cvp(options.cvpserver, ssl=True, port=options.port) cvpauth.authenticate(options.user,options.passwd) if (options.container is not None): createcontainer(cvpsvcauth,options.container) if (options.inventory is not None): importinventory(cvpauth,options.inventory,options.execute) if (options.configlet is not None and options.configlet_name is not None): uploadConfiglet(cvpsvcauth,options.configlet,options.configlet_name) if (options.configlet_name is not None and options.container_name is not None): assignConfigletToContainer(rcvauth,options.configlet_name,options.container_name)
def __init__(self): socket.setdefaulttimeout(3) urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) try: self.server = cvp.Cvp(host=host, ssl=True, port=443, tmpDir='') self.server.authenticate(user, password) except cvpServices.CvpError as error: timestamp = datetime.now().replace(microsecond=0) sys.stderr.write('{} {}ERROR{}: {}.\n'.format( timestamp, bcolors.ERROR, bcolors.NORMAL, error)) sys.exit(1) try: self.service = cvpServices.CvpService(host=host, ssl=True, port=443, tmpDir='') self.service.authenticate(user, password) except cvpServices.CvpError as error: timestamp = datetime.now().replace(microsecond=0) sys.stderr.write('{} {}ERROR{}: {}.\n'.format( timestamp, bcolors.ERROR, bcolors.NORMAL, error)) sys.exit(1)
def main(): if SYSLOG is True: assert SYSLOGSERVER is not None if EMAIL is True: assert EMAILFROM is not None assert EMAILTO is not None assert EMAILPASS is not None assert EMAILSERVER is not None try: global server server = cvp.Cvp(CVPSERVER) server.authenticate(CVPUSER, CVPPASS) except requests.HTTPError as e: print "Error connecting to CVP Server, trying again in 60 seconds: %s" % str( e) time.sleep(60) except packages.urllib3.exceptions.ProtocolError as e: if str( e ) == "('Connection aborted.', gaierror(8, 'nodename nor servname provided, or not known'))": print "DNS Error: The CVP Server %s can not be found" % CVPSERVER sys.exit(2) elif str( e ) == "('Connection aborted.', error(54, 'Connection reset by peer'))": print "Error, connection aborted" else: raise except: raise try: unreachable, outofcompliance = getComplianceList() # If there are any unreachable switches, send the list to the notify function for reporting if len(unreachable) > 0: text = "%s CVP_Compliance_Checker: UNREACHABLE: " % time.asctime() notify(unreachable, text, EMAIL, SYSLOG, PRINT) # If there are switches out of compliance, send the list to notify function for reporting if len(outofcompliance) > 0: text = "%s CVP_Compliance_Checker: OUT_OF_COMPLIANCE: " % time.asctime( ) notify(outofcompliance, text, EMAIL, SYSLOG, PRINT) # If CVP can't be reached, try again in 1 minute, could probably use a counter to abort after x tries except requests.HTTPError as e: print "Error reaching CVP server, trying again in 60 seconds %s" % str( e) time.sleep(60) #continue except packages.urllib3.exceptions.ProtocolError as e: if str( e ) == "('Connection aborted.', gaierror(8, 'nodename nor servname provided, or not known'))": print "DNS Error: The CVP Server %s can not be found. Check the hostname and try again." % CVPSERVER sys.exit(2) else: raise except: raise print "#" * 120 print "Executing Compliance Check @ ", time.asctime() print "#" * 120
def main(): '''Parses all the parameters provided by the user and calls methods to test the functionalities of cvp tools''' parser = argparse.ArgumentParser(description='CVP API test') parser.add_argument('--host', required=True) parser.add_argument('--port', default=80) parser.add_argument('--ssl', choices=[True, False], default=False) parser.add_argument('--user', default='cvpuser', required=True) parser.add_argument('--password', default='cvpuser', required=True) parser.add_argument('--swi', required=True) # We'll eventually make --file required, but we need to work out # how this works in our automated test environment / with multiple # folks running tests in parallel parser.add_argument('--file') args = parser.parse_args() print 'testing http://%s:%d as %s' % (args.host, args.port, args.user) server = cvp.Cvp(args.host, args.ssl, args.port) server.authenticate(args.user, args.password) clearCVPInstance(server) testConfiglet(server) #testImage( args, server ) #testContainer( server ) if args.file: testDevice(args, server) clearCVPInstance(server)
def main(): ## Load CVP Settings cvpsettings = CvpSettings() server = cvp.Cvp(cvpsettings.cvphost) server.authenticate(cvpsettings.cvpuser, cvpsettings.cvppasswd) #configfile = server.getConfiglet(cvpsettings.config) #config = yaml.safe_load(configfile.config) undefined = [d for d in server.getDevices() if d.containerName == 'Undefined'] print undefined
def login(): error = None global server if request.method == 'POST': user = request.form.get('user') password = request.form.get('passwd') host = request.form.get('host') # Actively connecting ot the VSD API try: server = cvp.Cvp(host) server.authenticate(user, password) except: flash('Login Session Failed...Check Credentials') return render_template('login.html', error=error) return render_template('menu.html', error=error) return render_template('login.html', error=error)
def main(): options = parseArgs() tmpDir = tempfile.mkdtemp() server = cvp.Cvp(options.host, options.ssl == 'true', options.port, tmpDir) server.authenticate(options.user, options.password) try: if options.action == 'restore': print 'Restoring objects:', ', '.join(options.objects) restore(server, options.tarFile, options.objects, options.objNames, options.skipVersionCheck) elif options.action == 'backup': print 'Backing up objects:', ', '.join(options.objects) backup(server, options.tarFile, options.host, options.objects, options.objNames, options.skipVersionCheck) elif options.action == 'reset': print 'Removing objects:', ', '.join(options.objects) reset(server, options.objects, options.skipVersionCheck) finally: shutil.rmtree(tmpDir)
test connectivity to the CSV API ''' import cvp import json host = '10.132.0.117' user = '******' password = '******' ip = '10.132.0.7' fqdn = 'lab.local' mac = '00-00-00-00-00-00' contain = 'Wookieware' cont_id = '' img = '' configlets = [] server = cvp.Cvp(host) server.authenticate(user, password) list = [] result = cvp.Device(ip, fqdn, mac, contain, img, configlets) print type(result) print(dir(result)) print result.fqdn devices = server.getDevices() print type(devices) for dev in devices: ip = dev.ipAddress mac = dev.macAddress
#!/usr/bin/env python import cvp from string import Template # # Info needed # ip = '192.168.0.5' user = '******' password = '******' snmp_community = 'kalleolle' ContainerName = 'Leaf' cvpServer = cvp.Cvp(ip) cvpServer.authenticate(user, password) Replacements = {"snmp_community": snmp_community} myConfig = Template(""" snmp-server community $snmp_community ro """).safe_substitute(Replacements) myConfigletName = 'Patriks SNMP community' myConfiglet = cvp.Configlet(myConfigletName, myConfig) cvpServer.addConfiglet(myConfiglet) ConfigletList = [] ConfigletList.append(myConfiglet)
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:
### Author: Tamas Plugor EMEA TAC ### Date: 2019-06-18 ### Demo script to remove a configlet from a device and generate a task import cvp import ssl ssl._create_default_https_context = ssl._create_unverified_context import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) host = '10.83.13.33' port = 443 tmpDir = '' d = cvp.Cvp(host, True, port, tmpDir) d.authenticate('cvpadmin', 'arastra') dev1 = d.getDevice('44:4c:a8:25:dc:41', provisioned=True) # save the configlet object in a variable cfg = d.getConfiglet('vlan1444') # provide the device and the list of configlet objects to be removed d.removeConfigletAppliedToDevice(dev1, [cfg]) # This will generate a task, it will return the taskID in a list #[u'1030'] ## This gives you the list of configlets under that device ## dev1.configlets #[u'aaa_policy', u'vrf_management', u'prompt', u'management_api', u'snmp_basics', u'time_config', u'user_accounts', u'aliases', u'event_cli_bootstrap', u'shannon_syslog', u'shannon_routes', u'up380_10.83.13.132_unique', u'JPE15470679lldp_int_desc', u'vlan 50', u'vlan1444', u'RECONCILE_10.83.13.132'] #
import cvp import ssl ssl._create_default_https_context = ssl._create_unverified_context import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) host = '10.83.13.33' d = cvp.Cvp(host, True, 443) d.authenticate('cvpadmin', 'arastra') container = d.getContainer('Tommy test') configletBuilder = d.getConfiglet("sys_telemetrybuilderv2") # add configlet to Container, in this case adding the SYS_TelemetryBuilderV2 to 'Tommy test' container d.mapConfigletToContainer(container, [configletBuilder]) # generate Configlets for Container based on configlet builder d.generateConfigletForContainer(container, configletBuilder, devicesList=None, inputs=None) # Result: # [Configlet "SYS_TelemetryBuilderV2_10.83.13.140_1", Configlet "SYS_TelemetryBuilderV2_10.83.13.132_2"]