Skip to content

Commit a33589d

Browse files
committed
fix(vmware,ovirt): fixes #130
1 parent df3fd6d commit a33589d

File tree

9 files changed

+105
-57
lines changed

9 files changed

+105
-57
lines changed

README.md

+24-23
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,30 @@ Example configuration can be found [here](#example-config).
6464

6565
### Source
6666

67-
| Parameter | Description | Source Type | Type | Possible values | Default | Required |
68-
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------ | --------------- | -------- | ---------------------------------------- | ---------- | -------- |
69-
| `source.name` | Name of the data source. | all | str | any | "" | Yes |
70-
| `source.type` | Type of the data source. | all | str | [ovirt, vmware, dnac, proxmox, paloalto] | "" | Yes |
71-
| `source.httpScheme` | Http scheme for the source | all | str | [ http,https] | https | No |
72-
| `source.hostname` | Hostname of the data source. | all | str | any | "" | Yes |
73-
| `source.port` | Port of the data source. | all | int | 0-65536 | 443 | No |
74-
| `source.username` | Username of the data source account. | all | str | any | "" | Yes |
75-
| `source.password` | Password of the data source account. | all | str | any | "" | Yes |
76-
| `source.apiToken` | Password of the data source account. | [**fortigate**] | str | any | "" | Yes |
77-
| `source.validateCert` | Enforce TLS certificate validation. | all | bool | [true, false] | false | No |
78-
| `source.tagColor` | TagColor for the source tag. | all | string | any | Predefined | No |
79-
| `source.ignoredSubnets` | List of subnets, which will be ignored (e.g. IPs won't be synced). | all | []string | any | [] | No |
80-
| `source.interfaceFilter` | Regex representation of interface names to be ignored (e.g. `(cali\|vxlan\|flannel\|[a-f0-9]{15})`) | all | string | any | [] | No |
81-
| `source.collectArpData` | Collect data from the arp table of the device. | [**paloalto**] | bool | [true, false] | false | No |
82-
| `source.hostSiteRelations` | Regex relations in format `regex = siteName`, that map each host that satisfies regex to site. | all | []string | any | [] | No |
83-
| `source.clusterSiteRelations` | Regex relations in format `regex = siteName`, that map each cluster that satisfies regex to site. | all | []string | any | [] | No |
84-
| `source.clusterTenantRelations` | Regex relations in format `regex = tenantName`, that map each cluster that satisfies regex to tenant. | all | []string | any | [] | No |
85-
| `source.hostTenantRelations` | Regex relations in format `regex = tenantName`, that map each host that satisfies regex to tenant. | all | []string | any | [] | No |
86-
| `source.vmTenantRelations` | Regex relations in format `regex = tenantName`, that map each vm that satisfies regex to tenant. | all | []string | any | [] | No |
87-
| `source.vlanGroupRelations` | Regex relations in format `regex = vlanGroup`, that map each vlan that satisfies regex to vlanGroup. | all | []string | any | [] | No |
88-
| `source.vlanTenantRelations` | Regex relations in format `regex = tenantName`, that map each vlan that satisfies regex to tenant. | all | []string | any | [] | No |
89-
| `source.customFieldMappings` | Mappings of format `customFieldName = option`. Currently, supported options are `contact`, `owner`, `description`. | [**vmware**] | []string | any | [] | No |
67+
| Parameter | Description | Source Type | Type | Possible values | Default | Required |
68+
| ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- | -------- | ---------------------------------------- | ---------- | -------- |
69+
| `source.name` | Name of the data source. | all | str | any | "" | Yes |
70+
| `source.type` | Type of the data source. | all | str | [ovirt, vmware, dnac, proxmox, paloalto] | "" | Yes |
71+
| `source.httpScheme` | Http scheme for the source | all | str | [ http,https] | https | No |
72+
| `source.hostname` | Hostname of the data source. | all | str | any | "" | Yes |
73+
| `source.port` | Port of the data source. | all | int | 0-65536 | 443 | No |
74+
| `source.username` | Username of the data source account. | all | str | any | "" | Yes |
75+
| `source.password` | Password of the data source account. | all | str | any | "" | Yes |
76+
| `source.apiToken` | Password of the data source account. | [**fortigate**] | str | any | "" | Yes |
77+
| `source.validateCert` | Enforce TLS certificate validation. | all | bool | [true, false] | false | No |
78+
| `source.tagColor` | TagColor for the source tag. | all | string | any | Predefined | No |
79+
| `source.ignoredSubnets` | List of subnets, which will be ignored (e.g. IPs won't be synced). | all | []string | any | [] | No |
80+
| `source.interfaceFilter` | Regex representation of interface names to be ignored (e.g. `(cali\|vxlan\|flannel\|[a-f0-9]{15})`) | all | string | any | [] | No |
81+
| `source.collectArpData` | Collect data from the arp table of the device. | [**paloalto**] | bool | [true, false] | false | No |
82+
| `source.datacenterClusterGroupRelations` | Regex relations in format `regex = clusterGroupName`, that map each datacenter that satisfies regex to clusterGroupname (see [#130](https://github.com/bl4ko/netbox-ssot/issues/130)). | [**vmware**, **ovirt**] | []string | any | [] | No |
83+
| `source.hostSiteRelations` | Regex relations in format `regex = siteName`, that map each host that satisfies regex to site. | all | []string | any | [] | No |
84+
| `source.clusterSiteRelations` | Regex relations in format `regex = siteName`, that map each cluster that satisfies regex to site. | all | []string | any | [] | No |
85+
| `source.clusterTenantRelations` | Regex relations in format `regex = tenantName`, that map each cluster that satisfies regex to tenant. | all | []string | any | [] | No |
86+
| `source.hostTenantRelations` | Regex relations in format `regex = tenantName`, that map each host that satisfies regex to tenant. | all | []string | any | [] | No |
87+
| `source.vmTenantRelations` | Regex relations in format `regex = tenantName`, that map each vm that satisfies regex to tenant. | all | []string | any | [] | No |
88+
| `source.vlanGroupRelations` | Regex relations in format `regex = vlanGroup`, that map each vlan that satisfies regex to vlanGroup. | all | []string | any | [] | No |
89+
| `source.vlanTenantRelations` | Regex relations in format `regex = tenantName`, that map each vlan that satisfies regex to tenant. | all | []string | any | [] | No |
90+
| `source.customFieldMappings` | Mappings of format `customFieldName = option`. Currently, supported options are `contact`, `owner`, `description`. | [**vmware**] | []string | any | [] | No |
9091

9192
### Example config
9293

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ github.com/PaloAltoNetworks/pango v0.10.2 h1:Tjn6vIzzAq6Dd7N0mDuiP8w8pz8k5W9zz/T
22
github.com/PaloAltoNetworks/pango v0.10.2/go.mod h1:GztcRnVLur7G+VFG7Z5ZKNFgScLtsycwPMp1qVebE5g=
33
github.com/buger/goterm v1.0.4 h1:Z9YvGmOih81P0FbVtEYTFF6YsSgxSUKEhf/f9bTMXbY=
44
github.com/buger/goterm v1.0.4/go.mod h1:HiFWV3xnkolgrBV3mY8m0X0Pumt4zg4QhbdOzQtB8tE=
5-
github.com/cisco-en-programmability/dnacenter-go-sdk/v5 v5.0.26 h1:qLIr8VW60CKwjNJydytrnukETVb0FSZKTO/QKqE9STA=
6-
github.com/cisco-en-programmability/dnacenter-go-sdk/v5 v5.0.26/go.mod h1:4Km+JuiyL/LsNRvO4dMWUSUVbnNBRmbwzJMU1oUbn0E=
75
github.com/cisco-en-programmability/dnacenter-go-sdk/v5 v5.0.27 h1:DxSEe5YY296zQgmwrViEAGgLZCdbGgKRzqq35BF/F7A=
86
github.com/cisco-en-programmability/dnacenter-go-sdk/v5 v5.0.27/go.mod h1:4Km+JuiyL/LsNRvO4dMWUSUVbnNBRmbwzJMU1oUbn0E=
97
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

internal/parser/parser.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,21 @@ type SourceConfig struct {
7373
ArpDataLifeSpan int `yaml:"arpDataLifeSpan"`
7474

7575
// Relations
76-
HostSiteRelations []string `yaml:"hostSiteRelations"`
77-
ClusterSiteRelations []string `yaml:"clusterSiteRelations"`
78-
ClusterTenantRelations []string `yaml:"clusterTenantRelations"`
79-
HostTenantRelations []string `yaml:"hostTenantRelations"`
80-
VMTenantRelations []string `yaml:"vmTenantRelations"`
81-
VlanGroupRelations []string `yaml:"vlanGroupRelations"`
82-
VlanTenantRelations []string `yaml:"vlanTenantRelations"`
76+
DatacenterClusterGroupRelations []string `yaml:"datacenterClusterGroupRelations"`
77+
HostSiteRelations []string `yaml:"hostSiteRelations"`
78+
ClusterSiteRelations []string `yaml:"clusterSiteRelations"`
79+
ClusterTenantRelations []string `yaml:"clusterTenantRelations"`
80+
HostTenantRelations []string `yaml:"hostTenantRelations"`
81+
VMTenantRelations []string `yaml:"vmTenantRelations"`
82+
VlanGroupRelations []string `yaml:"vlanGroupRelations"`
83+
VlanTenantRelations []string `yaml:"vlanTenantRelations"`
8384

8485
// Vmware specific relations
8586
CustomFieldMappings []string `yaml:"customFieldMappings"`
8687
}
8788

8889
func (s SourceConfig) String() string {
89-
return fmt.Sprintf("SourceConfig{Name: %s, Type: %s, HTTPScheme: %s, Hostname: %s, Port: %d, Username: %s, Password: %s, PermittedSubnets: %v, ValidateCert: %t, Tag: %s, TagColor: %s, HostSiteRelations: %v, ClusterSiteRelations: %v, clusterTenantRelations: %v, HostTenantRelations: %v, VmTenantRelations %v, VlanGroupRelations: %v, VlanTenantRelations: %v}", s.Name, s.Type, s.HTTPScheme, s.Hostname, s.Port, s.Username, s.Password, s.IgnoredSubnets, s.ValidateCert, s.Tag, s.TagColor, s.HostSiteRelations, s.ClusterSiteRelations, s.ClusterTenantRelations, s.HostTenantRelations, s.VMTenantRelations, s.VlanGroupRelations, s.VlanTenantRelations)
90+
return fmt.Sprintf("SourceConfig{Name: %s, Type: %s, HTTPScheme: %s, Hostname: %s, Port: %d, Username: %s, Password: %s, PermittedSubnets: %v, ValidateCert: %t, Tag: %s, TagColor: %s, DatacenterClusterGroupRelations: %s, HostSiteRelations: %v, ClusterSiteRelations: %v, clusterTenantRelations: %v, HostTenantRelations: %v, VmTenantRelations %v, VlanGroupRelations: %v, VlanTenantRelations: %v}", s.Name, s.Type, s.HTTPScheme, s.Hostname, s.Port, s.Username, s.Password, s.IgnoredSubnets, s.ValidateCert, s.Tag, s.TagColor, s.DatacenterClusterGroupRelations, s.HostSiteRelations, s.ClusterSiteRelations, s.ClusterTenantRelations, s.HostTenantRelations, s.VMTenantRelations, s.VlanGroupRelations, s.VlanTenantRelations)
9091
}
9192

9293
// Validates the user's config for limits and required fields.
@@ -244,6 +245,12 @@ func validateSourceConfig(config *Config) error {
244245
}
245246

246247
func validateSourceConfigRelations(externalSource *SourceConfig, externalSourceStr string) error {
248+
if len(externalSource.DatacenterClusterGroupRelations) > 0 {
249+
err := utils.ValidateRegexRelations(externalSource.DatacenterClusterGroupRelations)
250+
if err != nil {
251+
return fmt.Errorf("%s.datacenterClusterGroupRelations: %s", externalSourceStr, err)
252+
}
253+
}
247254
if len(externalSource.HostSiteRelations) > 0 {
248255
err := utils.ValidateRegexRelations(externalSource.HostSiteRelations)
249256
if err != nil {

internal/parser/parser_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ func TestParseConfigInvalidConfigs(t *testing.T) {
177177
{filename: "invalid_config30.yaml", expectedErr: "source[fortigate].apiToken is required for fortigate"},
178178
{filename: "invalid_config31.yaml", expectedErr: "netbox.arpDataLifeSpan: cannot be negative"},
179179
{filename: "invalid_config1111.yaml", expectedErr: "open testdata/invalid_config1111.yaml: no such file or directory"},
180+
{filename: "invalid_config32.yaml", expectedErr: "source[wrong].datacenterClusterGroupRelations: invalid regex: (wrong(), in relation: (wrong() = wwrong"},
180181
}
181182

182183
for _, tc := range testCases {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
logger:
2+
level: 2
3+
dest: "test"
4+
5+
netbox:
6+
apiToken: "netbox-token"
7+
port: 666
8+
hostname: netbox.example.com
9+
httpScheme: "http"
10+
11+
source:
12+
- name: wrong
13+
type: fmc
14+
hostname: fmc.example.com
15+
username: "test"
16+
password: "test"
17+
datacenterClusterGroupRelations:
18+
- (wrong() = wwrong

0 commit comments

Comments
 (0)