Skip to content

Commit

Permalink
cherry pick: support for virtual chassis
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Falk Nielsen committed Jul 31, 2024
1 parent cd12cd1 commit d58237a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ tenant_name: Tenant name from NetBox
site_name: Site name from NetBox
site_group: Site Group name from NetBox
site_address: Site address from NetBox
virtual_chassis_name: Virtual Chassis name from NetBox
```

### Expressions
Expand All @@ -70,7 +71,7 @@ site: The site object (go struct, most fields are CamelCase, ex: site.Slug)

Expressions have access to all expr functions and the following:
```
FindTag(<tags>, <tag_name)
FindTag(<tags>, <tag_name>)
```

### Debug
Expand Down
6 changes: 6 additions & 0 deletions internal/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ func (i *InventorySync) getDeviceSessions(devices []netbox.DeviceWithConfigConte
siteGroup = site.Group.Slug
}

virtualChassisName := ""
if device.VirtualChassis != nil {
virtualChassisName = device.VirtualChassis.Name
}

env := i.getCommonEnvironment("device")
env.Device = device
env.DeviceName = device.Display
Expand All @@ -135,6 +140,7 @@ func (i *InventorySync) getDeviceSessions(devices []netbox.DeviceWithConfigConte
env.SiteName = site.Display
env.SiteGroup = siteGroup
env.SiteAddress = siteAddress
env.VirtualChassisName = virtualChassisName

err = applyOverrides(i.cfg.Session.Overrides, env)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/evaluator/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Environment struct {
SiteName string `expr:"site_name"`
SiteGroup string `expr:"site_group"`
SiteAddress string `expr:"site_address"`
VirtualChassisName string `expr:"virtual_chassis_name"`

Device interface{} `expr:"device"`
Site interface{} `expr:"site"`
Expand Down

0 comments on commit d58237a

Please sign in to comment.