Skip to content

Commit 83fa8f5

Browse files
Paul Breauxzancas
authored andcommitted
Added modify to resource.py in ResourceBase.
1 parent 7c6f2a2 commit 83fa8f5

1 file changed

Lines changed: 45 additions & 8 deletions

File tree

f5/bigip/resource.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,53 @@ def __init__(self, container):
438438
"""
439439
super(ResourceBase, self).__init__(container)
440440

441-
def _update(self, **kwargs):
442-
"""wrapped with update, override that in a subclass to customize"""
441+
def _modify(self, **kwargs):
442+
"""Wrapped with modify, override in a subclass to customize."""
443+
444+
requests_params, patch_uri, session, read_only = \
445+
self._prepare_put_or_patch(kwargs)
446+
self._check_for_boolean_pair_reduction(kwargs)
447+
data_dict = self._pop_read_only_attrs(kwargs, read_only)
448+
data_dict.update(kwargs)
449+
response = session.patch(patch_uri, json=data_dict, **requests_params)
450+
self._local_update(response.json())
451+
452+
def modify(self, **kwargs):
453+
"""Modify the configuration of the resource on device based on kwargs
454+
455+
"""
456+
457+
self._modify(**kwargs)
458+
459+
def _check_for_boolean_pair_reduction(self, kwargs):
460+
"""Check if boolean pairs should be reduced in this resource."""
461+
462+
if 'reduction_forcing_pairs' in self._meta_data:
463+
for key1, key2 in self._meta_data['reduction_forcing_pairs']:
464+
kwargs = self._reduce_boolean_pair(kwargs, key1, key2)
465+
return kwargs
466+
467+
def _prepare_put_or_patch(self, kwargs):
468+
"""Retrieve the appropriate request items for put or patch calls."""
469+
443470
requests_params = self._handle_requests_params(kwargs)
444471
update_uri = self._meta_data['uri']
445472
session = self._meta_data['bigip']._meta_data['icr_session']
446473
read_only = self._meta_data.get('read_only_attributes', [])
474+
return requests_params, update_uri, session, read_only
475+
476+
def _pop_read_only_attrs(self, kwargs, read_only):
477+
"""Remove any read-only attributes from kwargs"""
478+
479+
for attr in read_only:
480+
kwargs.pop(attr, '')
481+
return kwargs
482+
483+
def _update(self, **kwargs):
484+
"""wrapped with update, override that in a subclass to customize"""
485+
486+
requests_params, update_uri, session, read_only = \
487+
self._prepare_put_or_patch(kwargs)
447488

448489
# Get the current state of the object on BIG-IP® and check the
449490
# generation Use pop here because we don't want force in the data_dict
@@ -452,10 +493,7 @@ def _update(self, **kwargs):
452493
# generation has a known server-side error
453494
self._check_generation()
454495

455-
# Reduce any boolean pairs as specified by the meta_data entry below
456-
if 'reduction_forcing_pairs' in self._meta_data:
457-
for key1, key2 in self._meta_data['reduction_forcing_pairs']:
458-
kwargs = self._reduce_boolean_pair(kwargs, key1, key2)
496+
kwargs = self._check_for_boolean_pair_reduction(kwargs)
459497

460498
# Save the meta data so we can add it back into self after we
461499
# load the new object.
@@ -474,8 +512,7 @@ def _update(self, **kwargs):
474512
# the data dict with the attributes. If they pass in read-only attrs
475513
# in the method call we are going to let BIG-IP® let them know about it
476514
# when it fails
477-
for attr in read_only:
478-
data_dict.pop(attr, '')
515+
data_dict = self._pop_read_only_attrs(data_dict, read_only)
479516

480517
data_dict.update(kwargs)
481518

0 commit comments

Comments
 (0)