openwisp-controller icon indicating copy to clipboard operation
openwisp-controller copied to clipboard

[feature] Add support for inherited variables in DeviceDetialView #818

Open dee077 opened this issue 7 months ago • 1 comments

Expose inherited variables (from templates, groups, and global) in API response via optional query param.

Fixes #818

Checklist

  • [x] I have read the OpenWISP Contributing Guidelines.
  • [x] I have manually tested the changes proposed in this pull request.
  • [x] I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • [ ] I have updated the documentation.

Reference to Existing Issue

Closes #818.

Description of Changes

  • Added a parameter inherited_variables to the DeviceDetailView to optionally include the inherited variables field from related objects.
    1. Config
    2. Group
    3. Templates
    4. Global (not sure the added one is correct)
  • Not sure if the add way of serializing the object is the correct way.

Sample response

{
  'id': '8237003b-ecb9-46f0-80cf-bb3f5c407afb',
  'name': 'default.test.device',
  'organization': 'f5e0b4e0-629f-47c8-8115-6ffaf89cd54c',
  'group': '2132c6b5-e85d-4d6a-bb3e-a9c6ba744dc3',
  'mac_address': '00:11:22:33:44:55',
  'key': 'XxtYUJsxaGAZAl7KuIE7lnFnKluUzshG',
  'last_ip': None,
  'management_ip': None,
  'is_deactivated': False,
  'model': 'TP-Link TL-WDR4300 v1',
  'os': 'LEDE Reboot 17.01-SNAPSHOT r3313-c2999ef',
  'system': '',
  'notes': '',
  'config': {
    'status': 'modified',
    'error_reason': '',
    'backend': 'netjsonconfig.OpenWrt',
    'templates': ['9ad08f5e-ca41-4f84-be38-523bca731989'],
    'context': {},
    'config': {
      'general': {}
    }
  },
  'created': '2025-05-07T13:31:03.711252+02:00',
  'modified': '2025-05-07T13:31:03.711252+02:00',
  
  // Newly added field
  
  'inherited_variables': {
    'global': {
      'vpnserver1': 'vpn.testdomain.com'
    },
    'group': {
      'id': '2132c6b5-e85d-4d6a-bb3e-a9c6ba744dc3',
      'name': 'Routers',
      'organization': 'f5e0b4e0-629f-47c8-8115-6ffaf89cd54c',
      'description': 'Group for all routers',
      'templates': [],
      'context': {},
      'meta_data': {},
      'created': '2025-05-07T13:31:03.708412+02:00',
      'modified': '2025-05-07T13:31:03.708412+02:00'
    },
    'config': {
      'status': 'modified',
      'error_reason': '',
      'backend': 'netjsonconfig.OpenWrt',
      'templates': ['9ad08f5e-ca41-4f84-be38-523bca731989'],
      'context': {},
      'config': {
        'general': {}
      }
    },
    'templates': [
      {
        'id': '9ad08f5e-ca41-4f84-be38-523bca731989',
        'name': 'test-template',
        'organization': 'f5e0b4e0-629f-47c8-8115-6ffaf89cd54c',
        'type': 'generic',
        'backend': 'netjsonconfig.OpenWrt',
        'vpn': None,
        'tags': [],
        'default': False,
        'required': False,
        'default_values': {},
        'config': {
          'interfaces': [
            {
              'name': 'eth0',
              'type': 'ethernet'
            }
          ]
        },
        'created': '2025-05-07T13:31:03.736374+02:00',
        'modified': '2025-05-07T13:31:03.736374+02:00'
      }
    ]
  }
}

dee077 avatar May 07 '25 11:05 dee077

Coverage Status

coverage: 98.825% (+0.001%) from 98.824% when pulling 86996bf0c6ada358d2e26d560174dcb64820f288 on dee077:issues/818-show-inherited-vars into f8e721fb126d6e0885f69d89c4e232fde4c9ea39 on openwisp:master.

coveralls avatar May 07 '25 11:05 coveralls

Closing this for now.

nemesifier avatar Aug 25 '25 19:08 nemesifier