Update netbox dto's

This commit is contained in:
Kalle Carlbark 2022-02-09 09:59:14 +01:00
parent d107d2f742
commit d98de3282c
No known key found for this signature in database
4 changed files with 111 additions and 54 deletions

View File

@ -1,2 +1,5 @@
[core]
sshCommand = "/usr/bin/ssh"
[user]
name = Kalle Carlbark
email = kalle.carlbark@kcbark.net

View File

@ -13,22 +13,31 @@ type ClusterTypesService service
// ClusterTypes is used to list cluster types
type ClusterTypes struct {
Next interface{} `json:"next"`
Previous interface{} `json:"previous"`
Results []struct {
CustomFields struct{} `json:"custom_fields"`
LastUpdated time.Time `json:"last_updated"`
Display string `json:"display"`
Slug string `json:"slug"`
Description string `json:"description"`
URL string `json:"url"`
Created string `json:"created"`
Name string `json:"name"`
Tags []interface{} `json:"tags"`
ID int `json:"id"`
ClusterCount int `json:"cluster_count"`
} `json:"results"`
Count int `json:"count"`
Next interface{} `json:"next"`
Previous interface{} `json:"previous"`
Results []ClusterType `json:"results"`
Count int `json:"count"`
}
type ClusterType struct {
CustomFields struct{} `json:"custom_fields"`
LastUpdated time.Time `json:"last_updated"`
Display string `json:"display"`
Slug string `json:"slug"`
Description string `json:"description"`
URL string `json:"url"`
Created string `json:"created"`
Name string `json:"name"`
Tags []struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
Color string `json:"color"`
ID int `json:"id"`
} `json:"tags"`
ID int `json:"id"`
ClusterCount int `json:"cluster_count"`
}
// ClusterTypeFilter is used to filter out VirtualizationClusters
@ -52,7 +61,7 @@ type ClusterTypeFilter struct {
Limit int64 `schema:"limit,omitempty"`
}
const clusterTypesPath = "/cluster-types/"
const clusterTypesPath = virtualizationPath + "/cluster-types/"
// List cluster types. ClusterTypeFilter is used to list based on filter queries.
func (s *ClusterTypesService) List(ctx context.Context, f *ClusterTypeFilter) (*ClusterTypes, error) {
@ -82,3 +91,23 @@ func (s *ClusterTypesService) List(ctx context.Context, f *ClusterTypeFilter) (*
return &clusterTypes, nil
}
// Get cluster type.
func (s *ClusterTypesService) Get(ctx context.Context, id string) (*ClusterTypes, error) {
var clusterTypes ClusterTypes
var query string
var req *http.Request
var err error
req, err = s.client.newRequest(ctx, "GET", clusterTypesPath+id+"/", query, nil)
if err != nil {
return &clusterTypes, err
}
_, err = s.client.do(req, &clusterTypes)
if err != nil {
return &clusterTypes, err
}
return &clusterTypes, nil
}

View File

@ -4,36 +4,48 @@ import (
"context"
"net/http"
"net/url"
"time"
"github.com/gorilla/schema"
)
type DeviceRolesService service
// DeviceRoles is used to list device roles
type DeviceRoles struct {
Count int `json:"count"`
Next string `json:"next"`
Previous string `json:"previous"`
Results []DeviceRole `json:"results"`
Count int `json:"count"`
}
// DeviceRole is a role of a device
type DeviceRole struct {
ID int `json:"id"`
URL string `json:"url"`
Name string `json:"name"`
Slug string `json:"slug"`
Color string `json:"color"`
VMRole bool `json:"vm_role"`
Description string `json:"description"`
DeviceCount int `json:"device_count"`
VirtualmachineCount int `json:"virtualmachine_count"`
LastUpdated time.Time `json:"last_updated"`
CustomFields struct{} `json:"custom_fields"`
URL string `json:"url"`
Display string `json:"display"`
Slug string `json:"slug"`
Color string `json:"color"`
Created string `json:"created"`
Description string `json:"description"`
Name string `json:"name"`
Tags []struct {
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
Color string `json:"color"`
ID int `json:"id"`
} `json:"tags"`
ID int `json:"id"`
DeviceCount int `json:"device_count"`
VirtualMachineCount int `json:"virtualmachine_count"`
VMRole bool `json:"vm_role"`
}
// DeviceTypeFilter is used to filter dcim_device_roles query to the Netbox API
type DeviceRoleFilter struct {
Offset int64 `schema:"offset,omitempty"`
Limit int64 `schema:"limit,omitempty"`
// User specific filters
ID string `schema:"id,omitempty"`
Name string `schema:"name,omitempty"`
@ -41,6 +53,9 @@ type DeviceRoleFilter struct {
Color string `schema:"color,omitempty"`
VMRole string `schema:"vm_role,omitempty"`
Q string `schema:"q,omitempty"`
Offset int64 `schema:"offset,omitempty"`
Limit int64 `schema:"limit,omitempty"`
}
const deviceRolesPath = dcimPath + "/device-roles"

View File

@ -15,29 +15,39 @@ type Platforms struct {
Count int `json:"count"`
Next interface{} `json:"next"`
Previous interface{} `json:"previous"`
Results []struct {
ID int `json:"id"`
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
Manufacturer struct {
ID int `json:"id"`
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
} `json:"manufacturer"`
NapalmDriver string `json:"napalm_driver"`
NapalmArgs interface{} `json:"napalm_args"`
Description string `json:"description"`
Tags []interface{} `json:"tags"`
CustomFields struct{} `json:"custom_fields"`
Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"`
DeviceCount int `json:"device_count"`
VirtualmachineCount int `json:"virtualmachine_count"`
} `json:"results"`
Results []Platform `json:"results"`
}
type Platform struct {
ID int `json:"id"`
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
Manufacturer struct {
ID int `json:"id"`
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
DevicetypeCount int `json:"devicetype_count"`
} `json:"manufacturer"`
NapalmDriver string `json:"napalm_driver"`
NapalmArgs string `json:"napalm_args"`
Description string `json:"description"`
Tags []struct {
ID int `json:"id"`
URL string `json:"url"`
Display string `json:"display"`
Name string `json:"name"`
Slug string `json:"slug"`
Color string `json:"color"`
} `json:"tags"`
CustomFields struct{} `json:"custom_fields"`
Created string `json:"created"`
LastUpdated time.Time `json:"last_updated"`
DeviceCount int `json:"device_count"`
VirtualmachineCount int `json:"virtualmachine_count"`
}
// PlatformFilter is used to filter out platforms
@ -61,7 +71,7 @@ type PlatformFilter struct {
Limit int64 `schema:"limit,omitempty"`
}
const platformsPath = "/platforms/"
const platformsPath = dcimPath + "/platforms/"
// List platforms. PlatformFilter is used to list based on filter queries.
func (s *PlatformsService) List(ctx context.Context, f *PlatformFilter) (*Platforms, error) {