def __init__(self,
              dnac,
              device_id,
              verify=False,
              timeout=5):
     """
     Creates a new DeviceArchive object and sets the target network device's ID.
     :param dnac: Reference to the program's Dnac object.
         type: Dnac object
         required: yes
         default: None
     :param device_id: The UUID in Cisco DNAC for the device to be managed.
         type: str
         required: yes
         default: None
     :param verify: Flag indicating whether or not to validate Cisco DNA Center's certificate.
         type: bool
         required: no
         default: False
     :param timeout: Number of seconds to wait for Cisco DNA Center to respond to an API call.
         type: int
         required: no
         default: 5
     """
     if dnac.version in SUPPORTED_DNAC_VERSIONS:
         path = DEVICE_ARCHIVE_RESOURCE_PATH[dnac.version]
     else:
         raise DnacError('%s: __init__: %s: %s' % (MODULE, UNSUPPORTED_DNAC_VERSION, dnac.version))
     self.__device = device_id
     self.__versions = []  # list of Version objects that contain the config files
     super(DeviceArchive, self).__init__(dnac,
                                         '%s_archive' % self.__device,
                                         resource=path,
                                         verify=verify,
                                         timeout=timeout)
    def __init__(self, dnac, deployment_id, verify=False, timeout=5):
        """
        Creates a deployment object and sets the deployment job's UUID.

        :param dnac: A reference to the master Dnac instance.
            type: Dnac object
            required: yes
            default: None
        :param deployment_id: The deployment job's UUID.
            type: str
            required: yes
            default: None
        :param verify: A flag that sets whether or not Cisco DNA Center's certificated should be authenticated.
            type: bool
            required: no
            default: False
        :param timeout: The number of seconds to wait for a response from Cisco DNAC.
            type: int
            required: no
            default: 5
        """
        if dnac.version in SUPPORTED_DNAC_VERSIONS:
            path = DEPLOYMENT_RESOURCE_PATH[dnac.version]
        else:
            raise DnacError('__init__: %s: %s' %
                            (UNSUPPORTED_DNAC_VERSION, dnac.version))
        self.__deployment = {}
        self.__deployment_id = deployment_id
        super(Deployment, self).__init__(dnac,
                                         ('deployment_%s' % deployment_id),
                                         resource=path,
                                         verify=verify,
                                         timeout=timeout)
Example #3
0
 def __init__(self, dnac, name, verify=False, timeout=5):
     """
     ConfigArchive's __init__ method initializes the object with an empty archive.
     :param dnac: A reference to the containing Dnac object.
         type: Dnac object
         default: none
         required: yes
     :param name: A user friendly name for finding this object in a Dnac instance.
         type: str
         default: none
         required: yes
     :param verify: A flag used to check Cisco DNAC's certificate.
         type: boolean
         default: False
         required: no
     :param timeout: The number of seconds to wait for Cisco DNAC's response.
         type: int
         default: 5
         required: no
     """
     if dnac.version in SUPPORTED_DNAC_VERSIONS:
         path = ARCHIVE_RESOURCE_PATH[dnac.version]
     else:
         raise DnacError('%s: __init__: %s: %s' %
                         (MODULE, UNSUPPORTED_DNAC_VERSION, dnac.version))
     self.__archive = {}  # key = deviceId, value = DeviceArchive
     super(ConfigArchive, self).__init__(dnac,
                                         '%s_archive' % name,
                                         resource=path,
                                         verify=verify,
                                         timeout=timeout)
