Skip to content

Commit db5086d

Browse files
authored
Merge pull request #1493 from cernymi/cernymi/api_verson
Rename variables 'version' to 'api_version' and 'full_version' to 'netbox_version'
2 parents 56a65f8 + 86f2b7f commit db5086d

File tree

8 files changed

+47
-31
lines changed

8 files changed

+47
-31
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- rename variable version to api_version.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- rename variable full_version to netbox_version.

docs/getting_started/contributing/modules/architecture.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ We set several instance attributes that are used within other methods throughout
292292
else:
293293
self.nb = nb_client
294294
try:
295-
self.version = self.nb.version
295+
self.api_version = self.nb.version
296296
except AttributeError:
297297
self.module.fail_json(msg="Must have pynetbox >=4.1.0")
298298

plugins/module_utils/netbox_dcim.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ def run(self):
114114

115115
# Handle rack and form_factor
116116
if endpoint_name == "rack":
117-
if self._version_check_greater(self.version, "4.1", greater_or_equal=True):
117+
if self._version_check_greater(
118+
self.api_version, "4.1", greater_or_equal=True
119+
):
118120
if "type" in data:
119121
data["form_factor"] = self._to_slug(data["type"])
120122
del data["type"]
@@ -193,7 +195,9 @@ def run(self):
193195
data["color"] = data["color"].lower()
194196

