diff --git a/config/config.go b/config/config.go index f5681bb..4a079a4 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,7 @@ package config type Config struct { + Token string AppID string AppSecret string SSOURL string diff --git a/internal/client/http-client.go b/internal/client/http-client.go index fa88772..d427bdc 100644 --- a/internal/client/http-client.go +++ b/internal/client/http-client.go @@ -17,6 +17,12 @@ func NewHttpClient(cfg config.Config) *http.Client { }, } + var expiredTime time.Time + + if cfg.Token != "" { + expiredTime = time.Now().AddDate(0, 0, 1) + } + return &http.Client{ Transport: &transport{ base: transCfg, @@ -24,6 +30,8 @@ func NewHttpClient(cfg config.Config) *http.Client { clientID: cfg.AppID, clientSecret: cfg.AppSecret, SSOURL: cfg.SSOURL, + token: cfg.Token, + expiryTime: expiredTime, //TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, }, diff --git a/pkg/cloudbroker/kvmppc.go b/pkg/cloudbroker/kvmppc.go index 78720d8..01175c9 100644 --- a/pkg/cloudbroker/kvmppc.go +++ b/pkg/cloudbroker/kvmppc.go @@ -1,6 +1,6 @@ package cloudbroker -import "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmppc" +import "github.com/rudecs/decort-sdk/pkg/cloudbroker/kvmppc" func (cb *CloudBroker) KVMPPC() *kvmppc.KVMPPC { return kvmppc.New(cb.client) diff --git a/pkg/cloudbroker/kvmppc/create.go b/pkg/cloudbroker/kvmppc/create.go new file mode 100644 index 0000000..11f0db8 --- /dev/null +++ b/pkg/cloudbroker/kvmppc/create.go @@ -0,0 +1,70 @@ +package kvmppc + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateRequest struct { + RGID uint64 `url:"rgId"` + Name string `url:"name"` + CPU uint64 `url:"cpu"` + RAM uint64 `url:"ram"` + ImageID uint64 `url:"imageId"` + BootDisk uint64 `url:"bootDisk,omitempty"` + SepID uint64 `url:"sepId,omitempty"` + Pool string `url:"pool,omitempty"` + NetType string `url:"netType,omitempty"` + NetID uint64 `url:"netId,omitempty"` + IPAddr string `url:"ipAddr,omitempty"` + UserData string `url:"userdata,omitempty"` + Desc string `url:"desc,omitempty"` + Start bool `url:"start,omitempty"` + StackID uint64 `url:"stackId,omitempty"` + IS string `url:"IS,omitempty"` + IpaType string `url:"ipaType,omitempty"` + Reason string `url:"reason,omitempty"` +} + +func (krq CreateRequest) Validate() error { + if krq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + if krq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + if krq.CPU == 0 { + return errors.New("validation-error: field CPU must be set") + } + if krq.RAM == 0 { + return errors.New("validation-error: field RAM must be set") + } + if krq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + + return nil +} + +func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/kvmppc/create" + + res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/kvmppc/create_blank.go b/pkg/cloudbroker/kvmppc/create_blank.go new file mode 100644 index 0000000..31db970 --- /dev/null +++ b/pkg/cloudbroker/kvmppc/create_blank.go @@ -0,0 +1,70 @@ +package kvmppc + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateBlankRequest struct { + RGID uint64 `url:"rgId"` + Name string `url:"name"` + CPU uint64 `url:"cpu"` + RAM uint64 `url:"ram"` + BootDisk uint64 `url:"bootDisk"` + SepID uint64 `url:"sepId"` + Pool string `url:"pool"` + NetType string `url:"netType,omitempty"` + NetID uint64 `url:"netId,omitempty"` + IPAddr string `url:"ipAddr,omitempty"` + Desc string `url:"desc,omitempty"` +} + +func (krq CreateBlankRequest) Validate() error { + if krq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + if krq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + if krq.CPU == 0 { + return errors.New("validation-error: field CPU must be set") + } + if krq.RAM == 0 { + return errors.New("validation-error: field RAM must be set") + } + if krq.BootDisk == 0 { + return errors.New("validation-error: field BootDisk must be set") + } + if krq.SepID == 0 { + return errors.New("validation-error: field SepID must be set") + } + if krq.Pool == "" { + return errors.New("validation-error: field Pool must be set") + } + + return nil +} + +func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/kvmppc/createBlank" + + res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil + +} diff --git a/pkg/cloudbroker/kvmppc/kvmppc.go b/pkg/cloudbroker/kvmppc/kvmppc.go new file mode 100644 index 0000000..8ae640d --- /dev/null +++ b/pkg/cloudbroker/kvmppc/kvmppc.go @@ -0,0 +1,13 @@ +package kvmppc + +import "github.com/rudecs/decort-sdk/interfaces" + +type KVMPPC struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *KVMPPC { + return &KVMPPC{ + client: client, + } +} diff --git a/pkg/cloudbroker/kvmppc/mass_create.go b/pkg/cloudbroker/kvmppc/mass_create.go new file mode 100644 index 0000000..95850cd --- /dev/null +++ b/pkg/cloudbroker/kvmppc/mass_create.go @@ -0,0 +1,73 @@ +package kvmppc + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type MassCreateRequest struct { + RGID uint64 `url:"rgId"` + Name string `url:"name"` + Count uint64 `url:"count"` + CPU uint64 `url:"cpu"` + RAM uint64 `url:"ram"` + ImageID uint64 `url:"imageId"` + BootDisk uint64 `url:"bootDisk,omitempty"` + SepID uint64 `url:"sepId,omitempty"` + Pool string `url:"pool,omitempty"` + NetType string `url:"netType,omitempty"` + NetID uint64 `url:"netId,omitempty"` + IPAddr string `url:"ipAddr,omitempty"` + UserData string `url:"userdata,omitempty"` + Desc string `url:"desc,omitempty"` + Start bool `url:"start,omitempty"` + Reason string `url:"reason,omitempty"` +} + +func (krq MassCreateRequest) Validate() error { + if krq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + if krq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + if krq.Count == 0 { + return errors.New("validation-error: field Count must be set") + } + if krq.CPU == 0 { + return errors.New("validation-error: field CPU must be set") + } + if krq.RAM == 0 { + return errors.New("validation-error: field RAM must be set") + } + if krq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + + return nil +} + +func (k KVMPPC) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudbroker/kvmppc/massCreate" + + res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + computes := make([]uint64, 0) + + err = json.Unmarshal(res, &computes) + if err != nil { + return nil, err + } + + return computes, nil +} diff --git a/pkg/cloudbroker/kvmx86.go b/pkg/cloudbroker/kvmx86.go index 0da6b71..5549f3d 100644 --- a/pkg/cloudbroker/kvmx86.go +++ b/pkg/cloudbroker/kvmx86.go @@ -1,7 +1,7 @@ package cloudbroker import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmx86" + "github.com/rudecs/decort-sdk/pkg/cloudbroker/kvmx86" ) func (cb *CloudBroker) KVMX86() *kvmx86.KVMX86 { diff --git a/pkg/cloudbroker/kvmx86/create.go b/pkg/cloudbroker/kvmx86/create.go new file mode 100644 index 0000000..04d4e5b --- /dev/null +++ b/pkg/cloudbroker/kvmx86/create.go @@ -0,0 +1,70 @@ +package kvmx86 + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateRequest struct { + RGID uint64 `url:"rgId"` + Name string `url:"name"` + CPU uint64 `url:"cpu"` + RAM uint64 `url:"ram"` + ImageID uint64 `url:"imageId"` + BootDisk uint64 `url:"bootDisk,omitempty"` + SepID uint64 `url:"sepId,omitempty"` + Pool string `url:"pool,omitempty"` + NetType string `url:"netType,omitempty"` + NetID uint64 `url:"netId,omitempty"` + IPAddr string `url:"ipAddr,omitempty"` + UserData string `url:"userdata,omitempty"` + Desc string `url:"desc,omitempty"` + Start bool `url:"start,omitempty"` + StackID uint64 `url:"stackId,omitempty"` + IS string `url:"IS,omitempty"` + IpaType string `url:"ipaType,omitempty"` + Reason string `url:"reason,omitempty"` +} + +func (krq CreateRequest) Validate() error { + if krq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + if krq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + if krq.CPU == 0 { + return errors.New("validation-error: field CPU must be set") + } + if krq.RAM == 0 { + return errors.New("validation-error: field RAM must be set") + } + if krq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + + return nil +} + +func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/kvmx86/create" + + res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/kvmx86/create_blank.go b/pkg/cloudbroker/kvmx86/create_blank.go new file mode 100644 index 0000000..77d4202 --- /dev/null +++ b/pkg/cloudbroker/kvmx86/create_blank.go @@ -0,0 +1,70 @@ +package kvmx86 + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateBlankRequest struct { + RGID uint64 `url:"rgId"` + Name string `url:"name"` + CPU uint64 `url:"cpu"` + RAM uint64 `url:"ram"` + BootDisk uint64 `url:"bootDisk"` + SepID uint64 `url:"sepId"` + Pool string `url:"pool"` + NetType string `url:"netType,omitempty"` + NetID uint64 `url:"netId,omitempty"` + IPAddr string `url:"ipAddr,omitempty"` + Desc string `url:"desc,omitempty"` +} + +func (krq CreateBlankRequest) Validate() error { + if krq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + if krq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + if krq.CPU == 0 { + return errors.New("validation-error: field CPU must be set") + } + if krq.RAM == 0 { + return errors.New("validation-error: field RAM must be set") + } + if krq.BootDisk == 0 { + return errors.New("validation-error: field BootDisk must be set") + } + if krq.SepID == 0 { + return errors.New("validation-error: field SepID must be set") + } + if krq.Pool == "" { + return errors.New("validation-error: field Pool must be set") + } + + return nil +} + +func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/kvmx86/createBlank" + + res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil + +} \ No newline at end of file diff --git a/pkg/cloudbroker/kvmx86/kvmx86.go b/pkg/cloudbroker/kvmx86/kvmx86.go new file mode 100644 index 0000000..1fa447a --- /dev/null +++ b/pkg/cloudbroker/kvmx86/kvmx86.go @@ -0,0 +1,13 @@ +package kvmx86 + +import "github.com/rudecs/decort-sdk/interfaces" + +type KVMX86 struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *KVMX86 { + return &KVMX86{ + client: client, + } +} diff --git a/pkg/cloudbroker/kvmx86/mass_create.go b/pkg/cloudbroker/kvmx86/mass_create.go new file mode 100644 index 0000000..144aed4 --- /dev/null +++ b/pkg/cloudbroker/kvmx86/mass_create.go @@ -0,0 +1,73 @@ +package kvmx86 + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type MassCreateRequest struct { + RGID uint64 `url:"rgId"` + Name string `url:"name"` + Count uint64 `url:"count"` + CPU uint64 `url:"cpu"` + RAM uint64 `url:"ram"` + ImageID uint64 `url:"imageId"` + BootDisk uint64 `url:"bootDisk,omitempty"` + SepID uint64 `url:"sepId,omitempty"` + Pool string `url:"pool,omitempty"` + NetType string `url:"netType,omitempty"` + NetID uint64 `url:"netId,omitempty"` + IPAddr string `url:"ipAddr,omitempty"` + UserData string `url:"userdata,omitempty"` + Desc string `url:"desc,omitempty"` + Start bool `url:"start,omitempty"` + Reason string `url:"reason,omitempty"` +} + +func (krq MassCreateRequest) Validate() error { + if krq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + if krq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + if krq.Count == 0 { + return errors.New("validation-error: field Count must be set") + } + if krq.CPU == 0 { + return errors.New("validation-error: field CPU must be set") + } + if krq.RAM == 0 { + return errors.New("validation-error: field RAM must be set") + } + if krq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + + return nil +} + +func (k KVMX86) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudbroker/kvmx86/massCreate" + + res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + computes := make([]uint64, 0) + + err = json.Unmarshal(res, &computes) + if err != nil { + return nil, err + } + + return computes, nil +} diff --git a/pkg/cloudbroker/rg.go b/pkg/cloudbroker/rg.go index f6ca4ce..ff4a672 100644 --- a/pkg/cloudbroker/rg.go +++ b/pkg/cloudbroker/rg.go @@ -1,6 +1,6 @@ package cloudbroker -import "github.com/rudecs/decort-sdk/pkg/cloudapi/rg" +import "github.com/rudecs/decort-sdk/pkg/cloudbroker/rg" func (cb *CloudBroker) RG() *rg.RG { return rg.New(cb.client) diff --git a/pkg/cloudbroker/rg/access_grant.go b/pkg/cloudbroker/rg/access_grant.go new file mode 100644 index 0000000..f384453 --- /dev/null +++ b/pkg/cloudbroker/rg/access_grant.go @@ -0,0 +1,54 @@ +package rg + +import ( + "context" + "errors" + "github.com/rudecs/decort-sdk/internal/validators" + "net/http" + "strconv" +) + +type AccessGrantRequest struct { + RGID uint64 `url:"rgId"` + User string `url:"user"` + Right string `url:"right"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq AccessGrantRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + if rgrq.User == "" { + return errors.New("validation-error: field User must be set") + } + + validate := validators.StringInSlice(rgrq.Right, []string{"R", "RCX", "ARCXDU"}) + if !validate { + return errors.New("field Right can only be one of 'R', 'RCX' or 'ARCXDU'") + } + + return nil +} + +func (r RG) AccessGrant(ctx context.Context, req AccessGrantRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/rg/accessGrant" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/rg/access_revoke.go b/pkg/cloudbroker/rg/access_revoke.go new file mode 100644 index 0000000..6a4b020 --- /dev/null +++ b/pkg/cloudbroker/rg/access_revoke.go @@ -0,0 +1,46 @@ +package rg + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type AccessRevokeRequest struct { + RGID uint64 `url:"rgId"` + User string `url:"user"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq AccessRevokeRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + if rgrq.User == "" { + return errors.New("validation-error: field User must be set") + } + + return nil +} + +func (r RG) AccessRevoke(ctx context.Context, req AccessRevokeRequest) (bool, error) { + if err := req.Validate(); err != nil { + return false, err + } + + url := "/cloudbroker/rg/accessRevoke" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/rg/affinity_group_computes.go b/pkg/cloudbroker/rg/affinity_group_computes.go new file mode 100644 index 0000000..809039d --- /dev/null +++ b/pkg/cloudbroker/rg/affinity_group_computes.go @@ -0,0 +1,46 @@ +package rg + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type AffinityGroupComputesRequest struct { + RGID uint64 `url:"rgId"` + AffinityGroup string `url:"affinityGroup"` +} + +func (rgrq AffinityGroupComputesRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + if rgrq.AffinityGroup == "" { + return errors.New("validation-error: field AffinityGroup must be set") + } + + return nil +} + +func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (AffinityGroupComputeList, error) { + if err := req.Validate(); err != nil { + return nil, err + } + + url := "/cloudbroker/rg/affinityGroupComputes" + + agcListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + agcList := AffinityGroupComputeList{} + + if err := json.Unmarshal(agcListRaw, &agcList); err != nil { + return nil, err + } + + return agcList, nil +} diff --git a/pkg/cloudbroker/rg/affinity_groups_get.go b/pkg/cloudbroker/rg/affinity_groups_get.go new file mode 100644 index 0000000..7a3ff30 --- /dev/null +++ b/pkg/cloudbroker/rg/affinity_groups_get.go @@ -0,0 +1,47 @@ +package rg + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type AffinityGroupsGetRequest struct { + RGID uint64 `url:"rgId"` + AffinityGroup string `url:"affinityGroup"` +} + +func (rgrq AffinityGroupsGetRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + if rgrq.AffinityGroup == "" { + return errors.New("validation-error: field AffinityGroup must be set") + } + + return nil +} + +func (r RG) AffinityGroupsGet(ctx context.Context, req AffinityGroupsGetRequest) ([]uint64, error) { + if err := req.Validate(); err != nil { + return nil, err + } + + url := "/cloudbroker/rg/affinityGroupsGet" + + agListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + agList := make([]uint64, 0) + + err = json.Unmarshal(agListRaw, &agList) + if err != nil { + return nil, err + } + + return agList, nil +} diff --git a/pkg/cloudbroker/rg/affinity_groups_list.go b/pkg/cloudbroker/rg/affinity_groups_list.go new file mode 100644 index 0000000..27cdd6b --- /dev/null +++ b/pkg/cloudbroker/rg/affinity_groups_list.go @@ -0,0 +1,42 @@ +package rg + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type AffinityGroupsListRequest struct { + RGID uint64 `url:"rgId"` +} + +func (rgrq AffinityGroupsListRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (map[string][]uint64, error) { + if err := req.Validate(); err != nil { + return nil, err + } + + url := "/cloudbroker/rg/affinityGroupsList" + + agListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + agList := make(map[string][]uint64) + + err = json.Unmarshal(agListRaw, &agList) + if err != nil { + return nil, err + } + + return agList, nil +} diff --git a/pkg/cloudbroker/rg/audits.go b/pkg/cloudbroker/rg/audits.go new file mode 100644 index 0000000..c57034f --- /dev/null +++ b/pkg/cloudbroker/rg/audits.go @@ -0,0 +1,41 @@ +package rg + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type AuditsRequest struct { + RGID uint64 `url:"rgId"` +} + +func (rgrq AuditsRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) Audits(ctx context.Context, req AuditsRequest) (AuditList, error) { + if err := req.Validate(); err != nil { + return nil, err + } + + url := "/cloudbroker/rg/audits" + + auditListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + auditList := AuditList{} + + if err := json.Unmarshal(auditListRaw, &auditList); err != nil { + return nil, err + } + + return auditList, nil +} diff --git a/pkg/cloudbroker/rg/create.go b/pkg/cloudbroker/rg/create.go new file mode 100644 index 0000000..f30a47d --- /dev/null +++ b/pkg/cloudbroker/rg/create.go @@ -0,0 +1,64 @@ +package rg + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateRequest struct { + AccountID uint64 `url:"accountId"` + GID uint64 `url:"gid"` + Name string `url:"name"` + MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"` + MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"` + MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"` + MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"` + MaxNumPublicIP uint64 `url:"maxNetworkPeerTransfer,omitempty"` + Owner string `url:"owner,omitempty"` + DefNet string `url:"def_net,omitempty"` + IPCIDR string `url:"ipcidr,omitempty"` + Desc string `url:"desc,omitempty"` + Reason string `url:"reason,omitempty"` + ExtNetID uint64 `url:"extNetId,omitempty"` + ExtIP string `url:"extIp,omitempty"` + RegisterComputes bool `url:"registerComputes,omitempty"` +} + +func (rgrq CreateRequest) Validate() error { + if rgrq.AccountID == 0 { + return errors.New("field AccountID can not be empty or equal to 0") + } + + if rgrq.GID == 0 { + return errors.New("field GID can not be empty or equal to 0") + } + + if len(rgrq.Name) < 2 { + return errors.New("field Name can not be shorter than two bytes") + } + + return nil +} + +func (r RG) Create(ctx context.Context, req CreateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/rg/create" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/rg/delete.go b/pkg/cloudbroker/rg/delete.go new file mode 100644 index 0000000..f38b844 --- /dev/null +++ b/pkg/cloudbroker/rg/delete.go @@ -0,0 +1,44 @@ +package rg + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteRequest struct { + RGID uint64 `url:"rgId"` + Force bool `url:"force,omitempty"` + Permanently bool `url:"permanently,omitempty"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq DeleteRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) Delete(ctx context.Context, req DeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/rg/delete" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/rg/disable.go b/pkg/cloudbroker/rg/disable.go new file mode 100644 index 0000000..a373690 --- /dev/null +++ b/pkg/cloudbroker/rg/disable.go @@ -0,0 +1,42 @@ +package rg + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DisableRequest struct { + RGID uint64 `url:"rgId"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq DisableRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) Disable(ctx context.Context, req DisableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/rg/disable" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/rg/enable.go b/pkg/cloudbroker/rg/enable.go new file mode 100644 index 0000000..bc1b49d --- /dev/null +++ b/pkg/cloudbroker/rg/enable.go @@ -0,0 +1,42 @@ +package rg + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type EnableRequest struct { + RGID uint64 `url:"rgId"` + Reason string `url:"reason"` +} + +func (rgrq EnableRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) Enable(ctx context.Context, req EnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/rg/enable" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/rg/get.go b/pkg/cloudbroker/rg/get.go new file mode 100644 index 0000000..145d9b7 --- /dev/null +++ b/pkg/cloudbroker/rg/get.go @@ -0,0 +1,44 @@ +package rg + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + RGID uint64 `url:"rgId"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq GetRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) Get(ctx context.Context, req GetRequest) (*ResourceGroup, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudbroker/rg/get" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + getResult := ResourceGroup{} + + err = json.Unmarshal(res, &getResult) + if err != nil { + return nil, err + } + + return &getResult, nil +} diff --git a/pkg/cloudbroker/rg/list.go b/pkg/cloudbroker/rg/list.go new file mode 100644 index 0000000..140a015 --- /dev/null +++ b/pkg/cloudbroker/rg/list.go @@ -0,0 +1,31 @@ +package rg + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + IncludeDeleted bool `url:"includedeleted,omitempty"` + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (r RG) List(ctx context.Context, req ListRequest) (List, error) { + url := "/cloudbroker/rg/list" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + list := List{} + + err = json.Unmarshal(res, &list) + if err != nil { + return nil, err + } + + return list, nil +} diff --git a/pkg/cloudbroker/rg/list_computes.go b/pkg/cloudbroker/rg/list_computes.go new file mode 100644 index 0000000..8623b85 --- /dev/null +++ b/pkg/cloudbroker/rg/list_computes.go @@ -0,0 +1,44 @@ +package rg + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListComputesRequest struct { + RGID uint64 `url:"rgId"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq ListComputesRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudbroker/rg/listComputes" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + listComputes := ListComputes{} + + err = json.Unmarshal(res, &listComputes) + if err != nil { + return nil, err + } + + return listComputes, nil +} diff --git a/pkg/cloudbroker/rg/list_deleted.go b/pkg/cloudbroker/rg/list_deleted.go new file mode 100644 index 0000000..57965a6 --- /dev/null +++ b/pkg/cloudbroker/rg/list_deleted.go @@ -0,0 +1,30 @@ +package rg + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListDeletedRequest struct { + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDeleted, error) { + url := "/cloudbroker/rg/listDeleted" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + listDeleted := ListDeleted{} + + err = json.Unmarshal(res, &listDeleted) + if err != nil { + return nil, err + } + + return listDeleted, nil +} diff --git a/pkg/cloudbroker/rg/list_lb.go b/pkg/cloudbroker/rg/list_lb.go new file mode 100644 index 0000000..9945d6b --- /dev/null +++ b/pkg/cloudbroker/rg/list_lb.go @@ -0,0 +1,43 @@ +package rg + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListLBRequest struct { + RGID uint64 `url:"rgId"` +} + +func (rgrq ListLBRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) ListLB(ctx context.Context, req ListLBRequest) (ListLB, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudbroker/rg/listLb" + + lbListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + lbList := ListLB{} + + err = json.Unmarshal(lbListRaw, &lbList) + if err != nil { + return nil, err + } + + return lbList, nil +} diff --git a/pkg/cloudbroker/rg/list_pfw.go b/pkg/cloudbroker/rg/list_pfw.go new file mode 100644 index 0000000..205f017 --- /dev/null +++ b/pkg/cloudbroker/rg/list_pfw.go @@ -0,0 +1,43 @@ +package rg + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListPFWRequest struct { + RGID uint64 `url:"rgId"` +} + +func (rgrq ListPFWRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (ListPFW, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudbroker/rg/listPFW" + + pfwListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + pfwList := ListPFW{} + + err = json.Unmarshal(pfwListRaw, &pfwList) + if err != nil { + return nil, err + } + + return pfwList, nil +} diff --git a/pkg/cloudbroker/rg/list_vins.go b/pkg/cloudbroker/rg/list_vins.go new file mode 100644 index 0000000..0a0a132 --- /dev/null +++ b/pkg/cloudbroker/rg/list_vins.go @@ -0,0 +1,44 @@ +package rg + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListVINSRequest struct { + RGID uint64 `url:"rgId"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq ListVINSRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudbroker/rg/listVins" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + listVINS := ListVINS{} + + err = json.Unmarshal(res, &listVINS) + if err != nil { + return nil, err + } + + return listVINS, nil +} diff --git a/pkg/cloudbroker/rg/mass_delete.go b/pkg/cloudbroker/rg/mass_delete.go new file mode 100644 index 0000000..3ad1cad --- /dev/null +++ b/pkg/cloudbroker/rg/mass_delete.go @@ -0,0 +1,38 @@ +package rg + +import ( + "context" + "errors" + "net/http" +) + +type MassDeleteRequest struct { + RGIDs []uint64 `url:"rgIds"` + Force bool `url:"force,omitempty"` + Permanently bool `url:"permanently,omitempty"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq MassDeleteRequest) Validate() error { + if len(rgrq.RGIDs) == 0 { + return errors.New("validation-error: field RGIDs must be set") + } + + return nil +} + +func (r RG) MassDelete(ctx context.Context, req MassDeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/rg/massDelete" + + _, err = r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + return true, nil +} diff --git a/pkg/cloudbroker/rg/mass_disable.go b/pkg/cloudbroker/rg/mass_disable.go new file mode 100644 index 0000000..d62b3c1 --- /dev/null +++ b/pkg/cloudbroker/rg/mass_disable.go @@ -0,0 +1,36 @@ +package rg + +import ( + "context" + "errors" + "net/http" +) + +type MassDisableRequest struct { + RGIDs []uint64 `url:"rgIds"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq MassDisableRequest) Validate() error { + if len(rgrq.RGIDs) == 0 { + return errors.New("validation-error: field RGIDs must be set") + } + + return nil +} + +func (r RG) MassDisable(ctx context.Context, req MassDisableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/rg/massDisable" + + _, err = r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + return true, nil +} diff --git a/pkg/cloudbroker/rg/mass_enable.go b/pkg/cloudbroker/rg/mass_enable.go new file mode 100644 index 0000000..884adde --- /dev/null +++ b/pkg/cloudbroker/rg/mass_enable.go @@ -0,0 +1,36 @@ +package rg + +import ( + "context" + "errors" + "net/http" +) + +type MassEnableRequest struct { + RGIDs []uint64 `url:"rgIds"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq MassEnableRequest) Validate() error { + if len(rgrq.RGIDs) == 0 { + return errors.New("validation-error: field RGIDs must be set") + } + + return nil +} + +func (r RG) MassEnable(ctx context.Context, req MassEnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/rg/massEnable" + + _, err = r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + return true, nil +} diff --git a/pkg/cloudbroker/rg/models.go b/pkg/cloudbroker/rg/models.go new file mode 100644 index 0000000..55903b3 --- /dev/null +++ b/pkg/cloudbroker/rg/models.go @@ -0,0 +1,264 @@ +package rg + +type Audit struct { + Call string `json:"call"` + ResponseTime float64 `json:"responsetime"` + StatusCode uint64 `json:"statuscode"` + Timestamp float64 `json:"timestamp"` + User string `json:"user"` +} +type AuditList []Audit + +type Current struct { + CPU uint64 `json:"cpu"` + DiskSize uint64 `json:"disksize"` + ExtIPs uint64 `json:"extips"` + ExtTraffic uint64 `json:"exttraffic"` + GPU uint64 `json:"gpu"` + RAM uint64 `json:"ram"` +} + +type Reserved struct { + CPU uint64 `json:"cpu"` + DiskSize uint64 `json:"disksize"` + ExtIPs uint64 `json:"extips"` + ExtTraffic uint64 `json:"exttraffic"` + GPU uint64 `json:"gpu"` + RAM uint64 `json:"ram"` +} + +type Resources struct { + Current Current `json:"Current"` + Reserved Reserved `json:"Reserved"` +} + +type ACL struct { + Explicit bool `json:"explicit"` + GUID string `json:"guid"` + Right string `json:"right"` + Status string `json:"status"` + Type string `json:"type"` + UserGroupID string `json:"userGroupId"` +} + +type ResourceLimits struct { + CuC float64 `json:"CU_C"` + CuD float64 `json:"CU_D"` + CuI float64 `json:"CU_I"` + CuM float64 `json:"CU_M"` + CuNp float64 `json:"CU_NP"` + GPUUnits float64 `json:"gpu_units"` +} + +type ResourceGroup struct { + Resources Resources `json:"Resources"` + InfoResponse +} + +type InfoResponse struct { + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + ACL []ACL `json:"acl"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DefNetID int64 `json:"def_net_id"` + DefNetType string `json:"def_net_type"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + Desc string `json:"desc"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + LockStatus string `json:"lockStatus"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + RegisterComputes bool `json:"registerComputes"` + ResourceLimits ResourceLimits `json:"resourceLimits"` + Secret string `json:"secret"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + VINS []interface{} `json:"vins"` + VMs []interface{} `json:"vms"` +} + +type List []InfoResponse + +type ListDeleted []InfoResponse + +type AffinityGroupCompute struct { + ComputeID uint64 `json:"computeId"` + OtherNode []uint64 `json:"otherNode"` + OtherNodeIndirect []uint64 `json:"otherNodeIndirect"` + OtherNodeIndirectSoft []uint64 `json:"otherNodeIndirectSoft"` + OtherNodeSoft []uint64 `json:"otherNodeSoft"` + SameNode []uint64 `json:"sameNode"` + SameNodeSoft []uint64 `json:"sameNodeSoft"` +} + +type AffinityGroupComputeList []AffinityGroupCompute + +type AffinityRules struct { + GUID string `json:"guid"` + Key string `json:"key"` + Mode string `json:"mode"` + Policy string `json:"policy"` + Topology string `json:"topology"` + Value string `json:"value"` +} + +type Compute struct { + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + AffinityLabel string `json:"affinityLabel"` + AffinityRules []AffinityRules `json:"affinityRules"` + AffinityWeight uint64 `json:"affinityWeight"` + AntiAffinityRules []interface{} `json:"antiAffinityRules"` + CPUs uint64 `json:"cpus"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + ID uint64 `json:"id"` + Name string `json:"name"` + RAM uint64 `json:"ram"` + Registered bool `json:"registered"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + TotalDisksSize uint64 `json:"totalDisksSize"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + UserManaged bool `json:"userManaged"` + VINSConnected uint64 `json:"vinsConnected"` +} + +type ListComputes []Compute + +type VINS struct { + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + Computes uint64 `json:"computes"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + ExternalIP string `json:"externalIP"` + ID uint64 `json:"id"` + Name string `json:"name"` + Network string `json:"network"` + PriVNFDevID uint64 `json:"priVnfDevId"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` +} + +type ListVINS []VINS + +type PFW struct { + PublicPortEnd uint64 `json:"Public Port End"` + PublicPortStart uint64 `json:"Public Port Start"` + VMID uint64 `json:"VM ID"` + VMIP string `json:"VM IP"` + VMName string `json:"VM Name"` + VMPort uint64 `json:"VM Port"` + VINSID uint64 `json:"ViNS ID"` + VINSName string `json:"ViNS Name"` +} + +type ListPFW []PFW + +type ServerSettings struct { + DownInter uint64 `json:"downinter"` + Fall uint64 `json:"fall"` + GUID string `json:"guid"` + Inter uint64 `json:"inter"` + MaxConn uint64 `json:"maxconn"` + MaxQueue uint64 `json:"maxqueue"` + Rise uint64 `json:"rise"` + SlowStart uint64 `json:"slowstart"` + Weight uint64 `json:"weight"` +} + +type Server struct { + Address string `json:"address"` + Check string `json:"check"` + GUID string `json:"guid"` + Name string `json:"name"` + Port uint64 `json:"port"` + ServerSettings ServerSettings `json:"serverSettings"` +} + +type Backends struct { + Algorithm string `json:"algorithm"` + GUID string `json:"guid"` + Name string `json:"name"` + ServerDefaultSettings ServerSettings `json:"serverDefaultSettings"` + Servers []Server `json:"servers"` +} + +type Binding struct { + Address string `json:"address"` + GUID string `json:"guid"` + Name string `json:"name"` + Port uint64 `json:"port"` +} + +type Frontend struct { + Backend string `json:"backend"` + Bindings []Binding `json:"bindings"` + GUID string `json:"guid"` + Name string `json:"name"` +} + +type PrimaryNode struct { + BackendIP string `json:"backendIp"` + ComputeID uint64 `json:"computeId"` + FrontendIP string `json:"frontendIp"` + GUID string `json:"guid"` + MgmtIP string `json:"mgmtIp"` + NetworkID uint64 `json:"networkId"` +} + +type SecondaryNode struct { + BackendIP string `json:"backendIp"` + ComputeID uint64 `json:"computeId"` + FrontendIP string `json:"frontendIp"` + GUID string `json:"guid"` + MgmtIP string `json:"mgmtIp"` + NetworkID uint64 `json:"networkId"` +} + +type LB struct { + HAMode bool `json:"HAmode"` + ACL []ACL `json:"acl"` + Backends []Backends `json:"backends"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + Desc string `json:"desc"` + DpAPIUser string `json:"dpApiUser"` + ExtNetID uint64 `json:"extnetId"` + Frontends []Frontend `json:"frontends"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + ImageID uint64 `json:"imageId"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + PrimaryNode PrimaryNode `json:"primaryNode"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + SecondaryNode SecondaryNode `json:"secondaryNode"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + VINSID uint64 `json:"vinsId"` +} + +type ListLB []LB diff --git a/pkg/cloudbroker/rg/restore.go b/pkg/cloudbroker/rg/restore.go new file mode 100644 index 0000000..8f7a079 --- /dev/null +++ b/pkg/cloudbroker/rg/restore.go @@ -0,0 +1,42 @@ +package rg + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RestoreRequest struct { + RGID uint64 `url:"rgId"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq RestoreRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) Restore(ctx context.Context, req RestoreRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/rg/restore" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/rg/rg.go b/pkg/cloudbroker/rg/rg.go new file mode 100644 index 0000000..73f48ca --- /dev/null +++ b/pkg/cloudbroker/rg/rg.go @@ -0,0 +1,13 @@ +package rg + +import "github.com/rudecs/decort-sdk/interfaces" + +type RG struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *RG { + return &RG{ + client: client, + } +} diff --git a/pkg/cloudbroker/rg/set_def_net.go b/pkg/cloudbroker/rg/set_def_net.go new file mode 100644 index 0000000..0945283 --- /dev/null +++ b/pkg/cloudbroker/rg/set_def_net.go @@ -0,0 +1,50 @@ +package rg + +import ( + "context" + "errors" + "github.com/rudecs/decort-sdk/internal/validators" + "net/http" + "strconv" +) + +type SetDefNetRequest struct { + RGID uint64 `url:"rgId"` + NetType string `url:"netType"` + NetID uint64 `url:"netId,omitempty"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq SetDefNetRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + validate := validators.StringInSlice(rgrq.NetType, []string{"PUBLIC", "PRIVATE"}) + if !validate { + return errors.New("validation-error: field NetType must be one of PRIVATE or PUBLIC") + } + + return nil +} + +func (r RG) SetDefNet(ctx context.Context, req SetDefNetRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/rg/setDefNet" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/rg/update.go b/pkg/cloudbroker/rg/update.go new file mode 100644 index 0000000..1239b90 --- /dev/null +++ b/pkg/cloudbroker/rg/update.go @@ -0,0 +1,50 @@ +package rg + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type UpdateRequest struct { + RGID uint64 `url:"rgId"` + Name string `url:"name,omitempty"` + Desc string `url:"desc,omitempty"` + MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"` + MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"` + MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"` + MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"` + MaxNumPublicIP uint64 `url:"maxNetworkPeerTransfer,omitempty"` + RegisterComputes bool `url:"registerComputes,omitempty"` + Reason string `url:"reason"` +} + +func (rgrq UpdateRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) Update(ctx context.Context, req UpdateRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/rg/update" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/rg/usage.go b/pkg/cloudbroker/rg/usage.go new file mode 100644 index 0000000..8a13f79 --- /dev/null +++ b/pkg/cloudbroker/rg/usage.go @@ -0,0 +1,44 @@ +package rg + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type UsageRequest struct { + RGID uint64 `url:"rgId"` + Reason string `url:"reason,omitempty"` +} + +func (rgrq UsageRequest) Validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + + return nil +} + +func (r RG) Usage(ctx context.Context, req UsageRequest) (*Reserved, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudbroker/rg/usage" + + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + usage := Reserved{} + + err = json.Unmarshal(res, &usage) + if err != nil { + return nil, err + } + + return &usage, nil +}