Refactoring

This commit is contained in:
stSolo
2022-08-11 16:39:39 +03:00
parent 9563097dcb
commit 39a6f9a1ce
300 changed files with 64 additions and 58 deletions

View File

@@ -0,0 +1,13 @@
package bservice
import "github.com/rudecs/decort-sdk/interfaces"
type BService struct {
client interfaces.Caller
}
func New(client interfaces.Caller) *BService {
return &BService{
client,
}
}

View File

@@ -0,0 +1,43 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type CreateRequest struct {
Name string `url:"name"`
RGID uint64 `url:"rgId"`
SSHUser string `url:"sshUser,omitempty"`
SSHKey string `url:"sshKey,omitempty"`
}
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")
}
return nil
}
func (b BService) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) {
if err := req.Validate(); err != nil {
return 0, err
}
url := "/cloudapi/bservice/create"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return 0, err
}
return strconv.ParseUint(string(res), 10, 64)
}

View File

@@ -0,0 +1,37 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DeleteRequest struct {
ServiceID uint64 `url:"serviceId"`
Permanently bool `url:"permanently,omitempty"`
}
func (bsrq DeleteRequest) Validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
}
func (b BService) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/delete"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,36 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DisableRequest struct {
ServiceID uint64 `url:"serviceId"`
}
func (bsrq DisableRequest) Validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
}
func (b BService) Disable(ctx context.Context, req DisableRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/delete"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,36 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type EnableRequest struct {
ServiceID uint64 `url:"serviceId"`
}
func (bsrq EnableRequest) Validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
}
func (b BService) Enable(ctx context.Context, req EnableRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/enable"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,41 @@
package bservice
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetRequest struct {
ServiceID uint64 `url:"serviceId"`
}
func (bsrq GetRequest) Validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
}
func (b BService) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*BasicService, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/bservice/get"
bsRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
bs := &BasicService{}
if err := json.Unmarshal(bsRaw, bs); err != nil {
return nil, err
}
return bs, nil
}

View File

@@ -0,0 +1,75 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
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"`
}
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")
}
return nil
}
func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest, options ...opts.DecortOpts) (uint64, error) {
if err := req.Validate(); err != nil {
return 0, err
}
url := "/cloudapi/bservice/groupAdd"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return 0, err
}
return strconv.ParseUint(string(res), 10, 64)
}

View File

@@ -0,0 +1,46 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GroupComputeRemoveRequest struct {
ServiceID uint64 `url:"serviceId"`
CompGroupID uint64 `url:"compgroupId"`
ComputeID uint64 `url:"computeId"`
}
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")
}
return nil
}
func (b BService) GroupComputeRemove(ctx context.Context, req GroupComputeRemoveRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/groupComputeRemove"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,46 @@
package bservice
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GroupGetRequest struct {
ServiceID uint64 `url:"serviceId"`
CompGroupID uint64 `url:"compgroupId"`
}
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")
}
return nil
}
func (b BService) GroupGet(ctx context.Context, req GroupGetRequest, options ...opts.DecortOpts) (*Group, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/bservice/groupGet"
groupRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
group := &Group{}
if err := json.Unmarshal(groupRaw, group); err != nil {
return nil, err
}
return group, nil
}

View File

@@ -0,0 +1,46 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GroupParentAddRequest struct {
ServiceID uint64 `url:"serviceId"`
CompGroupID uint64 `url:"compgroupId"`
ParentID uint64 `url:"parentId"`
}
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")
}
return nil
}
func (b BService) GroupParentAdd(ctx context.Context, req GroupParentAddRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/groupParentAdd"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,46 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GroupParentRemoveRequest struct {
ServiceID uint64 `url:"serviceId"`
CompGroupID uint64 `url:"compgroupId"`
ParentID uint64 `url:"parentId"`
}
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")
}
return nil
}
func (b BService) GroupParentRemove(ctx context.Context, req GroupParentRemoveRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/groupParentRemove"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,42 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GroupRemoveRequest struct {
ServiceID uint64 `url:"serviceId"`
CompGroupID uint64 `url:"compgroupId"`
}
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")
}
return nil
}
func (b BService) GroupRemove(ctx context.Context, req GroupRemoveRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/groupRemove"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,52 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GroupResizeRequest struct {
ServiceID uint64 `url:"serviceId"`
CompGroupID uint64 `url:"compgroupId"`
Count int64 `url:"count"`
Mode string `url:"mode"`
}
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"}) {
return errors.New("field Mode can only be one of 'RELATIVE' or 'ABSOLUTE'")
}
return nil
}
func (b BService) GroupResize(ctx context.Context, req GroupResizeRequest, options ...opts.DecortOpts) (uint64, error) {
if err := req.Validate(); err != nil {
return 0, err
}
url := "/cloudapi/bservice/groupResize"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return 0, err
}
return strconv.ParseUint(string(res), 10, 64)
}

View File