Example #4
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
Example #5
0
 def __init__(self,
              dnac,
              name=SITE_HIERARCHY_NAME,
              verify=False,
              timeout=5):
     """
     Creates at new Site object.
     :param dnac: The Cisco DNA Center cluster to which the site belongs.
         type: Dnac object
         required: yes
         default: none
     :param name: The site hierarchy's name.
         type: str
         required: no
         default: Either the Dnac object's name or IP address concatenated with SITE_HIERARCHY_NAME.
     :param verify: A flag indicating whether or not to validate the cluster's certificate.
         type: bool
         required: no
         default: False
     :param timeout: The number of seconds to wait for a response from a site hierarchy API call.
         type: int
         required: no
         default: 5
     """
     if dnac.version in SUPPORTED_DNAC_VERSIONS:
         path = SITE_RESOURCE_PATH[dnac.version]
     else:
         raise DnacError('__init__: %s: %s' %
                         (UNSUPPORTED_DNAC_VERSION, dnac.version))
     if dnac.name != NO_DNAC_PATH:
         site_hierarchy_name = '%s%s' % (dnac.name, name)
     elif dnac.ip != NO_DNAC_PATH:
         site_hierarchy_name = '%s%s' % (dnac.ip, name)
     else:
         raise DnacError('__init__: critical error: %s: %s' %
                         (NO_DNAC_PATH_ERROR, NO_DNAC_PATH_RESOLUTION))
     super(SiteHierarchy, self).__init__(dnac,
                                         site_hierarchy_name,
                                         resource=path,
                                         verify=verify,
                                         timeout=timeout)
     self.__all_sites = []
     self.__site_nodes = multi_key_dict()
     self.__site_count = NO_SITES
     self.load_sites()
Example #6
0
    def __init__(self, dnac, name, cmds=None, verify=False, timeout=5):
        """
        The __init__ method creates a CommandRunner object.  As with all
        classes that inherit from DnacApi, a minimum of a Dnac container
        and a name must be given.  Optionally, a dictionary of the CLI
        commands to run and the UUIDs of devices to run them on may
        be specified.

        Parameters:
            dnac: A reference to the containing Dnac object.
                type: Dnac object
                default: none
                required: yes
            name: A user friendly name for finding this object in a Dnac
                  instance.
                type: str
                default: none
                required: yes
            cmds: A dict with the commands and target devices.
                type: dict
                default: none
                required: no
            verify: A flag used to check Cisco DNAC's certificate.
                type: boolean
                default: False
                required: no
            timeout: The number of seconds to wait for Cisco DNAC's
                     response.
                type: int
                default: 5
                required: no

        Return Values:
            CommandRunner object: The newly constructed CommandRunner

        Usage:
            d = Dnac()
            cmds = {'commands': ['show version', 'show module'],
                    'deviceUuids': ['<switch>', '<router>]}
            cmd = CommandRunner(d, "aName", cmds=cmds)
        """
        # check Cisco DNA Center's version and set the resourece path
        if cmds is None:
            cmds = {}
        if dnac.version in SUPPORTED_DNAC_VERSIONS:
            path = COMMANDRUNNER_RESOURCE_PATH[dnac.version]
        else:
            raise DnacError('__init__: %s: %s' %
                            (UNSUPPORTED_DNAC_VERSION, dnac.version))
        # setup the attributes
        self.__cmds = cmds  # commands to run
        self.__task = None  # Task object created after running cmds
        super(CommandRunner, self).__init__(dnac,
                                            name,
                                            resource=path,
                                            verify=verify,
                                            timeout=timeout)
Example #7
0
    def __init__(self,
                 dnac,
                 name,
                 verify=False,
                 timeout=5):
        """
        The __init__ class method instantiates a new NetworkDevice object.
        Be certain that a Dnac object is first created, then pass that
        object and a user-friendly name for the NetworkDevice instance
        that can be used to access it in the Dnac.api dictionary.

        Parameters:
            dnac: A reference to the containing Dnac object.
                type: Dnac object
                default: none
                required: Yes
            name: A user friendly name for find this object in a Dnac
                  instance.
                type: str
                default: none
                required: yes
            verify: A flag used to check Cisco DNAC's certificate.
                type: boolean
                default: False
                required: no
            timeout: The number of seconds to wait for Cisco DNAC's
                     response.
                type: int
                default: 5
                required: no

        Return Values:
            NetworkDevice object: a new NetworkDevice object.

        Usage:
            d = Dnac()
            nd = NetworkDevice(d, 'network-device')
        """
        if dnac.version in SUPPORTED_DNAC_VERSIONS:
            path = NETWORK_DEVICE_RESOURCE_PATH[dnac.version]
        else:
            raise DnacError(
                '__init__: %s: %s' %
                (UNSUPPORTED_DNAC_VERSION, dnac.version)
                           )
        if dnac.version in DEVICE_DETAIL_RESOURCE_PATH:
            self.__detail_resource = DEVICE_DETAIL_RESOURCE_PATH[dnac.version]
        else:
            self.__detail_resource = None
        self.__devices = None  # API returns list or dict based on the call
        self.__vlans = []
        self.__device_detail = {}
        super(NetworkDevice, self).__init__(dnac,
                                            name,
                                            resource=path,
                                            verify=verify,
                                            timeout=timeout)
