Allow Netbox device modification (#53631)

* netbox_device: Allow device modification

* Add ability to update and existing device
* Allow check_mode
* Fail when device name is missing
* Fail when cannot resolve ID instead of taking ID 1 by default

* netbox_device: Add diff output

* netbox: Some refactoring

* Add diff output and check_mode to netbox_ip_address
* Deduplicate redundant code into netbox_utils

* netbox_utils: A few unit tests
This commit is contained in:
Bruno Inec 2019-04-07 12:17:11 +02:00 committed by Nilashish Chakraborty
parent a4c42ba687
commit c637104078
4 changed files with 248 additions and 55 deletions

View file

@ -237,7 +237,7 @@ def update_netbox_object(nb_obj, data, check_mode):
if not check_mode:
nb_obj.update(data)
udpated_obj = nb_obj.serialize()
updated_obj = nb_obj.serialize()
diff = _build_diff(before=data_before, after=data_after)
return updated_obj, diff
@ -312,7 +312,7 @@ def find_ids(nb, data):
try:
query_id = nb_endpoint.get(**{QUERY_TYPES.get(k, "q"): search})
except ValueError:
return ValueError(
raise ValueError(
"Multiple results found while searching for key: %s" % (k)
)
@ -320,6 +320,8 @@ def find_ids(nb, data):
data[k] = id_list
elif query_id:
data[k] = query_id.id
elif k in NO_DEFAULT_ID:
pass
else:
raise ValueError("Could not resolve id of %s: %s" % (k, v))