aristanetworks/cvprac

Factory Reset Device and Move to Undefined Container

Closed this issue · 1 comments

Additional functionality required in cvp_api to allow a device to be reset to factory defaults and returned to the Undefined container ready to be re-purposed.

Required code would be something like this:

def reset_device(self, app_name, device, create_task=True):
    ''' Reset device by moving it to the Undefined Container.

        Args:
            app_name (str): String to specify info/signifier of calling app
            device (dict): Device info
            container (dict): Container info
            create_task (bool): Determines whether or not to execute a save
                and create the tasks (if any)

        Returns:
            response (dict): A dict that contains a status and a list of
                task ids created (if any).

                Ex: {u'data': {u'status': u'success', u'taskIds': []}}
    '''
    info = '%s Reseting device %s moving it to Undefined' % (app_name,
                                                    device['fqdn'])
    self.log.debug('Attempting to Reset device %s moving it to Undefined'
                   % (device['fqdn']))
    if 'parentContainerId' in device:
        from_id = device['parentContainerId']
    else:
        parent_cont = self.get_parent_container_for_device(device['key'])
        from_id = parent_cont['key']
    data = {'data': [{'info': info,
                      'infoPreview': info,
                      'action': 'reset',
                      'nodeType': 'netelement',
                      'nodeId': device['key'],
                      'toId': 'undefined_container',
                      'fromId': from_id,
                      'nodeName': device['fqdn'],
                      'toName': 'Undefined',
                      'toIdType': 'container',
                      'childTasks': [],
                      'parentTask': ''}]}
    try:
        self._add_temp_action(data)
    # pylint: disable=invalid-name
    except CvpApiError as e:
        if 'Data already exists' in str(e):
            self.log.debug('Device %s already in container Undefined'
                           %device['fqdn'])
    if create_task:
        resp = self._save_topology_v2([])
        return resp