Example #8
0
    def __init__(self, dnac, name, verify=False, timeout=5):
        """
        Template's __init__ method constructs a new Template object. It automatically searches for the template in
        Cisco DNA Center by the Template's name.  If found, it will load the parent template information and all
        committed versions.  This class' attributes are decorator functions that directly access the template's info,
        the parent template, and all available versions.

        :param dnac: A reference to the master Dnac instance.
            type: Dnac object
            required: yes
            default: None
        :param name: The template's name as listed in Cisco DNA Center.
            type: str
            required: yes
            default: None
        :param verify: A flag that sets whether or not Cisco DNA Center's certificated should be authenticated.
            type: bool
            required: no
            default: False
        :param timeout: The number of seconds to wait for a response from Cisco DNAC.
            type: int
            required: no
            default: 5
        """
        # check Cisco DNA Center's version and set the resource path
        if dnac.version in SUPPORTED_DNAC_VERSIONS:
            path = TEMPLATE_RESOURCE_PATH[dnac.version]
        else:
            raise DnacError('__init__: %s: %s' %
                            (UNSUPPORTED_DNAC_VERSION, dnac.version))

        # template attributes
        self.__template = {
        }  # contents of the template info found by querying all available templates
        self.__versions = {
        }  # contents of the template's parent (index=0) and versionsInfo keyed by version number

        # deployment attributes
        self.__params = {
        }  # parameters and their values to apply during deployment
        self.__target_id = ''  # where to deploy the latest committed template
        self.__target_type = TARGET_BY_DEFAULT  # how to find the target
        self.__deployment = ''  # object for monitoring the deployment

        # DnacApi attributes
        super(Template, self).__init__(dnac,
                                       name,
                                       resource=path,
                                       verify=verify,
                                       timeout=timeout)

        # load the template
        if self.name != STUB_TEMPLATE:
            self.load_template(self.name)
Example #9
0
    def __init__(self, dnac, id, verify=False, timeout=5):
        """
        __init__ makes a new Task object.  An empty task object may be
        created by only passing a Dnac object and the task's UUID.
        The Task instance sets its name as "task_<id>" and the URL for
        querying the task's progress.

        Parameters:
            dnac: A reference to the containing Dnac object.
                type: Dnac object
                default: none
                required: yes
            id: The UUID of the task running on Cisco DNAC. The new object
                sets its name and url based on id's value:
                     name = "task_<id>"
                     url = "dnac.url/self.resource/<id>"
                type: str
                default: none
                required: yes
            verify: A flag used to check Cisco DNAC's certificate.
                type: boolean
                default: False
                required: no
            timeout: The number of seconds to wait for Cisco DNAC's response.
                type: int
                default: 5
                required: no

        Return Values:
            Task object: a new Task object.

        Usage:
            d = Dnac()
            id = <task ID from Cisco DNAC>
            task = Task(d, a_task_id)
            task.check_task()
        """
        # check Cisco DNA Center's version and set the resource path
        if dnac.version in SUPPORTED_DNAC_VERSIONS:
            path = TASK_RESOURCE_PATH[dnac.version]
        else:
            raise DnacError('__init__: %s: %s' %
                            (UNSUPPORTED_DNAC_VERSION, dnac.version))
        # setup the attributes
        self.__id = id
        self.__progress = TASK_EMPTY
        self.__file = None
        self.__file_id = ''
        super(Task, self).__init__(dnac, ('task_%s' % self.__id),
                                   resource=path,
                                   verify=verify,
                                   timeout=timeout)
