Skip to content

Commit

Permalink
fix: adding descriptions for device roles
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ko committed Sep 2, 2024
1 parent 935f007 commit a363298
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 46 deletions.
25 changes: 15 additions & 10 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,25 @@ const (

// Device Role constants.
const (
DeviceRoleFirewall = "Firewall"
DeviceRoleFirewallColor = "f57842"
DeviceRoleFirewall = "Firewall"
DeviceRoleFirewallDescription = "Device role for marking firewall device."
DeviceRoleFirewallColor = "f57842"

DeviceRoleSwitch = "Switch"
DeviceRoleSwitchColor = "7aefea"
DeviceRoleSwitch = "Switch"
DeviceRoleSwitchDescription = "Device role for marking switch device."
DeviceRoleSwitchColor = "7aefea"

DeviceRoleServer = "Server"
DeviceRoleServerColor = "00add8"
DeviceRoleServer = "Server"
DeviceRoleServerDescription = "Device role for marking server."
DeviceRoleServerColor = "00add8"

DeviceRoleContainer = "Container"
DeviceRoleContainerColor = "0db7ed"
DeviceRoleContainer = "Container"
DeviceRoleContainerDescription = "VM role for separating containers from VMs."
DeviceRoleContainerColor = "0db7ed"

DeviceRoleVMTemplate = "VM Template"
DeviceRoleVMTemplateColor = "82c1ea"
DeviceRoleVMTemplate = "VM Template"
DeviceRoleVMTemplateDescription = "VM role for separating VM templates from VMs."
DeviceRoleVMTemplateColor = "82c1ea"
)

// Constants used for variables in our contexts.
Expand Down
2 changes: 2 additions & 0 deletions internal/netbox/objects/dcim.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ type DeviceRole struct {
NetboxObject
// Name is the name of the device role. This field is required.
Name string `json:"name,omitempty"`
// Description is the description of the device Role.
Description string `json:"description,omitempty"`
// URL-friendly unique shorthand. This field is required.
Slug string `json:"slug,omitempty"`
// Color of the device role. This field is required.
Expand Down
9 changes: 5 additions & 4 deletions internal/source/fmc/fmc_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ func (fmcs *FMCSource) syncDevices(nbi *inventory.NetboxInventory) error {
return fmt.Errorf("match host to tenant %s", err)
}
deviceRole, err := nbi.AddDeviceRole(fmcs.Ctx, &objects.DeviceRole{
Name: constants.DeviceRoleFirewall,
Slug: utils.Slugify(constants.DeviceRoleFirewall),
Color: constants.DeviceRoleFirewallColor,
VMRole: false,
Name: constants.DeviceRoleFirewall,
Description: constants.DeviceRoleFirewallDescription,
Slug: utils.Slugify(constants.DeviceRoleFirewall),
Color: constants.DeviceRoleFirewallColor,
VMRole: false,

Check warning on line 50 in internal/source/fmc/fmc_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/fmc/fmc_sync.go#L46-L50

Added lines #L46 - L50 were not covered by tests
})
if err != nil {
return fmt.Errorf("add DeviceRole: %s", err)
Expand Down
9 changes: 5 additions & 4 deletions internal/source/fortigate/fortigate_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ func (fs *FortigateSource) syncDevice(nbi *inventory.NetboxInventory) error {
}

deviceRole, err := nbi.AddDeviceRole(fs.Ctx, &objects.DeviceRole{
Name: constants.DeviceRoleFirewall,
Slug: utils.Slugify(constants.DeviceRoleFirewall),
Color: constants.DeviceRoleFirewallColor,
VMRole: false,
Name: constants.DeviceRoleFirewall,
Description: constants.DeviceRoleFirewallDescription,
Slug: utils.Slugify(constants.DeviceRoleFirewall),
Color: constants.DeviceRoleFirewallColor,
VMRole: false,

Check warning on line 52 in internal/source/fortigate/fortigate_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/fortigate/fortigate_sync.go#L48-L52

Added lines #L48 - L52 were not covered by tests
})
if err != nil {
return fmt.Errorf("add DeviceRole: %s", err)
Expand Down
9 changes: 5 additions & 4 deletions internal/source/ios-xe/iosxe_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ func (is *IOSXESource) syncDevice(nbi *inventory.NetboxInventory) error {
}

deviceRole, err := nbi.AddDeviceRole(is.Ctx, &objects.DeviceRole{
Name: constants.DeviceRoleSwitch,
Slug: utils.Slugify(constants.DeviceRoleSwitch),
Color: constants.DeviceRoleSwitchColor,
VMRole: false,
Name: constants.DeviceRoleSwitch,
Description: constants.DeviceRoleSwitchDescription,
Slug: utils.Slugify(constants.DeviceRoleSwitch),
Color: constants.DeviceRoleSwitchColor,
VMRole: false,

Check warning on line 47 in internal/source/ios-xe/iosxe_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/ios-xe/iosxe_sync.go#L43-L47

Added lines #L43 - L47 were not covered by tests
})
if err != nil {
return fmt.Errorf("add device role: %s", err)
Expand Down
9 changes: 5 additions & 4 deletions internal/source/ovirt/ovirt_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,11 @@ func (o *OVirtSource) syncHosts(nbi *inventory.NetboxInventory) error {
mem /= (constants.KiB * constants.KiB * constants.KiB) // Value is in Bytes, we convert to GB

hostDeviceRoleStruct := &objects.DeviceRole{
Name: constants.DeviceRoleServer,
Slug: utils.Slugify(constants.DeviceRoleServer),
Color: constants.DeviceRoleServerColor,
VMRole: false,
Name: constants.DeviceRoleServer,
Description: constants.DeviceRoleServerDescription,
Slug: utils.Slugify(constants.DeviceRoleServer),
Color: constants.DeviceRoleServerColor,
VMRole: false,

Check warning on line 295 in internal/source/ovirt/ovirt_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/ovirt/ovirt_sync.go#L291-L295

Added lines #L291 - L295 were not covered by tests
}
hostDeviceRole, err := nbi.AddDeviceRole(o.Ctx, hostDeviceRoleStruct)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions internal/source/paloalto/paloalto_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ func (pas *PaloAltoSource) syncDevice(nbi *inventory.NetboxInventory) error {
}

deviceRoleStruct := &objects.DeviceRole{
Name: constants.DeviceRoleFirewall,
Slug: utils.Slugify(constants.DeviceRoleFirewall),
Color: constants.DeviceRoleFirewallColor,
VMRole: false,
Name: constants.DeviceRoleFirewall,
Description: constants.DeviceRoleFirewallDescription,
Slug: utils.Slugify(constants.DeviceRoleFirewall),
Color: constants.DeviceRoleFirewallColor,
VMRole: false,

Check warning on line 55 in internal/source/paloalto/paloalto_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/paloalto/paloalto_sync.go#L51-L55

Added lines #L51 - L55 were not covered by tests
}
deviceRole, err := nbi.AddDeviceRole(pas.Ctx, deviceRoleStruct)
if err != nil {
Expand Down
18 changes: 10 additions & 8 deletions internal/source/proxmox/proxmox_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ func (ps *ProxmoxSource) syncNodes(nbi *inventory.NetboxInventory) error {
}

deviceRoleStruct := &objects.DeviceRole{
Name: constants.DeviceRoleServer,
Slug: utils.Slugify(constants.DeviceRoleServer),
Color: constants.DeviceRoleServerColor,
VMRole: false,
Name: constants.DeviceRoleServer,
Description: constants.DeviceRoleServerDescription,
Slug: utils.Slugify(constants.DeviceRoleServer),
Color: constants.DeviceRoleServerColor,
VMRole: false,

Check warning on line 104 in internal/source/proxmox/proxmox_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/proxmox/proxmox_sync.go#L100-L104

Added lines #L100 - L104 were not covered by tests
}
hostDeviceRole, err := nbi.AddDeviceRole(ps.Ctx, deviceRoleStruct)
if err != nil {
Expand Down Expand Up @@ -347,10 +348,11 @@ func (ps *ProxmoxSource) syncContainers(nbi *inventory.NetboxInventory) error {
if len(ps.Containers) > 0 {
// Create container role
containerRole, err := nbi.AddDeviceRole(ps.Ctx, &objects.DeviceRole{
Name: constants.DeviceRoleContainer,
Slug: utils.Slugify(constants.DeviceRoleContainer),
Color: constants.DeviceRoleContainerColor,
VMRole: true,
Name: constants.DeviceRoleContainer,
Description: constants.DeviceRoleContainerDescription,
Slug: utils.Slugify(constants.DeviceRoleContainer),
Color: constants.DeviceRoleContainerColor,
VMRole: true,

Check warning on line 355 in internal/source/proxmox/proxmox_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/proxmox/proxmox_sync.go#L351-L355

Added lines #L351 - L355 were not covered by tests
})
if err != nil {
return fmt.Errorf("create container role: %s", err)
Expand Down
18 changes: 10 additions & 8 deletions internal/source/vmware/vmware_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ func (vc *VmwareSource) syncHosts(nbi *inventory.NetboxInventory) error {
hostMemGB := host.Summary.Hardware.MemorySize / constants.KiB / constants.KiB / constants.KiB

deviceRoleStruct := &objects.DeviceRole{
Name: constants.DeviceRoleServer,
Slug: utils.Slugify(constants.DeviceRoleServer),
Color: constants.DeviceRoleServerColor,
VMRole: false,
Name: constants.DeviceRoleServer,
Description: constants.DeviceRoleServerDescription,
Slug: utils.Slugify(constants.DeviceRoleServer),
Color: constants.DeviceRoleServerColor,
VMRole: false,

Check warning on line 257 in internal/source/vmware/vmware_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/vmware/vmware_sync.go#L253-L257

Added lines #L253 - L257 were not covered by tests
}
hostDeviceRole, err := nbi.AddDeviceRole(vc.Ctx, deviceRoleStruct)
if err != nil {
Expand Down Expand Up @@ -737,10 +738,11 @@ func (vc *VmwareSource) syncVM(nbi *inventory.NetboxInventory, vmKey string, vm
var templateRole *objects.DeviceRole
if isTemplate {
templateRoleStruct := &objects.DeviceRole{
Name: constants.DeviceRoleVMTemplate,
Slug: utils.Slugify(constants.DeviceRoleVMTemplate),
Color: constants.DeviceRoleVMTemplateColor,
VMRole: true,
Name: constants.DeviceRoleVMTemplate,
Description: constants.DeviceRoleVMTemplateDescription,
Slug: utils.Slugify(constants.DeviceRoleVMTemplate),
Color: constants.DeviceRoleVMTemplateColor,
VMRole: true,

Check warning on line 745 in internal/source/vmware/vmware_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/vmware/vmware_sync.go#L738-L745

Added lines #L738 - L745 were not covered by tests
}
var err error
templateRole, err = nbi.AddDeviceRole(vc.Ctx, templateRoleStruct)
Expand Down

0 comments on commit a363298

Please sign in to comment.