aristanetworks/cvprac

Get additional Device info using getNetElementInfoById

Closed this issue · 2 comments

Not all of the device information is returned by get_device_by_name function, this function gathers additional data using the getNetElementInfoById API call. This call provides information about Images associated with the device.

Suggested code would look like:

def get_net_element_info_by_device_id(self, d_id):
''' Return a dict of info about a device in CVP.

        Args:
            d_id (str): Device Id Key / System MAC.

        Returns:
            net element data (dict): Dict of info specific to the device
                requested or None if the name requested doesn't exist.
    '''
    self.log.debug('Attempt to get net element data for %s' % d_id)
    try:
        element_info = self.clnt.get('/provisioning/getNetElementInfoById.do?netElementId=%s'
                              % qplus(d_id), timeout=self.request_timeout)
    except CvpApiError as error:
        # Catch an invalid task_id error and return None
        if 'errorMessage' in str(error):
            self.log.debug('Device with id %s could not be found' % d_id)
            return None
        raise error
    return element_info

@Hugh-Adams

Since the only additional information from this API call is the images associated with the device I am considering naming the function something along the lines of get_device_image_info as to differentiate its purpose from get_device_by_name