Skip to content

Commit 04101a9

Browse files
bl4koclaude
andcommitted
feat: add ignoreTags and ignoreVMDisks config flags
- ignoreTags: skip syncing tags from source to NetBox (vmware) - ignoreVMDisks: skip syncing virtual disks (vmware, ovirt, proxmox) Both default to false for backward compatibility. Closes #626 Closes #627 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e380842 commit 04101a9

6 files changed

Lines changed: 29 additions & 12 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ Example configuration can be found [here](#example-config).
139139
| `source.ignoreAssetTags` | Don't sync asset tags of devices. | all | bool | [true, false] | false | No |
140140
| `source.ignoreSerialNumbers` | Don't sync serial numbers of devices. | all | bool | [true, false] | false | No |
141141
| `source.ignoreVMTemplates` | Don't sync vm templates. | [**vmware**, **proxmox**] | bool | [true, false] | false | No |
142+
| `source.ignoreVMDisks` | Don't sync virtual disks. | [**vmware**, **ovirt**, **proxmox**] | bool | [true, false] | false | No |
143+
| `source.ignoreTags` | Don't sync tags from source to NetBox. | [**vmware**] | bool | [true, false] | false | No |
142144
| `source.AssignDomainName` | Suffix node name with `AssignDomainName`. | [**proxmox**] | str | any | "" | No |
143145
| `source.vlanPrefix` | Prefix vlan name with `vlanPrefix`. | [**vmware**] | str | any | "" | No |
144146
| `source.datacenterClusterGroupRelations` | Regex relations in format `regex = clusterGroupName`, that map each datacenter that satisfies regex to clusterGroupname. | [**vmware**, **ovirt**] | []string | any | [] | No |

internal/parser/parser.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ type SourceConfig struct {
132132
IgnoreAssetTags bool `yaml:"ignoreAssetTags"`
133133
IgnoreSerialNumbers bool `yaml:"ignoreSerialNumbers"`
134134
IgnoreVMTemplates bool `yaml:"ignoreVMTemplates"`
135+
IgnoreVMDisks bool `yaml:"ignoreVMDisks"`
136+
IgnoreTags bool `yaml:"ignoreTags"`
135137
AssignDomainName string `yaml:"assignDomainName"`
136138
ContinueOnError bool `yaml:"continueOnError"`
137139
VlanPrefix string `yaml:"vlanPrefix"`
@@ -182,6 +184,8 @@ func (sc *SourceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
182184
IgnoreSerialNumbers bool `yaml:"ignoreSerialNumbers"`
183185
IgnoreAssetTags bool `yaml:"ignoreAssetTags"`
184186
IgnoreVMTemplates bool `yaml:"ignoreVMTemplates"`
187+
IgnoreVMDisks bool `yaml:"ignoreVMDisks"`
188+
IgnoreTags bool `yaml:"ignoreTags"`
185189
ContinueOnError bool `yaml:"continueOnError"`
186190
DefaultIPv4MaskBits int `yaml:"defaultIPv4MaskBits"`
187191
DefaultIPv6MaskBits int `yaml:"defaultIPv6MaskBits"`
@@ -227,6 +231,8 @@ func (sc *SourceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
227231
sc.IgnoreSerialNumbers = rawMarshal.IgnoreSerialNumbers
228232
sc.IgnoreAssetTags = rawMarshal.IgnoreAssetTags
229233
sc.IgnoreVMTemplates = rawMarshal.IgnoreVMTemplates
234+
sc.IgnoreVMDisks = rawMarshal.IgnoreVMDisks
235+
sc.IgnoreTags = rawMarshal.IgnoreTags
230236
sc.ContinueOnError = rawMarshal.ContinueOnError
231237
sc.DefaultIPv4MaskBits = rawMarshal.DefaultIPv4MaskBits
232238
sc.DefaultIPv6MaskBits = rawMarshal.DefaultIPv6MaskBits

internal/source/ovirt/ovirt_sync.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,11 @@ func (o *OVirtSource) syncVM(
10861086
return fmt.Errorf("failed to sync oVirt vm %s: %v", collectedVM.Name, err)
10871087
}
10881088

1089-
err = o.syncVMDisks(nbi, collectedVMDisks, nbVM)
1090-
if err != nil {
1091-
return fmt.Errorf("failed to sync oVirt vm %s's disks: %v", collectedVM.Name, err)
1089+
if !o.SourceConfig.IgnoreVMDisks {
1090+
err = o.syncVMDisks(nbi, collectedVMDisks, nbVM)
1091+
if err != nil {
1092+
return fmt.Errorf("failed to sync oVirt vm %s's disks: %v", collectedVM.Name, err)
1093+
}
10921094
}
10931095

10941096
err = o.syncVMInterfaces(nbi, ovirtVM, nbVM)

internal/source/proxmox/proxmox_sync.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,11 @@ func (ps *ProxmoxSource) syncVM( //nolint:gocyclo
631631
}
632632

633633
// Sync VM disks
634-
err = ps.syncVMDisks(nbi, nbVM, vmDisks)
635-
if err != nil {
636-
return fmt.Errorf("failed to sync vm's %+v disks: %s", nbVM, err)
634+
if !ps.SourceConfig.IgnoreVMDisks {
635+
err = ps.syncVMDisks(nbi, nbVM, vmDisks)
636+
if err != nil {
637+
return fmt.Errorf("failed to sync vm's %+v disks: %s", nbVM, err)
638+
}
637639
}
638640

639641
return nil

internal/source/vmware/vmware.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,17 @@ func (vc *VmwareSource) Init() error {
228228

229229
// Function that syncs all data from oVirt to Netbox.
230230
func (vc *VmwareSource) Sync(nbi *inventory.NetboxInventory) error {
231-
syncFunctions := []func(*inventory.NetboxInventory) error{
232-
vc.syncTags,
231+
syncFunctions := []func(*inventory.NetboxInventory) error{}
232+
if !vc.SourceConfig.IgnoreTags {
233+
syncFunctions = append(syncFunctions, vc.syncTags)
234+
}
235+
syncFunctions = append(syncFunctions,
233236
vc.syncNetworks,
234237
vc.syncDatacenters,
235238
vc.syncClusters,
236239
vc.syncHosts,
237240
vc.syncVMs,
238-
}
241+
)
239242
var encounteredErrors []error
240243
for _, syncFunc := range syncFunctions {
241244
startTime := time.Now()

internal/source/vmware/vmware_sync.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,9 +1238,11 @@ func (vc *VmwareSource) syncVM(
12381238
}
12391239

12401240
// Sync vm disks
1241-
err := vc.syncVMDisks(nbi, newVM, vmDisks)
1242-
if err != nil {
1243-
return fmt.Errorf("failed to sync vm's %+v disks: %s", newVM, err)
1241+
if !vc.SourceConfig.IgnoreVMDisks {
1242+
err := vc.syncVMDisks(nbi, newVM, vmDisks)
1243+
if err != nil {
1244+
return fmt.Errorf("failed to sync vm's %+v disks: %s", newVM, err)
1245+
}
12441246
}
12451247
}
12461248
return nil

0 commit comments

Comments
 (0)