Beispiel #1
0
    def run(self):
        MODULE = 'networkdevice_example.py'
        try:
            self.logger.info('%s: setting up Cisco DNA Center and its API...' %
                             MODULE)
            dnac = Dnac()
            ndapi = NetworkDevice(dnac, 'devices')

            self.logger.info('%s: getting all devices...' % MODULE)
            # The handle 'ndapi' could be used here, but the point of this example is
            # demonstrate how to get it directly from the Dnac.api{} using the API's name.
            devices = dnac.api['devices'].get_all_devices()

            self.logger.info('%s: found the following devices:' % MODULE)
            for device in devices:
                self.logger.info('hostname: %s\tserial: %s\tIP: %s' %
                                 (device['hostname'], device['serialNumber'],
                                  device['managementIpAddress']))
            return (True, devices)
        except Exception as err:
            return (False, MODULE + str(err))
Beispiel #2
0
# Main Program ########################################################################################################

if __name__ == '__main__':
    """
    usage: site_heirarchy_replicator <clusters_file>
    """

    # read the json encoded config file passed from the CLI
    clusters_file = open(sys.argv[1], mode='r')
    clusters_from_config_file = json.load(clusters_file)
    clusters_file.close()

    # create all the Dnac objects from the clusters that were listed in the config file
    clusters = []
    for cluster in clusters_from_config_file:
        # create a Dnac object
        dnac = Dnac(version=cluster['version'],
                    name=cluster['name'],
                    ip=cluster['ip'],
                    port=cluster['port'],
                    user=cluster['user'],
                    passwd=cluster['passwd'],
                    content_type=cluster['content_type'])
        # create a stub site for adding new sites
        stub_site = Site(dnac, STUB_SITE)
        stub_site.timeout = 60  # my lab's DNAC server is responding slowly; others may not need this
        # add the new Dnac instance to the global clusters list
        clusters.append(dnac)

    run(replicator, host='localhost', port=8088, reloader=True, debug=True)
from dnac import Dnac
from dnac.template import Template
import sys

## Main program

# collect command line arguments
templates = sys.argv[1:]

# connect to the source Cisco DNA Center cluster
d = Dnac(name='denlab-en-dnac.cisco.com',
         version='1.3.1.3',
         ip='10.94.164.223',
         port='443',
         user='******',
         passwd='C!sco123',
         content_type='application/json')

# for each template named on the command line
for template in templates:
    # get the template
    t = Template(d, template)

    # save the template
    t.export_template()

    # save all the template's versions
    for ver in t.versions:
        t.export_versioned_template(int(ver['version']))

    print('Exported template %s' % t.name)
Beispiel #4
0
from dnac import Dnac
from dnac.template import Template, TARGET_BY_ID

MODULE = 'template_example.py'

print('%s: preparing to deploy a template...' % MODULE)

dnac = Dnac()

template = Template(dnac, 'Set VLAN')

print('%s: setting the target device...' % MODULE)

dnac.api['Set VLAN'].targetId = '84e4b133-2668-4705-8163-5694c84e78fb'
dnac.api['Set VLAN'].targetType = TARGET_BY_ID

print('%s: setting the template\'s parameters...' % MODULE)

dnac.api['Set VLAN'].set_param('interface', 'g1/0/8')
dnac.api['Set VLAN'].set_param('description', 'Provisioned by %s' % MODULE)
dnac.api['Set VLAN'].set_param('vlan', 10)

print('%s: deploying the template...' % MODULE)

dnac.api['Set VLAN'].deploy_sync()

print('%s: deploy results: %s' %
      (MODULE, dnac.api['Set VLAN'].deployment.results))

print()
Beispiel #5
0
        self.__site_health = target_site_health
        return self.__site_health


# end get_site_health_by_name

# end class Site()

# begin unit test

if __name__ == '__main__':
    from dnac import Dnac
    import pprint

    pp = pprint.PrettyPrinter(indent=4)
    d = Dnac()
    s = Site(d, 'aSite')

    print('Site:')
    print()
    print('Getting the health of all sites...')
    print()

    s.get_all_sites_health()

    pp.pprint(s.site_health)

    print()
    print('Getting site health for Denver Office...')

    s.get_site_health_by_name('Denver Office')
    return template('create_new_archive', dnac=dnac, hosts=candidates)


@archiver.route('/create_new_device_archive', method='POST')
def create_new_device_archive():
    host = request.forms.get('host')
    host_id = device_api.get_device_by_name(host)['id']
    config_archive.add_new_archive(host_id)
    return template('create_new_device_archive', dnac=dnac, host=host)


if __name__ == '__main__':
    dnac = Dnac(name='',
                version='1.3.0.3',
                ip='10.1.41.218',
                port='443',
                user='******',
                passwd='P@$$w0rd',
                content_type='application/json')
    timestamp = TimeStamp()
    device_api = NetworkDevice(dnac, 'deviceapi')
    if bool(dnac.name):
        settings = ConfigArchiveSettings(dnac, dnac.name)
        config_archive = ConfigArchive(dnac, dnac.name)
        config_archive.load_all_archives()
    elif bool(dnac.ip):
        settings = ConfigArchiveSettings(dnac, dnac.name)
        config_archive = ConfigArchive(dnac, dnac.name)
        config_archive.load_all_archives()
    else:
        print('Could not connect to DNA Center.  Set the FQDN or IP in dnac_config.')
from dnac import Dnac
from dnac.project import Project, STUB_PROJECT
import sys

## Main program

# collect command line arguments
projects = sys.argv[1:]

# connect to the source Cisco DNA Center cluster
d = Dnac(name='',
         version='1.3.1.4',
         ip='10.91.33.113',
         port='443',
         user='******',
         passwd='c!sco123',
         content_type='application/json')

# create a dummy Project object to perform the import
p = Project(d, STUB_PROJECT)

# for each project given on the command line
for project in projects:

    # import the project into DNAC
    new_project = p.import_project(project)

    if bool(new_project):
        print('Project %s imported.' % new_project.name)