|
171 | 171 | - status
|
172 | 172 | - time_zone
|
173 | 173 | - utc_offset
|
| 174 | + - facility |
174 | 175 | default: []
|
175 | 176 | group_names_raw:
|
176 | 177 | description: Will not add the group_by choice name to the group names
|
@@ -543,6 +544,7 @@ def group_extractors(self):
|
543 | 544 | "asset_tag": self.extract_asset_tag,
|
544 | 545 | "time_zone": self.extract_site_time_zone,
|
545 | 546 | "utc_offset": self.extract_site_utc_offset,
|
| 547 | + "facility": self.extract_site_facility, |
546 | 548 | self._pluralize_group_by("site"): self.extract_site,
|
547 | 549 | self._pluralize_group_by("tenant"): self.extract_tenant,
|
548 | 550 | self._pluralize_group_by("tag"): self.extract_tags,
|
@@ -763,6 +765,12 @@ def extract_site_utc_offset(self, host):
|
763 | 765 | except Exception:
|
764 | 766 | return
|
765 | 767 |
|
| 768 | + def extract_site_facility(self, host): |
| 769 | + try: |
| 770 | + return self.sites_facility_lookup[host["site"]["id"]] |
| 771 | + except Exception: |
| 772 | + return |
| 773 | + |
766 | 774 | def extract_config_context(self, host):
|
767 | 775 | try:
|
768 | 776 | if self.flatten_config_context:
|
@@ -1062,6 +1070,17 @@ def get_utc_offset_for_site(site):
|
1062 | 1070 | if "utc_offset" in self.group_by:
|
1063 | 1071 | self.sites_utc_offset_lookup = dict(map(get_utc_offset_for_site, sites))
|
1064 | 1072 |
|
| 1073 | + def get_facility_for_site(site): |
| 1074 | + # Will fail if site does not have a facility defined in NetBox |
| 1075 | + try: |
| 1076 | + return (site["id"], site["facility"]) |
| 1077 | + except Exception: |
| 1078 | + return (site["id"], None) |
| 1079 | + |
| 1080 | + # Dictionary of site id to facility (if group by facility is used) |
| 1081 | + if "facility" in self.group_by: |
| 1082 | + self.sites_facility_lookup = dict(map(get_facility_for_site, sites)) |
| 1083 | + |
1065 | 1084 | # Note: depends on the result of refresh_sites_lookup for self.sites_with_prefixes
|
1066 | 1085 | def refresh_prefixes(self):
|
1067 | 1086 | # Pull all prefixes defined in NetBox
|
|
0 commit comments