Skip to content

Commit 0184ddb

Browse files
authored
Adds feature-module API (#1407)
Issues: Fixes #1406 Problem: The feature-module API did not exist. This prevented CGNAT from being provisioned Analysis: This patch adds it Tests: functional
1 parent d12866f commit 0184ddb

3 files changed

Lines changed: 134 additions & 0 deletions

File tree

f5/bigip/tm/sys/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from f5.bigip.tm.sys.db import Dbs
3737
from f5.bigip.tm.sys.dns import Dns
3838
from f5.bigip.tm.sys.failover import Failover
39+
from f5.bigip.tm.sys.feature_module import Feature_Module
3940
from f5.bigip.tm.sys.file import File
4041
from f5.bigip.tm.sys.folder import Folders
4142
from f5.bigip.tm.sys.global_settings import Global_Settings
@@ -71,6 +72,7 @@ def __init__(self, tm):
7172
Dbs,
7273
Dns,
7374
Failover,
75+
Feature_Module,
7476
File,
7577
Folders,
7678
Global_Settings,

f5/bigip/tm/sys/feature_module.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2018 F5 Networks Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
from f5.bigip.mixins import ExclusiveAttributesMixin
19+
from f5.bigip.resource import OrganizingCollection
20+
from f5.bigip.resource import UnnamedResource
21+
from f5.sdk_exception import UnsupportedOperation
22+
23+
24+
class Feature_Module(OrganizingCollection):
25+
def __init__(self, feature_module):
26+
super(Feature_Module, self).__init__(feature_module)
27+
self._meta_data['allowed_lazy_attributes'] = [Cgnat]
28+
self._meta_data['attribute_registry'] = {'tm:sys:feature-module:feature-modulestate': Cgnat}
29+
30+
31+
class Cgnat(UnnamedResource, ExclusiveAttributesMixin):
32+
def __init__(self, feature_module):
33+
super(Cgnat, self).__init__(feature_module)
34+
self._meta_data['required_json_kind'] = 'tm:sys:feature-module:feature-modulestate'
35+
self._meta_data['exclusive_attributes'].append(('enabled', 'disabled'))
36+
37+
def _endis_attrs(self):
38+
if 'disabled' in self.__dict__:
39+
self.__dict__['enabled'] = not self.__dict__['disabled']
40+
if 'enabled' in self.__dict__:
41+
self.__dict__['disabled'] = not self.__dict__['enabled']
42+
return None
43+
44+
def load(self, **kwargs):
45+
kwargs = self._reduce_boolean_pair(kwargs, 'enabled', 'disabled')
46+
newinst = self._stamp_out_core()
47+
newinst._refresh(**kwargs)
48+
newinst._endis_attrs()
49+
return newinst
50+
51+
def refresh(self, **kwargs):
52+
kwargs = self._reduce_boolean_pair(kwargs, 'enabled', 'disabled')
53+
self._refresh(**kwargs)
54+
self._endis_attrs()
55+
return self
56+
57+
def update(self, **kwargs):
58+
if 'enabled' in kwargs or 'disabled' in kwargs:
59+
self.__dict__.pop('enabled')
60+
self.__dict__.pop('disabled')
61+
self._update(**kwargs)
62+
self._endis_attrs()
63+
64+
def modify(self, **kwargs):
65+
if 'enabled' in kwargs or 'disabled' in kwargs:
66+
self.__dict__.pop('enabled')
67+
self.__dict__.pop('disabled')
68+
self._modify(**kwargs)
69+
self._endis_attrs()
70+
71+
def create(self, **kwargs):
72+
'''Create is not supported for db resources.
73+
74+
:raises: UnsupportedOperation
75+
'''
76+
raise UnsupportedOperation(
77+
"Resource doesn't support create."
78+
)
79+
80+
def delete(self, **kwargs):
81+
'''Delete is not supported for db resources.
82+
83+
:raises: UnsupportedOperation
84+
'''
85+
raise UnsupportedOperation(
86+
"Resource doesn't support delete."
87+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2018 F5 Networks Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import pytest
17+
18+
19+
@pytest.fixture
20+
def cgnat1(mgmt_root):
21+
resource = mgmt_root.tm.sys.feature_module.cgnat.load()
22+
yield resource
23+
resource.update(enabled=True)
24+
25+
26+
@pytest.fixture
27+
def cgnat2(mgmt_root):
28+
resource = mgmt_root.tm.sys.feature_module.cgnat.load()
29+
yield resource
30+
31+
32+
class TestFeatureModule(object):
33+
34+
def test_RUL(self, cgnat1, cgnat2):
35+
assert cgnat1.disabled == cgnat2.disabled
36+
assert cgnat1.enabled is True
37+
38+
# Update
39+
cgnat1.update(disabled=True)
40+
assert cgnat1.disabled is True
41+
assert cgnat1.disabled != cgnat2.disabled
42+
43+
# Refresh
44+
cgnat2.refresh()
45+
assert cgnat1.disabled == cgnat2.disabled

0 commit comments

Comments
 (0)