diff --git a/run.py b/run.py index 23601b2..f7fa16e 100644 --- a/run.py +++ b/run.py @@ -905,6 +905,7 @@ def __init__(self, vc_conn): }, } self.vc_tag = format_tag(vc_conn["HOST"]) + self.vrf_id = vc_conn.get("VRF_ID") self.vc = vCenterHandler( format_vcenter_conn(vc_conn), nb_api_version=self.nb_api_version ) @@ -1100,6 +1101,8 @@ def obj_exists(self, nb_obj_type, vc_data): quote_plus(vc_data["virtual_machine"]["name"]), query_key, vc_data[query_key] ) + elif self.vrf_id is not None and nb_obj_type in ("ip_addresses", "prefixes"): + query = "?{}={}&vrf_id={}".format(query_key, vc_data[query_key], self.vrf_id) else: query = "?{}={}".format( query_key, vc_data[query_key] @@ -1516,7 +1519,9 @@ def search_prefix(self, ip_addr): :rtype: dict """ result = {"tenant": None, "vrf": None} - query = "?contains={}".format(ip_addr) + query = ("?contains={}".format(ip_addr) + if self.vrf_id is None + else "?contains={}&vrf_id={}".format(ip_addr, self.vrf_id)) try: prefix_obj = self.request( req_type="get", nb_obj_type="prefixes", query=query diff --git a/settings.example.py b/settings.example.py index 632a657..310705b 100644 --- a/settings.example.py +++ b/settings.example.py @@ -33,7 +33,7 @@ # The USER argument supports SSO with @domain.tld suffix VC_HOSTS = [ # You can add more vCenter instances by duplicating the line below - {"HOST": "vcenter1.example.com", "PORT": 443, "USER": "", "PASS": ""}, + {"HOST": "vcenter1.example.com", "PORT": 443, "USER": "", "PASS": "", "VRF_ID": None}, ]