v1.0.0
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
// API Actor for managing Compute Group. This actor is a final API for endusers to manage Compute Group
|
||||
package bservice
|
||||
|
||||
import "github.com/rudecs/decort-sdk/interfaces"
|
||||
|
||||
// Structure for creating request to bservice
|
||||
type BService struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for bservice endpoints
|
||||
func New(client interfaces.Caller) *BService {
|
||||
return &BService{
|
||||
client,
|
||||
|
||||
@@ -7,18 +7,29 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for BasicService
|
||||
type CreateRequest struct {
|
||||
Name string `url:"name"`
|
||||
RGID uint64 `url:"rgId"`
|
||||
// Name of the service
|
||||
// Required: true
|
||||
Name string `url:"name"`
|
||||
|
||||
// ID of the Resource Group where this service will be placed
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId"`
|
||||
|
||||
// Name of the user to deploy SSH key for. Pass empty string if no SSH key deployment is required
|
||||
// Required: false
|
||||
SSHUser string `url:"sshUser,omitempty"`
|
||||
SSHKey string `url:"sshKey,omitempty"`
|
||||
|
||||
// SSH key to deploy for the specified user. Same key will be deployed to all computes of the service
|
||||
// Required: false
|
||||
SSHKey string `url:"sshKey,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq CreateRequest) Validate() error {
|
||||
func (bsrq CreateRequest) validate() error {
|
||||
if bsrq.Name == "" {
|
||||
return errors.New("field Name can not be empty")
|
||||
}
|
||||
|
||||
if bsrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -26,16 +37,24 @@ func (bsrq CreateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates blank BasicService instance
|
||||
func (b BService) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/create"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseUint(string(res), 10, 64)
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,12 +7,18 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete basic service
|
||||
type DeleteRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
// ID of the BasicService to be delete
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// If set to False, Basic service will be deleted to recycle bin. Otherwise destroyed immediately
|
||||
// Required: true
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq DeleteRequest) Validate() error {
|
||||
func (bsrq DeleteRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -20,16 +26,24 @@ func (bsrq DeleteRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes BasicService instance
|
||||
func (b BService) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/delete"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for disable service
|
||||
type DisableRequest struct {
|
||||
// ID of the service to disable
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq DisableRequest) Validate() error {
|
||||
func (bsrq DisableRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,16 +22,26 @@ func (bsrq DisableRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Disable disables service.
|
||||
// Disabling a service technically means setting model status
|
||||
// of all computes and service itself to DISABLED and stopping all computes.
|
||||
func (b BService) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/delete"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for disable service
|
||||
type EnableRequest struct {
|
||||
// ID of the service to enable
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq EnableRequest) Validate() error {
|
||||
func (bsrq EnableRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,16 +22,27 @@ func (bsrq EnableRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Enable enables service.
|
||||
// Enabling a service technically means setting model status of
|
||||
// all computes and service itself to ENABLED.
|
||||
// It does not start computes.
|
||||
func (b BService) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/enable"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get detailed information about service
|
||||
type GetRequest struct {
|
||||
// ID of the service to query information
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq GetRequest) Validate() error {
|
||||
func (bsrq GetRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,21 +22,26 @@ func (bsrq GetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Get(ctx context.Context, req GetRequest) (*BasicService, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
// Get gets detailed specifications for the BasicService.
|
||||
func (b BService) Get(ctx context.Context, req GetRequest) (*RecordBasicService, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/get"
|
||||
|
||||
bsRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bs := &BasicService{}
|
||||
if err := json.Unmarshal(bsRaw, bs); err != nil {
|
||||
info := RecordBasicService{}
|
||||
|
||||
err = json.Unmarshal(bsRaw, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bs, nil
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
@@ -7,50 +7,82 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for create new compute group within BasicService
|
||||
type GroupAddRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
Name string `url:"name"`
|
||||
Count uint64 `url:"count"`
|
||||
CPU uint64 `url:"cpu"`
|
||||
RAM uint64 `url:"ram"`
|
||||
Disk uint64 `url:"disk"`
|
||||
ImageID uint64 `url:"imageId"`
|
||||
Driver string `url:"driver"`
|
||||
Role string `url:"role,omitempty"`
|
||||
VINSes []uint64 `url:"vinses,omitempty"`
|
||||
ExtNets []uint64 `url:"extnets,omitempty"`
|
||||
TimeoutStart uint64 `url:"timeoutStart"`
|
||||
// ID of the Basic Service to add a group to
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// Name of the Compute Group to add
|
||||
// Required: true
|
||||
Name string `url:"name"`
|
||||
|
||||
// Computes number. Defines how many computes must be there in the group
|
||||
// Required: true
|
||||
Count uint64 `url:"count"`
|
||||
|
||||
// Compute CPU number. All computes in the group have the same CPU count
|
||||
// Required: true
|
||||
CPU uint64 `url:"cpu"`
|
||||
|
||||
// Compute RAM volume in MB. All computes in the group have the same RAM volume
|
||||
// Required: true
|
||||
RAM uint64 `url:"ram"`
|
||||
|
||||
// Compute boot disk size in GB
|
||||
// Required: true
|
||||
Disk uint64 `url:"disk"`
|
||||
|
||||
// OS image ID to create computes from
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId"`
|
||||
|
||||
// Compute driver
|
||||
// should be one of:
|
||||
// - KVM_X86
|
||||
// - KVM_PPC
|
||||
// Required: true
|
||||
Driver string `url:"driver"`
|
||||
|
||||
// Group role tag. Can be empty string, does not have to be unique
|
||||
// Required: false
|
||||
Role string `url:"role,omitempty"`
|
||||
|
||||
// List of ViNSes to connect computes to
|
||||
// Required: false
|
||||
VINSes []uint64 `url:"vinses,omitempty"`
|
||||
|
||||
// List of external networks to connect computes to
|
||||
// Required: false
|
||||
ExtNets []uint64 `url:"extnets,omitempty"`
|
||||
|
||||
// Time of Compute Group readiness
|
||||
// Required: false
|
||||
TimeoutStart uint64 `url:"timeoutStart"`
|
||||
}
|
||||
|
||||
func (bsrq GroupAddRequest) Validate() error {
|
||||
func (bsrq GroupAddRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Name == "" {
|
||||
return errors.New("field Name can not be empty")
|
||||
}
|
||||
|
||||
if bsrq.Count == 0 {
|
||||
return errors.New("field Count can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CPU == 0 {
|
||||
return errors.New("field CPU can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.RAM == 0 {
|
||||
return errors.New("field RAM can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Disk == 0 {
|
||||
return errors.New("field Disk can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.ImageID == 0 {
|
||||
return errors.New("field ImageID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Driver == "" {
|
||||
return errors.New("field Driver can not be empty")
|
||||
}
|
||||
@@ -58,16 +90,26 @@ func (bsrq GroupAddRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupAdd creates new Compute Group within BasicService.
|
||||
// Compute Group is NOT started automatically,
|
||||
// so you need to explicitly start it
|
||||
func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest) (uint64, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupAdd"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseUint(string(res), 10, 64)
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,21 +7,28 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for remove group compute
|
||||
type GroupComputeRemoveRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
// ID of the Basic Service
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// ID of the Compute GROUP
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
|
||||
// ID of the Compute
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (bsrq GroupComputeRemoveRequest) Validate() error {
|
||||
func (bsrq GroupComputeRemoveRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.ComputeID == 0 {
|
||||
return errors.New("field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -29,16 +36,24 @@ func (bsrq GroupComputeRemoveRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupComputeRemove makes group compute remove of the Basic Service
|
||||
func (b BService) GroupComputeRemove(ctx context.Context, req GroupComputeRemoveRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupComputeRemove"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,16 +7,21 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get detailed information about Compute Group
|
||||
type GroupGetRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// ID of the Compute Group
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
}
|
||||
|
||||
func (bsrq GroupGetRequest) Validate() error {
|
||||
func (bsrq GroupGetRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -24,21 +29,26 @@ func (bsrq GroupGetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupGet(ctx context.Context, req GroupGetRequest) (*Group, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupGet"
|
||||
groupRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
// GroupGet gets detailed specifications for the Compute Group
|
||||
func (b BService) GroupGet(ctx context.Context, req GroupGetRequest) (*RecordGroup, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
group := &Group{}
|
||||
if err := json.Unmarshal(groupRaw, group); err != nil {
|
||||
url := "/cloudapi/bservice/groupGet"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return group, nil
|
||||
info := RecordGroup{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
@@ -7,21 +7,29 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for add parent Compute Group relation emove parent Compute Group
|
||||
// relation to the specified Compute Group
|
||||
type GroupParentAddRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// ID of the Compute Group
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
ParentID uint64 `url:"parentId"`
|
||||
|
||||
// ID of the parent Compute Group to register with the current Compute Group
|
||||
// Required: true
|
||||
ParentID uint64 `url:"parentId"`
|
||||
}
|
||||
|
||||
func (bsrq GroupParentAddRequest) Validate() error {
|
||||
func (bsrq GroupParentAddRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.ParentID == 0 {
|
||||
return errors.New("field ParentID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -29,16 +37,24 @@ func (bsrq GroupParentAddRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupParentAdd add parent Compute Group relation to the specified Compute Group
|
||||
func (b BService) GroupParentAdd(ctx context.Context, req GroupParentAddRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupParentAdd"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,21 +7,30 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for remove parent Compute Group
|
||||
// relation to the specified Compute Group
|
||||
type GroupParentRemoveRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// ID of the Compute Group
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
ParentID uint64 `url:"parentId"`
|
||||
|
||||
// ID of the parent Compute Group
|
||||
// to remove from the current Compute Group
|
||||
// Required: true
|
||||
ParentID uint64 `url:"parentId"`
|
||||
}
|
||||
|
||||
func (bsrq GroupParentRemoveRequest) Validate() error {
|
||||
func (bsrq GroupParentRemoveRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.ParentID == 0 {
|
||||
return errors.New("field ParentID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -29,16 +38,24 @@ func (bsrq GroupParentRemoveRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupParentRemove removes parent Compute Group relation to the specified Compute Group
|
||||
func (b BService) GroupParentRemove(ctx context.Context, req GroupParentRemoveRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupParentRemove"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,16 +7,21 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for destroy the specified Compute Group
|
||||
type GroupRemoveRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// ID of the Compute Group
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
}
|
||||
|
||||
func (bsrq GroupRemoveRequest) Validate() error {
|
||||
func (bsrq GroupRemoveRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -24,17 +29,25 @@ func (bsrq GroupRemoveRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupRemove destroy the specified Compute Group
|
||||
func (b BService) GroupRemove(ctx context.Context, req GroupRemoveRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupRemove"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -9,43 +9,64 @@ import (
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for resize the group
|
||||
type GroupResizeRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// ID of the Compute Group to resize
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
Count int64 `url:"count"`
|
||||
Mode string `url:"mode"`
|
||||
|
||||
// Either delta or absolute value of computes
|
||||
// Required: true
|
||||
Count int64 `url:"count"`
|
||||
|
||||
// Either delta or absolute value of computes
|
||||
// Should be one of:
|
||||
// - ABSOLUTE
|
||||
// - RELATIVE
|
||||
// Required: true
|
||||
Mode string `url:"mode"`
|
||||
}
|
||||
|
||||
func (bsrq GroupResizeRequest) Validate() error {
|
||||
func (bsrq GroupResizeRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Mode == "RELATIVE" && bsrq.Count == 0 {
|
||||
return errors.New("field Count can not be equal to 0 if Mode if 'RELATIVE'")
|
||||
}
|
||||
|
||||
if !validators.StringInSlice(bsrq.Mode, []string{"RELATIVE", "ABSOLUTE"}) {
|
||||
validate := validators.StringInSlice(bsrq.Mode, []string{"RELATIVE", "ABSOLUTE"})
|
||||
if !validate {
|
||||
return errors.New("field Mode can only be one of 'RELATIVE' or 'ABSOLUTE'")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupResize resize the group by changing the number of computes
|
||||
func (b BService) GroupResize(ctx context.Context, req GroupResizeRequest) (uint64, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupResize"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseUint(string(res), 10, 64)
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,16 +7,21 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for start the specified Compute Group
|
||||
type GroupStartRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// ID of the Compute Group to start
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
}
|
||||
|
||||
func (bsrq GroupStartRequest) Validate() error {
|
||||
func (bsrq GroupStartRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -24,16 +29,24 @@ func (bsrq GroupStartRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupStart starts the specified Compute Group within BasicService
|
||||
func (b BService) GroupStart(ctx context.Context, req GroupStartRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupStart"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,17 +7,25 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for stop the specified Compute Group
|
||||
type GroupStopRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// ID of the Compute Group to stop
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
Force bool `url:"force,omitempty"`
|
||||
|
||||
// Force stop Compute Group
|
||||
// Required: true
|
||||
Force bool `url:"force,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq GroupStopRequest) Validate() error {
|
||||
func (bsrq GroupStopRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -25,16 +33,24 @@ func (bsrq GroupStopRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupStop stops the specified Compute Group within BasicService
|
||||
func (b BService) GroupStop(ctx context.Context, req GroupStopRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupStop"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,22 +7,45 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for update existing Compute group
|
||||
type GroupUpdateRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// ID of the Compute Group
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
Name string `url:"name,omitempty"`
|
||||
Role string `url:"role,omitempty"`
|
||||
CPU uint64 `url:"cpu,omitempty"`
|
||||
RAM uint64 `url:"ram,omitempty"`
|
||||
Disk uint64 `url:"disk,omitempty"`
|
||||
Force bool `url:"force,omitempty"`
|
||||
|
||||
// Specify non-empty string to update Compute Group name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty"`
|
||||
|
||||
// Specify non-empty string to update group role
|
||||
// Required: false
|
||||
Role string `url:"role,omitempty"`
|
||||
|
||||
// Specify positive value to set new compute CPU count
|
||||
// Required: false
|
||||
CPU uint64 `url:"cpu,omitempty"`
|
||||
|
||||
// Specify positive value to set new compute RAM volume in MB
|
||||
// Required: false
|
||||
RAM uint64 `url:"ram,omitempty"`
|
||||
|
||||
// Specify new compute boot disk size in GB
|
||||
// Required: false
|
||||
Disk uint64 `url:"disk,omitempty"`
|
||||
|
||||
// Force resize Compute Group
|
||||
// Required: false
|
||||
Force bool `url:"force,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq GroupUpdateRequest) Validate() error {
|
||||
func (bsrq GroupUpdateRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -30,16 +53,24 @@ func (bsrq GroupUpdateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupUpdate updates existing Compute group within Basic Service and apply new settings to its computes as necessary
|
||||
func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupUpdate"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,17 +7,25 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for update External Network settings
|
||||
type GroupUpdateExtNetRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
ExtNets []uint64 `url:"extnets,omitempty"`
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// ID of the Compute Group
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
|
||||
// List of Extnets to connect computes
|
||||
// Required: false
|
||||
ExtNets []uint64 `url:"extnets,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq GroupUpdateExtNetRequest) Validate() error {
|
||||
func (bsrq GroupUpdateExtNetRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -25,16 +33,24 @@ func (bsrq GroupUpdateExtNetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupUpdateExtNet updates External Network settings for the group according to the new list
|
||||
func (b BService) GroupUpdateExtNet(ctx context.Context, req GroupUpdateExtNetRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupUpdateExtnet"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,17 +7,25 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for update VINS settings
|
||||
type GroupUpdateVINSRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
VINSes []uint64 `url:"vinses,omitempty"`
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
|
||||
// ID of the Compute Group
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
|
||||
// List of ViNSes to connect computes
|
||||
// Required: false
|
||||
VINSes []uint64 `url:"vinses,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq GroupUpdateVINSRequest) Validate() error {
|
||||
func (bsrq GroupUpdateVINSRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -25,16 +33,24 @@ func (bsrq GroupUpdateVINSRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupUpdateVINS update ViNS settings for the group according to the new list
|
||||
func (b BService) GroupUpdateVINS(ctx context.Context, req GroupUpdateVINSRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupUpdateVins"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -6,39 +6,59 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list/deleted list BasicService instances
|
||||
type ListRequest struct {
|
||||
// ID of the account to query for BasicService instances
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
RGID uint64 `url:"rgId,omitempty"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
|
||||
// ID of the resource group to query for BasicService instances
|
||||
// Required: false
|
||||
RGID uint64 `url:"rgId,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (b BService) List(ctx context.Context, req ListRequest) (BasicServiceList, error) {
|
||||
// List gets list BasicService instances associated with the specified Resource Group
|
||||
func (b BService) List(ctx context.Context, req ListRequest) (ListBasicServices, error) {
|
||||
url := "/cloudapi/bservice/list"
|
||||
bsListRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bsList := BasicServiceList{}
|
||||
if err := json.Unmarshal(bsListRaw, &bsList); err != nil {
|
||||
list := ListBasicServices{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bsList, nil
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (b BService) ListDeleted(ctx context.Context, req ListRequest) (BasicServiceList, error) {
|
||||
// ListDeleted gets list deleted BasicService instances associated with the specified Resource Group
|
||||
func (b BService) ListDeleted(ctx context.Context, req ListRequest) (ListBasicServices, error) {
|
||||
url := "/cloudapi/bservice/listDeleted"
|
||||
bsListRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bsList := BasicServiceList{}
|
||||
if err := json.Unmarshal(bsListRaw, &bsList); err != nil {
|
||||
list := ListBasicServices{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bsList, nil
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -1,123 +1,334 @@
|
||||
package bservice
|
||||
|
||||
type BasicService struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
BaseDomain string `json:"baseDomain"`
|
||||
Computes []Compute `json:"computes"`
|
||||
CPUTotal uint64 `json:"cpuTotal"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
DiskTotal uint64 `json:"diskTotal"`
|
||||
GID uint64 `json:"gid"`
|
||||
Groups []uint64 `json:"groups"`
|
||||
GroupsName []string `json:"groupsName"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
ParentSrvID uint64 `json:"parentSrvId"`
|
||||
ParentSrvType string `json:"parentSrvType"`
|
||||
RAMTotal uint64 `json:"ramTotal"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
Snapshots []Snapshot `json:"snapshots"`
|
||||
SSHKey string `json:"sshKey"`
|
||||
SSHUser string `json:"sshUser"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
UserManaged bool `json:"userManaged"`
|
||||
// Detailed info about BasicService
|
||||
type RecordBasicService struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Base domain
|
||||
BaseDomain string `json:"baseDomain"`
|
||||
|
||||
// List Computes
|
||||
Computes ListComputes `json:"computes"`
|
||||
|
||||
// Number of cores
|
||||
CPUTotal uint64 `json:"cpuTotal"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Amount of disk space used, GB
|
||||
DiskTotal uint64 `json:"diskTotal"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// List of Service Compute Group IDs
|
||||
Groups []uint64 `json:"groups"`
|
||||
|
||||
// List of compute groups by name
|
||||
GroupsName []string `json:"groupsName"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Parent service ID
|
||||
ParentSrvID uint64 `json:"parentSrvId"`
|
||||
|
||||
// Parent service type
|
||||
ParentSrvType string `json:"parentSrvType"`
|
||||
|
||||
// Total amount of RAM, MB
|
||||
RAMTotal uint64 `json:"ramTotal"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// List of snapshots
|
||||
Snapshots ListSnapshots `json:"snapshots"`
|
||||
|
||||
// SSH key for connection
|
||||
SSHKey string `json:"sshKey"`
|
||||
|
||||
// Username for SSH connection
|
||||
SSHUser string `json:"sshUser"`
|
||||
|
||||
// status
|
||||
Status string `json:"status"`
|
||||
|
||||
// TechStatus
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// Whether user controlled
|
||||
UserManaged bool `json:"userManaged"`
|
||||
}
|
||||
|
||||
type Compute struct {
|
||||
CompGroupID uint64 `json:"compgroupId"`
|
||||
// Main information about Compute
|
||||
type ItemCompute struct {
|
||||
// Compute group ID
|
||||
CompGroupID uint64 `json:"compgroupId"`
|
||||
|
||||
// Compute group name
|
||||
CompGroupName string `json:"compgroupName"`
|
||||
|
||||
// compute group role
|
||||
CompGroupRole string `json:"compgroupRole"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Snapshot struct {
|
||||
GUID string `json:"guid"`
|
||||
Label string `json:"label"`
|
||||
// List of Computes
|
||||
type ListComputes []ItemCompute
|
||||
|
||||
// Main information about Snapshot
|
||||
type ItemSnapshot struct {
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Label
|
||||
Label string `json:"label"`
|
||||
|
||||
// Timestamp
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
Valid bool `json:"valid"`
|
||||
|
||||
// Valid or not
|
||||
Valid bool `json:"valid"`
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
Computes []GroupCompute `json:"computes"`
|
||||
Consistency bool `json:"consistency"`
|
||||
CPU uint64 `json:"cpu"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Disk uint64 `json:"disk"`
|
||||
Driver string `json:"driver"`
|
||||
ExtNets []uint64 `json:"extnets"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
ImageID uint64 `json:"imageId"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
Parents []uint64 `json:"parents"`
|
||||
RAM uint64 `json:"ram"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
Role string `json:"role"`
|
||||
SepID uint64 `json:"sepId"`
|
||||
SeqNo uint64 `json:"seqNo"`
|
||||
ServiceID uint64 `json:"serviceId"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
TimeoutStart uint64 `json:"timeoutStart"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
VINSes []uint64 `json:"vinses"`
|
||||
// List of Snapshots
|
||||
type ListSnapshots []ItemSnapshot
|
||||
|
||||
// Main information about Group
|
||||
type RecordGroup struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account Name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// List of Computes
|
||||
Computes ListGroupComputes `json:"computes"`
|
||||
|
||||
// Consistency or not
|
||||
Consistency bool `json:"consistency"`
|
||||
|
||||
// Number of CPU
|
||||
CPU uint64 `json:"cpu"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Amount of disk
|
||||
Disk uint64 `json:"disk"`
|
||||
|
||||
// Driver
|
||||
Driver string `json:"driver"`
|
||||
|
||||
// list of External Network IDs
|
||||
ExtNets []uint64 `json:"extnets"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Image ID
|
||||
ImageID uint64 `json:"imageId"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// List of Parent IDs
|
||||
Parents []uint64 `json:"parents"`
|
||||
|
||||
// Number of RAM, MB
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// Role
|
||||
Role string `json:"role"`
|
||||
|
||||
// SEPID
|
||||
SEPID uint64 `json:"sepId"`
|
||||
|
||||
// Sequence number
|
||||
SeqNo uint64 `json:"seqNo"`
|
||||
|
||||
// Service ID
|
||||
ServiceID uint64 `json:"serviceId"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// TechStatus
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Timeout Start
|
||||
TimeoutStart uint64 `json:"timeoutStart"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// List of VINS IDs
|
||||
VINSes []uint64 `json:"vinses"`
|
||||
}
|
||||
|
||||
type GroupCompute struct {
|
||||
ID uint64 `json:"id"`
|
||||
// Main information about Group Compute
|
||||
type ItemGroupCompute struct {
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// IP Addresses
|
||||
IPAddresses []string `json:"ipAddresses"`
|
||||
Name string `json:"name"`
|
||||
OSUsers []OSUser `json:"osUsers"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// List of information about OS Users
|
||||
OSUsers ListOSUsers `json:"osUsers"`
|
||||
}
|
||||
|
||||
type OSUser struct {
|
||||
Login string `json:"login"`
|
||||
// List of Group Computes
|
||||
type ListGroupComputes []ItemGroupCompute
|
||||
|
||||
// Main information about OS User
|
||||
type ItemOSUser struct {
|
||||
// Login
|
||||
Login string `json:"login"`
|
||||
|
||||
// Password
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type BasicServiceShort struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
BaseDomain string `json:"baseDomain"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
GID uint64 `json:"gid"`
|
||||
Groups []uint64 `json:"groups"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ParentSrvID uint64 `json:"parentSrvId"`
|
||||
ParentSrvType string `json:"parentSrvType"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
SSHUser string `json:"sshUser"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
UserManaged bool `json:"userManaged"`
|
||||
// List of information about OS Users
|
||||
type ListOSUsers []ItemOSUser
|
||||
|
||||
// Main information about BasicService
|
||||
type ItemBasicService struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Base domain
|
||||
BaseDomain string `json:"baseDomain"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// List of group IDs
|
||||
Groups []uint64 `json:"groups"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Parent service ID
|
||||
ParentSrvID uint64 `json:"parentSrvId"`
|
||||
|
||||
// Parent service type
|
||||
ParentSrvType string `json:"parentSrvType"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// SSH user
|
||||
SSHUser string `json:"sshUser"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// TechStatus
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// User Managed or not
|
||||
UserManaged bool `json:"userManaged"`
|
||||
}
|
||||
|
||||
type BasicServiceList []BasicServiceShort
|
||||
// List of BasicServices
|
||||
type ListBasicServices []ItemBasicService
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for restores BasicService instance
|
||||
type RestoreRequest struct {
|
||||
// ID of the BasicService to be restored
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq RestoreRequest) Validate() error {
|
||||
func (bsrq RestoreRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,16 +22,24 @@ func (bsrq RestoreRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Restore restores BasicService instance
|
||||
func (b BService) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/restore"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,16 +7,21 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for create snapshot
|
||||
type SnapshotCreateRequest struct {
|
||||
// ID of the Basic Service
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
Label string `url:"label"`
|
||||
|
||||
// Label of the snapshot
|
||||
// Required: true
|
||||
Label string `url:"label"`
|
||||
}
|
||||
|
||||
func (bsrq SnapshotCreateRequest) Validate() error {
|
||||
func (bsrq SnapshotCreateRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Label == "" {
|
||||
return errors.New("field Label can not be empty")
|
||||
}
|
||||
@@ -24,16 +29,24 @@ func (bsrq SnapshotCreateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SnapshotCreate create snapshot of the Basic Service
|
||||
func (b BService) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotCreate"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,16 +7,21 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete snapshot
|
||||
type SnapshotDeleteRequest struct {
|
||||
// ID of the Basic Service
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
Label string `url:"label"`
|
||||
|
||||
// Label of the snapshot
|
||||
// Required: true
|
||||
Label string `url:"label"`
|
||||
}
|
||||
|
||||
func (bsrq SnapshotDeleteRequest) Validate() error {
|
||||
func (bsrq SnapshotDeleteRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Label == "" {
|
||||
return errors.New("field Label can not be empty")
|
||||
}
|
||||
@@ -24,16 +29,24 @@ func (bsrq SnapshotDeleteRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SnapshotDelete delete snapshot of the Basic Service
|
||||
func (b BService) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotDelete"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list existing snapshots
|
||||
type SnapshotListRequest struct {
|
||||
// ID of the Basic Service
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq SnapshotListRequest) Validate() error {
|
||||
func (bsrq SnapshotListRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,21 +22,26 @@ func (bsrq SnapshotListRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest) ([]Snapshot, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotList"
|
||||
snapshotListRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
// SnapshotList gets list existing snapshots of the Basic Service
|
||||
func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest) (ListSnapshots, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
snapshotList := []Snapshot{}
|
||||
if err := json.Unmarshal(snapshotListRaw, &snapshotList); err != nil {
|
||||
url := "/cloudapi/bservice/snapshotList"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return snapshotList, nil
|
||||
list := ListSnapshots{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -7,16 +7,21 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for rollback snapshot
|
||||
type SnapshotRollbackRequest struct {
|
||||
// ID of the Basic Service
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
Label string `url:"label"`
|
||||
|
||||
// Label of the snapshot
|
||||
// Required: true
|
||||
Label string `url:"label"`
|
||||
}
|
||||
|
||||
func (bsrq SnapshotRollbackRequest) Validate() error {
|
||||
func (bsrq SnapshotRollbackRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Label == "" {
|
||||
return errors.New("field Label can not be empty")
|
||||
}
|
||||
@@ -24,16 +29,24 @@ func (bsrq SnapshotRollbackRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SnapshotRollback rollback snapshot of the Basic Service
|
||||
func (b BService) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotRollback"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for start service
|
||||
type StartRequest struct {
|
||||
// ID of the service to start
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq StartRequest) Validate() error {
|
||||
func (bsrq StartRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,16 +22,26 @@ func (bsrq StartRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start starts service.
|
||||
// Starting a service technically means starting computes from all
|
||||
// service groups according to group relations
|
||||
func (b BService) Start(ctx context.Context, req StartRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/start"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for stop service
|
||||
type StopRequest struct {
|
||||
// ID of the service to stop
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq StopRequest) Validate() error {
|
||||
func (bsrq StopRequest) validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,16 +22,26 @@ func (bsrq StopRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop stops service.
|
||||
// Stopping a service technically means stopping computes from
|
||||
// all service groups
|
||||
func (b BService) Stop(ctx context.Context, req StopRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/stop"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user