v1.8.0
This commit is contained in:
10
pkg/cloudapi/pcidevice/ids.go
Normal file
10
pkg/cloudapi/pcidevice/ids.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package pcidevice
|
||||
|
||||
// IDs gets array of PCIDeviceIDs from ListPCIDevices struct
|
||||
func (lpd ListPCIDevices) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lpd.Data))
|
||||
for _, lb := range lpd.Data {
|
||||
res = append(res, lb.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
76
pkg/cloudapi/pcidevice/list.go
Normal file
76
pkg/cloudapi/pcidevice/list.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package pcidevice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of pci devices
|
||||
type ListRequest struct {
|
||||
// Find by id
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by computeId
|
||||
// Required: false
|
||||
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by rgId
|
||||
// Required: false
|
||||
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of all pci devices as a ListPCIDevices struct
|
||||
func (p PCIDevice) List(ctx context.Context, req ListRequest) (*ListPCIDevices, error) {
|
||||
|
||||
res, err := p.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListPCIDevices{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of all pci devices as an array of bytes
|
||||
func (p PCIDevice) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/pcidevice/list"
|
||||
|
||||
res, err := p.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
50
pkg/cloudapi/pcidevice/models.go
Normal file
50
pkg/cloudapi/pcidevice/models.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package pcidevice
|
||||
|
||||
// Main information about PCI device
|
||||
type ItemPCIDevice struct {
|
||||
// CKey
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
// Meta
|
||||
Meta []interface{} `json:"_meta"`
|
||||
|
||||
// Compute ID
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
|
||||
// Description
|
||||
Description string `json:"description"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// HwPath
|
||||
HwPath string `json:"hwPath"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Stack ID
|
||||
StackID uint64 `json:"stackId"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// System name
|
||||
SystemName string `json:"systemName"`
|
||||
}
|
||||
|
||||
// List PCI devices
|
||||
type ListPCIDevices struct {
|
||||
// Data
|
||||
Data []ItemPCIDevice `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
15
pkg/cloudapi/pcidevice/pcidevice.go
Normal file
15
pkg/cloudapi/pcidevice/pcidevice.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package pcidevice
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
|
||||
// Structure for creating request to PCI device
|
||||
type PCIDevice struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for PCI device endpoints
|
||||
func New(client interfaces.Caller) *PCIDevice {
|
||||
return &PCIDevice{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
42
pkg/cloudapi/pcidevice/serialize.go
Normal file
42
pkg/cloudapi/pcidevice/serialize.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package pcidevice
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (l ListPCIDevices) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(l.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(l, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(l)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (i ItemPCIDevice) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(i, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(i)
|
||||
}
|
||||
Reference in New Issue
Block a user