예제 #1
0
 def get_device_detail_by_mac(self, mac):
     """
     get_device_detail_by_mac searches for a devices using its MAC address and returns a detailed listing of its
     current configuration state and health.
     :param mac: The network device's MAC address.
         type: str
         default: none
         required: yes
     :return: dict
     """
     if not self.__detail_resource:
         raise DnacError('get_device_detail_by_mac: %s: %s' %
                         (UNSUPPORTED_DNAC_VERSION, self.dnac.version))
     time = TimeStamp()
     query = '?timestamp=%s&searchBy=%s&identifier=%s' % \
             (time, mac, DEVICE_DETAIL_IDENTIFIERS['mac'])
     url = self.dnac.url + self.__detail_resource + query
     detail, status = self.crud.get(url,
                                    headers=self.dnac.hdrs,
                                    verify=self.verify,
                                    timeout=self.timeout)
     if status != OK:
         raise DnacApiError(MODULE, 'get_device_detail_by_mac',
                            REQUEST_NOT_OK, url, OK, status,
                            ERROR_MSGS[status], str(detail))
     self.__device_detail = detail['response']
     return self.__device_detail
예제 #2
0
    def get_all_sites_health(self):
        """
        Site class method get_all_sites_health retrieves the current health details for all sites in
        Cisco DNA Center.

        Parameters:
            None

        Return Values:
            dict: The health details for all sites.

        Usage:
            d = Dnac()
            all_sites = Site(d, 'ACME_sites')
            pprint.PrettyPrint(d.api['ACME_sites'].get_all_sites_health())
        """
        time = TimeStamp()
        query = '?timestamp=%s' % time
        url = self.dnac.url + self.resource + query
        health, status = self.crud.get(url,
                                       headers=self.dnac.hdrs,
                                       verify=self.verify,
                                       timeout=self.timeout)
        if status != OK:
            raise DnacApiError(MODULE, 'get_all_sites_health', REQUEST_NOT_OK,
                               url, OK, status, ERROR_MSGS[status],
                               str(health))
        self.__site_health = health['response']
        return self.__site_health
예제 #3
0
    def get_client_detail(self):
        """
        Get method get_client_detail makes a call to Cisco DNAC, retrieves the Client's state information,
        stores it in the client_detail attribute, and also returns the results for further processing.

        Parameters:
            None

        Return Values:
            dict: the Client's detailed state

        Usage:
            d = Dnac()
            host = Client(d, 'myPC', mac='a1:b2:c3:d4:e5:f6')
            pprint.PrettyPrint(d.api['myPC'].get_client_detail)
        """
        if self.__mac in ILLEGAL_MAC_ADDRS:
            raise DnacApiError(
                MODULE, 'get_client_detail', ILLEGAL_MAC, '',
                '', self.__mac, '', ''
            )
        time = TimeStamp()
        query = '?timestamp=%s&macAddress=%s' % (time, self.__mac)
        url = self.dnac.url + self.resource + query
        detail, status = self.crud.get(url,
                                       headers=self.dnac.hdrs,
                                       verify=self.verify,
                                       timeout=self.timeout)
        if status != OK:
            raise DnacApiError(
                MODULE, 'get_client_detail', REQUEST_NOT_OK, url,
                OK, status, ERROR_MSGS[status], str(detail)
            )
        self.__client_detail = detail
        return self.__client_detail
예제 #4
0
 def get_all_sites_health(self):
     """
     Returns the site health information for every site.
     :return: dict
     """
     time = TimeStamp()
     query = '?timestamp=%s' % time
     url = '%s%s%s' % (self.dnac.url, self.resource, query)
     health, status = self.crud.get(url,
                                    headers=self.dnac.hdrs,
                                    verify=self.verify,
                                    timeout=self.timeout)
     if status != OK:
         raise DnacApiError(MODULE, 'get_all_sites_health', REQUEST_NOT_OK,
                            url, OK, status, ERROR_MSGS[status],
                            str(health))
     self.__site_health = health['response']
     return self.__site_health
예제 #5
0
    def get_device_detail_by_mac(self, mac):
        """
        get_device_detail_by_mac searches for a devices using its MAC address
        and returns a detailed listing of its current configuration state
        and health.

        Parameters:
            mac: str
                default: None
                required: yes

        Return Values:
            dict: A dictionary of the device's current state

        Usage:
            d = Dnac()
            nd = NetworkDevice(d, 'network-device')
            mac = 'DE:AD:BE:EF:01:02'
            details = d.api['network-device'].get_device_detail_by_mac(mac)
            pprint.PrettyPrint(details)
        """
        if not self.__detail_resource:
            raise DnacError(
                'get_device_detail_by_mac: %s: %s' %
                (UNSUPPORTED_DNAC_VERSION, self.dnac.version)
            )
        time = TimeStamp()
        query = '?timestamp=%s&searchBy=%s&identifier=%s' % \
                (time, mac, DEVICE_DETAIL_IDENTIFIERS['mac'])
        url = self.dnac.url + self.__detail_resource + query
        detail, status = self.crud.get(url,
                                       headers=self.dnac.hdrs,
                                       verify=self.verify,
                                       timeout=self.timeout)
        if status != OK:
            raise DnacApiError(
                MODULE, 'get_device_detail_by_mac', REQUEST_NOT_OK, url,
                OK, status, ERROR_MSGS[status], str(detail)
            )
        self.__device_detail = detail['response']
        return self.__device_detail
예제 #6
0
 def get_client_detail(self):
     """
     Get method get_client_detail makes a call to Cisco DNAC, retrieves the Client's state information, stores it in
     the client_detail attribute, and also returns the results for further processing.
     :return: dict
     """
     if self.__mac in ILLEGAL_MAC_ADDRS:
         raise DnacApiError(MODULE, 'get_client_detail', ILLEGAL_MAC, '',
                            '', self.__mac, '', '')
     time = TimeStamp()
     query = '?timestamp=%s&macAddress=%s' % (time, self.__mac)
     url = self.dnac.url + self.resource + query
     detail, status = self.crud.get(url,
                                    headers=self.dnac.hdrs,
                                    verify=self.verify,
                                    timeout=self.timeout)
     if status != OK:
         raise DnacApiError(MODULE, 'get_client_detail', REQUEST_NOT_OK,
                            url, OK, status, ERROR_MSGS[status],
                            str(detail))
     self.__client_detail = detail
     return self.__client_detail
@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.')
        exit(1)
    run(archiver, host='localhost', port=8080, reloader=True, debug=True)