Skip to content

Commit

Permalink
adds cluster without site relation config bb-Ricardo#301
Browse files Browse the repository at this point in the history
  • Loading branch information
worldworm committed Jul 27, 2023
1 parent b9e236d commit 8f6aa61
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
6 changes: 6 additions & 0 deletions module/netbox/object_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,12 @@ def update(self, data=None, read_from_netbox=False, source=None):
if type_check_failed is True:
continue

# allows an empty site for netbox objects where a site is not mandatory
# required for clusters and sub-objects without site reference
if isinstance(self, (NBCluster, NBVM, NBVLAN)) and key == "site" and "name" in value and value["name"] is None:
parsed_data[key] = None
continue

# this is meant to be reference to a different object
if defined_value_type in NetBoxObject.__subclasses__() and defined_value_type != NBCustomField:

Expand Down
8 changes: 6 additions & 2 deletions module/sources/vmware/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,13 @@ def __init__(self):
address it is important to pick the correct site.
A VM always depends on the cluster site relation
a cluster can be specified as "Cluster-name" or
"Datacenter-name/Cluster-name" if multiple clusters have the same name
"Datacenter-name/Cluster-name" if multiple clusters have the same name.
When a vCenter cluster consists of hosts from multiple NetBox sites,
it is possible to leave the site for a NetBox cluster empty. All VMs from
this cluster will then also have no site reference.
The keyword "<NONE>" can be used as a value for this.
""",
config_example="Cluster_NYC = New York, Cluster_FFM.* = Frankfurt, Datacenter_TOKIO/.* = Tokio"),
config_example="Cluster_NYC = New York, Cluster_FFM.* = Frankfurt, Datacenter_TOKIO/.* = Tokio, Cluster_MultiSite = <NONE>"),
ConfigOption("host_site_relation",
str,
description="""Same as cluster site but on host level.
Expand Down
5 changes: 5 additions & 0 deletions module/sources/vmware/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ def get_site_name(self, object_type, object_name, cluster_name=""):
site_name = self.site_name
log.debug(f"No site relation for '{object_name}' found, using default site '{site_name}'")

# set the site for cluster to None if None-keyword ("<NONE>") is set via cluster_site_relation
if object_type == NBCluster and site_name == "<NONE>":
site_name = None
log.debug2(f"Site relation for '{object_name}' set to None")

return site_name

def get_object_based_on_macs(self, object_type, mac_list=None):
Expand Down
8 changes: 6 additions & 2 deletions settings-example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ password = super-secret
; address it is important to pick the correct site.
; A VM always depends on the cluster site relation
; a cluster can be specified as "Cluster-name" or
; "Datacenter-name/Cluster-name" if multiple clusters have the same name
;cluster_site_relation = Cluster_NYC = New York, Cluster_FFM.* = Frankfurt, Datacenter_TOKIO/.* = Tokio
; "Datacenter-name/Cluster-name" if multiple clusters have the same name.
; When a vCenter cluster consists of hosts from multiple NetBox sites,
; it is possible to leave the site for a NetBox cluster empty. All VMs from
; this cluster will then also have no site reference.
; The keyword "<NONE>" can be used as a value for this.
;cluster_site_relation = Cluster_NYC = New York, Cluster_FFM.* = Frankfurt, Datacenter_TOKIO/.* = Tokio, Cluster_MultiSite = <NONE>

; Same as cluster site but on host level. If unset it will fall back to
; cluster_site_relation
Expand Down

0 comments on commit 8f6aa61

Please sign in to comment.