v1.0.0
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
// API Actor for managing ComputeCI. This actor is a final API for admin to manage ComputeCI
|
||||
package computeci
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to computeci
|
||||
type ComputeCI struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for computeci endpoints
|
||||
func New(client interfaces.Caller) *ComputeCI {
|
||||
return &ComputeCI{
|
||||
client,
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for information about computeci
|
||||
type GetRequest struct {
|
||||
// ID of the Compute CI
|
||||
// Required: true
|
||||
ComputeCIID uint64 `url:"computeciId"`
|
||||
}
|
||||
|
||||
func (krq GetRequest) Validate() error {
|
||||
func (krq GetRequest) validate() error {
|
||||
if krq.ComputeCIID == 0 {
|
||||
return errors.New("field ComputeCIID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,21 +22,26 @@ func (krq GetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c ComputeCI) Get(ctx context.Context, req GetRequest) (*ComputeCIRecord, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/computeci/get"
|
||||
computeciRaw, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
// Get gets information about computeci by ID
|
||||
func (c ComputeCI) Get(ctx context.Context, req GetRequest) (*ItemComputeCI, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
computeci := &ComputeCIRecord{}
|
||||
if err := json.Unmarshal(computeciRaw, computeci); err != nil {
|
||||
url := "/cloudapi/computeci/get"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return computeci, nil
|
||||
info := ItemComputeCI{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
@@ -6,23 +6,36 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list of computeci
|
||||
type ListRequest struct {
|
||||
IncludeDeleted bool `url:"includeDeleted,omitempty"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
// If true list deleted instances as well
|
||||
// Required: false
|
||||
IncludeDeleted bool `url:"includeDeleted,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (c ComputeCI) List(ctx context.Context, req ListRequest) (ComputeCIList, error) {
|
||||
// List gets list of computeci instances
|
||||
func (c ComputeCI) List(ctx context.Context, req ListRequest) (ListComputeCI, error) {
|
||||
url := "/cloudapi/computeci/list"
|
||||
computeciListRaw, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
computeciList := ComputeCIList{}
|
||||
if err := json.Unmarshal(computeciListRaw, &computeciList); err != nil {
|
||||
list := ListComputeCI{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return computeciList, nil
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
package computeci
|
||||
|
||||
type ComputeCIRecord struct {
|
||||
// Main information about computeci
|
||||
type ItemComputeCI struct {
|
||||
// Custom fields
|
||||
CustomFields map[string]interface{} `json:"customFields"`
|
||||
Description string `json:"desc"`
|
||||
Drivers []string `json:"drivers"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Template string `jsnn:"template"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// List drivers
|
||||
Drivers []string `json:"drivers"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Template
|
||||
Template string `jsnn:"template"`
|
||||
}
|
||||
|
||||
type ComputeCIList []ComputeCIRecord
|
||||
// List of computeci instances
|
||||
type ListComputeCI []ItemComputeCI
|
||||
|
||||
Reference in New Issue
Block a user