Example #10
0
    def __init__(self, dnac, id, verify=False, timeout=5):
        """
        Class method __init__ creates a new File instance.  When
        making a File object, pass it a Dnac object and the UUID
        of the file in Cisco DNAC that this object represents.

        Parameters:
            dnac: A reference to the containing Dnac object.
                type: Dnac object
                default: none
                required: yes
            id: The UUID of the file in Cisco DNAC this object represents.
                If included as part of calling __init__, the new object sets
                its name and url based on id's value:
                    name = 'task_<id>'
                    url = 'dnac.url/self.respath/<id>'
                type: str
                default: none
                required: yes
            verify: A flag used to check Cisco DNAC's certificate.
                type: boolean
                default: False
                required: no
            timeout: The number of seconds to wait for Cisco DNAC's
                     response.
                type: int
                default: 5
                required: no

        Return Values:
            File object: a new File instance.

        Usage:
            d = Dnac()
            id = '<file UUID>'
            results = File(d, id)
        """
        # check Cisco DNA Center's version and set the resource path
        if dnac.version in SUPPORTED_DNAC_VERSIONS:
            path = FILE_RESOURCE_PATH[dnac.version]
        else:
            raise DnacError('__init__: %s: %s' %
                            (UNSUPPORTED_DNAC_VERSION, dnac.version))
        # setup the attributes
        self.__id = id  # use the fileId in the task's progress
        self.__results = []  # raw data in case further processing needed
        super(File, self).__init__(dnac, ('file_%s' % self.__id),
                                   resource=path,
                                   verify=verify,
                                   timeout=timeout)
Example #11
0
    def __init__(self,
                 dnac,
                 name,
                 verify=False,
                 timeout=5):
        """
        Upon creating a new Project object, __init__ sets the __project field as an empty dict.  As long as the
        project's name is not set to 'NEW_PROJECT', the Project attempts to load its attributes as given in Cisco
        DNA Center.  If its name is NEW_PROJECT, then this method creates an empty Project that can be used to
        import a project from a backup file (see the import_project method for more details).
        Usage:
            d = Dnac()
            proj = Project(d, 'aProject')
        :param dnac: a reference to the containing Dnac object
            type: Dnac object
            default: none
            required: yes
        :param name: the project's name as it appears in a live Cisco DNA Center cluster
            type: str
            default: none
            required: yes
        :param verify: a flag used to check DNAC's certificate
            type: bool
            default: False
            required: no
        :param timeout: the time in seconds to wait for an API response from DNA Center
            type: int
            default: 5
            required: no
        """
        if dnac.version in SUPPORTED_DNAC_VERSIONS:
            path = PROJECT_RESOURCE_PATH[dnac.version]
        else:
            raise DnacError('%s: __init__: %s: %s' % (MODULE, UNSUPPORTED_DNAC_VERSION, dnac.version))

        # initialize attributes
        self.__project = {}

        # setup the parent class
        super(Project, self).__init__(dnac,
                                      name,
                                      resource=path,
                                      verify=verify,
                                      timeout=timeout)

        # retrieve the project
        if self.name != STUB_PROJECT:
            self.load_project(self.name)
Example #12
0
    def __init__(self, dnac, name, site=NO_SITES, verify=False, timeout=5):

        if dnac.version in SUPPORTED_DNAC_VERSIONS:
            path = SITE_HEALTH_RESOURCE_PATH[
                dnac.version]  # change when a site resource becomes available
            self.__site_health_resource = SITE_HEALTH_RESOURCE_PATH[
                dnac.version]
        else:
            raise DnacError('__init__: %s: %s' %
                            (UNSUPPORTED_DNAC_VERSION, dnac.version))
        self.__sites = site
        self.__site_health = NO_SITE_HEALTH
        super(Site, self).__init__(dnac,
                                   name,
                                   resource=path,
                                   verify=verify,
                                   timeout=timeout)
