Skip to content

Commit c292f09

Browse files
authored
Support managing local licenses on an edge filer (#117)
1 parent 4a22502 commit c292f09

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

cterasdk/edge/licenses.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77

88
class Licenses(BaseCommand):
9-
""" Gateway License configuration APIs """
9+
""" Edge Filer License Configuration APIs """
10+
11+
def __init__(self, gateway):
12+
super().__init__(gateway)
13+
self.local = LocalLicenses(self._gateway)
1014

1115
@staticmethod
1216
def infer(ctera_license):
@@ -22,7 +26,7 @@ def apply(self, ctera_license):
2226
"""
2327
Apply a license
2428
25-
:param str ctera_license
29+
:param cterasdk.edge.enum.License ctera_license: License type
2630
"""
2731
inferred_license = Licenses.infer(ctera_license)
2832

@@ -42,3 +46,30 @@ def get(self):
4246
if len(inferred_license) == 8:
4347
inferred_license = inferred_license + '16'
4448
return 'EV' + inferred_license[8:]
49+
50+
51+
class LocalLicenses(BaseCommand):
52+
""" Edge Filer Local License Configuration APIs """
53+
54+
def get(self):
55+
"""
56+
Retrieve a list of local licenses installed
57+
"""
58+
return self._gateway.get('/config/device/licenses')
59+
60+
def add(self, code):
61+
"""
62+
Install a local license. Use this option when running the Edge Filer as a standalone appliance.
63+
64+
:param str code: License code
65+
"""
66+
logging.getLogger().info('Installing license. %s', {'code': code})
67+
response = self._gateway.add('/config/device/licenses', code)
68+
logging.getLogger().info("License added. %s", {'code': code})
69+
return response
70+
71+
def clear(self):
72+
"""
73+
Remove all local licenses
74+
"""
75+
self._gateway.put('/config/device/licenses', [])

tests/ut/test_edge_licenses.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
class TestEdgeLicenses(base_edge.BaseEdgeTest):
1010

11+
def setUp(self):
12+
super().setUp()
13+
self._local_license = 'MA645-83CDC-50127-CE61B-V64'
14+
1115
def test_edge_get_active_licenses(self):
1216
actual_licenses = ['NA', 'vGateway8', 'vGateway', 'vGateway32', 'vGateway64', 'vGateway128']
1317
expected_licenses = ['NA', 'EV8', 'EV16', 'EV32', 'EV64', 'EV128']
@@ -32,3 +36,22 @@ def test_apply_license_raise_input_error(self):
3236
with self.assertRaises(exception.InputError) as error:
3337
licenses.Licenses(self._filer).apply('Expected Failure')
3438
self.assertEqual('Invalid license type', error.exception.message)
39+
40+
def test_get_local_license(self):
41+
get_response = [self._local_license]
42+
self._init_filer(get_response=get_response)
43+
ret = licenses.Licenses(self._filer).local.get()
44+
self._filer.get.assert_called_once_with('/config/device/licenses')
45+
self.assertEqual(ret, get_response)
46+
47+
def test_apply_local_license(self):
48+
add_response = 'Success'
49+
self._init_filer(add_response=add_response)
50+
ret = licenses.Licenses(self._filer).local.add(self._local_license)
51+
self._filer.add.assert_called_once_with('/config/device/licenses', self._local_license)
52+
self.assertEqual(ret, add_response)
53+
54+
def test_clear_local_license(self):
55+
self._init_filer()
56+
licenses.Licenses(self._filer).local.clear()
57+
self._filer.put.assert_called_once_with('/config/device/licenses', [])

0 commit comments

Comments
 (0)