@@ -0,0 +1,41 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GroupStartRequest struct {
ServiceID uint64 `url:"serviceId"`
CompGroupID uint64 `url:"compgroupId"`
}
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")
}
return nil
}
func (b BService) GroupStart(ctx context.Context, req GroupStartRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/groupStart"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,42 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GroupStopRequest struct {
ServiceID uint64 `url:"serviceId"`
CompGroupID uint64 `url:"compgroupId"`
Force bool `url:"force,omitempty"`
}
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")
}
return nil
}
func (b BService) GroupStop(ctx context.Context, req GroupStopRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/groupStop"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,47 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GroupUpdateRequest struct {
ServiceID uint64 `url:"serviceId"`
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"`
}
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")
}
return nil
}
func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/groupUpdate"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,42 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GroupUpdateExtnetRequest struct {
ServiceID uint64 `url:"serviceId"`
CompGroupID uint64 `url:"compgroupId"`
Extnets []uint64 `url:"extnets,omitempty"`
}
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")
}
return nil
}
func (b BService) GroupUpdateExtnet(ctx context.Context, req GroupUpdateExtnetRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/groupUpdateExtnet"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,42 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GroupUpdateVINSRequest struct {
ServiceID uint64 `url:"serviceId"`
CompGroupID uint64 `url:"compgroupId"`
VINSes []uint64 `url:"vinses,omitempty"`
}
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")
}
return nil
}
func (b BService) GroupUpdateVINS(ctx context.Context, req GroupUpdateVINSRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/groupUpdateVins"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,46 @@
package bservice
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListRequest struct {
AccountID uint64 `url:"accountId,omitempty"`
RGID uint64 `url:"rgId,omitempty"`
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
}
func (b BService) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (BasicServiceList, error) {
url := "/cloudapi/bservice/list"
bsListRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
bsList := BasicServiceList{}
if err := json.Unmarshal(bsListRaw, &bsList); err != nil {
return nil, err
}
return bsList, nil
}
func (b BService) ListDeleted(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (BasicServiceList, error) {
url := "/cloudapi/bservice/listDeleted"
bsListRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
bsList := BasicServiceList{}
if err := json.Unmarshal(bsListRaw, &bsList); err != nil {
return nil, err
}
return bsList, nil
}

View File

@@ -0,0 +1,123 @@
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"`
}
type Compute struct {
CompGroupID uint64 `json:"compgroupId"`
CompGroupName string `json:"compgroupName"`
CompGroupRole string `json:"compgroupRole"`
ID uint64 `json:"id"`
Name string `json:"name"`
}
type Snapshot struct {
GUID string `json:"guid"`
Label string `json:"label"`
Timestamp uint64 `json:"timestamp"`
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"`
}
type GroupCompute struct {
ID uint64 `json:"id"`
IPAddresses []string `json:"ipAddresses"`
Name string `json:"name"`
OSUsers []OSUser `json:"osUsers"`
}
type OSUser struct {
Login string `json:"login"`
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"`
}
type BasicServiceList []BasicServiceShort

View File

@@ -0,0 +1,36 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type RestoreRequest struct {
ServiceID uint64 `url:"serviceId"`
}
func (bsrq RestoreRequest) Validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
}
func (b BService) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/restore"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,41 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SnapshotCreateRequest struct {
ServiceID uint64 `url:"serviceId"`
Label string `url:"label"`
}
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")
}
return nil
}
func (b BService) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/snapshotCreate"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,41 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SnapshotDeleteRequest struct {
ServiceID uint64 `url:"serviceId"`
Label string `url:"label"`
}
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")
}
return nil
}
func (b BService) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/snapshotDelete"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,41 @@
package bservice
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SnapshotListRequest struct {
ServiceID uint64 `url:"serviceId"`
}
func (bsrq SnapshotListRequest) Validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
}
func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest, options ...opts.DecortOpts) ([]Snapshot, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/bservice/snapshotList"
snapshotListRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
snapshotList := []Snapshot{}
if err := json.Unmarshal(snapshotListRaw, &snapshotList); err != nil {
return nil, err
}
return snapshotList, nil
}

View File

@@ -0,0 +1,41 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SnapshotRollbackRequest struct {
ServiceID uint64 `url:"serviceId"`
Label string `url:"label"`
}
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")
}
return nil
}
func (b BService) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/snapshotRollback"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,36 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type StartRequest struct {
ServiceID uint64 `url:"serviceId"`
}
func (bsrq StartRequest) Validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
}
func (b BService) Start(ctx context.Context, req StartRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/start"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}

View File

@@ -0,0 +1,36 @@
package bservice
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type StopRequest struct {
ServiceID uint64 `url:"serviceId"`
}
func (bsrq StopRequest) Validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
}
func (b BService) Stop(ctx context.Context, req StopRequest, options ...opts.DecortOpts) (bool, error) {
if err := req.Validate(); err != nil {
return false, err
}
url := "/cloudapi/bservice/stop"
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
return strconv.ParseBool(string(res))
}