Example #13
0
    def __init__(self, dnac, id, verify=False, timeout=5):
        """
        Deployment's __init__ method sets up a new Deployment object.
        It takes a Dnac object and the deployment UUID and then constructs
        a Deployment object whose name is 'deployment_<UUID>'.

        Parameters:
            dnac: A reference to the containing Dnac object.
                type: Dnac object
                default: none
                required: yes
            id: The UUID in Cisco DNA Center for the deployment job.
                type: str
                default: none
                required: no
            verify: A flag used to check Cisco DNAC's certificate.
                type: boolean
                default: False
                required: no
            timeout: The number of seconds to wait for Cisco DNAC's
                     response.
                type: int
                default: 5
                required: no

        Return Values:
            Deployment object: a new Deployment object.

        Usage:
            None.  Template objects automatically create Deployment objects.
        """
        if dnac.version in SUPPORTED_DNAC_VERSIONS:
            path = DEPLOYMENT_RESOURCE_PATH[dnac.version]
        else:
            raise DnacError('__init__: %s: %s' %
                            (UNSUPPORTED_DNAC_VERSION, dnac.version))
        self.__id = id
        self.__url = '%s/%s' % (path, self.__id)
        self.__status = ''  # for monitoring deployment status
        self.__results = {}  # stores deployment's results
        super(Deployment, self).__init__(dnac, ('deployment_%s' % self.__id),
                                         resource=path,
                                         verify=verify,
                                         timeout=timeout)
Example #14
0
 def __init__(
         self,
         dnac,
         site_name_hierarchy,  # use the site's name hierarchy to ensure uniqueness
         verify=False,
         timeout=5):
     """
     Creates a new Site object and loads its information from the Cisco DNA Center cluster specified.
     :param dnac: The Cisco DNAC cluster object from which to load the site's information.
         type: Dnac object
         required: yes
         default: none
     :param site_name_hierarchy: The site's full hierarchy name as given in Cisco DNA Center, e.g. Global/US/CA
         type: str
         required: yes
         default: none
     :param verify: A flag indicating whether or not to verify the cluster's certificate.
         type: bool
         required: no
         default: False
     :param timeout: The number of seconds to wait for a site API call to complete before abandoning the response.
         type: int
         required: no
         default: 5
     """
     if dnac.version in SUPPORTED_DNAC_VERSIONS:
         path = SITE_RESOURCE_PATH[dnac.version]
         self.__site_health_resource = SITE_HEALTH_RESOURCE_PATH[
             dnac.version]
     else:
         raise DnacError('__init__: %s: %s' %
                         (UNSUPPORTED_DNAC_VERSION, dnac.version))
     self.__site = NO_SITE
     self.__site_health = NO_SITE_HEALTH
     super(Site, self).__init__(dnac,
                                site_name_hierarchy,
                                resource=path,
                                verify=verify,
                                timeout=timeout)
     if site_name_hierarchy != STUB_SITE:
         self.load_site(site_name_hierarchy)
Example #15
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
Example #16
0
    def __init__(self,
                 dnac,
                 name,
                 mac=NULL_MAC,
                 verify=False,
                 timeout=5):

        if dnac.version in SUPPORTED_DNAC_VERSIONS:
            path = CLIENT_RESOURCE_PATH[dnac.version]
        else:
            raise DnacError(
                '__init__: %s: %s' %
                (UNSUPPORTED_DNAC_VERSION, dnac.version)
                           )
        self.__mac = mac
        self.__client_detail = {}
        super(Client, self).__init__(dnac,
                                     name,
                                     resource=path,
                                     verify=verify,
                                     timeout=timeout)
 def __init__(self,
              dnac,
              name,
              verify=False,
              timeout=5):
     """
     The ConfigArchiveSettings __init__ method creates a new object with blank settings.
     :param dnac: A reference to the containing Dnac object.
         type: Dnac object
         default: none
         required: yes
     :param name: A user friendly name for finding this object in a Dnac instance.
         type: str
         default: none
         required: yes
     :param verify: A flag used to check Cisco DNAC's certificate.
         type: boolean
         default: False
         required: no
     :param timeout: The number of seconds to wait for Cisco DNAC's response.
         type: int
         default: 5
         required: no
     """
     if dnac.version in SUPPORTED_DNAC_VERSIONS:
         path = ARCHIVE_SETTINGS_RESOURCE_PATH[dnac.version]
     else:
         raise DnacError(
             '__init__: %s: %s' %
             (UNSUPPORTED_DNAC_VERSION, dnac.version)
                        )
     self.__settings = {}  # global DNA Center archive settings
     super(ConfigArchiveSettings, self).__init__(dnac,
                                                 '%s_archive_settings' % name,
                                                 resource=path,
                                                 verify=verify,
                                                 timeout=timeout)