195197
if self.endpoint == "cables":
196-
if self._version_check_greater(self.version, "3.0", greater_or_equal=True):
198+
if self._version_check_greater(
199+
self.api_version, "3.0", greater_or_equal=True
200+
):
197201
cables = [
198202
nb_endpoint.get(
199203
termination_a_type=data["termination_a_type"],
@@ -222,7 +226,9 @@ def run(self):
222226
else:
223227
self._handle_errors(msg="More than one result returned for %s" % (name))
224228

225-
if self._version_check_greater(self.version, "3.3", greater_or_equal=True):
229+
if self._version_check_greater(
230+
self.api_version, "3.3", greater_or_equal=True
231+
):
226232
data["a_terminations"] = [
227233
{
228234
"object_id": data.pop("termination_a_id"),

plugins/module_utils/netbox_ipam.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def _ensure_ip_in_prefix_present_on_netif(
6262
"parent": data["prefix"],
6363
}
6464

65-
if not self._version_check_greater(self.version, "2.9", greater_or_equal=True):
65+
if not self._version_check_greater(
66+
self.api_version, "2.9", greater_or_equal=True
67+
):
6668
if not data.get("interface") or not data.get("prefix"):
6769
self._handle_errors("A prefix and interface is required")
6870
data_intf_key = "interface"
@@ -217,7 +219,7 @@ def run(self):
217219
data["slug"] = self._to_slug(name)
218220

219221
if self.endpoint == "services" and self._version_check_greater(
220-
self.version, "4.3", greater_or_equal=True
222+
self.api_version, "4.3", greater_or_equal=True
221223
):
222224
if "device" in data:
223225
data["parent_object_type"] = "dcim.device"

plugins/module_utils/netbox_tenancy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ def run(self):
112112
if self.endpoint == NB_CONTACTS:
113113
if data.get("groups"):
114114
if not self._version_check_greater(
115-
self.version, "4.3", greater_or_equal=True
115+
self.api_version, "4.3", greater_or_equal=True
116116
):
117117
raise Exception(
118-
f"contact_groups is not available in Netbox {self.version}. Use contact_group instead, or upgrade to Netbox 4.3 or greater."
118+
f"contact_groups is not available in Netbox {self.api_version}. Use contact_group instead, or upgrade to Netbox 4.3 or greater."
119119
)
120120
if data.get("group"):
121121
if self._version_check_greater(
122-
self.version, "4.3", greater_or_equal=True
122+
self.api_version, "4.3", greater_or_equal=True
123123
):
124124
raise Exception(
125-
f"contact_group is not available in Netbox {self.version}. Use contact_groups instead."
125+
f"contact_group is not available in Netbox {self.api_version}. Use contact_groups instead."
126126
)
127127

128128
# For ease and consistency of use, the contact assignment module takes the name of the contact, role, and target object rather than an ID or slug.

plugins/module_utils/netbox_utils.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -781,14 +781,14 @@ def __init__(self, module, endpoint, nb_client=None):
781781
else:
782782
self.nb = nb_client
783783
try:
784-
self.version = self._version_sanitize(self.nb.version)
784+
self.api_version = self._version_sanitize(self.nb.version)
785785
try:
786-
self.full_version = self._version_sanitize(
786+
self.netbox_version = self._version_sanitize(
787787
self.nb.status().get("netbox-version")
788788
)
789789
except Exception:
790790
# For NetBox versions without /api/status endpoint
791-
self.full_version = f"{self.version}.0"
791+
self.netbox_version = f"{self.api_version}.0"
792792
except AttributeError:
793793
self.module.fail_json(msg="Must have pynetbox >=4.1.0")
794794

@@ -850,14 +850,14 @@ def _connect_netbox_api(self, url, token, ssl_verify, cert, headers=None):
850850
nb = pynetbox.api(url, token=token)
851851
nb.http_session = session
852852
try:
853-
self.version = self._version_sanitize(nb.version)
853+
self.api_version = self._version_sanitize(nb.version)
854854
try:
855-
self.full_version = self._version_sanitize(
855+
self.netbox_version = self._version_sanitize(
856856
nb.status().get("netbox-version")
857857
)
858858
except Exception:
859859
# For NetBox versions without /api/status endpoint
860-
self.full_version = f"{self.version}.0"
860+
self.netbox_version = f"{self.api_version}.0"
861861
except AttributeError:
862862
self.module.fail_json(msg="Must have pynetbox >=4.1.0")
863863
except Exception:
@@ -941,7 +941,7 @@ def _convert_identical_keys(self, data):
941941
:params data (dict): Data dictionary after _find_ids method ran
942942
"""
943943
temp_dict = dict()
944-
if self._version_check_greater(self.version, "2.7", greater_or_equal=True):
944+
if self._version_check_greater(self.api_version, "2.7", greater_or_equal=True):
945945
if data.get("form_factor"):
946946
temp_dict["type"] = data.pop("form_factor")
947947

@@ -950,7 +950,7 @@ def _convert_identical_keys(self, data):
950950
temp_dict[key] = data[key]
951951
# TODO: Remove this once the lowest supported Netbox version is 3.6 or greater as we can use default logic of CONVERT_KEYS moving forward.
952952
elif key == "device_role" and not self._version_check_greater(
953-
self.version, "3.6", greater_or_equal=True
953+
self.api_version, "3.6", greater_or_equal=True
954954
):
955955
temp_dict[key] = data[key]
956956
elif key in CONVERT_KEYS:
@@ -1043,7 +1043,7 @@ def _build_query_params(
10431043
parent == "interface"
10441044
and "device" in module_data
10451045
and self._version_check_greater(
1046-
self.version, "3.6", greater_or_equal=True
1046+
self.api_version, "3.6", greater_or_equal=True
10471047
)
10481048
):
10491049
query_dict.update(
@@ -1130,7 +1130,7 @@ def _build_query_params(
11301130
elif parent == "rear_port_template" and self.endpoint == "front_port_templates":
11311131
if isinstance(module_data.get("rear_port_template"), str):
11321132
if self._version_check_greater(
1133-
self.version, "4.0", greater_or_equal=True
1133+
self.api_version, "4.0", greater_or_equal=True
11341134
):
11351135
rear_port_template = {
11361136
"device_type_id": module_data.get("device_type"),
@@ -1157,7 +1157,7 @@ def _build_query_params(
11571157
):
11581158
if isinstance(module_data.get("power_port_template"), str):
11591159
if self._version_check_greater(
1160-
self.version, "4.0", greater_or_equal=True
1160+
self.api_version, "4.0", greater_or_equal=True
11611161
):
11621162
power_port_template = {
11631163
"device_type_id": module_data.get("device_type"),
@@ -1192,7 +1192,7 @@ def _build_query_params(
11921192
elif "_template" in parent:
11931193
if query_dict.get("device_type"):
11941194
if self._version_check_greater(
1195-
self.version, "4.0", greater_or_equal=True
1195+
self.api_version, "4.0", greater_or_equal=True
11961196
):
11971197
query_dict["device_type_id"] = query_dict.pop("device_type")
11981198
else:
@@ -1202,8 +1202,8 @@ def _build_query_params(
12021202
# Netbox 4.3.0 - 4.4.3 is removed
12031203
elif parent == "services":
12041204
if self._version_check_greater(
1205-
self.version, "4.3", greater_or_equal=True
1206-
) and self._version_check_greater("4.4.4", self.full_version):
1205+
self.api_version, "4.3", greater_or_equal=True
1206+
) and self._version_check_greater("4.4.4", self.netbox_version):
12071207
query_dict.pop("parent_object_id", None)
12081208
query_dict.pop("parent_object_type", None)
12091209

@@ -1277,13 +1277,15 @@ def _find_app(self, endpoint):
12771277
if endpoint in v.keys():
12781278
if "introduced" in v[endpoint]:
12791279
pre_introduction = self._version_check_greater(
1280-
v[endpoint]["introduced"], self.version
1280+
v[endpoint]["introduced"], self.api_version
12811281
)
12821282
if pre_introduction:
12831283
continue
12841284
if "deprecated" in v[endpoint]:
12851285
after_deprecation = self._version_check_greater(
1286-
self.version, v[endpoint]["deprecated"], greater_or_equal=True
1286+
self.api_version,
1287+
v[endpoint]["deprecated"],
1288+
greater_or_equal=True,
12871289
)
12881290
if after_deprecation:
12891291
continue
@@ -1303,7 +1305,7 @@ def _find_ids(self, data, user_query_params):
13031305
if k in CONVERT_TO_ID:
13041306
if (
13051307
not self._version_check_greater(
1306-
self.version, "2.9", greater_or_equal=True
1308+
self.api_version, "2.9", greater_or_equal=True
13071309
)
13081310
and k == "tags"
13091311
) or (self.endpoint == "config_contexts" and k == "tags"):
@@ -1527,7 +1529,7 @@ def _update_netbox_object(self, data):
15271529
updated_obj["tags"] = set(data["tags"])
15281530

15291531
# Ensure idempotency for site on older netbox versions
1530-
version_pre_30 = self._version_check_greater("3.0", self.version)
1532+
version_pre_30 = self._version_check_greater("3.0", self.api_version)
15311533
if (
15321534
serialized_nb_obj.get("latitude")
15331535
and data.get("latitude")
@@ -1542,15 +1544,15 @@ def _update_netbox_object(self, data):
15421544
updated_obj["longitude"] = str(data["longitude"])
15431545

15441546
# Ensure idempotency for virtual machine on older netbox versions
1545-
version_pre_211 = self._version_check_greater("2.11", self.version)
1547+
version_pre_211 = self._version_check_greater("2.11", self.api_version)
15461548
if serialized_nb_obj.get("vcpus") and data.get("vcpus"):
15471549
if version_pre_211:
15481550
updated_obj["vcpus"] = int(data["vcpus"])
15491551
else:
15501552
updated_obj["vcpus"] = float(data["vcpus"])
15511553

15521554
# Ensure idempotency for cable on netbox versions later than 3.3
1553-
version_post_33 = self._version_check_greater(self.version, "3.3", True)
1555+
version_post_33 = self._version_check_greater(self.api_version, "3.3", True)
15541556
if (
15551557
serialized_nb_obj.get("a_terminations")
15561558
and serialized_nb_obj.get("b_terminations")

plugins/modules/netbox_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def main():
179179

180180
# Change port to ports for 2.10+ and convert to a list with the single integer
181181
if netbox_service.data.get("port") and netbox_service._version_check_greater(
182-
netbox_service.version, "2.10", greater_or_equal=True
182+
netbox_service.api_version, "2.10", greater_or_equal=True
183183
):
184184
netbox_service.data["ports"] = [netbox_service.data.pop("port")]
185185

0 commit comments

Comments
 (0)