Skip to content

Commit fc9761a

Browse files
authored
More fixes for devices in DG (#1368)
Problem: Supporting exists was not done. Still allowed for update and patch to be called. Analysis: Added support for the exists method. Removed update and patch because there is nothing reasonable to patch on a device Tests:
1 parent 061c7c1 commit fc9761a

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

f5/bigip/tm/cm/device_group.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from distutils.version import LooseVersion
3131
from f5.bigip.resource import Collection
3232
from f5.bigip.resource import Resource
33+
from f5.sdk_exception import UnsupportedMethod
3334

3435

3536
def fqdn_name(partition, value):
@@ -111,6 +112,23 @@ def __init__(self, devices_s):
111112
self._meta_data['required_json_kind'] =\
112113
'tm:cm:device-group:devices:devicesstate'
113114

115+
def _fixup_name(self, kwargs):
116+
# Name munging is required < 11.6.0 and on versions (and sub versions)
117+
# of 11.6.1.
118+
# TODO(Remove this when 11.6.1 is no longer supported)
119+
if 'name' in kwargs:
120+
kwargs['name'] = fqdn_name('Common', kwargs['name'])
121+
else:
122+
self.__dict__['name'] = fqdn_name('Common', self.__dict__['name'])
123+
124+
def update(self, **kwargs):
125+
raise UnsupportedMethod(
126+
"%s does not support the update method" % self.__class__.__name__)
127+
128+
def modify(self, **kwargs):
129+
raise UnsupportedMethod(
130+
"%s does not support the modify method" % self.__class__.__name__)
131+
114132
def create(self, **kwargs):
115133
# Name munging is required < 11.6.0 and on versions (and sub versions)
116134
# of 11.6.1.
@@ -123,14 +141,12 @@ def create(self, **kwargs):
123141
self._fixup_name(kwargs)
124142
return self._create(**kwargs)
125143

126-
def _fixup_name(self, kwargs):
144+
def exists(self, **kwargs):
127145
# Name munging is required < 11.6.0 and on versions (and sub versions)
128146
# of 11.6.1.
129147
# TODO(Remove this when 11.6.1 is no longer supported)
130-
if 'name' in kwargs:
131-
kwargs['name'] = fqdn_name('Common', kwargs['name'])
132-
else:
133-
self.__dict__['name'] = fqdn_name('Common', self.__dict__['name'])
148+
kwargs['partition'] = 'Common'
149+
return self._exists(**kwargs)
134150

135151
def delete(self, **kwargs):
136152
# Name munging is required < 11.6.0 and on versions (and sub versions)

f5/bigip/tm/cm/test/functional/test_device_group.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def test_device_group_CURDL(self, request, mgmt_root):
5050
dg2 = mgmt_root.tm.cm.device_groups.device_group.load(name=dg1.name)
5151
assert dg1.generation == dg2.generation
5252

53+
# Exists
54+
exists = mgmt_root.tm.cm.device_groups.device_group.exists(name=dg1.name)
55+
assert exists is True
56+
5357
# Update
5458
dg1.update(description=TEST_DESCR)
5559
assert dg1.generation > dg2.generation
@@ -69,6 +73,11 @@ def test_add_device(self, request, mgmt_root):
6973
d1 = dg1.devices_s.devices.create(
7074
name=this_device.name)
7175
assert len(dg1.devices_s.get_collection()) == 1
76+
77+
# Exists
78+
exists = dg1.devices_s.devices.exists(name=this_device.name)
79+
assert exists is True
80+
7281
# This needs to be in this format due to the change between
7382
# 11.6.0 Final and other versions.
7483
assert this_device.name in d1.name

0 commit comments

Comments
 (0)