Skip to content

Commit b288ee3

Browse files
authored
fix(proxmox): add domain name suffix if needed (#533)
1 parent 8de9efd commit b288ee3

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Example configuration can be found [here](#example-config).
9393
| `source.ignoreAssetTags` | Don't sync asset tags of devices. | all | bool | [true, false] | false | No |
9494
| `source.ignoreSerialNumbers` | Don't sync serial numbers of devices. | all | bool | [true, false] | false | No |
9595
| `source.ignoreVMTemplates` | Don't sync vm templates. | [**vmware**,**Proxmox**] | bool | [true, false] | false | No |
96+
| `source.AssignDomainName` | Suffix node name with `AssignDomainName`. | [**proxmox**] | str | any | "" | No |
9697
| `source.datacenterClusterGroupRelations` | Regex relations in format `regex = clusterGroupName`, that map each datacenter that satisfies regex to clusterGroupname. | [**vmware**, **ovirt**] | []string | any | [] | No |
9798
| `source.hostSiteRelations` | Regex relations in format `regex = siteName`, that map each host that satisfies regex to site. | all | []string | any | [] | No |
9899
| `source.clusterSiteRelations` | Regex relations in format `regex = siteName`, that map each cluster that satisfies regex to site. | all | []string | any | [] | No |

internal/parser/parser.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type SourceConfig struct {
132132
IgnoreAssetTags bool `yaml:"ignoreAssetTags"`
133133
IgnoreSerialNumbers bool `yaml:"ignoreSerialNumbers"`
134134
IgnoreVMTemplates bool `yaml:"ignoreVMTemplates"`
135+
AssignDomainName string `yaml:"assignDomainName"`
135136

136137
// Relations
137138
DatacenterClusterGroupRelations map[string]string `yaml:"datacenterClusterGroupRelations"`
@@ -165,6 +166,7 @@ func (sc *SourceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
165166
ValidateCert bool `yaml:"validateCert"`
166167
Tag string `yaml:"tag"`
167168
TagColor string `yaml:"tagColor"`
169+
AssignDomainName string `yaml:"assignDomainName"`
168170
IgnoredSubnets []string `yaml:"ignoredSubnets"`
169171
PermittedSubnets []string `yaml:"permittedSubnets"`
170172
InterfaceFilter string `yaml:"interfaceFilter"`
@@ -203,6 +205,7 @@ func (sc *SourceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
203205
sc.ValidateCert = rawMarshal.ValidateCert
204206
sc.Tag = rawMarshal.Tag
205207
sc.TagColor = rawMarshal.TagColor
208+
sc.AssignDomainName = rawMarshal.AssignDomainName
206209
sc.IgnoredSubnets = rawMarshal.IgnoredSubnets
207210
sc.PermittedSubnets = rawMarshal.PermittedSubnets
208211
sc.InterfaceFilter = rawMarshal.InterfaceFilter
@@ -323,7 +326,7 @@ func (sc SourceConfig) String() string {
323326
return fmt.Sprintf(
324327
"SourceConfig{Name: %s, Type: %s, HTTPScheme: %s, Hostname: %s, Port: %d, "+
325328
"Username: %s, Password: %s, PermittedSubnets: %v, ValidateCert: %t, "+
326-
"Tag: %s, TagColor: %s, DatacenterClusterGroupRelations: %s, "+
329+
"Tag: %s, TagColor: %s, AssignDomainName: %s, DatacenterClusterGroupRelations: %s, "+
327330
"HostSiteRelations: %v, ClusterSiteRelations: %v, ClusterTenantRelations: %v, "+
328331
"HostTenantRelations: %v, VmTenantRelations: %v, VlanGroupRelations: %v, "+
329332
"VlanTenantRelations: %v, WlanTenantRelations: %v}",
@@ -338,6 +341,7 @@ func (sc SourceConfig) String() string {
338341
sc.ValidateCert,
339342
sc.Tag,
340343
sc.TagColor,
344+
sc.AssignDomainName,
341345
sc.DatacenterClusterGroupRelations,
342346
sc.HostSiteRelations,
343347
sc.ClusterSiteRelations,

internal/source/proxmox/proxmox_sync.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ func (ps *ProxmoxSource) syncNodes(nbi *inventory.NetboxInventory) error {
7878
ps.NetboxNodes = make(map[string]*objects.Device, len(ps.Nodes))
7979
for _, node := range ps.Nodes {
8080
var hostSite *objects.Site
81+
82+
// Add domain name suffix if needed
83+
if ps.SourceConfig.AssignDomainName != "" {
84+
node.Name += ps.SourceConfig.AssignDomainName
85+
}
86+
8187
if ps.NetboxCluster.ScopeType == constants.ContentTypeDcimSite {
8288
hostSite = nbi.GetSiteByID(ps.NetboxCluster.ScopeID)
8389
}
@@ -227,6 +233,11 @@ func (ps *ProxmoxSource) syncVMs(nbi *inventory.NetboxInventory) error {
227233
var wg sync.WaitGroup
228234

229235
for nodeName, vms := range ps.Vms {
236+
// Add domain name suffix if needed
237+
if ps.SourceConfig.AssignDomainName != "" {
238+
nodeName += ps.SourceConfig.AssignDomainName
239+
}
240+
230241
nbHost := ps.NetboxNodes[nodeName]
231242
for _, vm := range vms {
232243
guard <- struct{}{} // Block if maxGoroutines are running
@@ -463,6 +474,11 @@ func (ps *ProxmoxSource) syncContainers(nbi *inventory.NetboxInventory) error {
463474
return fmt.Errorf("create container role: %s", err)
464475
}
465476
for nodeName, containers := range ps.Containers {
477+
// Add domain name suffix if needed
478+
if ps.SourceConfig.AssignDomainName != "" {
479+
nodeName += ps.SourceConfig.AssignDomainName
480+
}
481+
466482
nbHost := ps.NetboxNodes[nodeName]
467483
for _, container := range containers {
468484
// Determine Container status

0 commit comments

Comments
 (0)