Example #18
0
 def get_site_count(self):
     """
     Makes a call to the Cisco DNA Center cluster requesting the total number of sites available.
     :return: int
     """
     # get the number of sites in the hierarchy
     if self.dnac.version in SUPPORTED_DNAC_VERSIONS:
         count_path = SITE_COUNT_RESOURCE_PATH[self.dnac.version]
     else:
         raise DnacError('__init__: %s: %s' %
                         (UNSUPPORTED_DNAC_VERSION, self.dnac.version))
     url = '%s%s%s' % (self.dnac.url, self.resource, count_path)
     response, status = self.crud.get(url,
                                      headers=self.dnac.hdrs,
                                      verify=self.verify,
                                      timeout=self.timeout)
     if status != OK:
         raise DnacApiError(MODULE, 'get_site_count', REQUEST_NOT_OK, url,
                            OK, status, ERROR_MSGS[status], '')
     self.__site_count = response['response']
     if self.__site_count <= NO_SITES:
         raise DnacApiError(MODULE, 'get_site_count', NO_SITES_ERROR, '',
                            '', '', '', '')
     return self.__site_count
Example #19
0
 def __init__(self, dnac, name, mac=NULL_MAC, verify=False, timeout=5):
     """
     Creates a new client object.
     :param dnac: A reference to the program's Dnac instance.
         type: Dnac object
         required: yes
         default: None
     :param name: The client's name.
         type: str
         required: yes
         default: None
     :param mac: The client's MAC address
         type: str
         required: no
         default: NULL_MAC (00:00:00:00:00:00)
     :param verify: A flag to determine whether or not to verify Cisco DNA Center's certificate.
         type: bool
         required: no
         default: False
     :param timeout: The time in seconds to wait for Cisco DNAC's response.
         type: int
         required: no
         default: 5
     """
     if dnac.version in SUPPORTED_DNAC_VERSIONS:
         path = CLIENT_RESOURCE_PATH[dnac.version]
     else:
         raise DnacError('__init__: %s: %s' %
                         (UNSUPPORTED_DNAC_VERSION, dnac.version))
     self.__mac = mac
     self.__client_detail = {}
     super(Client, self).__init__(dnac,
                                  name,
                                  resource=path,
                                  verify=verify,
                                  timeout=timeout)
Example #20
0
 def __init__(self,
              dnac,
              device_id,
              version_id,
              verify=False,
              timeout=5):
     """
     Instantiates a new Version object.
     :param dnac: A reference to the master script's Dnac object.
         type: Dnac object
         required: yes
         default: None
     :param device_id: The UUID for the device whose archive is being managed.
         type: str
         required: yes
         default: none
     :param version_id: The UUID of the version being queried.
         type: str
         required: yes
         default: None
     :param verify: A flag that determines whether or not Cisco DNA Center's certificate should be authenticated.
         type: bool
         required: no
         default: False
     :param timeout: The number of seconds to wait for Cisco DNAC to respond to a query.
         type: int
         required: no
         default: 5
     """
     if dnac.version in SUPPORTED_DNAC_VERSIONS:
         path = '%s/%s%s/%s' % (VERSION_RESOURCE_PATH[dnac.version],
                               device_id,
                               VERSION_SUB_RESOURCE_PATH[dnac.version],
                               version_id)
     else:
         raise DnacError('__init__: %s: %s' % (UNSUPPORTED_DNAC_VERSION, dnac.version))
     self.__id = version_id
     self.__device_id = device_id
     self.__config_files = {}  # key = fileType, value = File object
     name = 'version_%s' % self.__id
     super(Version, self).__init__(dnac,
                                   name,
                                   resource=path,
                                   verify=verify,
                                   timeout=timeout)
     # load the version
     url = self.dnac.url + self.resource
     version, status = self.crud.get(url,
                                     headers=self.dnac.hdrs,
                                     verify=self.verify,
                                     timeout=self.timeout)
     if status != OK:
         raise DnacApiError(
             MODULE, '__init__', REQUEST_NOT_OK, url, OK, status, ERROR_MSGS[status], str(version)
                           )
     self.__created_time = version['versions'][0]['createdTime']
     self.__sync_status = version['versions'][0]['startupRunningStatus']
     for file in version['versions'][0]['files']:
         # iterate through all the archive's versions and load the config files
         if file['fileType'] not in CONFIG_FILE_TYPES:
             # ignore VLAN data files
             if file['fileType'] == VLAN:
                 continue
             raise DnacApiError(
                 MODULE, '__init__', ILLEGAL_CONFIG_FILE_TYPE, '',
                 str(CONFIG_FILE_TYPES), '', file['fileType'], ''
             )
         config_file = File(dnac, file['fileId'])
         config_file.get_results(is_json=False)
         self.__config_files[file['fileType']] = config_file
