Add new abilities

* List cluster types
* List Platforms
This commit is contained in:
Kalle Carlbark 2022-02-09 08:16:20 +01:00
parent e47de1a498
commit d107d2f742
No known key found for this signature in database
3 changed files with 187 additions and 8 deletions

84
cluster_types.go Normal file
View file

@ -0,0 +1,84 @@
package netboxgo
import (
"context"
"net/http"
"net/url"
"time"
"github.com/gorilla/schema"
)
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"`
}
// ClusterTypeFilter is used to filter out VirtualizationClusters
type ClusterTypeFilter struct {
// User specific filters
ID string `schema:"id,omitempty"`
Name string `schema:"name,omitempty"`
Slug string `schema:"slug,omitempty"`
Description string `schema:"description,omitempty"`
Created string `schema:"created,omitempty"`
CreatedGTE string `schema:"created__gte,omitempty"`
CreatedLTE string `schema:"created__lte,omitempty"`
LastUpdated string `schema:"last_updated,omitempty"`
LastUpdatedGTE string `schema:"last_updated__gte,omitempty"`
LastUpdatedLTE string `schema:"last_updated__lte,omitempty"`
IDIn string `schema:"id__in,omitempty"`
Q string `schema:"q,omitempty"`
Tag string `schema:"tag,omitempty"`
Offset int64 `schema:"offset,omitempty"`
Limit int64 `schema:"limit,omitempty"`
}
const clusterTypesPath = "/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) {
var clusterTypes ClusterTypes
var query string
var req *http.Request
var err error
encoder := schema.NewEncoder()
form := url.Values{}
err = encoder.Encode(f, form)
if err != nil {
return &clusterTypes, err
}
query = form.Encode()
req, err = s.client.newRequest(ctx, "GET", clusterTypesPath, 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

@ -21,21 +21,23 @@ type Client struct {
// Virtualization *Virtualization
// Secret *Secret
Tenants *TenantsService
Sites *SitesService
SiteGroups *SiteGroupsService
VirtualMachines *VirtualMachinesService
Clusters *ClustersService
VLANs *VLANsService
Secrets *SecretsService
InventoryItems *InventoryItemsService
ClusterTypes *ClusterTypesService
Devices *DevicesService
DeviceRoles *DeviceRolesService
DeviceTypes *DeviceTypesService
Interfaces *InterfacesService
InventoryItems *InventoryItemsService
Secrets *SecretsService
Sites *SitesService
SiteGroups *SiteGroupsService
Platforms *PlatformsService
Prefixes *PrefixesService
VRFs *VRFsService
RearPorts *RearPortsService
Tenants *TenantsService
VirtualMachines *VirtualMachinesService
VRFs *VRFsService
VLANs *VLANsService
// baseURL is the URL used for the base URL of the API
baseURL *url.URL

93
platforms.go Normal file
View file

@ -0,0 +1,93 @@
package netboxgo
import (
"context"
"net/http"
"net/url"
"time"
"github.com/gorilla/schema"
)
type PlatformsService service
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"`
}
// PlatformFilter is used to filter out platforms
type PlatformFilter struct {
// User specific filters
ID string `schema:"id,omitempty"`
Name string `schema:"name,omitempty"`
Slug string `schema:"slug,omitempty"`
Description string `schema:"description,omitempty"`
Created string `schema:"created,omitempty"`
CreatedGTE string `schema:"created__gte,omitempty"`
CreatedLTE string `schema:"created__lte,omitempty"`
LastUpdated string `schema:"last_updated,omitempty"`
LastUpdatedGTE string `schema:"last_updated__gte,omitempty"`
LastUpdatedLTE string `schema:"last_updated__lte,omitempty"`
IDIn string `schema:"id__in,omitempty"`
Q string `schema:"q,omitempty"`
Tag string `schema:"tag,omitempty"`
Offset int64 `schema:"offset,omitempty"`
Limit int64 `schema:"limit,omitempty"`
}
const platformsPath = "/platforms/"
// List platforms. PlatformFilter is used to list based on filter queries.
func (s *PlatformsService) List(ctx context.Context, f *PlatformFilter) (*Platforms, error) {
var platforms Platforms
var query string
var req *http.Request
var err error
encoder := schema.NewEncoder()
form := url.Values{}
err = encoder.Encode(f, form)
if err != nil {
return &platforms, err
}
query = form.Encode()
req, err = s.client.newRequest(ctx, "GET", platformsPath, query, nil)
if err != nil {
return &platforms, err
}
_, err = s.client.do(req, &platforms)
if err != nil {
return &platforms, err
}
return &platforms, nil
}