v1.14.7
This commit is contained in:
50
pkg/sdn/hypervisors/get.go
Normal file
50
pkg/sdn/hypervisors/get.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package hypervisors
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get information about hypervisor
|
||||
type GetRequest struct {
|
||||
// Name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Port info (available options: detailed, general)
|
||||
// Required: false
|
||||
PortInfo string `url:"port_info,omitempty" json:"port_info,omitempty"`
|
||||
}
|
||||
|
||||
// Get gets current configuration of a hypervisor as a RecordHypervisor
|
||||
func (hv Hypervisors) Get(ctx context.Context, req GetRequest) (*RecordHypervisor, error) {
|
||||
res, err := hv.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordHypervisor{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets information about a hypervisor as an array of bytes
|
||||
func (hv Hypervisors) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/hypervisor/get"
|
||||
|
||||
res, err := hv.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
Reference in New Issue
Block a user