Example #21
0
    def __init__(self,
                 dnac,
                 name,
                 version=0,
                 verify=False,
                 timeout=5):
        """
        Template's __init__ method constructs a new Template object.
        It automatically searches for the template in Cisco DNA Center
        by the Template's name.  If found, then it will search for the
        committed version of the template according to the value passed
        in the version keyword argument.  If no version is selected, it
        chooses the latest version available.

        Parameters:
            dnac: A reference to the containing Dnac object.
                type: Dnac object
                default: none
                required: yes
            name: The template's exact name, including its case, in
                  Cisco DNA Center.
                type: str
                default: none
                required: yes
            version: The template version that will be deployed.  When set
                     to zero, Template selects the latest version.
                type: int
                default: 0
                required: no
            verify: A flag used to check Cisco DNAC's certificate.
                type: boolean
                default: False
                required: no
            timeout: The number of seconds to wait for Cisco DNAC's
                     response.
                type: int
                default: 5
                required: no

        Return Values:
            Template object: a newly build Template instance.

        Usage:
            d = Dnac()
            template = Template(d, 'Enable BGP', version=5)
        """
        # version is the template's version and must not be negative
        if version < 0:
            raise DnacApiError(
                MODULE, '__init__', ILLEGAL_VERSION, '', '',
                version, '', LEGAL_VERSIONS
            )
        # check Cisco DNA Center's version and set the resource path
        if dnac.version in SUPPORTED_DNAC_VERSIONS:
            path = TEMPLATE_RESOURCE_PATH[dnac.version]
        else:
            raise DnacError(
                '__init__: %s: %s' %
                (UNSUPPORTED_DNAC_VERSION, dnac.version)
            )
        # setup initial attribute values
        self.__template_id = ''  # base template ID
        self.__version = version  # requested template version, 0 = latest
        self.__versioned_template = {}
        self.__versioned_template_id = ''  # template that can be deployed
        self.__versioned_template_params = {}
        self.__target_id = ''  # where to deploy the template
        self.__target_type = TARGET_BY_DEFAULT  # how to find the target
        self.__deployment = ''  # object for monitoring the deployment
        super(Template, self).__init__(dnac,
                                       name,
                                       resource=path,
                                       verify=verify,
                                       timeout=timeout)
        # retrieve the template ID by its name
        self.__template_id = self.get_template_by_name(self.name)
        if not self.__template_id:  # template could not be found
            raise DnacApiError(
                MODULE, '__init__', TEMPLATE_NOT_FOUND, '',
                '', self.__template_id, '', ''
            )
        # retrieve the versioned template
        # get_versioned_template_by_name sets self.__versioned_template
        self.get_versioned_template_by_name(self.name, self.__version)
        if not bool(self.__versioned_template):  # template is empty
            # get_versioned_template_by_name should catch this condition, but
            # just in case, here's another integrity check
            raise DnacApiError(
                MODULE, '__init__', UNKNOWN_VERSION, '',
                '', self.__versioned_template, '',
                '%s version %i' % (self.name, self.__version)
            )