|
46 | 46 | NB_SITE_GROUPS = "site_groups"
|
47 | 47 | NB_VIRTUAL_CHASSIS = "virtual_chassis"
|
48 | 48 |
|
| 49 | +try: |
| 50 | + from packaging.version import Version |
| 51 | +except ImportError as imp_exc: |
| 52 | + PACKAGING_IMPORT_ERROR = imp_exc |
| 53 | +else: |
| 54 | + PACKAGING_IMPORT_ERROR = None |
| 55 | + |
49 | 56 |
|
50 | 57 | class NetboxDcimModule(NetboxModule):
|
51 | 58 | def __init__(self, module, endpoint):
|
@@ -141,14 +148,24 @@ def run(self):
|
141 | 148 | data["color"] = data["color"].lower()
|
142 | 149 |
|
143 | 150 | if self.endpoint == "cables":
|
144 |
| - cables = [ |
145 |
| - cable |
146 |
| - for cable in nb_endpoint.all() |
147 |
| - if cable.termination_a_type == data["termination_a_type"] |
148 |
| - and cable.termination_a_id == data["termination_a_id"] |
149 |
| - and cable.termination_b_type == data["termination_b_type"] |
150 |
| - and cable.termination_b_id == data["termination_b_id"] |
151 |
| - ] |
| 151 | + if Version(self.full_version) >= Version("3.0.6"): |
| 152 | + cables = [ |
| 153 | + nb_endpoint.get( |
| 154 | + termination_a_type=data["termination_a_type"], |
| 155 | + termination_a_id=data["termination_a_id"], |
| 156 | + termination_b_type=data["termination_b_type"], |
| 157 | + termination_b_id=data["termination_b_id"], |
| 158 | + ) |
| 159 | + ] |
| 160 | + else: |
| 161 | + cables = [ |
| 162 | + cable |
| 163 | + for cable in nb_endpoint.all() |
| 164 | + if cable.termination_a_type == data["termination_a_type"] |
| 165 | + and cable.termination_a_id == data["termination_a_id"] |
| 166 | + and cable.termination_b_type == data["termination_b_type"] |
| 167 | + and cable.termination_b_id == data["termination_b_id"] |
| 168 | + ] |
152 | 169 | if len(cables) == 0:
|
153 | 170 | self.nb_object = None
|
154 | 171 | elif len(cables) == 1:
|
|
0 commit comments