diff --git a/.golangci.yaml b/.golangci.yaml index ce6e6eb8..9ef8f83b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -2,14 +2,15 @@ # - https://golangci-lint.run/usage/linters/ run: + allow-parallel-runners: true timeout: 10m -linters-settings: - govet: - enable-all: true - disable: - - fieldalignment # too strict - - shadow # too strict +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + exclude-files: + - ".*_test\\.go" linters: disable-all: true @@ -17,7 +18,6 @@ linters: - errcheck - exportloopref - goconst - - gocyclo - gofmt - goimports - gosimple @@ -32,16 +32,3 @@ linters: - unparam - unused - revive - -issues: - max-issues-per-linter: 0 - max-same-issues: 0 - exclude-rules: - - path: _test\.go - linters: - - errcheck - - gosimple - - ineffassign - - staticcheck - - unused - - revive \ No newline at end of file diff --git a/Makefile b/Makefile index 61ca597f..1c1bc7c9 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ vet: ## Run go vet against code go vet ./... lint: golangci-lint ## Run golangci-lint against code - $(GOLANGCI_LINT) run -v ./... + GOPATH= GOROOT= $(GOLANGCI_LINT) run -v ./... pre-commit-install: pre-commit ## Install pre-commit hooks @if [ "$(GITHUB_ACTIONS)" != "true" ]; then \ @@ -58,7 +58,7 @@ BIN_DIR ?= ./bin bin-dir: test -d $(BIN_DIR) || mkdir $(BIN_DIR) -GOLANGCI_VERSION ?= 1.59.1 +GOLANGCI_VERSION ?= 1.54.2 .PHONY: golangci-lint golangci-lint: bin-dir if ! test -f $(BIN_DIR)/golangci-lint-linux-amd64; then \ diff --git a/client/account.go b/client/account.go index 7b94b874..8a5bd2c6 100644 --- a/client/account.go +++ b/client/account.go @@ -3,13 +3,14 @@ package client import ( "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// ListCloudAccounts returns a list of all cloud account summaries. func (h *V1Client) ListCloudAccounts() ([]*models.V1CloudAccountSummary, error) { - params := clientV1.NewV1CloudAccountsListSummaryParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsListSummaryParamsWithContext(h.ctx). WithLimit(apiutil.Ptr(int64(0))) resp, err := h.Client.V1CloudAccountsListSummary(params) if apiutil.Is404(err) { @@ -20,6 +21,7 @@ func (h *V1Client) ListCloudAccounts() ([]*models.V1CloudAccountSummary, error) return resp.Payload.Items, nil } +// GetCloudAccount retrieves an existing cloud account summary. func (h *V1Client) GetCloudAccount(uid string) (*models.V1CloudAccountSummary, error) { accounts, err := h.ListCloudAccounts() if err != nil { diff --git a/client/account_aws.go b/client/account_aws.go index 238e7b44..fd53a314 100644 --- a/client/account_aws.go +++ b/client/account_aws.go @@ -1,7 +1,7 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) @@ -17,11 +17,12 @@ func toV1AwsCloudAccount(account *models.V1AwsAccount) *models.V1AwsCloudAccount } } +// CreateCloudAccountAws creates a new AWS cloud account. func (h *V1Client) CreateCloudAccountAws(account *models.V1AwsAccount) (string, error) { if err := h.validateCloudAccountAws(account); err != nil { return "", err } - params := clientV1.NewV1CloudAccountsAwsCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsAwsCreateParamsWithContext(h.ctx). WithBody(account) resp, err := h.Client.V1CloudAccountsAwsCreate(params) @@ -38,33 +39,36 @@ func (h *V1Client) validateCloudAccountAws(account *models.V1AwsAccount) error { } // validate account - params := clientV1.NewV1AwsAccountValidateParamsWithContext(h.ctx). + params := clientv1.NewV1AwsAccountValidateParamsWithContext(h.ctx). WithAwsCloudAccount(toV1AwsCloudAccount(account)) _, err := h.Client.V1AwsAccountValidate(params) return err } +// UpdateCloudAccountAws updates an existing AWS cloud account. func (h *V1Client) UpdateCloudAccountAws(account *models.V1AwsAccount) error { if err := h.validateCloudAccountAws(account); err != nil { return err } - params := clientV1.NewV1CloudAccountsAwsUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsAwsUpdateParamsWithContext(h.ctx). WithUID(account.Metadata.UID). WithBody(account) _, err := h.Client.V1CloudAccountsAwsUpdate(params) return err } +// DeleteCloudAccountAws deletes an existing AWS cloud account. func (h *V1Client) DeleteCloudAccountAws(uid string) error { - params := clientV1.NewV1CloudAccountsAwsDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsAwsDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1CloudAccountsAwsDelete(params) return err } +// GetCloudAccountAws retrieves an existing AWS cloud account. func (h *V1Client) GetCloudAccountAws(uid string) (*models.V1AwsAccount, error) { - params := clientV1.NewV1CloudAccountsAwsGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsAwsGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1CloudAccountsAwsGet(params) if apiutil.Is404(err) { @@ -75,8 +79,9 @@ func (h *V1Client) GetCloudAccountAws(uid string) (*models.V1AwsAccount, error) return resp.Payload, nil } +// GetCloudAccountsAws retrieves all AWS cloud accounts. func (h *V1Client) GetCloudAccountsAws() ([]*models.V1AwsAccount, error) { - params := clientV1.NewV1CloudAccountsAwsListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsAwsListParamsWithContext(h.ctx). WithLimit(apiutil.Ptr(int64(0))) resp, err := h.Client.V1CloudAccountsAwsList(params) if err != nil { diff --git a/client/account_azure.go b/client/account_azure.go index 513dff51..10eb72ae 100644 --- a/client/account_azure.go +++ b/client/account_azure.go @@ -1,7 +1,7 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) @@ -17,13 +17,14 @@ func toV1AzureCloudAccount(account *models.V1AzureAccount) *models.V1AzureCloudA } } +// CreateCloudAccountAzure creates a new Azure cloud account. func (h *V1Client) CreateCloudAccountAzure(account *models.V1AzureAccount) (string, error) { // validate account if err := h.validateCloudAccountAzure(account); err != nil { return "", err } - params := clientV1.NewV1CloudAccountsAzureCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsAzureCreateParamsWithContext(h.ctx). WithBody(account) resp, err := h.Client.V1CloudAccountsAzureCreate(params) if err != nil { @@ -39,20 +40,21 @@ func (h *V1Client) validateCloudAccountAzure(account *models.V1AzureAccount) err } // validate account - params := clientV1.NewV1AzureAccountValidateParamsWithContext(h.ctx). + params := clientv1.NewV1AzureAccountValidateParamsWithContext(h.ctx). WithAzureCloudAccount(toV1AzureCloudAccount(account)) _, err := h.Client.V1AzureAccountValidate(params) return err } +// UpdateCloudAccountAzure updates an existing Azure cloud account. func (h *V1Client) UpdateCloudAccountAzure(account *models.V1AzureAccount) error { // validate account if err := h.validateCloudAccountAzure(account); err != nil { return err } - params := clientV1.NewV1CloudAccountsAzureUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsAzureUpdateParamsWithContext(h.ctx). WithUID(account.Metadata.UID). WithBody(account) @@ -60,15 +62,17 @@ func (h *V1Client) UpdateCloudAccountAzure(account *models.V1AzureAccount) error return err } +// DeleteCloudAccountAzure deletes an existing Azure cloud account. func (h *V1Client) DeleteCloudAccountAzure(uid string) error { - params := clientV1.NewV1CloudAccountsAzureDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsAzureDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1CloudAccountsAzureDelete(params) return err } +// GetCloudAccountAzure retrieves an existing Azure cloud account. func (h *V1Client) GetCloudAccountAzure(uid string) (*models.V1AzureAccount, error) { - params := clientV1.NewV1CloudAccountsAzureGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsAzureGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1CloudAccountsAzureGet(params) if apiutil.Is404(err) { @@ -79,8 +83,9 @@ func (h *V1Client) GetCloudAccountAzure(uid string) (*models.V1AzureAccount, err return resp.Payload, nil } +// GetCloudAccountsAzure retrieves all Azure cloud accounts. func (h *V1Client) GetCloudAccountsAzure() ([]*models.V1AzureAccount, error) { - params := clientV1.NewV1CloudAccountsAzureListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsAzureListParamsWithContext(h.ctx). WithLimit(apiutil.Ptr(int64(0))) resp, err := h.Client.V1CloudAccountsAzureList(params) if err != nil { diff --git a/client/account_custom_cloud.go b/client/account_custom_cloud.go index 5bff3f23..baa7e51c 100644 --- a/client/account_custom_cloud.go +++ b/client/account_custom_cloud.go @@ -3,17 +3,18 @@ package client import ( "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateAccountCustomCloud creates a custom cloud account. func (h *V1Client) CreateAccountCustomCloud(account *models.V1CustomAccountEntity, cloudType string) (string, error) { - pcgId := account.Metadata.Annotations[OverlordUID] - if err := h.CheckPCG(pcgId); err != nil { + pcgID := account.Metadata.Annotations[OverlordUID] + if err := h.CheckPCG(pcgID); err != nil { return "", err } - params := clientV1.NewV1CloudAccountsCustomCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsCustomCreateParamsWithContext(h.ctx). WithBody(account). WithCloudType(cloudType) resp, err := h.Client.V1CloudAccountsCustomCreate(params) @@ -23,8 +24,9 @@ func (h *V1Client) CreateAccountCustomCloud(account *models.V1CustomAccountEntit return *resp.Payload.UID, nil } +// GetCustomCloudAccount retrieves an existing custom cloud account. func (h *V1Client) GetCustomCloudAccount(uid, cloudType string) (*models.V1CustomAccount, error) { - params := clientV1.NewV1CloudAccountsCustomGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsCustomGetParamsWithContext(h.ctx). WithCloudType(cloudType). WithUID(uid) resp, err := h.Client.V1CloudAccountsCustomGet(params) @@ -34,8 +36,9 @@ func (h *V1Client) GetCustomCloudAccount(uid, cloudType string) (*models.V1Custo return resp.Payload, nil } +// UpdateAccountCustomCloud updates an existing custom cloud account. func (h *V1Client) UpdateAccountCustomCloud(uid string, account *models.V1CustomAccountEntity, cloudType string) error { - params := clientV1.NewV1CloudAccountsCustomUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsCustomUpdateParamsWithContext(h.ctx). WithBody(account). WithCloudType(cloudType). WithUID(uid) @@ -43,16 +46,18 @@ func (h *V1Client) UpdateAccountCustomCloud(uid string, account *models.V1Custom return err } +// DeleteCloudAccountCustomCloud deletes an existing custom cloud account. func (h *V1Client) DeleteCloudAccountCustomCloud(uid, cloudType string) error { - params := clientV1.NewV1CloudAccountsCustomDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsCustomDeleteParamsWithContext(h.ctx). WithCloudType(cloudType). WithUID(uid) _, err := h.Client.V1CloudAccountsCustomDelete(params) return err } +// ValidateCustomCloudType validates a custom cloud type. func (h *V1Client) ValidateCustomCloudType(cloudType string) error { - params := clientV1.NewV1CustomCloudTypesGetParamsWithContext(h.ctx) + params := clientv1.NewV1CustomCloudTypesGetParamsWithContext(h.ctx) resp, err := h.Client.V1CustomCloudTypesGet(params) if err != nil { return err @@ -61,16 +66,16 @@ func (h *V1Client) ValidateCustomCloudType(cloudType string) error { if c.Name == cloudType { if c.IsCustom { return nil - } else { - return fmt.Errorf("cloud - `%s` is not a valid custom cloud", cloudType) } + return fmt.Errorf("cloud '%s' is not a valid custom cloud", cloudType) } } - return fmt.Errorf("cloud - `%s` is not a valid cloud", cloudType) + return fmt.Errorf("cloud '%s' is not a valid cloud", cloudType) } +// GetCustomCloudAccountList retrieves all custom cloud accounts. func (h *V1Client) GetCustomCloudAccountList(cloudType string) ([]*models.V1CustomAccount, error) { - params := clientV1.NewV1CloudAccountsCustomListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsCustomListParamsWithContext(h.ctx). WithLimit(apiutil.Ptr(int64(0))). WithCloudType(cloudType) resp, err := h.Client.V1CloudAccountsCustomList(params) diff --git a/client/account_gcp.go b/client/account_gcp.go index 373917c4..0e9d64ee 100644 --- a/client/account_gcp.go +++ b/client/account_gcp.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateCloudAccountGcp creates a new GCP cloud account. func (h *V1Client) CreateCloudAccountGcp(account *models.V1GcpAccountEntity) (string, error) { - params := clientV1.NewV1CloudAccountsGcpCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsGcpCreateParamsWithContext(h.ctx). WithBody(account) resp, err := h.Client.V1CloudAccountsGcpCreate(params) if err != nil { @@ -16,23 +17,26 @@ func (h *V1Client) CreateCloudAccountGcp(account *models.V1GcpAccountEntity) (st return *resp.Payload.UID, nil } +// UpdateCloudAccountGcp updates an existing GCP cloud account. func (h *V1Client) UpdateCloudAccountGcp(account *models.V1GcpAccountEntity) error { - params := clientV1.NewV1CloudAccountsGcpUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsGcpUpdateParamsWithContext(h.ctx). WithUID(account.Metadata.UID). WithBody(account) _, err := h.Client.V1CloudAccountsGcpUpdate(params) return err } +// DeleteCloudAccountGcp deletes an existing GCP cloud account. func (h *V1Client) DeleteCloudAccountGcp(uid string) error { - params := clientV1.NewV1CloudAccountsGcpDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsGcpDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1CloudAccountsGcpDelete(params) return err } +// GetCloudAccountGcp retrieves an existing GCP cloud account. func (h *V1Client) GetCloudAccountGcp(uid string) (*models.V1GcpAccount, error) { - params := clientV1.NewV1CloudAccountsGcpGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsGcpGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1CloudAccountsGcpGet(params) if apiutil.Is404(err) { @@ -43,8 +47,9 @@ func (h *V1Client) GetCloudAccountGcp(uid string) (*models.V1GcpAccount, error) return resp.Payload, nil } +// GetCloudAccountsGcp retrieves all GCP cloud accounts. func (h *V1Client) GetCloudAccountsGcp() ([]*models.V1GcpAccount, error) { - params := clientV1.NewV1CloudAccountsGcpListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsGcpListParamsWithContext(h.ctx). WithLimit(apiutil.Ptr(int64(0))) resp, err := h.Client.V1CloudAccountsGcpList(params) if err != nil { diff --git a/client/account_maas.go b/client/account_maas.go index 0555848c..209fae87 100644 --- a/client/account_maas.go +++ b/client/account_maas.go @@ -1,24 +1,25 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func toV1OverlordsUIDMaasAccountValidateBody(account *models.V1MaasAccount) clientV1.V1OverlordsUIDMaasAccountValidateBody { - return clientV1.V1OverlordsUIDMaasAccountValidateBody{ +func toV1OverlordsUIDMaasAccountValidateBody(account *models.V1MaasAccount) clientv1.V1OverlordsUIDMaasAccountValidateBody { + return clientv1.V1OverlordsUIDMaasAccountValidateBody{ Account: account.Spec, } } +// CreateCloudAccountMaas creates a new MAAS cloud account. func (h *V1Client) CreateCloudAccountMaas(account *models.V1MaasAccount) (string, error) { // validate account if err := h.validateCloudAccountMaas(account); err != nil { return "", err } - params := clientV1.NewV1CloudAccountsMaasCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsMaasCreateParamsWithContext(h.ctx). WithBody(account) resp, err := h.Client.V1CloudAccountsMaasCreate(params) if err != nil { @@ -29,27 +30,28 @@ func (h *V1Client) CreateCloudAccountMaas(account *models.V1MaasAccount) (string func (h *V1Client) validateCloudAccountMaas(account *models.V1MaasAccount) error { // check PCG - pcgId := account.Metadata.Annotations[OverlordUID] - if err := h.CheckPCG(pcgId); err != nil { + pcgID := account.Metadata.Annotations[OverlordUID] + if err := h.CheckPCG(pcgID); err != nil { return err } // validate account - params := clientV1.NewV1OverlordsUIDMaasAccountValidateParamsWithContext(h.ctx). - WithUID(pcgId). + params := clientv1.NewV1OverlordsUIDMaasAccountValidateParamsWithContext(h.ctx). + WithUID(pcgID). WithBody(toV1OverlordsUIDMaasAccountValidateBody(account)) _, err := h.Client.V1OverlordsUIDMaasAccountValidate(params) return err } +// UpdateCloudAccountMaas updates an existing MAAS cloud account. func (h *V1Client) UpdateCloudAccountMaas(account *models.V1MaasAccount) error { // validate account if err := h.validateCloudAccountMaas(account); err != nil { return err } - params := clientV1.NewV1CloudAccountsMaasUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsMaasUpdateParamsWithContext(h.ctx). WithUID(account.Metadata.UID). WithBody(account) @@ -57,15 +59,17 @@ func (h *V1Client) UpdateCloudAccountMaas(account *models.V1MaasAccount) error { return err } +// DeleteCloudAccountMaas deletes an existing MAAS cloud account. func (h *V1Client) DeleteCloudAccountMaas(uid string) error { - params := clientV1.NewV1CloudAccountsMaasDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsMaasDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1CloudAccountsMaasDelete(params) return err } +// GetCloudAccountMaas retrieves an existing MAAS cloud account. func (h *V1Client) GetCloudAccountMaas(uid string) (*models.V1MaasAccount, error) { - params := clientV1.NewV1CloudAccountsMaasGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsMaasGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1CloudAccountsMaasGet(params) if apiutil.Is404(err) { @@ -76,8 +80,9 @@ func (h *V1Client) GetCloudAccountMaas(uid string) (*models.V1MaasAccount, error return resp.Payload, nil } +// GetCloudAccountsMaas retrieves all MAAS cloud accounts. func (h *V1Client) GetCloudAccountsMaas() ([]*models.V1MaasAccount, error) { - params := clientV1.NewV1CloudAccountsMaasListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsMaasListParamsWithContext(h.ctx). WithLimit(apiutil.Ptr(int64(0))) response, err := h.Client.V1CloudAccountsMaasList(params) if err != nil { diff --git a/client/account_openstack.go b/client/account_openstack.go index 327fbfe8..7e3e1e89 100644 --- a/client/account_openstack.go +++ b/client/account_openstack.go @@ -1,24 +1,25 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -func toV1OverlordsUIDOpenStackAccountValidateBody(account *models.V1OpenStackAccount) clientV1.V1OverlordsUIDOpenStackAccountValidateBody { - return clientV1.V1OverlordsUIDOpenStackAccountValidateBody{ +func toV1OverlordsUIDOpenStackAccountValidateBody(account *models.V1OpenStackAccount) clientv1.V1OverlordsUIDOpenStackAccountValidateBody { + return clientv1.V1OverlordsUIDOpenStackAccountValidateBody{ Account: account.Spec, } } +// CreateCloudAccountOpenStack creates a new OpenStack cloud account. func (h *V1Client) CreateCloudAccountOpenStack(account *models.V1OpenStackAccount) (string, error) { // validate account if err := h.validateCloudAccountOpenStack(account); err != nil { return "", err } - params := clientV1.NewV1CloudAccountsOpenStackCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsOpenStackCreateParamsWithContext(h.ctx). WithBody(account) resp, err := h.Client.V1CloudAccountsOpenStackCreate(params) if err != nil { @@ -29,41 +30,44 @@ func (h *V1Client) CreateCloudAccountOpenStack(account *models.V1OpenStackAccoun func (h *V1Client) validateCloudAccountOpenStack(account *models.V1OpenStackAccount) error { // check PCG - pcgId := account.Metadata.Annotations[OverlordUID] - if err := h.CheckPCG(pcgId); err != nil { + pcgID := account.Metadata.Annotations[OverlordUID] + if err := h.CheckPCG(pcgID); err != nil { return err } // validate account - params := clientV1.NewV1OverlordsUIDOpenStackAccountValidateParamsWithContext(h.ctx). - WithUID(pcgId). + params := clientv1.NewV1OverlordsUIDOpenStackAccountValidateParamsWithContext(h.ctx). + WithUID(pcgID). WithBody(toV1OverlordsUIDOpenStackAccountValidateBody(account)) _, err := h.Client.V1OverlordsUIDOpenStackAccountValidate(params) return err } +// UpdateCloudAccountOpenStack updates an existing OpenStack cloud account. func (h *V1Client) UpdateCloudAccountOpenStack(account *models.V1OpenStackAccount) error { if err := h.validateCloudAccountOpenStack(account); err != nil { return err } - params := clientV1.NewV1CloudAccountsOpenStackUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsOpenStackUpdateParamsWithContext(h.ctx). WithUID(account.Metadata.UID). WithBody(account) _, err := h.Client.V1CloudAccountsOpenStackUpdate(params) return err } +// DeleteCloudAccountOpenStack deletes an existing OpenStack cloud account. func (h *V1Client) DeleteCloudAccountOpenStack(uid string) error { - params := clientV1.NewV1CloudAccountsOpenStackDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsOpenStackDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1CloudAccountsOpenStackDelete(params) return err } +// GetCloudAccountOpenStack retrieves an existing OpenStack cloud account. func (h *V1Client) GetCloudAccountOpenStack(uid string) (*models.V1OpenStackAccount, error) { - params := clientV1.NewV1CloudAccountsOpenStackGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsOpenStackGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1CloudAccountsOpenStackGet(params) if apiutil.Is404(err) { @@ -74,8 +78,9 @@ func (h *V1Client) GetCloudAccountOpenStack(uid string) (*models.V1OpenStackAcco return resp.Payload, nil } +// GetCloudAccountsOpenStack retrieves all OpenStack cloud accounts. func (h *V1Client) GetCloudAccountsOpenStack() ([]*models.V1OpenStackAccount, error) { - params := clientV1.NewV1CloudAccountsOpenStackListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsOpenStackListParamsWithContext(h.ctx). WithLimit(apiutil.Ptr(int64(0))) resp, err := h.Client.V1CloudAccountsOpenStackList(params) if err != nil { diff --git a/client/account_tke.go b/client/account_tke.go index 8fbd8e1a..5812293f 100644 --- a/client/account_tke.go +++ b/client/account_tke.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateCloudAccountTke creates a new TKE cloud account. func (h *V1Client) CreateCloudAccountTke(account *models.V1TencentAccount) (string, error) { - params := clientV1.NewV1CloudAccountsTencentCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsTencentCreateParamsWithContext(h.ctx). WithBody(account) resp, err := h.Client.V1CloudAccountsTencentCreate(params) if err != nil { @@ -16,23 +17,26 @@ func (h *V1Client) CreateCloudAccountTke(account *models.V1TencentAccount) (stri return *resp.Payload.UID, nil } -func (h *V1Client) UpdateCloudAccountTencent(account *models.V1TencentAccount) error { - params := clientV1.NewV1CloudAccountsTencentUpdateParamsWithContext(h.ctx). +// UpdateCloudAccountTke updates an existing TKE cloud account. +func (h *V1Client) UpdateCloudAccountTke(account *models.V1TencentAccount) error { + params := clientv1.NewV1CloudAccountsTencentUpdateParamsWithContext(h.ctx). WithUID(account.Metadata.UID). WithBody(account) _, err := h.Client.V1CloudAccountsTencentUpdate(params) return err } +// DeleteCloudAccountTke deletes an existing TKE cloud account. func (h *V1Client) DeleteCloudAccountTke(uid string) error { - params := clientV1.NewV1CloudAccountsTencentDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsTencentDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1CloudAccountsTencentDelete(params) return err } +// GetCloudAccountTke retrieves an existing TKE cloud account. func (h *V1Client) GetCloudAccountTke(uid string) (*models.V1TencentAccount, error) { - params := clientV1.NewV1CloudAccountsTencentGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsTencentGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1CloudAccountsTencentGet(params) if apiutil.Is404(err) { @@ -43,8 +47,9 @@ func (h *V1Client) GetCloudAccountTke(uid string) (*models.V1TencentAccount, err return resp.Payload, nil } +// GetCloudAccountsTke retrieves all TKE cloud accounts. func (h *V1Client) GetCloudAccountsTke() ([]*models.V1TencentAccount, error) { - params := clientV1.NewV1CloudAccountsTencentListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsTencentListParamsWithContext(h.ctx). WithLimit(apiutil.Ptr(int64(0))) resp, err := h.Client.V1CloudAccountsTencentList(params) if err != nil { diff --git a/client/account_vsphere.go b/client/account_vsphere.go index 495ade2c..fd361125 100644 --- a/client/account_vsphere.go +++ b/client/account_vsphere.go @@ -1,18 +1,19 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) // convert V1VsphereAccount to V1OverlordVsphereAccountEntity -func toV1OverlordsUIDVsphereAccountValidateBody(account *models.V1VsphereAccount) clientV1.V1OverlordsUIDVsphereAccountValidateBody { - return clientV1.V1OverlordsUIDVsphereAccountValidateBody{ +func toV1OverlordsUIDVsphereAccountValidateBody(account *models.V1VsphereAccount) clientv1.V1OverlordsUIDVsphereAccountValidateBody { + return clientv1.V1OverlordsUIDVsphereAccountValidateBody{ Account: account.Spec, } } +// CreateCloudAccountVsphere creates a new vSphere cloud account. func (h *V1Client) CreateCloudAccountVsphere(account *models.V1VsphereAccount) (string, error) { // validate account if err := h.validateCloudAccountVsphere(account); err != nil { @@ -20,7 +21,7 @@ func (h *V1Client) CreateCloudAccountVsphere(account *models.V1VsphereAccount) ( } // create account - params := clientV1.NewV1CloudAccountsVsphereCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsVsphereCreateParamsWithContext(h.ctx). WithBody(account) resp, err := h.Client.V1CloudAccountsVsphereCreate(params) if err != nil { @@ -31,42 +32,45 @@ func (h *V1Client) CreateCloudAccountVsphere(account *models.V1VsphereAccount) ( func (h *V1Client) validateCloudAccountVsphere(account *models.V1VsphereAccount) error { // check PCG - pcgId := account.Metadata.Annotations[OverlordUID] - if err := h.CheckPCG(pcgId); err != nil { + pcgID := account.Metadata.Annotations[OverlordUID] + if err := h.CheckPCG(pcgID); err != nil { return err } // validate account - params := clientV1.NewV1OverlordsUIDVsphereAccountValidateParamsWithContext(h.ctx). - WithUID(pcgId). + params := clientv1.NewV1OverlordsUIDVsphereAccountValidateParamsWithContext(h.ctx). + WithUID(pcgID). WithBody(toV1OverlordsUIDVsphereAccountValidateBody(account)) _, err := h.Client.V1OverlordsUIDVsphereAccountValidate(params) return err } +// UpdateCloudAccountVsphere updates an existing vSphere cloud account. func (h *V1Client) UpdateCloudAccountVsphere(account *models.V1VsphereAccount) error { // validate account if err := h.validateCloudAccountVsphere(account); err != nil { return err } - params := clientV1.NewV1CloudAccountsVsphereUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsVsphereUpdateParamsWithContext(h.ctx). WithUID(account.Metadata.UID). WithBody(account) _, err := h.Client.V1CloudAccountsVsphereUpdate(params) return err } +// DeleteCloudAccountVsphere deletes an existing vSphere cloud account. func (h *V1Client) DeleteCloudAccountVsphere(uid string) error { - params := clientV1.NewV1CloudAccountsVsphereDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsVsphereDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1CloudAccountsVsphereDelete(params) return err } +// GetCloudAccountVsphere retrieves an existing vSphere cloud account. func (h *V1Client) GetCloudAccountVsphere(uid string) (*models.V1VsphereAccount, error) { - params := clientV1.NewV1CloudAccountsVsphereGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsVsphereGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1CloudAccountsVsphereGet(params) if apiutil.Is404(err) { @@ -77,8 +81,9 @@ func (h *V1Client) GetCloudAccountVsphere(uid string) (*models.V1VsphereAccount, return resp.Payload, nil } +// GetCloudAccountsVsphere retrieves all vSphere cloud accounts. func (h *V1Client) GetCloudAccountsVsphere() ([]*models.V1VsphereAccount, error) { - params := clientV1.NewV1CloudAccountsVsphereListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudAccountsVsphereListParamsWithContext(h.ctx). WithLimit(apiutil.Ptr(int64(0))) resp, err := h.Client.V1CloudAccountsVsphereList(params) if err != nil { diff --git a/client/addon_deployment_update.go b/client/addon_deployment_update.go index b09a8790..853b455b 100644 --- a/client/addon_deployment_update.go +++ b/client/addon_deployment_update.go @@ -5,10 +5,11 @@ import ( "math/rand" "time" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// UpdateAddonDeployment updates the addon deployment for a cluster. func (h *V1Client) UpdateAddonDeployment(cluster *models.V1SpectroCluster, body *models.V1SpectroClusterProfiles, newProfile *models.V1ClusterProfile) error { uid := cluster.Metadata.UID @@ -19,7 +20,7 @@ func (h *V1Client) UpdateAddonDeployment(cluster *models.V1SpectroCluster, body } resolveNotifications := true - params := clientV1.NewV1SpectroClustersPatchProfilesParams(). + params := clientv1.NewV1SpectroClustersPatchProfilesParams(). WithContext(ContextForScope(cluster.Metadata.Annotations[Scope], h.projectUID)). WithUID(uid). WithBody(body). @@ -28,6 +29,7 @@ func (h *V1Client) UpdateAddonDeployment(cluster *models.V1SpectroCluster, body return h.PatchWithRetry(params) } +// IsProfileAttachedByName checks if a profile is already attached to a cluster. func IsProfileAttachedByName(cluster *models.V1SpectroCluster, newProfile *models.V1ClusterProfile) (bool, string) { for _, profile := range cluster.Spec.ClusterProfileTemplates { if profile.Name == newProfile.Metadata.Name { @@ -37,9 +39,10 @@ func IsProfileAttachedByName(cluster *models.V1SpectroCluster, newProfile *model return false, "" } +// CreateAddonDeployment creates an addon deployment for a cluster. func (h *V1Client) CreateAddonDeployment(cluster *models.V1SpectroCluster, body *models.V1SpectroClusterProfiles) error { resolveNotifications := false // during initial creation we never need to resolve packs - params := clientV1.NewV1SpectroClustersPatchProfilesParams(). + params := clientv1.NewV1SpectroClustersPatchProfilesParams(). WithContext(ContextForScope(cluster.Metadata.Annotations[Scope], h.projectUID)). WithUID(cluster.Metadata.UID). WithBody(body). @@ -48,7 +51,8 @@ func (h *V1Client) CreateAddonDeployment(cluster *models.V1SpectroCluster, body return h.PatchWithRetry(params) } -func (h *V1Client) PatchWithRetry(params *clientV1.V1SpectroClustersPatchProfilesParams) error { +// PatchWithRetry patches cluster's profiles with with retry logic. +func (h *V1Client) PatchWithRetry(params *clientv1.V1SpectroClustersPatchProfilesParams) error { var err error rand.NewSource(time.Now().UnixNano()) for attempt := 0; attempt < h.retryAttempts; attempt++ { @@ -64,13 +68,15 @@ func (h *V1Client) PatchWithRetry(params *clientV1.V1SpectroClustersPatchProfile return err } -func (h *V1Client) ClustersPatchProfiles(params *clientV1.V1SpectroClustersPatchProfilesParams) error { +// ClustersPatchProfiles patches a cluster's profiles. +func (h *V1Client) ClustersPatchProfiles(params *clientv1.V1SpectroClustersPatchProfilesParams) error { _, err := h.Client.V1SpectroClustersPatchProfiles(params) return err } +// DeleteAddonDeployment deletes an addon deployment for a cluster. func (h *V1Client) DeleteAddonDeployment(uid string, body *models.V1SpectroClusterProfilesDeleteEntity) error { - params := clientV1.NewV1SpectroClustersDeleteProfilesParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersDeleteProfilesParamsWithContext(h.ctx). WithUID(uid). WithBody(body) _, err := h.Client.V1SpectroClustersDeleteProfiles(params) diff --git a/client/alert.go b/client/alert.go index 164b358c..b435bddc 100644 --- a/client/alert.go +++ b/client/alert.go @@ -1,12 +1,13 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// CreateAlert creates a new alert. func (h *V1Client) CreateAlert(body *models.V1Channel, projectUID, component string) (string, error) { - params := clientV1.NewV1ProjectsUIDAlertCreateParamsWithContext(h.ctx). + params := clientv1.NewV1ProjectsUIDAlertCreateParamsWithContext(h.ctx). WithBody(body). WithUID(projectUID). WithComponent(component) @@ -17,8 +18,9 @@ func (h *V1Client) CreateAlert(body *models.V1Channel, projectUID, component str return *resp.Payload.UID, nil } +// UpdateAlert updates an existing alert. func (h *V1Client) UpdateAlert(body *models.V1Channel, projectUID, component, alertUID string) (string, error) { - params := clientV1.NewV1ProjectsUIDAlertsUIDUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1ProjectsUIDAlertsUIDUpdateParamsWithContext(h.ctx). WithBody(body). WithUID(projectUID). WithComponent(component). @@ -28,11 +30,11 @@ func (h *V1Client) UpdateAlert(body *models.V1Channel, projectUID, component, al return "", err } return "success", nil - } -func (h *V1Client) ReadAlert(projectUID, component, alertUID string) (*models.V1Channel, error) { - params := clientV1.NewV1ProjectsUIDAlertsUIDGetParamsWithContext(h.ctx). +// GetAlert retrieves an existing alert. +func (h *V1Client) GetAlert(projectUID, component, alertUID string) (*models.V1Channel, error) { + params := clientv1.NewV1ProjectsUIDAlertsUIDGetParamsWithContext(h.ctx). WithUID(projectUID). WithComponent(component). WithAlertUID(alertUID) @@ -41,11 +43,11 @@ func (h *V1Client) ReadAlert(projectUID, component, alertUID string) (*models.V1 return nil, err } return resp.Payload, nil - } -func (h *V1Client) DeleteAlerts(projectUID, component, alertUID string) error { - params := clientV1.NewV1ProjectsUIDAlertsUIDDeleteParamsWithContext(h.ctx). +// DeleteAlert deletes an existing alert. +func (h *V1Client) DeleteAlert(projectUID, component, alertUID string) error { + params := clientv1.NewV1ProjectsUIDAlertsUIDDeleteParamsWithContext(h.ctx). WithUID(projectUID). WithComponent(component). WithAlertUID(alertUID) diff --git a/client/apiutil/apiutil.go b/client/apiutil/apiutil.go index 590575a9..cd3f3dee 100644 --- a/client/apiutil/apiutil.go +++ b/client/apiutil/apiutil.go @@ -1,3 +1,4 @@ +// Package apiutil provides utilities for the Spectro Cloud API client. package apiutil import ( @@ -11,15 +12,18 @@ import ( "github.com/spectrocloud/palette-api-go/models" ) +// IsBase64 returns a boolean indicating whether a string is base64 encoded. func IsBase64(s string) bool { _, err := base64.StdEncoding.DecodeString(s) return err == nil } +// Base64DecodeString decodes a base64-encoded string. func Base64DecodeString(s string) ([]byte, error) { return base64.StdEncoding.DecodeString(s) } +// StringHash hashes a string using FNV-1a. func StringHash(name string) string { return strconv.FormatUint(uint64(hash(name)), 10) } @@ -30,6 +34,7 @@ func hash(s string) uint32 { return h.Sum32() } +// Ptr returns a pointer to any value. func Ptr[T any](v T) *T { return &v } @@ -43,7 +48,8 @@ func Is404(err error) bool { return false } -func ToV1ErrorObj(err interface{}) *models.V1Error { +// ToV1ErrorObj converts an error to a V1Error object. +func ToV1ErrorObj(err any) *models.V1Error { if err != nil { tErr, ok := err.(*transport.TransportError) if ok { diff --git a/client/appliance.go b/client/appliance.go index 00605080..d045e1d2 100644 --- a/client/appliance.go +++ b/client/appliance.go @@ -4,14 +4,16 @@ import ( "fmt" "github.com/spectrocloud/gomi/pkg/ptr" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/herr" ) -func (h *V1Client) SearchApplianceSummaries(filter *models.V1SearchFilterSpec, sort []*models.V1SearchFilterSortSpec) ([]*models.V1EdgeHostsMetadata, error) { +// TODO: edgev1 deprecation - params := clientV1.NewV1DashboardEdgehostsSearchParamsWithContext(h.ctx). +// SearchApplianceSummaries retrieves a list of edge host summaries based on the provided filter and sort criteria. +func (h *V1Client) SearchApplianceSummaries(filter *models.V1SearchFilterSpec, sort []*models.V1SearchFilterSortSpec) ([]*models.V1EdgeHostsMetadata, error) { + params := clientv1.NewV1DashboardEdgehostsSearchParamsWithContext(h.ctx). WithBody(&models.V1SearchFilterSummarySpec{ Filter: filter, Sort: sort, @@ -29,10 +31,10 @@ func (h *V1Client) SearchApplianceSummaries(filter *models.V1SearchFilterSpec, s } params.WithContinue(ptr.StringPtr(resp.Payload.Listmeta.Continue)) } - return hosts, nil } +// GetAppliances returns a list of edge host metadata, filtered by the provided tags, status, health, and architecture. func (h *V1Client) GetAppliances(tags map[string]string, status, health, architecture string) ([]*models.V1EdgeHostsMetadata, error) { filter := getApplianceFilter(nil, tags, status, health, architecture) appliances, err := h.SearchApplianceSummaries(filter, nil) @@ -42,8 +44,9 @@ func (h *V1Client) GetAppliances(tags map[string]string, status, health, archite return appliances, nil } +// GetAppliance retrieves an existing edge host by UID. func (h *V1Client) GetAppliance(uid string) (*models.V1EdgeHostDevice, error) { - params := clientV1.NewV1EdgeHostDevicesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1EdgeHostDevicesUIDGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1EdgeHostDevicesUIDGet(params) if err != nil { @@ -55,6 +58,7 @@ func (h *V1Client) GetAppliance(uid string) (*models.V1EdgeHostDevice, error) { return resp.Payload, nil } +// GetApplianceByName retrieves an existing edge host by name. func (h *V1Client) GetApplianceByName(name string, tags map[string]string, status, health, architecture string) (*models.V1EdgeHostDevice, error) { filters := []*models.V1SearchFilterItem{applianceNameEqFilter(name)} applianceSummaries, err := h.SearchApplianceSummaries(getApplianceFilter(filters, tags, status, health, architecture), nil) @@ -71,8 +75,9 @@ func (h *V1Client) GetApplianceByName(name string, tags map[string]string, statu return appliance, nil } +// CreateAppliance creates a new edge host. func (h *V1Client) CreateAppliance(createHostDevice *models.V1EdgeHostDeviceEntity) (string, error) { - params := clientV1.NewV1EdgeHostDevicesCreateParamsWithContext(h.ctx). + params := clientv1.NewV1EdgeHostDevicesCreateParamsWithContext(h.ctx). WithBody(createHostDevice) resp, err := h.Client.V1EdgeHostDevicesCreate(params) if err != nil { @@ -81,8 +86,9 @@ func (h *V1Client) CreateAppliance(createHostDevice *models.V1EdgeHostDeviceEnti return *resp.Payload.UID, nil } +// UpdateAppliance updates an existing edge host. func (h *V1Client) UpdateAppliance(uid string, appliance *models.V1EdgeHostDevice) error { - params := clientV1.NewV1EdgeHostDevicesUIDUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1EdgeHostDevicesUIDUpdateParamsWithContext(h.ctx). WithBody(appliance). WithUID(uid) _, err := h.Client.V1EdgeHostDevicesUIDUpdate(params) @@ -92,16 +98,18 @@ func (h *V1Client) UpdateAppliance(uid string, appliance *models.V1EdgeHostDevic return nil } +// UpdateApplianceMeta updates the metadata of an existing edge host. func (h *V1Client) UpdateApplianceMeta(uid string, appliance *models.V1EdgeHostDeviceMetaUpdateEntity) error { - params := clientV1.NewV1EdgeHostDevicesUIDMetaUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1EdgeHostDevicesUIDMetaUpdateParamsWithContext(h.ctx). WithBody(appliance). WithUID(uid) _, err := h.Client.V1EdgeHostDevicesUIDMetaUpdate(params) return err } +// DeleteAppliance deletes an existing edge host. func (h *V1Client) DeleteAppliance(uid string) error { - params := clientV1.NewV1EdgeHostDevicesUIDDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1EdgeHostDevicesUIDDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1EdgeHostDevicesUIDDelete(params) return err diff --git a/client/application.go b/client/application.go index f8d00f7a..c5064d4c 100644 --- a/client/application.go +++ b/client/application.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// GetApplication retrieves an existing application deployment. func (h *V1Client) GetApplication(uid string) (*models.V1AppDeployment, error) { - params := clientV1.NewV1AppDeploymentsUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1AppDeploymentsUIDGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1AppDeploymentsUIDGet(params) if apiutil.Is404(err) { @@ -18,8 +19,9 @@ func (h *V1Client) GetApplication(uid string) (*models.V1AppDeployment, error) { return resp.Payload, nil } +// SearchAppDeploymentSummaries retrieves a list of application deployment summaries based on the filter and sort criteria. func (h *V1Client) SearchAppDeploymentSummaries(filter *models.V1AppDeploymentFilterSpec, sortBy []*models.V1AppDeploymentSortSpec) ([]*models.V1AppDeploymentSummary, error) { - params := clientV1.NewV1DashboardAppDeploymentsParamsWithContext(h.ctx). + params := clientv1.NewV1DashboardAppDeploymentsParamsWithContext(h.ctx). WithBody(&models.V1AppDeploymentsFilterSpec{ Filter: filter, Sort: sortBy, @@ -33,8 +35,9 @@ func (h *V1Client) SearchAppDeploymentSummaries(filter *models.V1AppDeploymentFi return resp.Payload.AppDeployments, nil } +// CreateApplicationWithNewSandboxCluster creates a new application deployment inside a new virtual cluster. func (h *V1Client) CreateApplicationWithNewSandboxCluster(body *models.V1AppDeploymentClusterGroupEntity) (string, error) { - params := clientV1.NewV1AppDeploymentsClusterGroupCreateParamsWithContext(h.ctx). + params := clientv1.NewV1AppDeploymentsClusterGroupCreateParamsWithContext(h.ctx). WithBody(body) resp, err := h.Client.V1AppDeploymentsClusterGroupCreate(params) if err != nil { @@ -43,8 +46,9 @@ func (h *V1Client) CreateApplicationWithNewSandboxCluster(body *models.V1AppDepl return *resp.Payload.UID, nil } +// CreateApplicationWithExistingSandboxCluster creates a new application deployment within an existing virtual cluster. func (h *V1Client) CreateApplicationWithExistingSandboxCluster(body *models.V1AppDeploymentVirtualClusterEntity) (string, error) { - params := clientV1.NewV1AppDeploymentsVirtualClusterCreateParamsWithContext(h.ctx). + params := clientv1.NewV1AppDeploymentsVirtualClusterCreateParamsWithContext(h.ctx). WithBody(body) resp, err := h.Client.V1AppDeploymentsVirtualClusterCreate(params) if err != nil { @@ -53,17 +57,19 @@ func (h *V1Client) CreateApplicationWithExistingSandboxCluster(body *models.V1Ap return *resp.Payload.UID, nil } +// DeleteApplication deletes an existing application deployment. func (h *V1Client) DeleteApplication(uid string) error { - params := clientV1.NewV1AppDeploymentsUIDDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1AppDeploymentsUIDDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1AppDeploymentsUIDDelete(params) return err } -func (h *V1Client) ApplyApplicationUpdate(uid, notificationUid string) error { - params := clientV1.NewV1AppDeploymentsUIDProfileApplyParamsWithContext(h.ctx). +// ApplyApplicationUpdate applies an update to an existing application deployment. +func (h *V1Client) ApplyApplicationUpdate(uid, notificationUID string) error { + params := clientv1.NewV1AppDeploymentsUIDProfileApplyParamsWithContext(h.ctx). WithUID(uid). - WithNotify(¬ificationUid) + WithNotify(¬ificationUID) _, err := h.Client.V1AppDeploymentsUIDProfileApply(params) return err } diff --git a/client/application_profile.go b/client/application_profile.go index a9ead2eb..4d22e4b3 100644 --- a/client/application_profile.go +++ b/client/application_profile.go @@ -5,14 +5,15 @@ import ( "github.com/pkg/errors" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" "github.com/spectrocloud/palette-sdk-go/client/herr" ) +// GetApplicationProfileByNameAndVersion retrieves an application profile by name and version. func (h *V1Client) GetApplicationProfileByNameAndVersion(profileName, version string) (*models.V1AppProfileSummary, string, string, error) { - params := clientV1.NewV1DashboardAppProfilesParamsWithContext(h.ctx). + params := clientv1.NewV1DashboardAppProfilesParamsWithContext(h.ctx). WithLimit(apiutil.Ptr(int64(0))) profiles, err := h.Client.V1DashboardAppProfiles(params) if err != nil { @@ -30,8 +31,9 @@ func (h *V1Client) GetApplicationProfileByNameAndVersion(profileName, version st return nil, "", "", fmt.Errorf("application profile '%s' not found for version '%s'", profileName, version) } +// GetApplicationProfile retrieves an existing application profile by UID. func (h *V1Client) GetApplicationProfile(uid string) (*models.V1AppProfile, error) { - params := clientV1.NewV1AppProfilesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1AppProfilesUIDGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1AppProfilesUIDGet(params) if err != nil { @@ -43,8 +45,9 @@ func (h *V1Client) GetApplicationProfile(uid string) (*models.V1AppProfile, erro return resp.Payload, nil } +// GetApplicationProfileTiers retrieves the tiers of an application profile. func (h *V1Client) GetApplicationProfileTiers(applicationProfileUID string) ([]*models.V1AppTier, error) { - params := clientV1.NewV1AppProfilesUIDTiersGetParamsWithContext(h.ctx). + params := clientv1.NewV1AppProfilesUIDTiersGetParamsWithContext(h.ctx). WithUID(applicationProfileUID) resp, err := h.Client.V1AppProfilesUIDTiersGet(params) if apiutil.Is404(err) { @@ -55,8 +58,9 @@ func (h *V1Client) GetApplicationProfileTiers(applicationProfileUID string) ([]* return resp.Payload.Spec.AppTiers, nil } +// GetApplicationProfileTierManifestContent retrieves the content of a manifest in a tier of an application profile. func (h *V1Client) GetApplicationProfileTierManifestContent(applicationProfileUID, tierUID, manifestUID string) (string, error) { - params := clientV1.NewV1AppProfilesUIDTiersUIDManifestsUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1AppProfilesUIDTiersUIDManifestsUIDGetParamsWithContext(h.ctx). WithUID(applicationProfileUID). WithTierUID(tierUID). WithManifestUID(manifestUID) @@ -69,14 +73,15 @@ func (h *V1Client) GetApplicationProfileTierManifestContent(applicationProfileUI return resp.Payload.Spec.Published.Content, nil } +// SearchAppProfileSummaries retrieves a list of application profile summaries based on the provided filter and sort criteria. func (h *V1Client) SearchAppProfileSummaries(filter *models.V1AppProfileFilterSpec, sortBy []*models.V1AppProfileSortSpec) ([]*models.V1AppProfileSummary, error) { - params := clientV1.NewV1DashboardAppProfilesParamsWithContext(h.ctx). + params := clientv1.NewV1DashboardAppProfilesParamsWithContext(h.ctx). WithBody(&models.V1AppProfilesFilterSpec{ Filter: filter, Sort: sortBy, }) var appProfiles []*models.V1AppProfileSummary - var resp *clientV1.V1DashboardAppProfilesOK + var resp *clientv1.V1DashboardAppProfilesOK var err error for { if resp != nil { @@ -87,33 +92,36 @@ func (h *V1Client) SearchAppProfileSummaries(filter *models.V1AppProfileFilterSp return nil, nil } else if err != nil { return nil, err + } else if resp == nil { + break } - if resp != nil && resp.Payload != nil { - if resp.Payload.AppProfiles != nil { - appProfiles = append(appProfiles, resp.Payload.AppProfiles...) - } - if resp.Payload.Listmeta == nil || len(resp.Payload.Listmeta.Continue) == 0 { - break - } - } else { + if resp.Payload == nil { + break + } + if resp.Payload.AppProfiles != nil { + appProfiles = append(appProfiles, resp.Payload.AppProfiles...) + } + if resp.Payload.Listmeta == nil || len(resp.Payload.Listmeta.Continue) == 0 { break } } return appProfiles, nil } +// PatchApplicationProfile patches an existing application profile. func (h *V1Client) PatchApplicationProfile(appProfileUID string, metadata *models.V1AppProfileMetaEntity) error { - params := clientV1.NewV1AppProfilesUIDMetadataUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1AppProfilesUIDMetadataUpdateParamsWithContext(h.ctx). WithUID(appProfileUID). WithBody(metadata) _, err := h.Client.V1AppProfilesUIDMetadataUpdate(params) return err } +// CreateApplicationProfileTiers creates tiers for an application profile. func (h *V1Client) CreateApplicationProfileTiers(appProfileUID string, appTiers []*models.V1AppTierEntity) error { var err error for _, appTier := range appTiers { - params := clientV1.NewV1AppProfilesUIDTiersCreateParamsWithContext(h.ctx). + params := clientv1.NewV1AppProfilesUIDTiersCreateParamsWithContext(h.ctx). WithUID(appProfileUID). WithBody(appTier) _, tmpErr := h.Client.V1AppProfilesUIDTiersCreate(params) @@ -124,8 +132,9 @@ func (h *V1Client) CreateApplicationProfileTiers(appProfileUID string, appTiers return err } +// UpdateApplicationProfileTiers updates tiers for an application profile. func (h *V1Client) UpdateApplicationProfileTiers(appProfileUID, tierUID string, appTier *models.V1AppTierUpdateEntity) error { - params := clientV1.NewV1AppProfilesUIDTiersUIDUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1AppProfilesUIDTiersUIDUpdateParamsWithContext(h.ctx). WithUID(appProfileUID). WithTierUID(tierUID). WithBody(appTier) @@ -136,10 +145,11 @@ func (h *V1Client) UpdateApplicationProfileTiers(appProfileUID, tierUID string, return err } +// DeleteApplicationProfileTiers deletes tiers from an application profile. func (h *V1Client) DeleteApplicationProfileTiers(appProfileUID string, appTiers []string) error { var err error for _, appTierUID := range appTiers { - params := clientV1.NewV1AppProfilesUIDTiersUIDDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1AppProfilesUIDTiersUIDDeleteParamsWithContext(h.ctx). WithUID(appProfileUID). WithTierUID(appTierUID) _, tmpErr := h.Client.V1AppProfilesUIDTiersUIDDelete(params) @@ -150,8 +160,9 @@ func (h *V1Client) DeleteApplicationProfileTiers(appProfileUID string, appTiers return err } +// CreateApplicationProfile creates a new application profile. func (h *V1Client) CreateApplicationProfile(appProfile *models.V1AppProfileEntity) (string, error) { - params := clientV1.NewV1AppProfilesCreateParamsWithContext(h.ctx). + params := clientv1.NewV1AppProfilesCreateParamsWithContext(h.ctx). WithBody(appProfile) resp, err := h.Client.V1AppProfilesCreate(params) if err != nil { @@ -160,12 +171,13 @@ func (h *V1Client) CreateApplicationProfile(appProfile *models.V1AppProfileEntit return *resp.Payload.UID, nil } +// DeleteApplicationProfile deletes an existing application profile. func (h *V1Client) DeleteApplicationProfile(uid string) error { profile, err := h.GetApplicationProfile(uid) if err != nil { return err } - params := clientV1.NewV1AppProfilesUIDDeleteParams(). + params := clientv1.NewV1AppProfilesUIDDeleteParams(). WithContext(ContextForScope(profile.Metadata.Annotations[Scope], h.projectUID)). WithUID(uid) _, err = h.Client.V1AppProfilesUIDDelete(params) diff --git a/client/backup_storage_location.go b/client/backup_storage_location.go index 0bf36ece..8923285d 100644 --- a/client/backup_storage_location.go +++ b/client/backup_storage_location.go @@ -1,12 +1,13 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// ListBackupStorageLocation returns a list of all backup storage locations. func (h *V1Client) ListBackupStorageLocation() ([]*models.V1UserAssetsLocation, error) { - params := clientV1.NewV1UsersAssetsLocationGetParamsWithContext(h.ctx) + params := clientv1.NewV1UsersAssetsLocationGetParamsWithContext(h.ctx) resp, err := h.Client.V1UsersAssetsLocationGet(params) if err != nil { return nil, err @@ -14,8 +15,9 @@ func (h *V1Client) ListBackupStorageLocation() ([]*models.V1UserAssetsLocation, return resp.Payload.Items, nil } +// GetBackupStorageLocation retrieves an existing backup storage location. func (h *V1Client) GetBackupStorageLocation(uid string) (*models.V1UserAssetsLocation, error) { - params := clientV1.NewV1UsersAssetsLocationGetParamsWithContext(h.ctx) + params := clientv1.NewV1UsersAssetsLocationGetParamsWithContext(h.ctx) resp, err := h.Client.V1UsersAssetsLocationGet(params) if err != nil { return nil, err @@ -28,8 +30,9 @@ func (h *V1Client) GetBackupStorageLocation(uid string) (*models.V1UserAssetsLoc return nil, nil } +// GetS3BackupStorageLocation retrieves an existing S3 backup storage location. func (h *V1Client) GetS3BackupStorageLocation(uid string) (*models.V1UserAssetsLocationS3, error) { - params := clientV1.NewV1UsersAssetsLocationS3GetParamsWithContext(h.ctx). + params := clientv1.NewV1UsersAssetsLocationS3GetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1UsersAssetsLocationS3Get(params) if err != nil { @@ -38,8 +41,9 @@ func (h *V1Client) GetS3BackupStorageLocation(uid string) (*models.V1UserAssetsL return resp.Payload, nil } +// CreateS3BackupStorageLocation creates a new S3 backup storage location. func (h *V1Client) CreateS3BackupStorageLocation(bsl *models.V1UserAssetsLocationS3) (string, error) { - params := clientV1.NewV1UsersAssetsLocationS3CreateParamsWithContext(h.ctx). + params := clientv1.NewV1UsersAssetsLocationS3CreateParamsWithContext(h.ctx). WithBody(bsl) resp, err := h.Client.V1UsersAssetsLocationS3Create(params) if err != nil { @@ -48,16 +52,18 @@ func (h *V1Client) CreateS3BackupStorageLocation(bsl *models.V1UserAssetsLocatio return *resp.Payload.UID, nil } +// UpdateS3BackupStorageLocation updates an existing S3 backup storage location. func (h *V1Client) UpdateS3BackupStorageLocation(uid string, bsl *models.V1UserAssetsLocationS3) error { - params := clientV1.NewV1UsersAssetsLocationS3UpdateParamsWithContext(h.ctx). + params := clientv1.NewV1UsersAssetsLocationS3UpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(bsl) _, err := h.Client.V1UsersAssetsLocationS3Update(params) return err } +// DeleteS3BackupStorageLocation deletes an existing S3 backup storage location. func (h *V1Client) DeleteS3BackupStorageLocation(uid string) error { - params := clientV1.NewV1UsersAssetsLocationS3DeleteParamsWithContext(h.ctx). + params := clientv1.NewV1UsersAssetsLocationS3DeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1UsersAssetsLocationS3Delete(params) return err diff --git a/client/client.go b/client/client.go index 0acb46cc..2061d1c6 100644 --- a/client/client.go +++ b/client/client.go @@ -1,3 +1,4 @@ +// Package client provides a client for the Spectro Cloud API. package client import ( @@ -9,12 +10,13 @@ import ( "github.com/go-openapi/strfmt" "github.com/spectrocloud/palette-api-go/apiutil/transport" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// V1Client is a client for the Spectro Cloud API. type V1Client struct { - Client clientV1.ClientService + Client clientv1.ClientService ctx context.Context apikey string @@ -29,6 +31,7 @@ type V1Client struct { retryAttempts int } +// New creates a new V1Client. func New(options ...func(*V1Client)) *V1Client { client := &V1Client{ ctx: context.Background(), @@ -38,46 +41,53 @@ func New(options ...func(*V1Client)) *V1Client { for _, o := range options { o(client) } - client.Client = clientV1.New(client.getTransport(), strfmt.Default) + client.Client = clientv1.New(client.getTransport(), strfmt.Default) return client } +// WithAPIKey sets the API key for the client. func WithAPIKey(apiKey string) func(*V1Client) { return func(v *V1Client) { v.apikey = apiKey } } +// WithJWT sets the JWT for the client. func WithJWT(jwt string) func(*V1Client) { return func(v *V1Client) { v.jwt = jwt } } +// WithUsername sets the username for the client. func WithUsername(username string) func(*V1Client) { return func(v *V1Client) { v.username = username } } +// WithPassword sets the password for the client. func WithPassword(password string) func(*V1Client) { return func(v *V1Client) { v.password = password } } +// WithHubbleURI sets the Hubble URI for the client. func WithHubbleURI(hubbleURI string) func(*V1Client) { return func(v *V1Client) { v.hubbleURI = hubbleURI } } +// WithInsecureSkipVerify sets insecureSkipVerify for the client. func WithInsecureSkipVerify(insecureSkipVerify bool) func(*V1Client) { return func(v *V1Client) { v.insecureSkipVerify = insecureSkipVerify } } +// WithScopeProject sets the project UID for the client. func WithScopeProject(projectUID string) func(*V1Client) { return func(v *V1Client) { v.projectUID = projectUID @@ -85,30 +95,35 @@ func WithScopeProject(projectUID string) func(*V1Client) { } } +// WithScopeTenant sets the tenant scope for the client. func WithScopeTenant() func(*V1Client) { return func(v *V1Client) { v.ctx = ContextForScope("tenant", "") } } +// WithRetries sets the number of retries for the client. func WithRetries(retries int) func(*V1Client) { return func(v *V1Client) { v.retryAttempts = retries } } +// WithSchemes sets the schemes for the client. func WithSchemes(schemes []string) func(*V1Client) { return func(v *V1Client) { v.schemes = schemes } } +// WithTransportDebug sets the client's HTTP transport debug flag. func WithTransportDebug() func(*V1Client) { return func(v *V1Client) { v.transportDebug = true } } +// ContextForScope returns a context with the given scope and optional project UID. func ContextForScope(scope, projectUID string) context.Context { ctx := context.Background() if scope == "project" { @@ -121,6 +136,7 @@ func ContextForScope(scope, projectUID string) context.Context { return ctx } +// Clone creates a new V1Client with the same configuration as the original. func (h *V1Client) Clone() *V1Client { opts := []func(*V1Client){ WithHubbleURI(h.hubbleURI), @@ -147,12 +163,13 @@ func (h *V1Client) Clone() *V1Client { return New(opts...) } -func (h *V1Client) getTransport() (t *transport.Runtime) { +func (h *V1Client) getTransport() *transport.Runtime { if h.username != "" && h.password != "" { - if err := h.authenticate(); err != nil { + if err := h.handleBasicAuth(); err != nil { return nil } } + var t *transport.Runtime if h.apikey != "" { t = h.apiKeyTransport() } else if h.jwt != "" { @@ -160,12 +177,12 @@ func (h *V1Client) getTransport() (t *transport.Runtime) { } else { t = h.baseTransport() } - return + return t } func (h *V1Client) apiKeyTransport() *transport.Runtime { httpTransport := h.baseTransport() - httpTransport.DefaultAuthentication = openapiclient.APIKeyAuth(authApiKey, authTokenInput, h.apikey) + httpTransport.DefaultAuthentication = openapiclient.APIKeyAuth(authAPIKey, authTokenInput, h.apikey) return httpTransport } @@ -175,11 +192,11 @@ func (h *V1Client) jwtTransport() *transport.Runtime { return httpTransport } -func (h *V1Client) authenticate() error { +func (h *V1Client) handleBasicAuth() error { httpTransport := h.baseTransport() - c := clientV1.New(httpTransport, strfmt.Default) + c := clientv1.New(httpTransport, strfmt.Default) - params := &clientV1.V1AuthenticateParams{ + params := &clientv1.V1AuthenticateParams{ Body: &models.V1AuthLogin{ EmailID: h.username, Password: strfmt.Password(h.password), @@ -212,6 +229,7 @@ func (h *V1Client) httpClient() *http.Client { } } +// Validate validates the configuration for a project-scoped client. func (h *V1Client) Validate() error { // API key can only be validated by making an API call if h.apikey != "" { @@ -223,6 +241,7 @@ func (h *V1Client) Validate() error { return nil } +// ValidateTenantAdmin validates the configuration for a tenant-scoped client. func (h *V1Client) ValidateTenantAdmin() error { // API key can only be validated by making an API call if h.apikey != "" { diff --git a/client/cluster.go b/client/cluster.go index 3004121e..a62321ed 100644 --- a/client/cluster.go +++ b/client/cluster.go @@ -8,35 +8,38 @@ import ( "path/filepath" "strings" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" "github.com/spectrocloud/palette-sdk-go/client/herr" ) +// DeleteCluster deletes a cluster. func (h *V1Client) DeleteCluster(uid string) error { cluster, err := h.GetCluster(uid) if err != nil || cluster == nil { return err } - params := clientV1.NewV1SpectroClustersDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersDeleteParamsWithContext(h.ctx). WithUID(uid) _, err = h.Client.V1SpectroClustersDelete(params) return err } +// ForceDeleteCluster force-deletes a cluster, which may orphan cloud resources. func (h *V1Client) ForceDeleteCluster(uid string, forceDelete bool) error { cluster, err := h.GetCluster(uid) if err != nil || cluster == nil { return err } - params := clientV1.NewV1SpectroClustersDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersDeleteParamsWithContext(h.ctx). WithUID(uid). WithForceDelete(&forceDelete) _, err = h.Client.V1SpectroClustersDelete(params) return err } +// GetCluster retrieves an existing cluster. Returns nil if the cluster's status is nil or the cluster has been deleted. func (h *V1Client) GetCluster(uid string) (*models.V1SpectroCluster, error) { cluster, err := h.GetClusterWithoutStatus(uid) if err != nil { @@ -48,8 +51,9 @@ func (h *V1Client) GetCluster(uid string) (*models.V1SpectroCluster, error) { return cluster, nil } +// GetClusterWithoutStatus retrieves an existing cluster regardless of its status. func (h *V1Client) GetClusterWithoutStatus(uid string) (*models.V1SpectroCluster, error) { - params := clientV1.NewV1SpectroClustersGetParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1SpectroClustersGet(params) if apiutil.Is404(err) { @@ -60,6 +64,7 @@ func (h *V1Client) GetClusterWithoutStatus(uid string) (*models.V1SpectroCluster return resp.Payload, nil } +// GetClusterByName retrieves an existing cluster by name. Returns nil if the cluster's status is nil or the cluster has been deleted. func (h *V1Client) GetClusterByName(name string, virtual bool) (*models.V1SpectroCluster, error) { filters := []*models.V1SearchFilterItem{clusterNameEqFilter(name)} clusterSummaries, err := h.SearchClusterSummaries(getClusterFilter(filters, virtual), nil) @@ -76,8 +81,9 @@ func (h *V1Client) GetClusterByName(name string, virtual bool) (*models.V1Spectr return cluster, nil } +// GetClusterSummary retrieves an existing cluster's summary. func (h *V1Client) GetClusterSummary(clusterID string) (*models.V1SpectroClusterUIDSummary, error) { - params := clientV1.NewV1SpectroClustersSummaryUIDParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersSummaryUIDParamsWithContext(h.ctx). WithUID(clusterID) resp, err := h.Client.V1SpectroClustersSummaryUID(params) if err != nil { @@ -86,8 +92,9 @@ func (h *V1Client) GetClusterSummary(clusterID string) (*models.V1SpectroCluster return resp.Payload, nil } +// SearchClusterSummaries retrieves a list of cluster summaries based on the provided filter and sort criteria. func (h *V1Client) SearchClusterSummaries(filter *models.V1SearchFilterSpec, sort []*models.V1SearchFilterSortSpec) ([]*models.V1SpectroClusterSummary, error) { - params := clientV1.NewV1SpectroClustersSearchFilterSummaryParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersSearchFilterSummaryParamsWithContext(h.ctx). WithBody(&models.V1SearchFilterSummarySpec{ Filter: filter, Sort: sort, @@ -101,9 +108,10 @@ func (h *V1Client) SearchClusterSummaries(filter *models.V1SearchFilterSpec, sor return resp.Payload.Items, nil } +// GetClusterKubeConfig retrieves a cluster's kubeconfig. func (h *V1Client) GetClusterKubeConfig(uid string) (string, error) { builder := &strings.Builder{} - params := clientV1.NewV1SpectroClustersUIDKubeConfigParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDKubeConfigParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1SpectroClustersUIDKubeConfig(params, builder) if err != nil { @@ -115,9 +123,10 @@ func (h *V1Client) GetClusterKubeConfig(uid string) (string, error) { return parseKubeconfig(builder) } +// GetClusterAdminKubeConfig retrieves a cluster's admin kubeconfig. func (h *V1Client) GetClusterAdminKubeConfig(uid string) (string, error) { builder := &strings.Builder{} - params := clientV1.NewV1SpectroClustersUIDAdminKubeConfigParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDAdminKubeConfigParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1SpectroClustersUIDAdminKubeConfig(params, builder) if err != nil { @@ -132,18 +141,19 @@ func (h *V1Client) GetClusterAdminKubeConfig(uid string) (string, error) { func parseKubeconfig(builder *strings.Builder) (string, error) { kubeconfig := builder.String() if apiutil.IsBase64(kubeconfig) { - bytes, err := apiutil.Base64DecodeString(kubeconfig) + bs, err := apiutil.Base64DecodeString(kubeconfig) if err != nil { return "", err } - return string(bytes), nil + return string(bs), nil } return kubeconfig, nil } +// GetClusterImportManifest retrieves a cluster's import manifest. func (h *V1Client) GetClusterImportManifest(uid string) (string, error) { builder := &strings.Builder{} - params := clientV1.NewV1SpectroClustersUIDImportManifestParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDImportManifestParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1SpectroClustersUIDImportManifest(params, builder) if err != nil { @@ -152,8 +162,9 @@ func (h *V1Client) GetClusterImportManifest(uid string) (string, error) { return builder.String(), nil } +// UpdateClusterProfileValues updates a cluster's profile values. func (h *V1Client) UpdateClusterProfileValues(uid string, profiles *models.V1SpectroClusterProfiles) error { - params := clientV1.NewV1SpectroClustersUpdateProfilesParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUpdateProfilesParamsWithContext(h.ctx). WithUID(uid). WithBody(profiles). WithResolveNotification(apiutil.Ptr(true)) @@ -161,8 +172,9 @@ func (h *V1Client) UpdateClusterProfileValues(uid string, profiles *models.V1Spe return err } +// ImportClusterGeneric imports a cluster using a generic import manifest. func (h *V1Client) ImportClusterGeneric(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clientV1.NewV1SpectroClustersGenericImportParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersGenericImportParamsWithContext(h.ctx). WithBody(&models.V1SpectroGenericClusterImportEntity{ Metadata: meta, }) @@ -173,15 +185,17 @@ func (h *V1Client) ImportClusterGeneric(meta *models.V1ObjectMetaInputEntity) (s return *resp.Payload.UID, nil } +// ApproveClusterRepave approves a cluster repave. func (h *V1Client) ApproveClusterRepave(clusterUID string) error { - params := clientV1.NewV1SpectroClustersUIDRepaveApproveUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDRepaveApproveUpdateParamsWithContext(h.ctx). WithUID(clusterUID) _, err := h.Client.V1SpectroClustersUIDRepaveApproveUpdate(params) return err } +// GetRepaveReasons retrieves a cluster's repave reasons. func (h *V1Client) GetRepaveReasons(clusterUID string) ([]string, error) { - params := clientV1.NewV1SpectroClustersUIDRepaveGetParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDRepaveGetParamsWithContext(h.ctx). WithUID(clusterUID) resp, err := h.Client.V1SpectroClustersUIDRepaveGet(params) if err != nil { @@ -252,8 +266,9 @@ func clusterNameEqFilter(name string) *models.V1SearchFilterItem { } } +// GetLogFetcherStatus retrieves a cluster's log fetcher status. func (h *V1Client) GetLogFetcherStatus(uid string, logFetcherUID *string) (*models.V1ClusterLogFetcher, error) { - params := clientV1.NewV1ClusterFeatureLogFetcherGetParamsWithContext(h.ctx).WithUID(uid).WithRequestID(logFetcherUID) + params := clientv1.NewV1ClusterFeatureLogFetcherGetParamsWithContext(h.ctx).WithUID(uid).WithRequestID(logFetcherUID) resp, err := h.Client.V1ClusterFeatureLogFetcherGet(params) if err != nil { return nil, err @@ -261,8 +276,11 @@ func (h *V1Client) GetLogFetcherStatus(uid string, logFetcherUID *string) (*mode return resp.Payload, nil } -func (h *V1Client) InitiateDownloadOfClusterLogs(uid string, V1ClusterLogFetcherRequestObj *models.V1ClusterLogFetcherRequest) (*string, error) { - params := clientV1.NewV1ClusterFeatureLogFetcherCreateParamsWithContext(h.ctx).WithUID(uid).WithBody(V1ClusterLogFetcherRequestObj) +// InitiateDownloadOfClusterLogs initiates the download of a cluster's logs. +// Returns a log fetcher uid which is required to perform the log download. +// Before downloading logs, the log fetcher's status should be checked. +func (h *V1Client) InitiateDownloadOfClusterLogs(uid string, req *models.V1ClusterLogFetcherRequest) (*string, error) { + params := clientv1.NewV1ClusterFeatureLogFetcherCreateParamsWithContext(h.ctx).WithUID(uid).WithBody(req) resp, err := h.Client.V1ClusterFeatureLogFetcherCreate(params) if err != nil { return nil, err @@ -270,12 +288,13 @@ func (h *V1Client) InitiateDownloadOfClusterLogs(uid string, V1ClusterLogFetcher return resp.GetPayload().UID, nil } +// DownloadLogs downloads a cluster's logs, given a cluster uid and a log fetcher uid generated via InitiateDownloadOfClusterLogs. func (h *V1Client) DownloadLogs(uid string, logFetcherUID string) (io.Writer, error) { filename := "logs-" + uid + ".zip" var buf bytes.Buffer writer := io.Writer(&buf) - params := clientV1.NewV1ClusterFeatureLogFetcherLogDownloadParamsWithContext(h.ctx).WithUID(logFetcherUID).WithFileName(&filename) + params := clientv1.NewV1ClusterFeatureLogFetcherLogDownloadParamsWithContext(h.ctx).WithUID(logFetcherUID).WithFileName(&filename) resp, err := h.Client.V1ClusterFeatureLogFetcherLogDownload(params, writer) if err != nil { return nil, err diff --git a/client/cluster_aks.go b/client/cluster_aks.go index d27e2529..05c8cfaf 100644 --- a/client/cluster_aks.go +++ b/client/cluster_aks.go @@ -3,13 +3,14 @@ package client import ( "time" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateClusterAks creates a new AKS cluster. func (h *V1Client) CreateClusterAks(cluster *models.V1SpectroAzureClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersAksCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersAksCreateParamsWithContext(h.ctx). WithBody(cluster). WithTimeout(90 * time.Second) resp, err := h.Client.V1SpectroClustersAksCreate(params) @@ -19,16 +20,18 @@ func (h *V1Client) CreateClusterAks(cluster *models.V1SpectroAzureClusterEntity) return *resp.Payload.UID, nil } +// CreateMachinePoolAks creates a new AKS machine pool. func (h *V1Client) CreateMachinePoolAks(cloudConfigUID string, machinePool *models.V1AzureMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsAksMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAksMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsAksMachinePoolCreate(params) return err } +// UpdateMachinePoolAks updates an existing AKS machine pool. func (h *V1Client) UpdateMachinePoolAks(cloudConfigUID string, machinePool *models.V1AzureMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsAksMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAksMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -36,16 +39,18 @@ func (h *V1Client) UpdateMachinePoolAks(cloudConfigUID string, machinePool *mode return err } +// DeleteMachinePoolAks deletes an existing AKS machine pool. func (h *V1Client) DeleteMachinePoolAks(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsAksMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAksMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsAksMachinePoolDelete(params) return err } +// GetCloudConfigAks retrieves an existing AKS cluster's cloud config. func (h *V1Client) GetCloudConfigAks(configUID string) (*models.V1AzureCloudConfig, error) { - params := clientV1.NewV1CloudConfigsAksGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAksGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsAksGet(params) if apiutil.Is404(err) { @@ -56,8 +61,9 @@ func (h *V1Client) GetCloudConfigAks(configUID string) (*models.V1AzureCloudConf return resp.Payload, nil } +// GetNodeStatusMapAks retrieves the status of all nodes in an AKS machine pool. func (h *V1Client) GetNodeStatusMapAks(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsAksPoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAksPoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsAksPoolMachinesList(params) diff --git a/client/cluster_aws.go b/client/cluster_aws.go index c2994c60..2d6cf7d4 100644 --- a/client/cluster_aws.go +++ b/client/cluster_aws.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateClusterAws creates a new AWS IaaS cluster. func (h *V1Client) CreateClusterAws(cluster *models.V1SpectroAwsClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersAwsCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersAwsCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1SpectroClustersAwsCreate(params) if err != nil { @@ -16,16 +17,18 @@ func (h *V1Client) CreateClusterAws(cluster *models.V1SpectroAwsClusterEntity) ( return *resp.Payload.UID, nil } +// CreateMachinePoolAws creates a new AWS IaaS machine pool. func (h *V1Client) CreateMachinePoolAws(cloudConfigUID string, machinePool *models.V1AwsMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsAwsMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAwsMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsAwsMachinePoolCreate(params) return err } +// UpdateMachinePoolAws updates an existing AWS IaaS machine pool. func (h *V1Client) UpdateMachinePoolAws(cloudConfigUID string, machinePool *models.V1AwsMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsAwsMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAwsMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -33,16 +36,18 @@ func (h *V1Client) UpdateMachinePoolAws(cloudConfigUID string, machinePool *mode return err } +// DeleteMachinePoolAws deletes an existing AWS IaaS machine pool. func (h *V1Client) DeleteMachinePoolAws(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsAwsMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAwsMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsAwsMachinePoolDelete(params) return err } +// GetCloudConfigAws retrieves an existing AWS IaaS cluster's cloud config. func (h *V1Client) GetCloudConfigAws(configUID string) (*models.V1AwsCloudConfig, error) { - params := clientV1.NewV1CloudConfigsAwsGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAwsGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsAwsGet(params) if apiutil.Is404(err) { @@ -53,8 +58,9 @@ func (h *V1Client) GetCloudConfigAws(configUID string) (*models.V1AwsCloudConfig return resp.Payload, nil } +// ImportClusterAws imports an existing AWS IaaS cluster. func (h *V1Client) ImportClusterAws(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clientV1.NewV1SpectroClustersAwsImportParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersAwsImportParamsWithContext(h.ctx). WithBody(&models.V1SpectroAwsClusterImportEntity{ Metadata: meta, }, @@ -66,8 +72,9 @@ func (h *V1Client) ImportClusterAws(meta *models.V1ObjectMetaInputEntity) (strin return *resp.Payload.UID, nil } +// GetNodeStatusMapAws retrieves the status of all nodes in an AWS IaaS machine pool. func (h *V1Client) GetNodeStatusMapAws(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsAwsPoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAwsPoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsAwsPoolMachinesList(params) diff --git a/client/cluster_azure.go b/client/cluster_azure.go index 77ed8c07..50196567 100644 --- a/client/cluster_azure.go +++ b/client/cluster_azure.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateClusterAzure creates a new Azure IaaS cluster. func (h *V1Client) CreateClusterAzure(cluster *models.V1SpectroAzureClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersAzureCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersAzureCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1SpectroClustersAzureCreate(params) if err != nil { @@ -16,16 +17,18 @@ func (h *V1Client) CreateClusterAzure(cluster *models.V1SpectroAzureClusterEntit return *resp.Payload.UID, nil } +// CreateMachinePoolAzure creates a new Azure IaaS machine pool. func (h *V1Client) CreateMachinePoolAzure(cloudConfigUID string, machinePool *models.V1AzureMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsAzureMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAzureMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsAzureMachinePoolCreate(params) return err } +// UpdateMachinePoolAzure updates an existing Azure IaaS machine pool. func (h *V1Client) UpdateMachinePoolAzure(cloudConfigUID string, machinePool *models.V1AzureMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsAzureMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAzureMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -33,16 +36,18 @@ func (h *V1Client) UpdateMachinePoolAzure(cloudConfigUID string, machinePool *mo return err } +// DeleteMachinePoolAzure deletes an existing Azure IaaS machine pool. func (h *V1Client) DeleteMachinePoolAzure(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsAzureMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAzureMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsAzureMachinePoolDelete(params) return err } +// GetCloudConfigAzure retrieves an existing Azure IaaS cluster's cloud config. func (h *V1Client) GetCloudConfigAzure(configUID string) (*models.V1AzureCloudConfig, error) { - params := clientV1.NewV1CloudConfigsAzureGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAzureGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsAzureGet(params) if apiutil.Is404(err) { @@ -53,8 +58,9 @@ func (h *V1Client) GetCloudConfigAzure(configUID string) (*models.V1AzureCloudCo return resp.Payload, nil } +// ImportClusterAzure imports an existing Azure IaaS cluster. func (h *V1Client) ImportClusterAzure(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clientV1.NewV1SpectroClustersAzureImportParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersAzureImportParamsWithContext(h.ctx). WithBody(&models.V1SpectroAzureClusterImportEntity{ Metadata: meta, }, @@ -66,8 +72,9 @@ func (h *V1Client) ImportClusterAzure(meta *models.V1ObjectMetaInputEntity) (str return *resp.Payload.UID, nil } +// GetNodeStatusMapAzure retrieves the status of all nodes in an Azure IaaS machine pool. func (h *V1Client) GetNodeStatusMapAzure(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsAzurePoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAzurePoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsAzurePoolMachinesList(params) diff --git a/client/cluster_backup_config.go b/client/cluster_backup_config.go index 0d76d695..6045727c 100644 --- a/client/cluster_backup_config.go +++ b/client/cluster_backup_config.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/herr" ) +// GetClusterBackupConfig gets the scheduled backup configuration for a cluster. func (h *V1Client) GetClusterBackupConfig(uid string) (*models.V1ClusterBackup, error) { - params := clientV1.NewV1ClusterFeatureBackupGetParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterFeatureBackupGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1ClusterFeatureBackupGet(params) if err != nil { @@ -19,22 +20,25 @@ func (h *V1Client) GetClusterBackupConfig(uid string) (*models.V1ClusterBackup, return resp.Payload, nil } +// CreateClusterBackupConfig creates a new scheduled backup configuration for a cluster. func (h *V1Client) CreateClusterBackupConfig(uid string, config *models.V1ClusterBackupConfig) error { - params := clientV1.NewV1ClusterFeatureBackupCreateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterFeatureBackupCreateParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1ClusterFeatureBackupCreate(params) return err } +// UpdateClusterBackupConfig updates an existing scheduled backup configuration for a cluster. func (h *V1Client) UpdateClusterBackupConfig(uid string, config *models.V1ClusterBackupConfig) error { - params := clientV1.NewV1ClusterFeatureBackupUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterFeatureBackupUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1ClusterFeatureBackupUpdate(params) return err } +// ApplyClusterBackupConfig creates a new scheduled backup configuration for a cluster or updates its scheduled backup configuration if one exists. func (h *V1Client) ApplyClusterBackupConfig(uid string, config *models.V1ClusterBackupConfig) error { policy, err := h.GetClusterBackupConfig(uid) if err != nil { @@ -46,8 +50,9 @@ func (h *V1Client) ApplyClusterBackupConfig(uid string, config *models.V1Cluster return h.UpdateClusterBackupConfig(uid, config) } +// CreateClusterBackupConfigOnDemand creates a new on-demand backup configuration for a cluster. func (h *V1Client) CreateClusterBackupConfigOnDemand(uid string, config *models.V1ClusterBackupConfig) (*models.V1UID, error) { - params := clientV1.NewV1ClusterFeatureBackupOnDemandCreateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterFeatureBackupOnDemandCreateParamsWithContext(h.ctx). WithBody(config). WithUID(uid) resp, err := h.Client.V1ClusterFeatureBackupOnDemandCreate(params) @@ -57,8 +62,9 @@ func (h *V1Client) CreateClusterBackupConfigOnDemand(uid string, config *models. return resp.Payload, nil } +// DeleteClusterBackupConfigOnDemand deletes an existing on-demand backup configuration for a cluster. func (h *V1Client) DeleteClusterBackupConfigOnDemand(uid string, config *models.V1ClusterBackupConfig) error { - params := clientV1.NewV1ClusterFeatureBackupDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterFeatureBackupDeleteParamsWithContext(h.ctx). WithUID(uid). WithRequestUID(config.BackupLocationUID). WithBackupName(config.BackupName) @@ -66,8 +72,9 @@ func (h *V1Client) DeleteClusterBackupConfigOnDemand(uid string, config *models. return err } +// CreateClusterRestoreConfigOnDemand creates a new on-demand restore configuration for a cluster. func (h *V1Client) CreateClusterRestoreConfigOnDemand(uid string, config *models.V1ClusterRestoreConfig) (*models.V1UID, error) { - params := clientV1.NewV1ClusterFeatureRestoreOnDemandCreateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterFeatureRestoreOnDemandCreateParamsWithContext(h.ctx). WithBody(config). WithUID(uid) resp, err := h.Client.V1ClusterFeatureRestoreOnDemandCreate(params) @@ -77,8 +84,9 @@ func (h *V1Client) CreateClusterRestoreConfigOnDemand(uid string, config *models return resp.Payload, nil } +// GetClusterRestoreConfigOnDemand retrieces an existing on-demand restore configuration for a cluster. func (h *V1Client) GetClusterRestoreConfigOnDemand(uid string) (*models.V1ClusterRestore, error) { - params := clientV1.NewV1ClusterFeatureRestoreGetParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterFeatureRestoreGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1ClusterFeatureRestoreGet(params) if err != nil { diff --git a/client/cluster_custom_cloud.go b/client/cluster_custom_cloud.go index c54cbd35..f4ba3a8d 100644 --- a/client/cluster_custom_cloud.go +++ b/client/cluster_custom_cloud.go @@ -1,12 +1,13 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// CreateClusterCustomCloud creates a custom cloud cluster. func (h *V1Client) CreateClusterCustomCloud(cluster *models.V1SpectroCustomClusterEntity, cloudType string) (string, error) { - params := clientV1.NewV1SpectroClustersCustomCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersCustomCreateParamsWithContext(h.ctx). WithCloudType(cloudType). WithBody(cluster) resp, err := h.Client.V1SpectroClustersCustomCreate(params) @@ -16,8 +17,9 @@ func (h *V1Client) CreateClusterCustomCloud(cluster *models.V1SpectroCustomClust return *resp.Payload.UID, nil } +// GetCloudConfigCustomCloud retrieves an existing custom cloud cluster's cloud config. func (h *V1Client) GetCloudConfigCustomCloud(configUID, cloudType string) (*models.V1CustomCloudConfig, error) { - params := clientV1.NewV1CloudConfigsCustomGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsCustomGetParamsWithContext(h.ctx). WithCloudType(cloudType). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsCustomGet(params) @@ -27,8 +29,9 @@ func (h *V1Client) GetCloudConfigCustomCloud(configUID, cloudType string) (*mode return resp.Payload, nil } +// UpdateCloudConfigCustomCloud updates an existing custom cloud cluster's cloud config. func (h *V1Client) UpdateCloudConfigCustomCloud(updatedConfig *models.V1CustomCloudClusterConfigEntity, configUID, cloudType string) error { - params := clientV1.NewV1CloudConfigsCustomUIDClusterConfigParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsCustomUIDClusterConfigParamsWithContext(h.ctx). WithCloudType(cloudType). WithBody(updatedConfig). WithConfigUID(configUID) @@ -36,8 +39,9 @@ func (h *V1Client) UpdateCloudConfigCustomCloud(updatedConfig *models.V1CustomCl return err } +// CreateMachinePoolCustomCloud creates a new custom cloud machine pool. func (h *V1Client) CreateMachinePoolCustomCloud(mpEntity *models.V1CustomMachinePoolConfigEntity, configUID, cloudType string) error { - params := clientV1.NewV1CloudConfigsCustomMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsCustomMachinePoolCreateParamsWithContext(h.ctx). WithCloudType(cloudType). WithBody(mpEntity). WithConfigUID(configUID) @@ -45,8 +49,9 @@ func (h *V1Client) CreateMachinePoolCustomCloud(mpEntity *models.V1CustomMachine return err } +// UpdateMachinePoolCustomCloud updates an existing custom cloud machine pool. func (h *V1Client) UpdateMachinePoolCustomCloud(mpEntity *models.V1CustomMachinePoolConfigEntity, machinePoolName, configUID, cloudType string) error { - params := clientV1.NewV1CloudConfigsCustomMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsCustomMachinePoolUpdateParamsWithContext(h.ctx). WithCloudType(cloudType). WithBody(mpEntity). WithConfigUID(configUID). @@ -55,8 +60,9 @@ func (h *V1Client) UpdateMachinePoolCustomCloud(mpEntity *models.V1CustomMachine return err } +// DeleteMachinePoolCustomCloud deletes an existing custom cloud machine pool. func (h *V1Client) DeleteMachinePoolCustomCloud(mpName string, configUID, cloudType string) error { - params := clientV1.NewV1CloudConfigsCustomMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsCustomMachinePoolDeleteParamsWithContext(h.ctx). WithCloudType(cloudType). WithConfigUID(configUID). WithMachinePoolName(mpName) diff --git a/client/cluster_edge.go b/client/cluster_edge.go index 1199e215..e869bdc7 100644 --- a/client/cluster_edge.go +++ b/client/cluster_edge.go @@ -1,13 +1,16 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// TODO: edgev1 deprecation + +// CreateClusterEdge creates a new edge cluster. func (h *V1Client) CreateClusterEdge(cluster *models.V1SpectroEdgeClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersEdgeCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersEdgeCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1SpectroClustersEdgeCreate(params) if err != nil { @@ -16,16 +19,18 @@ func (h *V1Client) CreateClusterEdge(cluster *models.V1SpectroEdgeClusterEntity) return *resp.Payload.UID, nil } +// CreateMachinePoolEdge creates a new edge machine pool. func (h *V1Client) CreateMachinePoolEdge(cloudConfigUID string, machinePool *models.V1EdgeMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsEdgeMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsEdgeMachinePoolCreate(params) return err } +// UpdateMachinePoolEdge updates an existing edge machine pool. func (h *V1Client) UpdateMachinePoolEdge(cloudConfigUID string, machinePool *models.V1EdgeMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsEdgeMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -33,16 +38,18 @@ func (h *V1Client) UpdateMachinePoolEdge(cloudConfigUID string, machinePool *mod return err } +// DeleteMachinePoolEdge deletes an existing edge machine pool. func (h *V1Client) DeleteMachinePoolEdge(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsEdgeMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsEdgeMachinePoolDelete(params) return err } +// GetCloudConfigEdge retrieves an existing edge cluster's cloud config. func (h *V1Client) GetCloudConfigEdge(configUID string) (*models.V1EdgeCloudConfig, error) { - params := clientV1.NewV1CloudConfigsEdgeGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsEdgeGet(params) if apiutil.Is404(err) { @@ -53,8 +60,9 @@ func (h *V1Client) GetCloudConfigEdge(configUID string) (*models.V1EdgeCloudConf return resp.Payload, nil } +// GetNodeStatusMapEdge retrieves the status of all nodes in an edge machine pool. func (h *V1Client) GetNodeStatusMapEdge(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsEdgePoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgePoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsEdgePoolMachinesList(params) diff --git a/client/cluster_edge_native.go b/client/cluster_edge_native.go index b07eff2f..4fe095db 100644 --- a/client/cluster_edge_native.go +++ b/client/cluster_edge_native.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) @@ -12,9 +12,10 @@ import ( // CRUDL operations on edge registration tokens are all tenant scoped. // See: hubble/services/svccore/perms/edgetoken_acl.go +// GetRegistrationToken retrieves an existing registration token by name. func (h *V1Client) GetRegistrationToken(tokenName string) (string, error) { // ACL scoped to tenant only - params := clientV1.NewV1EdgeTokensListParams() + params := clientv1.NewV1EdgeTokensListParams() resp, err := h.Client.V1EdgeTokensList(params) if err != nil { return "", err @@ -31,20 +32,21 @@ func (h *V1Client) GetRegistrationToken(tokenName string) (string, error) { return "", nil } +// CreateRegistrationToken creates a new registration token. func (h *V1Client) CreateRegistrationToken(tokenName string, body *models.V1EdgeTokenEntity) (string, error) { // ACL scoped to tenant only - params := clientV1.NewV1EdgeTokensCreateParams(). + params := clientv1.NewV1EdgeTokensCreateParams(). WithBody(body) _, err := h.Client.V1EdgeTokensCreate(params) if err != nil { return "", err } return h.GetRegistrationToken(tokenName) - } +// GetEdgeHost retrieves an existing edge host by UID. func (h *V1Client) GetEdgeHost(edgeHostID string) (*models.V1EdgeHostDevice, error) { - params := clientV1.NewV1EdgeHostDevicesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1EdgeHostDevicesUIDGetParamsWithContext(h.ctx). WithUID(edgeHostID) resp, err := h.Client.V1EdgeHostDevicesUIDGet(params) if err != nil { @@ -53,11 +55,13 @@ func (h *V1Client) GetEdgeHost(edgeHostID string) (*models.V1EdgeHostDevice, err return resp.Payload, nil } +// ListEdgeHosts returns a list of all edge hosts. +// TODO: expose pagination params func (h *V1Client) ListEdgeHosts() ([]*models.V1EdgeHostsMetadata, error) { continueToken := "" var items []*models.V1EdgeHostsMetadata for ok := true; ok; ok = (continueToken != "") { - params := clientV1.NewV1DashboardEdgehostsSearchParamsWithContext(h.ctx) + params := clientv1.NewV1DashboardEdgehostsSearchParamsWithContext(h.ctx) resp, err := h.Client.V1DashboardEdgehostsSearch(params) if err != nil { return nil, err @@ -69,12 +73,14 @@ func (h *V1Client) ListEdgeHosts() ([]*models.V1EdgeHostsMetadata, error) { return items, nil } +// GetEdgeHostsByTags returns a list of edge hosts filtered by the provided tags. +// TODO: expose pagination params func (h *V1Client) GetEdgeHostsByTags(tags map[string]string) ([]*models.V1EdgeHostsMetadata, error) { continueToken := "" var items []*models.V1EdgeHostsMetadata filter := GetEdgeFilter(nil, tags) for ok := true; ok; ok = (continueToken != "") { - params := clientV1.NewV1DashboardEdgehostsSearchParamsWithContext(h.ctx). + params := clientv1.NewV1DashboardEdgehostsSearchParamsWithContext(h.ctx). WithBody(&models.V1SearchFilterSummarySpec{ Filter: filter, Sort: nil, @@ -90,6 +96,7 @@ func (h *V1Client) GetEdgeHostsByTags(tags map[string]string) ([]*models.V1EdgeH return items, nil } +// GetEdgeFilter returns a filter spec for listing edge hosts by tags and extra filters. func GetEdgeFilter(extraFilters []*models.V1SearchFilterItem, tags map[string]string) *models.V1SearchFilterSpec { filter := &models.V1SearchFilterSpec{ Conjunction: and(), @@ -133,8 +140,9 @@ func GetEdgeFilter(extraFilters []*models.V1SearchFilterItem, tags map[string]st return filter } +// CreateClusterEdgeNative creates a new edge native cluster. func (h *V1Client) CreateClusterEdgeNative(cluster *models.V1SpectroEdgeNativeClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersEdgeNativeCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersEdgeNativeCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1SpectroClustersEdgeNativeCreate(params) if err != nil { @@ -143,16 +151,18 @@ func (h *V1Client) CreateClusterEdgeNative(cluster *models.V1SpectroEdgeNativeCl return *resp.Payload.UID, nil } +// CreateMachinePoolEdgeNative creates a new edge native machine pool. func (h *V1Client) CreateMachinePoolEdgeNative(cloudConfigUID string, machinePool *models.V1EdgeNativeMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsEdgeNativeMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeNativeMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsEdgeNativeMachinePoolCreate(params) return err } +// UpdateMachinePoolEdgeNative updates an existing edge native machine pool. func (h *V1Client) UpdateMachinePoolEdgeNative(cloudConfigUID string, machinePool *models.V1EdgeNativeMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsEdgeNativeMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeNativeMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -160,8 +170,9 @@ func (h *V1Client) UpdateMachinePoolEdgeNative(cloudConfigUID string, machinePoo return err } +// GetMachineEdgeNative retrieves an existing edge native machine by UID. func (h *V1Client) GetMachineEdgeNative(machineUID, machinePoolName, cloudConfigUID string) (*models.V1EdgeNativeMachine, error) { - params := clientV1.NewV1CloudConfigsEdgeNativePoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeNativePoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName). WithMachineUID(machineUID) @@ -172,8 +183,9 @@ func (h *V1Client) GetMachineEdgeNative(machineUID, machinePoolName, cloudConfig return resp.Payload, nil } +// DeleteMachineEdgeNative deletes an existing edge native machine. func (h *V1Client) DeleteMachineEdgeNative(edgeHostUID, machinePool, cloudConfigUID string) error { - params := clientV1.NewV1CloudConfigsEdgeNativePoolMachinesUIDDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeNativePoolMachinesUIDDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePool). WithMachineUID(edgeHostUID) @@ -181,8 +193,9 @@ func (h *V1Client) DeleteMachineEdgeNative(edgeHostUID, machinePool, cloudConfig return err } +// ListMachinesInPoolEdgeNative returns a list of machines in an edge native machine pool. func (h *V1Client) ListMachinesInPoolEdgeNative(machinePoolName, cloudConfigUID string) ([]*models.V1EdgeNativeMachine, error) { - params := clientV1.NewV1CloudConfigsEdgeNativePoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeNativePoolMachinesListParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) resp, err := h.Client.V1CloudConfigsEdgeNativePoolMachinesList(params) @@ -192,16 +205,18 @@ func (h *V1Client) ListMachinesInPoolEdgeNative(machinePoolName, cloudConfigUID return resp.Payload.Items, nil } +// DeleteMachinePoolEdgeNative deletes an existing edge native machine pool. func (h *V1Client) DeleteMachinePoolEdgeNative(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsEdgeNativeMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeNativeMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsEdgeNativeMachinePoolDelete(params) return err } +// GetCloudConfigEdgeNative retrieves an existing edge native cluster's cloud config. func (h *V1Client) GetCloudConfigEdgeNative(configUID string) (*models.V1EdgeNativeCloudConfig, error) { - params := clientV1.NewV1CloudConfigsEdgeNativeGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeNativeGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsEdgeNativeGet(params) if apiutil.Is404(err) { @@ -212,8 +227,9 @@ func (h *V1Client) GetCloudConfigEdgeNative(configUID string) (*models.V1EdgeNat return resp.Payload, nil } +// GetNodeStatusMapEdgeNative retrieves the status of all nodes in an edge native machine pool. func (h *V1Client) GetNodeStatusMapEdgeNative(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsEdgeNativePoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeNativePoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsEdgeNativePoolMachinesList(params) diff --git a/client/cluster_edge_vsphere.go b/client/cluster_edge_vsphere.go index 1b1da1cd..c7544ead 100644 --- a/client/cluster_edge_vsphere.go +++ b/client/cluster_edge_vsphere.go @@ -1,13 +1,16 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// TODO: edgev1 deprecation + +// CreateClusterEdgeVsphere creates a vSphere edge cluster. func (h *V1Client) CreateClusterEdgeVsphere(cluster *models.V1SpectroVsphereClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersVsphereCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVsphereCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1SpectroClustersVsphereCreate(params) if err != nil { @@ -16,16 +19,18 @@ func (h *V1Client) CreateClusterEdgeVsphere(cluster *models.V1SpectroVsphereClus return *resp.Payload.UID, nil } +// CreateMachinePoolEdgeVsphere creates a new vSphere edge machine pool. func (h *V1Client) CreateMachinePoolEdgeVsphere(cloudConfigUID string, machinePool *models.V1VsphereMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsVsphereMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVsphereMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsVsphereMachinePoolCreate(params) return err } +// UpdateMachinePoolEdgeVsphere updates an existing vSphere edge machine pool. func (h *V1Client) UpdateMachinePoolEdgeVsphere(cloudConfigUID string, machinePool *models.V1VsphereMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsVsphereMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVsphereMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -33,16 +38,18 @@ func (h *V1Client) UpdateMachinePoolEdgeVsphere(cloudConfigUID string, machinePo return err } +// DeleteMachinePoolEdgeVsphere deletes an existing vSphere edge machine pool. func (h *V1Client) DeleteMachinePoolEdgeVsphere(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsVsphereMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVsphereMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsVsphereMachinePoolDelete(params) return err } +// GetCloudConfigEdgeVsphere retrieves an existing vSphere edge cluster's cloud config. func (h *V1Client) GetCloudConfigEdgeVsphere(configUID string) (*models.V1VsphereCloudConfig, error) { - params := clientV1.NewV1CloudConfigsVsphereGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVsphereGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsVsphereGet(params) if apiutil.Is404(err) { @@ -53,8 +60,9 @@ func (h *V1Client) GetCloudConfigEdgeVsphere(configUID string) (*models.V1Vspher return resp.Payload, nil } +// ImportClusterEdgeVsphere imports an existing vSphere edge cluster. func (h *V1Client) ImportClusterEdgeVsphere(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clientV1.NewV1SpectroClustersVsphereImportParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVsphereImportParamsWithContext(h.ctx). WithBody(&models.V1SpectroVsphereClusterImportEntity{ Metadata: meta, }, @@ -66,8 +74,9 @@ func (h *V1Client) ImportClusterEdgeVsphere(meta *models.V1ObjectMetaInputEntity return *resp.Payload.UID, nil } +// GetNodeStatusMapEdgeVsphere retrieves the status of all nodes in a vSphere edge machine pool. func (h *V1Client) GetNodeStatusMapEdgeVsphere(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsVspherePoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVspherePoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsVspherePoolMachinesList(params) diff --git a/client/cluster_eks.go b/client/cluster_eks.go index 387ddef0..8be1bbaa 100644 --- a/client/cluster_eks.go +++ b/client/cluster_eks.go @@ -3,13 +3,14 @@ package client import ( "time" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateClusterEks creates a new EKS cluster. func (h *V1Client) CreateClusterEks(cluster *models.V1SpectroEksClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersEksCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersEksCreateParamsWithContext(h.ctx). WithBody(cluster). WithTimeout(90 * time.Second) resp, err := h.Client.V1SpectroClustersEksCreate(params) @@ -19,16 +20,18 @@ func (h *V1Client) CreateClusterEks(cluster *models.V1SpectroEksClusterEntity) ( return *resp.Payload.UID, nil } +// CreateMachinePoolEks creates a new EKS machine pool. func (h *V1Client) CreateMachinePoolEks(cloudConfigUID string, machinePool *models.V1EksMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsEksMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEksMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsEksMachinePoolCreate(params) return err } +// UpdateMachinePoolEks updates an existing EKS machine pool. func (h *V1Client) UpdateMachinePoolEks(cloudConfigUID string, machinePool *models.V1EksMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsEksMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEksMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -36,24 +39,27 @@ func (h *V1Client) UpdateMachinePoolEks(cloudConfigUID string, machinePool *mode return err } +// DeleteMachinePoolEks deletes an existing EKS machine pool. func (h *V1Client) DeleteMachinePoolEks(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsEksMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEksMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsEksMachinePoolDelete(params) return err } +// UpdateFargateProfilesEks updates an existing EKS cluster's fargate profiles. func (h *V1Client) UpdateFargateProfilesEks(cloudConfigUID string, fargateProfiles *models.V1EksFargateProfiles) error { - params := clientV1.NewV1CloudConfigsEksUIDFargateProfilesUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEksUIDFargateProfilesUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(fargateProfiles) _, err := h.Client.V1CloudConfigsEksUIDFargateProfilesUpdate(params) return err } +// GetCloudConfigEks retrieves an existing EKS cluster's cloud config. func (h *V1Client) GetCloudConfigEks(configUID string) (*models.V1EksCloudConfig, error) { - params := clientV1.NewV1CloudConfigsEksGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEksGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsEksGet(params) if apiutil.Is404(err) { @@ -64,8 +70,9 @@ func (h *V1Client) GetCloudConfigEks(configUID string) (*models.V1EksCloudConfig return resp.Payload, nil } +// GetNodeStatusMapEks retrieves the status of all nodes in an EKS machine pool. func (h *V1Client) GetNodeStatusMapEks(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsEksPoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEksPoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsEksPoolMachinesList(params) diff --git a/client/cluster_gcp.go b/client/cluster_gcp.go index 5d886eed..e2a923fd 100644 --- a/client/cluster_gcp.go +++ b/client/cluster_gcp.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateClusterGcp creates a new GCP IaaS cluster. func (h *V1Client) CreateClusterGcp(cluster *models.V1SpectroGcpClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersGcpCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersGcpCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1SpectroClustersGcpCreate(params) if err != nil { @@ -16,16 +17,18 @@ func (h *V1Client) CreateClusterGcp(cluster *models.V1SpectroGcpClusterEntity) ( return *resp.Payload.UID, nil } +// CreateMachinePoolGcp creates a new GCP IaaS machine pool. func (h *V1Client) CreateMachinePoolGcp(cloudConfigUID string, machinePool *models.V1GcpMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsGcpMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsGcpMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsGcpMachinePoolCreate(params) return err } +// UpdateMachinePoolGcp updates an existing GCP IaaS machine pool. func (h *V1Client) UpdateMachinePoolGcp(cloudConfigUID string, machinePool *models.V1GcpMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsGcpMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsGcpMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -33,16 +36,18 @@ func (h *V1Client) UpdateMachinePoolGcp(cloudConfigUID string, machinePool *mode return err } +// DeleteMachinePoolGcp deletes an existing GCP IaaS machine pool. func (h *V1Client) DeleteMachinePoolGcp(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsGcpMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsGcpMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsGcpMachinePoolDelete(params) return err } +// GetCloudConfigGcp retrieves an existing GCP IaaS cluster's cloud config. func (h *V1Client) GetCloudConfigGcp(configUID string) (*models.V1GcpCloudConfig, error) { - params := clientV1.NewV1CloudConfigsGcpGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsGcpGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsGcpGet(params) if apiutil.Is404(err) { @@ -53,8 +58,9 @@ func (h *V1Client) GetCloudConfigGcp(configUID string) (*models.V1GcpCloudConfig return resp.Payload, nil } +// ImportClusterGcp imports an existing GCP IaaS cluster. func (h *V1Client) ImportClusterGcp(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clientV1.NewV1SpectroClustersGcpImportParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersGcpImportParamsWithContext(h.ctx). WithBody(&models.V1SpectroGcpClusterImportEntity{ Metadata: meta, }, @@ -66,8 +72,9 @@ func (h *V1Client) ImportClusterGcp(meta *models.V1ObjectMetaInputEntity) (strin return *resp.Payload.UID, nil } +// GetNodeStatusMapGcp retrieves the status of all nodes in a GCP IaaS machine pool. func (h *V1Client) GetNodeStatusMapGcp(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsGcpPoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsGcpPoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsGcpPoolMachinesList(params) diff --git a/client/cluster_gke.go b/client/cluster_gke.go index f56997e5..5a99c564 100644 --- a/client/cluster_gke.go +++ b/client/cluster_gke.go @@ -1,12 +1,13 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// CreateClusterGke creates a GKE cluster. func (h *V1Client) CreateClusterGke(cluster *models.V1SpectroGcpClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersGkeCreateParamsWithContext(h.ctx).WithBody(cluster) + params := clientv1.NewV1SpectroClustersGkeCreateParamsWithContext(h.ctx).WithBody(cluster) success, err := h.Client.V1SpectroClustersGkeCreate(params) if err != nil { return "", err @@ -15,8 +16,9 @@ func (h *V1Client) CreateClusterGke(cluster *models.V1SpectroGcpClusterEntity) ( return *success.Payload.UID, nil } +// GetCloudConfigGke retrieves an existing GKE cluster's cloud config. func (h *V1Client) GetCloudConfigGke(configUID string) (*models.V1GcpCloudConfig, error) { - params := clientV1.NewV1CloudConfigsGkeGetParamsWithContext(h.ctx).WithConfigUID(configUID) + params := clientv1.NewV1CloudConfigsGkeGetParamsWithContext(h.ctx).WithConfigUID(configUID) success, err := h.Client.V1CloudConfigsGkeGet(params) if err != nil { @@ -26,15 +28,17 @@ func (h *V1Client) GetCloudConfigGke(configUID string) (*models.V1GcpCloudConfig return success.Payload, nil } -func (h *V1Client) CreateMachinePoolGke(cloudConfigId string, machinePool *models.V1GcpMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsGkeMachinePoolCreateParamsWithContext(h.ctx).WithConfigUID(cloudConfigId).WithBody(machinePool) +// CreateMachinePoolGke creates a new GKE machine pool. +func (h *V1Client) CreateMachinePoolGke(cloudConfigID string, machinePool *models.V1GcpMachinePoolConfigEntity) error { + params := clientv1.NewV1CloudConfigsGkeMachinePoolCreateParamsWithContext(h.ctx).WithConfigUID(cloudConfigID).WithBody(machinePool) _, err := h.Client.V1CloudConfigsGkeMachinePoolCreate(params) return err } -func (h *V1Client) UpdateMachinePoolGke(cloudConfigId string, machinePool *models.V1GcpMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsGkeMachinePoolUpdateParamsWithContext(h.ctx). - WithConfigUID(cloudConfigId). +// UpdateMachinePoolGke updates an existing GKE machine pool. +func (h *V1Client) UpdateMachinePoolGke(cloudConfigID string, machinePool *models.V1GcpMachinePoolConfigEntity) error { + params := clientv1.NewV1CloudConfigsGkeMachinePoolUpdateParamsWithContext(h.ctx). + WithConfigUID(cloudConfigID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -42,14 +46,16 @@ func (h *V1Client) UpdateMachinePoolGke(cloudConfigId string, machinePool *model return err } -func (h *V1Client) DeleteMachinePoolGke(cloudConfigId string, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsGkeMachinePoolDeleteParamsWithContext(h.ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName) +// DeleteMachinePoolGke deletes an existing GKE machine pool. +func (h *V1Client) DeleteMachinePoolGke(cloudConfigID string, machinePoolName string) error { + params := clientv1.NewV1CloudConfigsGkeMachinePoolDeleteParamsWithContext(h.ctx).WithConfigUID(cloudConfigID).WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsGkeMachinePoolDelete(params) return err } +// GetNodeStatusMapGke retrieves the status of all nodes in a GKE machine pool. func (h *V1Client) GetNodeStatusMapGke(configUID string, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsGkePoolMachinesListParamsWithContext(h.ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) + params := clientv1.NewV1CloudConfigsGkePoolMachinesListParamsWithContext(h.ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsGkePoolMachinesList(params) nMap := map[string]models.V1CloudMachineStatus{} diff --git a/client/cluster_group.go b/client/cluster_group.go index 27ab5a5c..96ecf43e 100644 --- a/client/cluster_group.go +++ b/client/cluster_group.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateClusterGroup creates a new cluster group. func (h *V1Client) CreateClusterGroup(cluster *models.V1ClusterGroupEntity) (string, error) { - params := clientV1.NewV1ClusterGroupsCreateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterGroupsCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1ClusterGroupsCreate(params) if err != nil { @@ -16,13 +17,15 @@ func (h *V1Client) CreateClusterGroup(cluster *models.V1ClusterGroupEntity) (str return *resp.Payload.UID, nil } +// DeleteClusterGroup deletes an existing cluster group. func (h *V1Client) DeleteClusterGroup(uid string) error { - params := clientV1.NewV1ClusterGroupsUIDDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterGroupsUIDDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1ClusterGroupsUIDDelete(params) return err } +// GetClusterGroup retrieves an existing cluster group whose status is active. func (h *V1Client) GetClusterGroup(uid string) (*models.V1ClusterGroup, error) { group, err := h.GetClusterGroupWithoutStatus(uid) if err != nil { @@ -34,8 +37,9 @@ func (h *V1Client) GetClusterGroup(uid string) (*models.V1ClusterGroup, error) { return group, nil } +// GetClusterGroupWithoutStatus retrieves an existing cluster group, regardless of status. func (h *V1Client) GetClusterGroupWithoutStatus(uid string) (*models.V1ClusterGroup, error) { - params := clientV1.NewV1ClusterGroupsUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterGroupsUIDGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1ClusterGroupsUIDGet(params) if apiutil.Is404(err) { @@ -46,20 +50,8 @@ func (h *V1Client) GetClusterGroupWithoutStatus(uid string) (*models.V1ClusterGr return resp.Payload, nil } -func (h *V1Client) GetClusterGroupByName(name string) (*models.V1ObjectScopeEntity, error) { - metadata, err := h.getClusterGroupMetadata() - if err != nil { - return nil, err - } - for _, groupMeta := range metadata { - if groupMeta.Name == name { - return groupMeta, nil - } - } - return nil, nil -} - -func (h *V1Client) GetClusterGroupByNameForProject(name string) (*models.V1ClusterGroupSummary, error) { +// GetClusterGroupSummaryByName retrieves a summary for an existing cluster group by name. +func (h *V1Client) GetClusterGroupSummaryByName(name string) (*models.V1ClusterGroupSummary, error) { summaries, err := h.GetClusterGroupSummaries() if err != nil { return nil, err @@ -72,16 +64,32 @@ func (h *V1Client) GetClusterGroupByNameForProject(name string) (*models.V1Clust return nil, nil } -func (h *V1Client) GetClusterGroupMetadata() ([]*models.V1ObjectScopeEntity, error) { - metadata, err := h.getClusterGroupMetadata() +// GetClusterGroupScopeMetadata retrieves scope metadata for all cluster groups. +func (h *V1Client) GetClusterGroupScopeMetadata() ([]*models.V1ObjectScopeEntity, error) { + metadata, err := h.clusterGroupMetadata() if err != nil { return nil, err } return metadata, nil } +// GetClusterGroupScopeMetadataByName retrieves scope metadata for an existing cluster group by name. +func (h *V1Client) GetClusterGroupScopeMetadataByName(name string) (*models.V1ObjectScopeEntity, error) { + metadata, err := h.clusterGroupMetadata() + if err != nil { + return nil, err + } + for _, groupMeta := range metadata { + if groupMeta.Name == name { + return groupMeta, nil + } + } + return nil, nil +} + +// GetClusterGroupSummaries retrieves summaries for all cluster groups. func (h *V1Client) GetClusterGroupSummaries() ([]*models.V1ClusterGroupSummary, error) { - params := clientV1.NewV1ClusterGroupsHostClusterSummaryParamsWithContext(h.ctx) + params := clientv1.NewV1ClusterGroupsHostClusterSummaryParamsWithContext(h.ctx) resp, err := h.Client.V1ClusterGroupsHostClusterSummary(params) if apiutil.Is404(err) { return nil, nil @@ -91,9 +99,9 @@ func (h *V1Client) GetClusterGroupSummaries() ([]*models.V1ClusterGroupSummary, return resp.Payload.Summaries, nil } -// Update cluster group metadata by invoking V1ClusterGroupsUIDMetaUpdate API +// UpdateClusterGroupMeta updates an existing cluster group's metadata. func (h *V1Client) UpdateClusterGroupMeta(clusterGroup *models.V1ClusterGroupEntity) error { - params := clientV1.NewV1ClusterGroupsUIDMetaUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterGroupsUIDMetaUpdateParamsWithContext(h.ctx). WithUID(clusterGroup.Metadata.UID). WithBody(&models.V1ObjectMeta{ Name: clusterGroup.Metadata.Name, @@ -104,25 +112,26 @@ func (h *V1Client) UpdateClusterGroupMeta(clusterGroup *models.V1ClusterGroupEnt return err } -// Update cluster group by invoking V1ClusterGroupsUIDHostClusterUpdate API +// UpdateClusterGroup updates an existing cluster group. func (h *V1Client) UpdateClusterGroup(uid string, clusterGroup *models.V1ClusterGroupHostClusterEntity) error { - params := clientV1.NewV1ClusterGroupsUIDHostClusterUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterGroupsUIDHostClusterUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(clusterGroup) _, err := h.Client.V1ClusterGroupsUIDHostClusterUpdate(params) return err } -func (h *V1Client) UpdateClusterProfileInClusterGroup(clusterGroupUid string, clusterProfiles *models.V1SpectroClusterProfiles) error { - params := clientV1.NewV1ClusterGroupsUIDProfilesUpdateParamsWithContext(h.ctx). - WithUID(clusterGroupUid). +// UpdateClusterProfileInClusterGroup updates an existing cluster group's default cluster profiles. +func (h *V1Client) UpdateClusterProfileInClusterGroup(clusterGroupUID string, clusterProfiles *models.V1SpectroClusterProfiles) error { + params := clientv1.NewV1ClusterGroupsUIDProfilesUpdateParamsWithContext(h.ctx). + WithUID(clusterGroupUID). WithBody(clusterProfiles) _, err := h.Client.V1ClusterGroupsUIDProfilesUpdate(params) return err } -func (h *V1Client) getClusterGroupMetadata() ([]*models.V1ObjectScopeEntity, error) { - params := clientV1.NewV1ClusterGroupsHostClusterMetadataParamsWithContext(h.ctx) +func (h *V1Client) clusterGroupMetadata() ([]*models.V1ObjectScopeEntity, error) { + params := clientv1.NewV1ClusterGroupsHostClusterMetadataParamsWithContext(h.ctx) resp, err := h.Client.V1ClusterGroupsHostClusterMetadata(params) if apiutil.Is404(err) { return nil, nil diff --git a/client/cluster_host_config.go b/client/cluster_host_config.go index 05259216..f09dc340 100644 --- a/client/cluster_host_config.go +++ b/client/cluster_host_config.go @@ -1,25 +1,15 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// UpdateClusterHostConfig updates an existing cluster's virtual cluster hosting config. func (h *V1Client) UpdateClusterHostConfig(uid string, config *models.V1HostClusterConfigEntity) error { - params := clientV1.NewV1HostClusterConfigUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1HostClusterConfigUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1HostClusterConfigUpdate(params) return err } - -func (h *V1Client) ApplyClusterHostConfig(uid string, config *models.V1HostClusterConfigEntity) error { - policy, err := h.GetClusterScanConfig(uid) - if err != nil { - return err - } - if policy == nil { - return h.UpdateClusterHostConfig(uid, config) - } - return h.UpdateClusterHostConfig(uid, config) -} diff --git a/client/cluster_libvirt.go b/client/cluster_libvirt.go index 743fb5e2..7f669a04 100644 --- a/client/cluster_libvirt.go +++ b/client/cluster_libvirt.go @@ -1,13 +1,16 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// TODO: edgev1 deprecation + +// CreateClusterLibvirt creates a new libvirt edge cluster. func (h *V1Client) CreateClusterLibvirt(cluster *models.V1SpectroLibvirtClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersLibvirtCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersLibvirtCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1SpectroClustersLibvirtCreate(params) if err != nil { @@ -16,16 +19,18 @@ func (h *V1Client) CreateClusterLibvirt(cluster *models.V1SpectroLibvirtClusterE return *resp.Payload.UID, nil } +// CreateMachinePoolLibvirt creates a new libvirt edge machine pool. func (h *V1Client) CreateMachinePoolLibvirt(cloudConfigUID string, machinePool *models.V1LibvirtMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsLibvirtMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsLibvirtMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsLibvirtMachinePoolCreate(params) return err } +// UpdateMachinePoolLibvirt updates an existing libvirt edge machine pool. func (h *V1Client) UpdateMachinePoolLibvirt(cloudConfigUID string, machinePool *models.V1LibvirtMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsLibvirtMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsLibvirtMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -33,16 +38,18 @@ func (h *V1Client) UpdateMachinePoolLibvirt(cloudConfigUID string, machinePool * return err } +// DeleteMachinePoolLibvirt deletes an existing libvirt edge machine pool. func (h *V1Client) DeleteMachinePoolLibvirt(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsLibvirtMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsLibvirtMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsLibvirtMachinePoolDelete(params) return err } +// GetCloudConfigLibvirt retrieves an existing libvirt edge cluster's cloud config. func (h *V1Client) GetCloudConfigLibvirt(configUID string) (*models.V1LibvirtCloudConfig, error) { - params := clientV1.NewV1CloudConfigsLibvirtGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsLibvirtGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsLibvirtGet(params) if apiutil.Is404(err) { @@ -53,8 +60,9 @@ func (h *V1Client) GetCloudConfigLibvirt(configUID string) (*models.V1LibvirtClo return resp.Payload, nil } +// GetNodeStatusMapLibvirt retrieves the status of all nodes in a libvirt machine pool. func (h *V1Client) GetNodeStatusMapLibvirt(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsLibvirtPoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsLibvirtPoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsLibvirtPoolMachinesList(params) diff --git a/client/cluster_location_config.go b/client/cluster_location_config.go index d6b57795..e70540cb 100644 --- a/client/cluster_location_config.go +++ b/client/cluster_location_config.go @@ -1,10 +1,11 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// GetClusterLocationConfig returns a cluster's location config. func (h *V1Client) GetClusterLocationConfig(uid string) (*models.V1ClusterLocation, error) { clusterStatus, err := h.GetClusterWithoutStatus(uid) if err != nil { @@ -13,14 +14,16 @@ func (h *V1Client) GetClusterLocationConfig(uid string) (*models.V1ClusterLocati return clusterStatus.Status.Location, nil } +// UpdateClusterLocationConfig updates a cluster's location config. func (h *V1Client) UpdateClusterLocationConfig(uid string, config *models.V1SpectroClusterLocationInputEntity) error { - params := clientV1.NewV1SpectroClustersUIDLocationPutParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDLocationPutParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1SpectroClustersUIDLocationPut(params) return err } +// ApplyClusterLocationConfig creates a new cluster location config or updates an existing one. func (h *V1Client) ApplyClusterLocationConfig(uid string, config *models.V1SpectroClusterLocationInputEntity) error { _, err := h.GetClusterLocationConfig(uid) if err != nil { diff --git a/client/cluster_maas.go b/client/cluster_maas.go index d5ee197f..5abcee45 100644 --- a/client/cluster_maas.go +++ b/client/cluster_maas.go @@ -1,15 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -// Cluster - +// CreateClusterMaas creates a new MAAS cluster. func (h *V1Client) CreateClusterMaas(cluster *models.V1SpectroMaasClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersMaasCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersMaasCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1SpectroClustersMaasCreate(params) if err != nil { @@ -18,18 +17,18 @@ func (h *V1Client) CreateClusterMaas(cluster *models.V1SpectroMaasClusterEntity) return *resp.Payload.UID, nil } -// Machine Pool - +// CreateMachinePoolMaas creates a new MAAS machine pool. func (h *V1Client) CreateMachinePoolMaas(cloudConfigUID string, machinePool *models.V1MaasMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsMaasMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsMaasMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsMaasMachinePoolCreate(params) return err } +// UpdateMachinePoolMaas updates an existing MAAS machine pool. func (h *V1Client) UpdateMachinePoolMaas(cloudConfigUID string, machinePool *models.V1MaasMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsMaasMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsMaasMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -37,18 +36,18 @@ func (h *V1Client) UpdateMachinePoolMaas(cloudConfigUID string, machinePool *mod return err } +// DeleteMachinePoolMaas deletes an existing MAAS machine pool. func (h *V1Client) DeleteMachinePoolMaas(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsMaasMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsMaasMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsMaasMachinePoolDelete(params) return err } -// Cloud Config - +// GetCloudConfigMaas retrieves an existing MAAS cluster's cloud config. func (h *V1Client) GetCloudConfigMaas(configUID string) (*models.V1MaasCloudConfig, error) { - params := clientV1.NewV1CloudConfigsMaasGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsMaasGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsMaasGet(params) if apiutil.Is404(err) { @@ -59,10 +58,9 @@ func (h *V1Client) GetCloudConfigMaas(configUID string) (*models.V1MaasCloudConf return resp.Payload, nil } -// Import - +// ImportClusterMaas imports an existing MAAS cluster. func (h *V1Client) ImportClusterMaas(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clientV1.NewV1SpectroClustersMaasImportParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersMaasImportParamsWithContext(h.ctx). WithBody(&models.V1SpectroMaasClusterImportEntity{ Metadata: meta, }, @@ -74,8 +72,9 @@ func (h *V1Client) ImportClusterMaas(meta *models.V1ObjectMetaInputEntity) (stri return *resp.Payload.UID, nil } +// GetNodeStatusMapMaas retrieves the status of all nodes in a MAAS machine pool. func (h *V1Client) GetNodeStatusMapMaas(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsMaasPoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsMaasPoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsMaasPoolMachinesList(params) diff --git a/client/cluster_metadata_config.go b/client/cluster_metadata_config.go index 0610e144..9fe1afcc 100644 --- a/client/cluster_metadata_config.go +++ b/client/cluster_metadata_config.go @@ -1,20 +1,23 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// UpdateClusterMetadata updates an existing cluster's metadata: annotations, labels, and name. func (h *V1Client) UpdateClusterMetadata(uid string, config *models.V1ObjectMetaInputEntitySchema) error { - params := clientV1.NewV1SpectroClustersUIDMetadataUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDMetadataUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1SpectroClustersUIDMetadataUpdate(params) return err } +// UpdateAdditionalClusterMetadata updates an existing cluster's additional metadata attributes. +// TODO: what are additional metadata attributes? func (h *V1Client) UpdateAdditionalClusterMetadata(uid string, additionalMeta *models.V1ClusterMetaAttributeEntity) error { - params := clientV1.NewV1SpectroClustersUIDClusterMetaAttributeUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDClusterMetaAttributeUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(additionalMeta) _, err := h.Client.V1SpectroClustersUIDClusterMetaAttributeUpdate(params) diff --git a/client/cluster_namespace_config.go b/client/cluster_namespace_config.go index 5bc319bd..8f631265 100644 --- a/client/cluster_namespace_config.go +++ b/client/cluster_namespace_config.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/herr" ) +// GetClusterNamespaceConfig gets the namespaced resource configuration for a cluster. func (h *V1Client) GetClusterNamespaceConfig(uid string) (*models.V1ClusterNamespaceResources, error) { - params := clientV1.NewV1SpectroClustersUIDConfigNamespacesGetParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDConfigNamespacesGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1SpectroClustersUIDConfigNamespacesGet(params) if err != nil { @@ -19,15 +20,17 @@ func (h *V1Client) GetClusterNamespaceConfig(uid string) (*models.V1ClusterNames return resp.Payload, nil } -// UpdateClusterNamespaceConfig no create for namespaces, there is only update. +// UpdateClusterNamespaceConfig updates an existing namespaced resource configuration for a cluster. +// Create is not supported for namespaced resources. func (h *V1Client) UpdateClusterNamespaceConfig(uid string, config *models.V1ClusterNamespaceResourcesUpdateEntity) error { - params := clientV1.NewV1SpectroClustersUIDConfigNamespacesUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDConfigNamespacesUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1SpectroClustersUIDConfigNamespacesUpdate(params) return err } +// ApplyClusterNamespaceConfig creates a new namespaced resource configuration for a cluster or updates its namespaced resource configuration if one exists. func (h *V1Client) ApplyClusterNamespaceConfig(uid string, config []*models.V1ClusterNamespaceResourceInputEntity) error { _, err := h.GetClusterNamespaceConfig(uid) if err != nil { diff --git a/client/cluster_openstack.go b/client/cluster_openstack.go index aa682a73..6306162d 100644 --- a/client/cluster_openstack.go +++ b/client/cluster_openstack.go @@ -1,15 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/herr" ) -// Cluster - +// CreateClusterOpenStack creates a new OpenStack cluster. func (h *V1Client) CreateClusterOpenStack(cluster *models.V1SpectroOpenStackClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersOpenStackCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersOpenStackCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1SpectroClustersOpenStackCreate(params) if err != nil { @@ -18,18 +17,18 @@ func (h *V1Client) CreateClusterOpenStack(cluster *models.V1SpectroOpenStackClus return *resp.Payload.UID, nil } -// Machine Pool - +// CreateMachinePoolOpenStack creates a new OpenStack machine pool. func (h *V1Client) CreateMachinePoolOpenStack(cloudConfigUID string, machinePool *models.V1OpenStackMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsOpenStackMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsOpenStackMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsOpenStackMachinePoolCreate(params) return err } +// UpdateMachinePoolOpenStack updates an existing OpenStack machine pool. func (h *V1Client) UpdateMachinePoolOpenStack(cloudConfigUID string, machinePool *models.V1OpenStackMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsOpenStackMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsOpenStackMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -37,18 +36,18 @@ func (h *V1Client) UpdateMachinePoolOpenStack(cloudConfigUID string, machinePool return err } +// DeleteMachinePoolOpenStack deletes an existing OpenStack machine pool. func (h *V1Client) DeleteMachinePoolOpenStack(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsOpenStackMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsOpenStackMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsOpenStackMachinePoolDelete(params) return err } -// Cloud Config - +// GetCloudConfigOpenStack retrieves an existing OpenStack cluster's cloud config. func (h *V1Client) GetCloudConfigOpenStack(configUID string) (*models.V1OpenStackCloudConfig, error) { - params := clientV1.NewV1CloudConfigsOpenStackGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsOpenStackGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsOpenStackGet(params) if herr.IsNotFound(err) { @@ -59,10 +58,9 @@ func (h *V1Client) GetCloudConfigOpenStack(configUID string) (*models.V1OpenStac return resp.Payload, nil } -// Import - +// ImportClusterOpenStack imports an existing OpenStack cluster. func (h *V1Client) ImportClusterOpenStack(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clientV1.NewV1SpectroClustersOpenStackImportParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersOpenStackImportParamsWithContext(h.ctx). WithBody(&models.V1SpectroOpenStackClusterImportEntity{ Metadata: meta, }, @@ -74,8 +72,9 @@ func (h *V1Client) ImportClusterOpenStack(meta *models.V1ObjectMetaInputEntity) return *resp.Payload.UID, nil } +// GetNodeStatusMapOpenStack retrieves the status of all nodes in an OpenStack machine pool. func (h *V1Client) GetNodeStatusMapOpenStack(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsOpenStackPoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsOpenStackPoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsOpenStackPoolMachinesList(params) diff --git a/client/cluster_ospatch_config.go b/client/cluster_ospatch_config.go index 8d18c5eb..4bf99253 100644 --- a/client/cluster_ospatch_config.go +++ b/client/cluster_ospatch_config.go @@ -1,12 +1,13 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// UpdateClusterOsPatchConfig updates an existing cluster's OS patching configuration. func (h *V1Client) UpdateClusterOsPatchConfig(uid string, config *models.V1OsPatchEntity) error { - params := clientV1.NewV1SpectroClustersUIDOsPatchUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDOsPatchUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1SpectroClustersUIDOsPatchUpdate(params) diff --git a/client/cluster_profile.go b/client/cluster_profile.go index 67e0bbd4..b2b37447 100644 --- a/client/cluster_profile.go +++ b/client/cluster_profile.go @@ -6,13 +6,14 @@ import ( "io" "os" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// GetClusterProfileSummary returns a summary for an existing cluster profile. func (h *V1Client) GetClusterProfileSummary(uid string) (*models.V1ClusterProfileSummary, error) { - params := clientV1.NewV1ClusterProfilesUIDSummaryParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesUIDSummaryParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1ClusterProfilesUIDSummary(params) if err != nil { @@ -21,8 +22,9 @@ func (h *V1Client) GetClusterProfileSummary(uid string) (*models.V1ClusterProfil return resp.Payload, nil } +// GetClusterProfileUID returns the UID of a cluster profile based on the profile name and version. func (h *V1Client) GetClusterProfileUID(profileName, profileVersion string) (string, error) { - params := clientV1.NewV1ClusterProfilesMetadataParamsWithContext(h.ctx) + params := clientv1.NewV1ClusterProfilesMetadataParamsWithContext(h.ctx) resp, err := h.Client.V1ClusterProfilesMetadata(params) if err != nil { return "", err @@ -35,12 +37,17 @@ func (h *V1Client) GetClusterProfileUID(profileName, profileVersion string) (str return "", fmt.Errorf("cluster profile %s not found", profileName) } +// ImportClusterProfile imports a cluster profile given the profile content as a string. func (h *V1Client) ImportClusterProfile(profileContent string) (string, error) { tmpFile, err := os.CreateTemp(os.TempDir(), "profile-import") if err != nil { return "", err } - defer os.Remove(tmpFile.Name()) + defer func() { + if err := os.Remove(tmpFile.Name()); err != nil { + fmt.Printf("failed to remove tmp file %s: %v", tmpFile.Name(), err) + } + }() if _, err = tmpFile.Write([]byte(profileContent)); err != nil { return "", err } @@ -48,7 +55,7 @@ func (h *V1Client) ImportClusterProfile(profileContent string) (string, error) { if err != nil { return "", err } - params := clientV1.NewV1ClusterProfilesImportFileParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesImportFileParamsWithContext(h.ctx). WithPublish(apiutil.Ptr(true)). WithImportFile(f) resp, err := h.Client.V1ClusterProfilesImportFile(params) @@ -56,25 +63,26 @@ func (h *V1Client) ImportClusterProfile(profileContent string) (string, error) { return "", err } return *resp.Payload.UID, nil - } +// UpgradeClusterProfile upgrades a cluster profile with the given profile content. func (h *V1Client) UpgradeClusterProfile(clusterUID string, body *models.V1SpectroClusterProfiles) error { - params := clientV1.NewV1SpectroClustersUpdateProfilesParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUpdateProfilesParamsWithContext(h.ctx). WithUID(clusterUID). WithBody(body) _, err := h.Client.V1SpectroClustersUpdateProfiles(params) return err } -func (h *V1Client) AttachAddonToCluster(clusterUID, profileUID string, profileUIDs []string) error { +// AttachAddonsToCluster attaches one or more addon profiles to a cluster. +func (h *V1Client) AttachAddonsToCluster(clusterUID string, profileUIDs []string) error { // get existing cluster profile uid list on the cluster currentClusterInfo, err := h.GetCluster(clusterUID) if err != nil { return err } - profileList := make([]*models.V1SpectroClusterProfileEntity, 0, len(profileUID)) + profileList := make([]*models.V1SpectroClusterProfileEntity, 0, len(currentClusterInfo.Spec.ClusterProfileTemplates)) packList := make([]*models.V1PackValuesEntity, 0, len(currentClusterInfo.Spec.ClusterProfileTemplates)) for _, clusterProfile := range currentClusterInfo.Spec.ClusterProfileTemplates { @@ -83,7 +91,7 @@ func (h *V1Client) AttachAddonToCluster(clusterUID, profileUID string, profileUI Manifests: nil, Name: value.Name, Tag: value.Tag, - //Type: models.NewV1PackType(models.V1PackType(value.Type)), + // Type: models.NewV1PackType(models.V1PackType(value.Type)), Type: models.V1PackType(value.Type), Values: value.Values, }) @@ -117,13 +125,11 @@ func (h *V1Client) AttachAddonToCluster(clusterUID, profileUID string, profileUI profiles := &models.V1SpectroClusterProfiles{ Profiles: profileList, } - if err := h.UpgradeClusterProfile(clusterUID, profiles); err != nil { - return err - } - return nil + return h.UpgradeClusterProfile(clusterUID, profiles) } +// DeleteClusterProfile deletes an existing cluster profile. func (h *V1Client) DeleteClusterProfile(uid string) error { profile, err := h.GetClusterProfile(uid) if err != nil { @@ -131,14 +137,15 @@ func (h *V1Client) DeleteClusterProfile(uid string) error { } else if profile == nil { return fmt.Errorf("cluster profile %s not found", uid) } - params := clientV1.NewV1ClusterProfilesDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesDeleteParamsWithContext(h.ctx). WithUID(uid) _, err = h.Client.V1ClusterProfilesDelete(params) return err } +// GetClusterProfile retrieves an existing cluster profile by UID. func (h *V1Client) GetClusterProfile(uid string) (*models.V1ClusterProfile, error) { - params := clientV1.NewV1ClusterProfilesGetParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1ClusterProfilesGet(params) if apiutil.Is404(err) { @@ -149,8 +156,9 @@ func (h *V1Client) GetClusterProfile(uid string) (*models.V1ClusterProfile, erro return resp.Payload, nil } +// GetClusterProfiles retrieves all cluster profiles. func (h *V1Client) GetClusterProfiles() ([]*models.V1ClusterProfileMetadata, error) { - params := clientV1.NewV1ClusterProfilesMetadataParamsWithContext(h.ctx) + params := clientv1.NewV1ClusterProfilesMetadataParamsWithContext(h.ctx) resp, err := h.Client.V1ClusterProfilesMetadata(params) if err != nil { return nil, err @@ -158,24 +166,27 @@ func (h *V1Client) GetClusterProfiles() ([]*models.V1ClusterProfileMetadata, err return resp.Payload.Items, nil } +// PatchClusterProfile patches an existing cluster profile's metadata. func (h *V1Client) PatchClusterProfile(clusterProfile *models.V1ClusterProfileUpdateEntity, metadata *models.V1ProfileMetaEntity) error { - params := clientV1.NewV1ClusterProfilesUIDMetadataUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesUIDMetadataUpdateParamsWithContext(h.ctx). WithUID(clusterProfile.Metadata.UID). WithBody(metadata) _, err := h.Client.V1ClusterProfilesUIDMetadataUpdate(params) return err } +// UpdateClusterProfile updates an existing cluster profile. func (h *V1Client) UpdateClusterProfile(clusterProfile *models.V1ClusterProfileUpdateEntity) error { - params := clientV1.NewV1ClusterProfilesUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesUpdateParamsWithContext(h.ctx). WithUID(clusterProfile.Metadata.UID). WithBody(clusterProfile) _, err := h.Client.V1ClusterProfilesUpdate(params) return err } +// CreateClusterProfile creates a new cluster profile. func (h *V1Client) CreateClusterProfile(clusterProfile *models.V1ClusterProfileEntity) (string, error) { - params := clientV1.NewV1ClusterProfilesCreateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesCreateParamsWithContext(h.ctx). WithBody(clusterProfile) resp, err := h.Client.V1ClusterProfilesCreate(params) if err != nil { @@ -184,15 +195,18 @@ func (h *V1Client) CreateClusterProfile(clusterProfile *models.V1ClusterProfileE return *resp.Payload.UID, nil } +// PublishClusterProfile publishes an existing cluster profile. +// TODO: what does it mean to publish a cluster profile? func (h *V1Client) PublishClusterProfile(uid string) error { - params := clientV1.NewV1ClusterProfilesPublishParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesPublishParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1ClusterProfilesPublish(params) return err } +// GetProfileVariables retrieves all variables for a cluster profile. func (h *V1Client) GetProfileVariables(uid string) ([]*models.V1Variable, error) { - params := clientV1.NewV1ClusterProfilesUIDVariablesGetParamsWithContext(h.ctx).WithUID(uid) + params := clientv1.NewV1ClusterProfilesUIDVariablesGetParamsWithContext(h.ctx).WithUID(uid) resp, err := h.Client.V1ClusterProfilesUIDVariablesGet(params) if err != nil { return nil, err @@ -200,26 +214,30 @@ func (h *V1Client) GetProfileVariables(uid string) ([]*models.V1Variable, error) return resp.Payload.Variables, nil } +// UpdateProfileVariables updates variables for a cluster profile. func (h *V1Client) UpdateProfileVariables(variables *models.V1Variables, uid string) error { - params := clientV1.NewV1ClusterProfilesUIDVariablesPutParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesUIDVariablesPutParamsWithContext(h.ctx). WithUID(uid). WithBody(variables) _, err := h.Client.V1ClusterProfilesUIDVariablesPut(params) return err } +// ExportClusterProfile exports a cluster profile in the specified format. +// Supported formats are yaml and json. func (h *V1Client) ExportClusterProfile(uid, format string) (bytes.Buffer, error) { var buf bytes.Buffer writer := io.Writer(&buf) - params := clientV1.NewV1ClusterProfilesUIDExportParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesUIDExportParamsWithContext(h.ctx). WithUID(uid). WithFormat(&format) _, err := h.Client.V1ClusterProfilesUIDExport(params, writer) return buf, err } +// BulkDeleteClusterProfiles deletes multiple cluster profiles. func (h *V1Client) BulkDeleteClusterProfiles(uids []string) (*models.V1BulkDeleteResponse, error) { - params := clientV1.NewV1ClusterProfilesBulkDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesBulkDeleteParamsWithContext(h.ctx). WithBody(&models.V1BulkDeleteRequest{ Uids: uids, }) diff --git a/client/cluster_profile_import.go b/client/cluster_profile_import.go index 137c6216..5c9e597a 100644 --- a/client/cluster_profile_import.go +++ b/client/cluster_profile_import.go @@ -3,12 +3,13 @@ package client import ( "github.com/go-openapi/runtime" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateClusterProfileImport creates a new cluster profile from a cluster profile import file. func (h *V1Client) CreateClusterProfileImport(importFile runtime.NamedReadCloser) (string, error) { - params := clientV1.NewV1ClusterProfilesImportFileParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesImportFileParamsWithContext(h.ctx). WithPublish(apiutil.Ptr(true)). WithImportFile(importFile) resp, err := h.Client.V1ClusterProfilesImportFile(params) diff --git a/client/cluster_rbac_config.go b/client/cluster_rbac_config.go index ac2b6a04..c3f3ca98 100644 --- a/client/cluster_rbac_config.go +++ b/client/cluster_rbac_config.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/herr" ) +// GetClusterRbacConfig retrieves the RBAC configuration for a cluster. func (h *V1Client) GetClusterRbacConfig(uid string) (*models.V1ClusterRbacs, error) { - params := clientV1.NewV1SpectroClustersUIDConfigRbacsGetParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDConfigRbacsGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1SpectroClustersUIDConfigRbacsGet(params) if err != nil { @@ -19,22 +20,25 @@ func (h *V1Client) GetClusterRbacConfig(uid string) (*models.V1ClusterRbacs, err return resp.Payload, nil } +// CreateClusterRbacConfig creates a new RBAC configuration for a cluster. func (h *V1Client) CreateClusterRbacConfig(uid string, config *models.V1ClusterRbac) error { - params := clientV1.NewV1WorkspacesClusterRbacCreateParamsWithContext(h.ctx). + params := clientv1.NewV1WorkspacesClusterRbacCreateParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1WorkspacesClusterRbacCreate(params) return err } +// UpdateClusterRbacConfig updates an existing RBAC configuration for a cluster. func (h *V1Client) UpdateClusterRbacConfig(uid string, config *models.V1ClusterRbacResourcesUpdateEntity) error { - params := clientV1.NewV1SpectroClustersUIDConfigRbacsUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDConfigRbacsUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1SpectroClustersUIDConfigRbacsUpdate(params) return err } +// ApplyClusterRbacConfig creates a new RBAC configuration for a cluster or updates its RBAC configuration if one exists. func (h *V1Client) ApplyClusterRbacConfig(uid string, config []*models.V1ClusterRbacInputEntity) error { rbac, err := h.GetClusterRbacConfig(uid) if err != nil { diff --git a/client/cluster_scan_config.go b/client/cluster_scan_config.go index cdbad84d..2e3036a1 100644 --- a/client/cluster_scan_config.go +++ b/client/cluster_scan_config.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/herr" ) +// GetClusterScanConfig retrieves the cluster scan configuration for a cluster. func (h *V1Client) GetClusterScanConfig(uid string) (*models.V1ClusterComplianceScan, error) { - params := clientV1.NewV1ClusterFeatureComplianceScanGetParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterFeatureComplianceScanGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1ClusterFeatureComplianceScanGet(params) if err != nil { @@ -19,22 +20,25 @@ func (h *V1Client) GetClusterScanConfig(uid string) (*models.V1ClusterCompliance return resp.Payload, nil } +// CreateClusterScanConfig creates a new cluster scan configuration for a cluster. func (h *V1Client) CreateClusterScanConfig(uid string, config *models.V1ClusterComplianceScheduleConfig) error { - params := clientV1.NewV1ClusterFeatureComplianceScanCreateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterFeatureComplianceScanCreateParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1ClusterFeatureComplianceScanCreate(params) return err } +// UpdateClusterScanConfig updates an existing cluster scan configuration for a cluster. func (h *V1Client) UpdateClusterScanConfig(uid string, config *models.V1ClusterComplianceScheduleConfig) error { - params := clientV1.NewV1ClusterFeatureComplianceScanUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterFeatureComplianceScanUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1ClusterFeatureComplianceScanUpdate(params) return err } +// ApplyClusterScanConfig creates a new cluster scan configuration for a cluster or updates its cluster scan configuration if one exists. func (h *V1Client) ApplyClusterScanConfig(uid string, config *models.V1ClusterComplianceScheduleConfig) error { policy, err := h.GetClusterScanConfig(uid) if err != nil { @@ -46,8 +50,9 @@ func (h *V1Client) ApplyClusterScanConfig(uid string, config *models.V1ClusterCo return h.UpdateClusterScanConfig(uid, config) } +// GetComplianceScanOnDemandScanLogs retrieves the on-demand scan logs for a cluster. func (h *V1Client) GetComplianceScanOnDemandScanLogs(uid string) (*models.V1ClusterComplianceScanLogs, error) { - params := clientV1.NewV1ClusterFeatureComplianceScanLogsGetParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterFeatureComplianceScanLogsGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1ClusterFeatureComplianceScanLogsGet(params) if err != nil { @@ -56,8 +61,9 @@ func (h *V1Client) GetComplianceScanOnDemandScanLogs(uid string) (*models.V1Clus return resp.Payload, nil } +// CreateComplianceScanOnDemandCreateClusterScanConfig creates a new on-demand scan configuration for a cluster. func (h *V1Client) CreateComplianceScanOnDemandCreateClusterScanConfig(uid string, config *models.V1ClusterComplianceOnDemandConfig) error { - params := clientV1.NewV1ClusterFeatureComplianceScanOnDemandCreateParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterFeatureComplianceScanOnDemandCreateParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1ClusterFeatureComplianceScanOnDemandCreate(params) diff --git a/client/cluster_tke.go b/client/cluster_tke.go index bcf2b0df..efc6ac2f 100644 --- a/client/cluster_tke.go +++ b/client/cluster_tke.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateClusterTke creates a new TKE cluster. func (h *V1Client) CreateClusterTke(cluster *models.V1SpectroTencentClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersTkeCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersTkeCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1SpectroClustersTkeCreate(params) if err != nil { @@ -16,16 +17,18 @@ func (h *V1Client) CreateClusterTke(cluster *models.V1SpectroTencentClusterEntit return *resp.Payload.UID, nil } +// CreateMachinePoolTke creates a new TKE machine pool. func (h *V1Client) CreateMachinePoolTke(cloudConfigUID string, machinePool *models.V1TencentMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsTkeMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsTkeMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsTkeMachinePoolCreate(params) return err } +// UpdateMachinePoolTke updates an existing TKE machine pool. func (h *V1Client) UpdateMachinePoolTke(cloudConfigUID string, machinePool *models.V1TencentMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsTkeMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsTkeMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -33,16 +36,18 @@ func (h *V1Client) UpdateMachinePoolTke(cloudConfigUID string, machinePool *mode return err } +// DeleteMachinePoolTke deletes an existing TKE machine pool. func (h *V1Client) DeleteMachinePoolTke(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsTkeMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsTkeMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsTkeMachinePoolDelete(params) return err } +// GetCloudConfigTke retrieves an existing TKE cluster's cloud config. func (h *V1Client) GetCloudConfigTke(configUID string) (*models.V1TencentCloudConfig, error) { - params := clientV1.NewV1CloudConfigsTkeGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsTkeGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsTkeGet(params) if apiutil.Is404(err) { @@ -53,8 +58,9 @@ func (h *V1Client) GetCloudConfigTke(configUID string) (*models.V1TencentCloudCo return resp.Payload, nil } +// GetNodeStatusMapTke retrieves the status of all nodes in a TKE machine pool. func (h *V1Client) GetNodeStatusMapTke(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsTkePoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsTkePoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsTkePoolMachinesList(params) diff --git a/client/cluster_virtual.go b/client/cluster_virtual.go index 5920b723..b69edf6d 100644 --- a/client/cluster_virtual.go +++ b/client/cluster_virtual.go @@ -1,13 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateClusterVirtual creates a new virtual cluster. func (h *V1Client) CreateClusterVirtual(cluster *models.V1SpectroVirtualClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersVirtualCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVirtualCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1SpectroClustersVirtualCreate(params) if err != nil { @@ -16,40 +17,48 @@ func (h *V1Client) CreateClusterVirtual(cluster *models.V1SpectroVirtualClusterE return *resp.Payload.UID, nil } +// ResizeClusterVirtual resizes a virtual cluster's CPU, RAM, and storage configuration. func (h *V1Client) ResizeClusterVirtual(configUID string, body *models.V1VirtualClusterResize) error { - params := clientV1.NewV1CloudConfigsVirtualUIDUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVirtualUIDUpdateParamsWithContext(h.ctx). WithConfigUID(configUID). WithBody(body) _, err := h.Client.V1CloudConfigsVirtualUIDUpdate(params) return err } +// CreateMachinePoolVirtual creates a new virtual machine pool. +// TODO: deprecate unused virtual cluster functions func (h *V1Client) CreateMachinePoolVirtual(cloudConfigUID string, machinePool *models.V1VirtualMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsVirtualMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVirtualMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsVirtualMachinePoolCreate(params) return err } +// UpdateMachinePoolVirtual updates an existing virtual machine pool. +// TODO: deprecate unused virtual cluster functions func (h *V1Client) UpdateMachinePoolVirtual(cloudConfigUID string, machinePool *models.V1VirtualMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsVirtualMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVirtualMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsVirtualMachinePoolUpdate(params) return err } +// DeleteMachinePoolVirtual deletes an existing virtual machine pool. +// TODO: deprecate unused virtual cluster functions func (h *V1Client) DeleteMachinePoolVirtual(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsVirtualMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVirtualMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsVirtualMachinePoolDelete(params) return err } +// GetCloudConfigVirtual retrieves an existing virtual cluster's cloud config. func (h *V1Client) GetCloudConfigVirtual(configUID string) (*models.V1VirtualCloudConfig, error) { - params := clientV1.NewV1CloudConfigsVirtualGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVirtualGetParamsWithContext(h.ctx). WithConfigUID(configUID) resp, err := h.Client.V1CloudConfigsVirtualGet(params) if apiutil.Is404(err) { @@ -60,8 +69,9 @@ func (h *V1Client) GetCloudConfigVirtual(configUID string) (*models.V1VirtualClo return resp.Payload, nil } +// VirtualClusterLifecycleConfigChange pauses or unpauses an existing virtual cluster. func (h *V1Client) VirtualClusterLifecycleConfigChange(uid string, body *models.V1LifecycleConfigEntity) (string, error) { - params := clientV1.NewV1SpectroClustersUIDLifecycleConfigUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersUIDLifecycleConfigUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(body) _, err := h.Client.V1SpectroClustersUIDLifecycleConfigUpdate(params) @@ -71,8 +81,9 @@ func (h *V1Client) VirtualClusterLifecycleConfigChange(uid string, body *models. return "Success", nil } +// GetNodeStatusMapVirtual retrieves the status of all nodes in a virtual machine pool. func (h *V1Client) GetNodeStatusMapVirtual(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsVirtualPoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVirtualPoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsVirtualPoolMachinesList(params) diff --git a/client/cluster_vsphere.go b/client/cluster_vsphere.go index f8e5ae97..adf44cb0 100644 --- a/client/cluster_vsphere.go +++ b/client/cluster_vsphere.go @@ -1,15 +1,14 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) -// Cluster - +// CreateClusterVsphere creates a new vSphere cluster. func (h *V1Client) CreateClusterVsphere(cluster *models.V1SpectroVsphereClusterEntity) (string, error) { - params := clientV1.NewV1SpectroClustersVsphereCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVsphereCreateParamsWithContext(h.ctx). WithBody(cluster) resp, err := h.Client.V1SpectroClustersVsphereCreate(params) if err != nil { @@ -18,18 +17,18 @@ func (h *V1Client) CreateClusterVsphere(cluster *models.V1SpectroVsphereClusterE return *resp.Payload.UID, nil } -// Machine Pool - +// CreateMachinePoolVsphere creates a new vSphere machine pool. func (h *V1Client) CreateMachinePoolVsphere(cloudConfigUID string, machinePool *models.V1VsphereMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsVsphereMachinePoolCreateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVsphereMachinePoolCreateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithBody(machinePool) _, err := h.Client.V1CloudConfigsVsphereMachinePoolCreate(params) return err } +// UpdateMachinePoolVsphere updates an existing vSphere machine pool. func (h *V1Client) UpdateMachinePoolVsphere(cloudConfigUID string, machinePool *models.V1VsphereMachinePoolConfigEntity) error { - params := clientV1.NewV1CloudConfigsVsphereMachinePoolUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVsphereMachinePoolUpdateParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(*machinePool.PoolConfig.Name). WithBody(machinePool) @@ -37,19 +36,19 @@ func (h *V1Client) UpdateMachinePoolVsphere(cloudConfigUID string, machinePool * return err } +// DeleteMachinePoolVsphere deletes an existing vSphere machine pool. func (h *V1Client) DeleteMachinePoolVsphere(cloudConfigUID, machinePoolName string) error { - params := clientV1.NewV1CloudConfigsVsphereMachinePoolDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVsphereMachinePoolDeleteParamsWithContext(h.ctx). WithConfigUID(cloudConfigUID). WithMachinePoolName(machinePoolName) _, err := h.Client.V1CloudConfigsVsphereMachinePoolDelete(params) return err } -// Cloud Config - -func (h *V1Client) GetCloudConfigVsphere(configUID string) (*models.V1VsphereCloudConfig, error) { - params := clientV1.NewV1CloudConfigsVsphereGetParamsWithContext(h.ctx). - WithConfigUID(configUID) +// GetCloudConfigVsphere retrieves an existing vSphere cluster's cloud config. +func (h *V1Client) GetCloudConfigVsphere(uid string) (*models.V1VsphereCloudConfig, error) { + params := clientv1.NewV1CloudConfigsVsphereGetParamsWithContext(h.ctx). + WithConfigUID(uid) resp, err := h.Client.V1CloudConfigsVsphereGet(params) if apiutil.Is404(err) { return nil, nil @@ -59,28 +58,18 @@ func (h *V1Client) GetCloudConfigVsphere(configUID string) (*models.V1VsphereClo return resp.Payload, nil } -func (h *V1Client) GetCloudConfigVsphereValues(uid string) (*models.V1VsphereCloudConfig, error) { - params := clientV1.NewV1CloudConfigsVsphereGetParamsWithContext(h.ctx). - WithConfigUID(uid) - resp, err := h.Client.V1CloudConfigsVsphereGet(params) - if err != nil { - return nil, err - } - return resp.Payload, nil -} - -func (h *V1Client) UpdateCloudConfigVsphereValues(uid string, cloudConfig *models.V1VsphereCloudClusterConfigEntity) error { - params := clientV1.NewV1CloudConfigsVsphereUIDClusterConfigParamsWithContext(h.ctx). +// UpdateCloudConfigVsphere updates an existing vSphere cluster's cloud config. +func (h *V1Client) UpdateCloudConfigVsphere(uid string, cloudConfig *models.V1VsphereCloudClusterConfigEntity) error { + params := clientv1.NewV1CloudConfigsVsphereUIDClusterConfigParamsWithContext(h.ctx). WithConfigUID(uid). WithBody(cloudConfig) _, err := h.Client.V1CloudConfigsVsphereUIDClusterConfig(params) return err } -// Import - +// ImportClusterVsphere imports an existing vSphere cluster. func (h *V1Client) ImportClusterVsphere(meta *models.V1ObjectMetaInputEntity) (string, error) { - params := clientV1.NewV1SpectroClustersVsphereImportParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVsphereImportParamsWithContext(h.ctx). WithBody(&models.V1SpectroVsphereClusterImportEntity{ Metadata: meta, }, @@ -92,8 +81,9 @@ func (h *V1Client) ImportClusterVsphere(meta *models.V1ObjectMetaInputEntity) (s return *resp.Payload.UID, nil } +// GetNodeStatusMapVsphere retrieves the status of all nodes in a vSphere machine pool. func (h *V1Client) GetNodeStatusMapVsphere(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientV1.NewV1CloudConfigsVspherePoolMachinesListParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVspherePoolMachinesListParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machinePoolName) mpList, err := h.Client.V1CloudConfigsVspherePoolMachinesList(params) diff --git a/client/constants.go b/client/constants.go index 6b9f7734..ca13a185 100644 --- a/client/constants.go +++ b/client/constants.go @@ -2,9 +2,13 @@ package client const ( authTokenInput = "header" - authApiKey = "ApiKey" + authAPIKey = "ApiKey" authJwt = "Authorization" - OverlordUID = "overlordUid" - Scope = "scope" + // OverlordUID is an annotation key used to link a cloud accounts with a private cloud gateway. + OverlordUID = "overlordUID" + + // Scope is the key for the scope in the Palette authorization context + // One of: "project", "system", "tenant" + Scope = "scope" ) diff --git a/client/datavolume.go b/client/datavolume.go index a1090b5f..1806e296 100644 --- a/client/datavolume.go +++ b/client/datavolume.go @@ -3,10 +3,11 @@ package client import ( "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// CreateDataVolume creates a new data volume. func (h *V1Client) CreateDataVolume(uid, name string, body *models.V1VMAddVolumeEntity) (string, error) { cluster, err := h.GetCluster(uid) if err != nil { @@ -14,7 +15,7 @@ func (h *V1Client) CreateDataVolume(uid, name string, body *models.V1VMAddVolume } else if cluster == nil { return "", fmt.Errorf("cluster with uid %s not found", uid) } - params := clientV1.NewV1SpectroClustersVMAddVolumeParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVMAddVolumeParamsWithContext(h.ctx). WithUID(uid). WithBody(body). WithVMName(name). @@ -26,6 +27,7 @@ func (h *V1Client) CreateDataVolume(uid, name string, body *models.V1VMAddVolume return resp.AuditUID, nil } +// DeleteDataVolume deletes an existing data volume. func (h *V1Client) DeleteDataVolume(uid, namespace, name string, body *models.V1VMRemoveVolumeEntity) error { cluster, err := h.GetCluster(uid) if err != nil { @@ -34,7 +36,7 @@ func (h *V1Client) DeleteDataVolume(uid, namespace, name string, body *models.V1 if cluster == nil { return fmt.Errorf("cluster with uid %s not found", uid) } - params := clientV1.NewV1SpectroClustersVMRemoveVolumeParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVMRemoveVolumeParamsWithContext(h.ctx). WithUID(uid). WithVMName(name). WithNamespace(namespace). diff --git a/client/events.go b/client/events.go index 3fd6c756..ab71aa56 100644 --- a/client/events.go +++ b/client/events.go @@ -3,12 +3,14 @@ package client import ( "time" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// GetEvents retrieves events for a given object. +// TODO: which kinds are supported? func (h *V1Client) GetEvents(kind, uid string, continueVar, fields, filters, orderBy *string, limit, offset *int64, timeout *time.Duration) ([]*models.V1Event, error) { - params := clientV1.NewV1EventsComponentsObjTypeUIDListParamsWithContext(h.ctx). + params := clientv1.NewV1EventsComponentsObjTypeUIDListParamsWithContext(h.ctx). WithObjectKind(kind). WithObjectUID(uid) if continueVar != nil { @@ -39,8 +41,10 @@ func (h *V1Client) GetEvents(kind, uid string, continueVar, fields, filters, ord return resp.Payload.Items, nil } +// GetNotifications retrieves notifications for a given object. +// TODO: which kinds are supported? func (h *V1Client) GetNotifications(kind, uid string, continueVar, fields, filters, isDone, orderBy *string, limit, offset *int64, timeout *time.Duration) ([]*models.V1Notification, error) { - params := clientV1.NewV1NotificationsObjTypeUIDListParamsWithContext(h.ctx). + params := clientv1.NewV1NotificationsObjTypeUIDListParamsWithContext(h.ctx). WithObjectKind(kind). WithObjectUID(uid) if continueVar != nil { diff --git a/client/filter.go b/client/filter.go index 5f8dd69a..31eaef46 100644 --- a/client/filter.go +++ b/client/filter.go @@ -3,7 +3,7 @@ package client import ( "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) @@ -11,9 +11,10 @@ import ( // CRUDL operations on tag filters are all tenant scoped. // See: hubble/services/svccore/perms/filter_acl.go +// CreateTagFilter creates a new tag filter. func (h *V1Client) CreateTagFilter(body *models.V1TagFilter) (*models.V1UID, error) { // ACL scoped to tenant only - params := clientV1.NewV1TagFiltersCreateParams(). + params := clientv1.NewV1TagFiltersCreateParams(). WithBody(body) resp, err := h.Client.V1TagFiltersCreate(params) if err != nil { @@ -22,18 +23,20 @@ func (h *V1Client) CreateTagFilter(body *models.V1TagFilter) (*models.V1UID, err return resp.Payload, nil } +// UpdateTagFilter updates an existing tag filter. func (h *V1Client) UpdateTagFilter(uid string, body *models.V1TagFilter) error { // ACL scoped to tenant only - params := clientV1.NewV1TagFilterUIDUpdateParams(). + params := clientv1.NewV1TagFilterUIDUpdateParams(). WithUID(uid). WithBody(body) _, err := h.Client.V1TagFilterUIDUpdate(params) return err } +// GetTagFilter retrieves an existing tag filter by UID. func (h *V1Client) GetTagFilter(uid string) (*models.V1TagFilterSummary, error) { // ACL scoped to tenant only - params := clientV1.NewV1TagFilterUIDGetParams(). + params := clientv1.NewV1TagFilterUIDGetParams(). WithUID(uid) resp, err := h.Client.V1TagFilterUIDGet(params) if err != nil { @@ -42,9 +45,10 @@ func (h *V1Client) GetTagFilter(uid string) (*models.V1TagFilterSummary, error) return resp.Payload, nil } +// ListTagFilters retrieves all tag filters. func (h *V1Client) ListTagFilters() (*models.V1FiltersSummary, error) { // ACL scoped to tenant only - params := clientV1.NewV1FiltersListParams(). + params := clientv1.NewV1FiltersListParams(). WithLimit(apiutil.Ptr(int64(0))) resp, err := h.Client.V1FiltersList(params) if err != nil { @@ -53,6 +57,7 @@ func (h *V1Client) ListTagFilters() (*models.V1FiltersSummary, error) { return resp.Payload, nil } +// GetTagFilterByName retrieves an existing tag filter by name. func (h *V1Client) GetTagFilterByName(name string) (*models.V1FilterSummary, error) { filters, err := h.ListTagFilters() if err != nil { @@ -66,9 +71,10 @@ func (h *V1Client) GetTagFilterByName(name string) (*models.V1FilterSummary, err return nil, fmt.Errorf("filter not found for name %s", name) } -func (h *V1Client) DeleteTag(uid string) error { +// DeleteTagFilter deletes an existing tag filter. +func (h *V1Client) DeleteTagFilter(uid string) error { // ACL scoped to tenant only - params := clientV1.NewV1TagFilterUIDDeleteParams(). + params := clientv1.NewV1TagFilterUIDDeleteParams(). WithUID(uid) _, err := h.Client.V1TagFilterUIDDelete(params) return err diff --git a/client/herr/errors.go b/client/herr/errors.go index 5aa32e12..94065c43 100644 --- a/client/herr/errors.go +++ b/client/herr/errors.go @@ -1,15 +1,19 @@ +// Package herr provides error handling utilities for the Spectro Cloud API client. package herr import "github.com/spectrocloud/palette-sdk-go/client/apiutil" +// IsNotFound returns a boolean indicating whether an error is a ResourceNotFound error. func IsNotFound(err error) bool { return apiutil.ToV1ErrorObj(err).Code == "ResourceNotFound" } +// IsEdgeHostDeviceNotRegistered returns a boolean indicating whether an error is an EdgeHostDeviceNotRegistered error. func IsEdgeHostDeviceNotRegistered(err error) bool { return apiutil.ToV1ErrorObj(err).Code == "EdgeHostDeviceNotRegistered" } +// IsBackupNotConfigured returns a boolean indicating whether an error is a BackupNotConfigured error. func IsBackupNotConfigured(err error) bool { return apiutil.ToV1ErrorObj(err).Code == "BackupNotConfigured" } diff --git a/client/macro.go b/client/macro.go index 9313826d..26206154 100644 --- a/client/macro.go +++ b/client/macro.go @@ -1,14 +1,15 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateMacro creates a new macro. func (h *V1Client) CreateMacro(uid string, macros *models.V1Macros) error { if uid != "" { - params := clientV1.NewV1ProjectsUIDMacrosCreateParamsWithContext(h.ctx). + params := clientv1.NewV1ProjectsUIDMacrosCreateParamsWithContext(h.ctx). WithUID(uid). WithBody(macros) _, err := h.Client.V1ProjectsUIDMacrosCreate(params) @@ -19,33 +20,36 @@ func (h *V1Client) CreateMacro(uid string, macros *models.V1Macros) error { return err } // As discussed with hubble team, we should not set context for tenant macros. - params := clientV1.NewV1TenantsUIDMacrosCreateParams(). + params := clientv1.NewV1TenantsUIDMacrosCreateParams(). WithTenantUID(tenantUID). WithBody(macros) _, err = h.Client.V1TenantsUIDMacrosCreate(params) return err } +// GetMacro retrieves an existing macro by name and project UID. func (h *V1Client) GetMacro(name, projectUID string) (*models.V1Macro, error) { macros, err := h.GetMacros(projectUID) if err != nil { return nil, err } - id := h.GetMacroID(projectUID, name) + id := GetMacroID(projectUID, name) for _, macro := range macros { - if h.GetMacroID(projectUID, macro.Name) == id { + if GetMacroID(projectUID, macro.Name) == id { return macro, nil } } return nil, nil } +// GetMacros retrieves all macros in a project or tenant. +// If projectUID is empty, tenant macros are returned. func (h *V1Client) GetMacros(projectUID string) ([]*models.V1Macro, error) { var macros []*models.V1Macro if projectUID != "" { - params := clientV1.NewV1ProjectsUIDMacrosListParamsWithContext(h.ctx). + params := clientv1.NewV1ProjectsUIDMacrosListParamsWithContext(h.ctx). WithUID(projectUID) resp, err := h.Client.V1ProjectsUIDMacrosList(params) if err != nil { @@ -58,7 +62,7 @@ func (h *V1Client) GetMacros(projectUID string) ([]*models.V1Macro, error) { return nil, err } // As discussed with hubble team, we should not set context for tenant macros. - params := clientV1.NewV1TenantsUIDMacrosListParams(). + params := clientv1.NewV1TenantsUIDMacrosListParams(). WithTenantUID(tenantUID) resp, err := h.Client.V1TenantsUIDMacrosList(params) if err != nil { @@ -70,9 +74,10 @@ func (h *V1Client) GetMacros(projectUID string) ([]*models.V1Macro, error) { return macros, nil } +// UpdateMacro updates an existing macro. func (h *V1Client) UpdateMacro(uid string, macros *models.V1Macros) error { if uid != "" { - params := clientV1.NewV1ProjectsUIDMacrosUpdateByMacroNameParamsWithContext(h.ctx). + params := clientv1.NewV1ProjectsUIDMacrosUpdateByMacroNameParamsWithContext(h.ctx). WithUID(uid). WithBody(macros) _, err := h.Client.V1ProjectsUIDMacrosUpdateByMacroName(params) @@ -83,16 +88,17 @@ func (h *V1Client) UpdateMacro(uid string, macros *models.V1Macros) error { return err } // As discussed with hubble team, we should not set context for tenant macros. - params := clientV1.NewV1TenantsUIDMacrosUpdateByMacroNameParams(). + params := clientv1.NewV1TenantsUIDMacrosUpdateByMacroNameParams(). WithTenantUID(tenantUID). WithBody(macros) _, err = h.Client.V1TenantsUIDMacrosUpdateByMacroName(params) return err } +// DeleteMacro deletes an existing macro. func (h *V1Client) DeleteMacro(uid string, body *models.V1Macros) error { if uid != "" { - params := clientV1.NewV1ProjectsUIDMacrosDeleteByMacroNameParamsWithContext(h.ctx). + params := clientv1.NewV1ProjectsUIDMacrosDeleteByMacroNameParamsWithContext(h.ctx). WithUID(uid). WithBody(body) _, err := h.Client.V1ProjectsUIDMacrosDeleteByMacroName(params) @@ -105,7 +111,7 @@ func (h *V1Client) DeleteMacro(uid string, body *models.V1Macros) error { return err } // As discussed with hubble team, we should not set context for tenant macros. - params := clientV1.NewV1TenantsUIDMacrosDeleteByMacroNameParams(). + params := clientv1.NewV1TenantsUIDMacrosDeleteByMacroNameParams(). WithTenantUID(tenantUID). WithBody(body) _, err = h.Client.V1TenantsUIDMacrosDeleteByMacroName(params) @@ -117,7 +123,9 @@ func (h *V1Client) DeleteMacro(uid string, body *models.V1Macros) error { return err } -func (h *V1Client) GetMacroID(uid, name string) string { +// GetMacroID returns the hash of the macro name and project UID. +// Provide an empty string for project UID to get the hash for tenant macros. +func GetMacroID(uid, name string) string { var hash string if uid != "" { hash = apiutil.StringHash(name + uid) diff --git a/client/macros.go b/client/macros.go index f47cf3e5..e786e9a0 100644 --- a/client/macros.go +++ b/client/macros.go @@ -3,13 +3,14 @@ package client import ( "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// CreateMacros creates a new macro. func (h *V1Client) CreateMacros(uid string, macros *models.V1Macros) (string, error) { if uid != "" { - params := clientV1.NewV1ProjectsUIDMacrosCreateParamsWithContext(h.ctx). + params := clientv1.NewV1ProjectsUIDMacrosCreateParamsWithContext(h.ctx). WithUID(uid). WithBody(macros) _, err := h.Client.V1ProjectsUIDMacrosCreate(params) @@ -22,7 +23,7 @@ func (h *V1Client) CreateMacros(uid string, macros *models.V1Macros) (string, er return "", err } // As discussed with hubble team, we should not set context for tenant macros. - params := clientV1.NewV1TenantsUIDMacrosCreateParams(). + params := clientv1.NewV1TenantsUIDMacrosCreateParams(). WithTenantUID(tenantUID). WithBody(macros) _, err = h.Client.V1TenantsUIDMacrosCreate(params) @@ -37,7 +38,9 @@ func (h *V1Client) CreateMacros(uid string, macros *models.V1Macros) (string, er return macrosID, nil } -func (h *V1Client) GetTFMacrosV2(tfMacrosMap map[string]interface{}, projectUID string) ([]*models.V1Macro, error) { +// GetTFMacrosV2 retrieves all macros in a project or tenant, filtered by the given map. +// Macros whose names are in the map and values are non-nil are returned. +func (h *V1Client) GetTFMacrosV2(tfMacrosMap map[string]any, projectUID string) ([]*models.V1Macro, error) { allMacros, err := h.GetMacrosV2(projectUID) if err != nil { return nil, err @@ -56,7 +59,9 @@ func (h *V1Client) GetTFMacrosV2(tfMacrosMap map[string]interface{}, projectUID return tfMacros, nil } -func (h *V1Client) GetExistMacros(tfMacrosMap map[string]interface{}, projectUID string) ([]*models.V1Macro, error) { +// GetExistMacros retrieves all macros in a project or tenant, filtered by the given map. +// Macros whose names are not in the map are returned. +func (h *V1Client) GetExistMacros(tfMacrosMap map[string]any, projectUID string) ([]*models.V1Macro, error) { allMacros, err := h.GetMacrosV2(projectUID) if err != nil { return nil, err @@ -73,12 +78,12 @@ func (h *V1Client) GetExistMacros(tfMacrosMap map[string]interface{}, projectUID } return existMacros, nil - } +// GetMacrosV2 retrieves all existing macros at either project or tenant scope. func (h *V1Client) GetMacrosV2(projectUID string) ([]*models.V1Macro, error) { if projectUID != "" { - params := clientV1.NewV1ProjectsUIDMacrosListParamsWithContext(h.ctx). + params := clientv1.NewV1ProjectsUIDMacrosListParamsWithContext(h.ctx). WithUID(projectUID) macrosListOk, err := h.Client.V1ProjectsUIDMacrosList(params) if err != nil { @@ -91,7 +96,7 @@ func (h *V1Client) GetMacrosV2(projectUID string) ([]*models.V1Macro, error) { return nil, err } // As discussed with hubble team, we should not set context for tenant macros. - params := clientV1.NewV1TenantsUIDMacrosListParams(). + params := clientv1.NewV1TenantsUIDMacrosListParams(). WithTenantUID(tenantUID) macrosListOk, err := h.Client.V1TenantsUIDMacrosList(params) if err != nil { @@ -100,9 +105,10 @@ func (h *V1Client) GetMacrosV2(projectUID string) ([]*models.V1Macro, error) { return macrosListOk.Payload.Macros, nil } +// UpdateMacros updates an existing macro. func (h *V1Client) UpdateMacros(uid string, macros *models.V1Macros) error { if uid != "" { - params := clientV1.NewV1ProjectsUIDMacrosUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1ProjectsUIDMacrosUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(macros) _, err := h.Client.V1ProjectsUIDMacrosUpdate(params) @@ -113,16 +119,17 @@ func (h *V1Client) UpdateMacros(uid string, macros *models.V1Macros) error { return err } // As discussed with hubble team, we should not set context for tenant macros. - params := clientV1.NewV1TenantsUIDMacrosUpdateParams(). + params := clientv1.NewV1TenantsUIDMacrosUpdateParams(). WithTenantUID(tenantUID). WithBody(macros) _, err = h.Client.V1TenantsUIDMacrosUpdate(params) return err } +// DeleteMacros deletes an existing macro. func (h *V1Client) DeleteMacros(uid string, body *models.V1Macros) error { if uid != "" { - params := clientV1.NewV1ProjectsUIDMacrosDeleteByMacroNameParamsWithContext(h.ctx). + params := clientv1.NewV1ProjectsUIDMacrosDeleteByMacroNameParamsWithContext(h.ctx). WithUID(uid). WithBody(body) _, err := h.Client.V1ProjectsUIDMacrosDeleteByMacroName(params) @@ -133,13 +140,15 @@ func (h *V1Client) DeleteMacros(uid string, body *models.V1Macros) error { return err } // As discussed with hubble team, we should not set context for tenant macros. - params := clientV1.NewV1TenantsUIDMacrosDeleteByMacroNameParams(). + params := clientv1.NewV1TenantsUIDMacrosDeleteByMacroNameParams(). WithTenantUID(tenantUID). WithBody(body) _, err = h.Client.V1TenantsUIDMacrosDeleteByMacroName(params) return err } +// GetMacrosID returns the hash ID for a macro, given a project UID. +// If the project UID is empty, the tenant UID is used. func (h *V1Client) GetMacrosID(uid string) (string, error) { hashID := "" if uid != "" { diff --git a/client/node_actions.go b/client/node_actions.go index efec773d..6b29d33e 100644 --- a/client/node_actions.go +++ b/client/node_actions.go @@ -1,14 +1,13 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) -type GetMaintenanceStatus func(string, string, string) (*models.V1MachineMaintenanceStatus, error) - +// ToggleMaintenanceOnNode updates maintenance configuration for a node. func (h *V1Client) ToggleMaintenanceOnNode(nodeMaintenance *models.V1MachineMaintenance, cloudType, configUID, machineName, nodeID string) error { - params := clientV1.NewV1CloudConfigsMachinePoolsMachineUIDMaintenanceUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsMachinePoolsMachineUIDMaintenanceUpdateParamsWithContext(h.ctx). WithBody(nodeMaintenance). WithCloudType(cloudType). WithConfigUID(configUID). @@ -19,12 +18,9 @@ func (h *V1Client) ToggleMaintenanceOnNode(nodeMaintenance *models.V1MachineMain return err } -func (h *V1Client) GetNodeMaintenanceStatus(fn GetMaintenanceStatus, configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - return fn(configUID, machineName, nodeID) -} - +// GetNodeMaintenanceStatusAws retrieves maintenance status for an AWS IaaS node. func (h *V1Client) GetNodeMaintenanceStatusAws(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsAwsPoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAwsPoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -36,8 +32,9 @@ func (h *V1Client) GetNodeMaintenanceStatusAws(configUID, machineName, nodeID st return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusMaas retrieves maintenance status for a MAAS node. func (h *V1Client) GetNodeMaintenanceStatusMaas(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsMaasPoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsMaasPoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -49,8 +46,9 @@ func (h *V1Client) GetNodeMaintenanceStatusMaas(configUID, machineName, nodeID s return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusAks retrieves maintenance status for an AKS node. func (h *V1Client) GetNodeMaintenanceStatusAks(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsAksPoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAksPoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -62,8 +60,9 @@ func (h *V1Client) GetNodeMaintenanceStatusAks(configUID, machineName, nodeID st return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusAzure retrieves maintenance status for an Azure IaaS node. func (h *V1Client) GetNodeMaintenanceStatusAzure(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsAzurePoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsAzurePoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -75,21 +74,9 @@ func (h *V1Client) GetNodeMaintenanceStatusAzure(configUID, machineName, nodeID return resp.Payload.Status.MaintenanceStatus, nil } -func (h *V1Client) GetNodeMaintenanceStatusCoxEdge(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsCoxEdgePoolMachinesUIDGetParamsWithContext(h.ctx). - WithConfigUID(configUID). - WithMachinePoolName(machineName). - WithMachineUID(nodeID) - - resp, err := h.Client.V1CloudConfigsCoxEdgePoolMachinesUIDGet(params) - if err != nil { - return nil, err - } - return resp.Payload.Status.MaintenanceStatus, nil -} - +// GetNodeMaintenanceStatusEdgeNative retrieves maintenance status for an edge native node. func (h *V1Client) GetNodeMaintenanceStatusEdgeNative(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsEdgeNativePoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgeNativePoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -101,8 +88,10 @@ func (h *V1Client) GetNodeMaintenanceStatusEdgeNative(configUID, machineName, no return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusEdge retrieves maintenance status for an edge node. +// TODO: edgev1 deprecation func (h *V1Client) GetNodeMaintenanceStatusEdge(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsEdgePoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEdgePoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -114,8 +103,10 @@ func (h *V1Client) GetNodeMaintenanceStatusEdge(configUID, machineName, nodeID s return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusEdgeVsphere retrieves maintenance status for a vSphere edge node. +// TODO: edgev1 deprecation func (h *V1Client) GetNodeMaintenanceStatusEdgeVsphere(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsVspherePoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVspherePoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -127,8 +118,9 @@ func (h *V1Client) GetNodeMaintenanceStatusEdgeVsphere(configUID, machineName, n return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusEks retrieves maintenance status for an EKS node. func (h *V1Client) GetNodeMaintenanceStatusEks(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsEksPoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsEksPoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -140,8 +132,9 @@ func (h *V1Client) GetNodeMaintenanceStatusEks(configUID, machineName, nodeID st return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusGcp retrieves maintenance status for a GCP IaaS node. func (h *V1Client) GetNodeMaintenanceStatusGcp(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsGcpPoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsGcpPoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -153,8 +146,9 @@ func (h *V1Client) GetNodeMaintenanceStatusGcp(configUID, machineName, nodeID st return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusGeneric retrieves maintenance status for a generic node. func (h *V1Client) GetNodeMaintenanceStatusGeneric(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsGenericPoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsGenericPoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -166,8 +160,9 @@ func (h *V1Client) GetNodeMaintenanceStatusGeneric(configUID, machineName, nodeI return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusGke retrieves maintenance status for a GKE node. func (h *V1Client) GetNodeMaintenanceStatusGke(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsGkePoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsGkePoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -179,8 +174,10 @@ func (h *V1Client) GetNodeMaintenanceStatusGke(configUID, machineName, nodeID st return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusLibvirt retrieves maintenance status for a libvirt node. +// TODO: edgev1 deprecation func (h *V1Client) GetNodeMaintenanceStatusLibvirt(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsLibvirtPoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsLibvirtPoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -192,8 +189,9 @@ func (h *V1Client) GetNodeMaintenanceStatusLibvirt(configUID, machineName, nodeI return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusOpenStack retrieves maintenance status for an OpenStack node. func (h *V1Client) GetNodeMaintenanceStatusOpenStack(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsOpenStackPoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsOpenStackPoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -205,8 +203,9 @@ func (h *V1Client) GetNodeMaintenanceStatusOpenStack(configUID, machineName, nod return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusTke retrieves maintenance status for a TKE node. func (h *V1Client) GetNodeMaintenanceStatusTke(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsTkePoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsTkePoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -218,8 +217,10 @@ func (h *V1Client) GetNodeMaintenanceStatusTke(configUID, machineName, nodeID st return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeVirtualMaintenanceStatusVirtual retrieves maintenance status for a virtual node. +// TODO: deprecate unused virtual cluster functions func (h *V1Client) GetNodeVirtualMaintenanceStatusVirtual(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsVirtualPoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVirtualPoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) @@ -231,8 +232,9 @@ func (h *V1Client) GetNodeVirtualMaintenanceStatusVirtual(configUID, machineName return resp.Payload.Status.MaintenanceStatus, nil } +// GetNodeMaintenanceStatusVsphere retrieves maintenance status for a vSphere node. func (h *V1Client) GetNodeMaintenanceStatusVsphere(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientV1.NewV1CloudConfigsVspherePoolMachinesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1CloudConfigsVspherePoolMachinesUIDGetParamsWithContext(h.ctx). WithConfigUID(configUID). WithMachinePoolName(machineName). WithMachineUID(nodeID) diff --git a/client/organization.go b/client/organization.go index f73f16f8..90689222 100644 --- a/client/organization.go +++ b/client/organization.go @@ -1,12 +1,13 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// GetOrganizationByName retrieves an organization by name. func (h *V1Client) GetOrganizationByName(name string) (*models.V1LoginResponse, error) { - params := clientV1.NewV1AuthOrgParamsWithContext(h.ctx). + params := clientv1.NewV1AuthOrgParamsWithContext(h.ctx). WithOrgName(&name) resp, err := h.Client.V1AuthOrg(params) if err != nil || resp == nil { @@ -15,8 +16,9 @@ func (h *V1Client) GetOrganizationByName(name string) (*models.V1LoginResponse, return resp.Payload, nil } +// ListOrganizations retrieves all organizations. func (h *V1Client) ListOrganizations() ([]*models.V1Organization, error) { - params := clientV1.NewV1AuthOrgsParamsWithContext(h.ctx) + params := clientv1.NewV1AuthOrgsParamsWithContext(h.ctx) resp, err := h.Client.V1AuthOrgs(params) if err != nil { return nil, err @@ -24,8 +26,10 @@ func (h *V1Client) ListOrganizations() ([]*models.V1Organization, error) { return resp.Payload.Organizations, nil } +// SwitchOrganization switches the caller's active organization. +// Returns an authorization token for the target organization. func (h *V1Client) SwitchOrganization(orgName string) (string, error) { - params := clientV1.NewV1AuthOrgSwitchParamsWithContext(h.ctx). + params := clientv1.NewV1AuthOrgSwitchParamsWithContext(h.ctx). WithOrgName(orgName) resp, err := h.Client.V1AuthOrgSwitch(params) if err != nil || resp == nil { diff --git a/client/pack.go b/client/pack.go index ef49e40f..182a6d73 100644 --- a/client/pack.go +++ b/client/pack.go @@ -3,13 +3,14 @@ package client import ( "strings" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// SearchPacks retrieves a list of pack metadata based on the filter and sort criteria. func (h *V1Client) SearchPacks(filter *models.V1PackFilterSpec, sortBy []*models.V1PackSortSpec) ([]*models.V1PackMetadata, error) { - params := clientV1.NewV1PacksSearchParamsWithContext(h.ctx). + params := clientv1.NewV1PacksSearchParamsWithContext(h.ctx). WithBody(&models.V1PacksFilterSpec{ Filter: filter, Sort: sortBy, @@ -23,8 +24,9 @@ func (h *V1Client) SearchPacks(filter *models.V1PackFilterSpec, sortBy []*models return resp.Payload.Items, nil } +// GetClusterProfileManifestPack retrieves all manifests for a pack in a cluster profile. func (h *V1Client) GetClusterProfileManifestPack(clusterProfileUID, packName string) ([]*models.V1ManifestEntity, error) { - params := clientV1.NewV1ClusterProfilesUIDPacksUIDManifestsParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesUIDPacksUIDManifestsParamsWithContext(h.ctx). WithUID(clusterProfileUID). WithPackName(packName) resp, err := h.Client.V1ClusterProfilesUIDPacksUIDManifests(params) @@ -36,8 +38,9 @@ func (h *V1Client) GetClusterProfileManifestPack(clusterProfileUID, packName str return resp.Payload.Items, nil } +// GetPacks retrieves a list of pack summaries based on the provided registry UID and filter criteria. func (h *V1Client) GetPacks(filters []string, registryUID string) ([]*models.V1PackSummary, error) { - params := clientV1.NewV1PacksSummaryListParamsWithContext(h.ctx) + params := clientv1.NewV1PacksSummaryListParamsWithContext(h.ctx) if filters != nil { filterString := apiutil.Ptr(strings.Join(filters, "AND")) params = params.WithFilters(filterString) @@ -55,8 +58,9 @@ func (h *V1Client) GetPacks(filters []string, registryUID string) ([]*models.V1P return packs, nil } +// GetPacksByProfile retrieves all packs for a cluster profile. func (h *V1Client) GetPacksByProfile(profileUID string) ([]*models.V1ClusterProfilePacksEntity, error) { - params := clientV1.NewV1ClusterProfilesUIDPacksGetParamsWithContext(h.ctx). + params := clientv1.NewV1ClusterProfilesUIDPacksGetParamsWithContext(h.ctx). WithUID(profileUID) resp, err := h.Client.V1ClusterProfilesUIDPacksGet(params) if err != nil { @@ -65,8 +69,9 @@ func (h *V1Client) GetPacksByProfile(profileUID string) ([]*models.V1ClusterProf return resp.Payload.Items, nil } +// GetPacksByNameAndRegistry retrieves a pack by name and registry UID. func (h *V1Client) GetPacksByNameAndRegistry(name, registryUID string) (*models.V1PackTagEntity, error) { - params := clientV1.NewV1PacksNameRegistryUIDListParamsWithContext(h.ctx). + params := clientv1.NewV1PacksNameRegistryUIDListParamsWithContext(h.ctx). WithPackName(name). WithRegistryUID(registryUID) resp, err := h.Client.V1PacksNameRegistryUIDList(params) @@ -76,8 +81,9 @@ func (h *V1Client) GetPacksByNameAndRegistry(name, registryUID string) (*models. return resp.Payload, nil } +// GetPack retrieves a pack by UID. func (h *V1Client) GetPack(uid string) (*models.V1PackTagEntity, error) { - params := clientV1.NewV1PacksUIDParamsWithContext(h.ctx). + params := clientv1.NewV1PacksUIDParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1PacksUID(params) if err != nil { @@ -86,6 +92,8 @@ func (h *V1Client) GetPack(uid string) (*models.V1PackTagEntity, error) { return resp.Payload, nil } +// GetPackRegistry retrieves a pack registry by UID and pack type. +// If packUID is "uid" or packType is "manifest", it returns Spectro Cloud's 'Public Repo' registry. func (h *V1Client) GetPackRegistry(packUID, packType string) string { if packUID == "uid" || packType == "manifest" { registry, err := h.GetPackRegistryCommonByName("Public Repo") diff --git a/client/private_cloud_gateway.go b/client/private_cloud_gateway.go index ef9d1c64..ec3dac37 100644 --- a/client/private_cloud_gateway.go +++ b/client/private_cloud_gateway.go @@ -4,15 +4,16 @@ import ( "errors" "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) // PCG - Generic +// GetPCGId retrieves the UID of a Private Cloud Gateway by name. func (h *V1Client) GetPCGId(name *string) (string, error) { - params := clientV1.NewV1OverlordsListParamsWithContext(h.ctx) + params := clientv1.NewV1OverlordsListParamsWithContext(h.ctx) resp, err := h.Client.V1OverlordsList(params) if err != nil { return "", err @@ -25,8 +26,9 @@ func (h *V1Client) GetPCGId(name *string) (string, error) { return "", errors.New("Private Cloud Gateway not found: " + *name) } -func (h *V1Client) GetPCGById(uid string) (*models.V1Overlord, error) { - params := clientV1.NewV1OverlordsUIDGetParamsWithContext(h.ctx). +// GetPCGByID retrieves a Private Cloud Gateway by UID. +func (h *V1Client) GetPCGByID(uid string) (*models.V1Overlord, error) { + params := clientv1.NewV1OverlordsUIDGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1OverlordsUIDGet(params) if err != nil { @@ -35,8 +37,9 @@ func (h *V1Client) GetPCGById(uid string) (*models.V1Overlord, error) { return resp.Payload, nil } +// GetPCGByName retrieves a Private Cloud Gateway by name. func (h *V1Client) GetPCGByName(name string) (*models.V1Overlord, error) { - params := clientV1.NewV1OverlordsListParamsWithContext(h.ctx). + params := clientv1.NewV1OverlordsListParamsWithContext(h.ctx). WithName(&name) resp, err := h.Client.V1OverlordsList(params) if err != nil { @@ -48,8 +51,9 @@ func (h *V1Client) GetPCGByName(name string) (*models.V1Overlord, error) { return nil, nil } +// GetPairingCode retrieves a pairing code for a Private Cloud Gateway by cloud type. func (h *V1Client) GetPairingCode(cloudType string) (string, error) { - params := clientV1.NewV1OverlordsPairingCodeParamsWithContext(h.ctx). + params := clientv1.NewV1OverlordsPairingCodeParamsWithContext(h.ctx). WithCloudType(&cloudType) resp, err := h.Client.V1OverlordsPairingCode(params) if err != nil { @@ -58,30 +62,33 @@ func (h *V1Client) GetPairingCode(cloudType string) (string, error) { return resp.Payload.PairingCode, nil } -func (h *V1Client) CheckPCG(pcgId string) error { - if pcgId == "" { +// CheckPCG checks if a Private Cloud Gateway is running. +// Returns an error if the PCG is not found or is not running. +func (h *V1Client) CheckPCG(pcgID string) error { + if pcgID == "" { return nil // no pcg to check } - pcg, err := h.GetPCGById(pcgId) + pcg, err := h.GetPCGByID(pcgID) if err != nil { return err } if pcg == nil { - return fmt.Errorf("private cloud gateway not found: %s", pcgId) + return fmt.Errorf("private cloud gateway not found: %s", pcgID) } if pcg.Status == nil { - return fmt.Errorf("private cloud gateway status not found: %s", pcgId) + return fmt.Errorf("private cloud gateway status not found: %s", pcgID) } if pcg.Status.State != "Running" { - return fmt.Errorf("private cloud gateway is not running: %s", pcgId) + return fmt.Errorf("private cloud gateway is not running: %s", pcgID) } return nil // pcg is running } // PCG - vSphere +// CreatePCGVsphere creates a new vSphere Private Cloud Gateway. func (h *V1Client) CreatePCGVsphere(uid string, cloudConfig *models.V1OverlordVsphereCloudConfig) (string, error) { - params := clientV1.NewV1OverlordsUIDVsphereCloudConfigCreateParamsWithContext(h.ctx). + params := clientv1.NewV1OverlordsUIDVsphereCloudConfigCreateParamsWithContext(h.ctx). WithUID(uid). WithBody(cloudConfig) resp, err := h.Client.V1OverlordsUIDVsphereCloudConfigCreate(params) @@ -89,11 +96,11 @@ func (h *V1Client) CreatePCGVsphere(uid string, cloudConfig *models.V1OverlordVs return "", err } return *resp.Payload.UID, nil - } +// CreatePCGCloudAccountVsphere creates a new vSphere PCG cloud account. func (h *V1Client) CreatePCGCloudAccountVsphere(uid string, account *models.V1OverlordVsphereAccountCreate) (string, error) { - params := clientV1.NewV1OverlordsUIDVsphereAccountCreateParamsWithContext(h.ctx). + params := clientv1.NewV1OverlordsUIDVsphereAccountCreateParamsWithContext(h.ctx). WithUID(uid). WithBody(account) resp, err := h.Client.V1OverlordsUIDVsphereAccountCreate(params) @@ -103,8 +110,9 @@ func (h *V1Client) CreatePCGCloudAccountVsphere(uid string, account *models.V1Ov return *resp.Payload.UID, nil } +// GetPCGManifestVsphere retrieves a vSphere PCG manifest by pairing code. func (h *V1Client) GetPCGManifestVsphere(pairingCode string) (string, error) { - params := clientV1.NewV1OverlordsVsphereManifestParamsWithContext(h.ctx). + params := clientv1.NewV1OverlordsVsphereManifestParamsWithContext(h.ctx). WithPairingCode(pairingCode) resp, err := h.Client.V1OverlordsVsphereManifest(params) if err != nil { @@ -113,8 +121,9 @@ func (h *V1Client) GetPCGManifestVsphere(pairingCode string) (string, error) { return resp.Payload.Manifest, nil } +// GetPCGClusterProfileVsphere retrieves a vSphere PCG cluster profile by PCG UID. func (h *V1Client) GetPCGClusterProfileVsphere(uid string) (*models.V1ClusterProfile, error) { - params := clientV1.NewV1OverlordsUIDVsphereClusterProfileParamsWithContext(h.ctx). + params := clientv1.NewV1OverlordsUIDVsphereClusterProfileParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1OverlordsUIDVsphereClusterProfile(params) if err != nil { @@ -123,18 +132,20 @@ func (h *V1Client) GetPCGClusterProfileVsphere(uid string) (*models.V1ClusterPro return resp.Payload, nil } -func (h *V1Client) CreateDDNSSearchDomainVsphere(vsphereDnsMapping *models.V1VsphereDNSMapping) error { - params := clientV1.NewV1VsphereDNSMappingCreateParamsWithContext(h.ctx). - WithBody(vsphereDnsMapping) +// CreateDDNSSearchDomainVsphere creates a new vSphere DDNS search domain. +func (h *V1Client) CreateDDNSSearchDomainVsphere(vsphereDNSMapping *models.V1VsphereDNSMapping) error { + params := clientv1.NewV1VsphereDNSMappingCreateParamsWithContext(h.ctx). + WithBody(vsphereDNSMapping) _, err := h.Client.V1VsphereDNSMappingCreate(params) return err } // PCG - OpenStack -func (h *V1Client) CreatePCGCloudAccountOpenStack(overlordUid string, account *models.V1OverlordOpenStackAccountCreate) (string, error) { - params := clientV1.NewV1OverlordsUIDOpenStackAccountCreateParamsWithContext(h.ctx). - WithUID(overlordUid). +// CreatePCGCloudAccountOpenStack creates a new OpenStack PCG cloud account. +func (h *V1Client) CreatePCGCloudAccountOpenStack(overlordUID string, account *models.V1OverlordOpenStackAccountCreate) (string, error) { + params := clientv1.NewV1OverlordsUIDOpenStackAccountCreateParamsWithContext(h.ctx). + WithUID(overlordUID). WithBody(account) resp, err := h.Client.V1OverlordsUIDOpenStackAccountCreate(params) if err != nil { @@ -143,9 +154,10 @@ func (h *V1Client) CreatePCGCloudAccountOpenStack(overlordUid string, account *m return *resp.Payload.UID, nil } -func (h *V1Client) CreatePCGOpenStack(overlordUid string, cloudConfig *models.V1OverlordOpenStackCloudConfig) (string, error) { - params := clientV1.NewV1OverlordsUIDOpenStackCloudConfigCreateParamsWithContext(h.ctx). - WithUID(overlordUid). +// CreatePCGOpenStack creates a new OpenStack Private Cloud Gateway. +func (h *V1Client) CreatePCGOpenStack(overlordUID string, cloudConfig *models.V1OverlordOpenStackCloudConfig) (string, error) { + params := clientv1.NewV1OverlordsUIDOpenStackCloudConfigCreateParamsWithContext(h.ctx). + WithUID(overlordUID). WithBody(cloudConfig) resp, err := h.Client.V1OverlordsUIDOpenStackCloudConfigCreate(params) if err != nil { @@ -154,8 +166,9 @@ func (h *V1Client) CreatePCGOpenStack(overlordUid string, cloudConfig *models.V1 return *resp.Payload.UID, nil } +// GetPCGManifestOpenStack retrieves an OpenStack PCG manifest by pairing code. func (h *V1Client) GetPCGManifestOpenStack(pairingCode string) (string, error) { - params := clientV1.NewV1OverlordsOpenStackManifestParamsWithContext(h.ctx). + params := clientv1.NewV1OverlordsOpenStackManifestParamsWithContext(h.ctx). WithPairingCode(pairingCode) resp, err := h.Client.V1OverlordsOpenStackManifest(params) if err != nil { @@ -164,8 +177,9 @@ func (h *V1Client) GetPCGManifestOpenStack(pairingCode string) (string, error) { return resp.Payload.Manifest, nil } +// GetPCGClusterProfileOpenStack retrieves an OpenStack PCG cluster profile by PCG UID. func (h *V1Client) GetPCGClusterProfileOpenStack(uid string) (*models.V1ClusterProfile, error) { - params := clientV1.NewV1OverlordsUIDOpenStackClusterProfileParamsWithContext(h.ctx). + params := clientv1.NewV1OverlordsUIDOpenStackClusterProfileParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1OverlordsUIDOpenStackClusterProfile(params) if err != nil { @@ -176,9 +190,10 @@ func (h *V1Client) GetPCGClusterProfileOpenStack(uid string) (*models.V1ClusterP // PCG - MAAS -func (h *V1Client) CreatePCGCloudAccountMaas(overlordUid string, account *models.V1OverlordMaasAccountCreate) (string, error) { - params := clientV1.NewV1OverlordsUIDMaasAccountCreateParamsWithContext(h.ctx). - WithUID(overlordUid). +// CreatePCGCloudAccountMaas creates a new MAAS PCG cloud account. +func (h *V1Client) CreatePCGCloudAccountMaas(overlordUID string, account *models.V1OverlordMaasAccountCreate) (string, error) { + params := clientv1.NewV1OverlordsUIDMaasAccountCreateParamsWithContext(h.ctx). + WithUID(overlordUID). WithBody(account) resp, err := h.Client.V1OverlordsUIDMaasAccountCreate(params) if err != nil { @@ -187,9 +202,10 @@ func (h *V1Client) CreatePCGCloudAccountMaas(overlordUid string, account *models return *resp.Payload.UID, nil } -func (h *V1Client) CreatePCGMaas(overlordUid string, cloudConfig *models.V1OverlordMaasCloudConfig) (string, error) { - params := clientV1.NewV1OverlordsUIDMaasCloudConfigCreateParamsWithContext(h.ctx). - WithUID(overlordUid). +// CreatePCGMaas creates a new MAAS Private Cloud Gateway. +func (h *V1Client) CreatePCGMaas(overlordUID string, cloudConfig *models.V1OverlordMaasCloudConfig) (string, error) { + params := clientv1.NewV1OverlordsUIDMaasCloudConfigCreateParamsWithContext(h.ctx). + WithUID(overlordUID). WithBody(cloudConfig) resp, err := h.Client.V1OverlordsUIDMaasCloudConfigCreate(params) if err != nil { @@ -198,8 +214,9 @@ func (h *V1Client) CreatePCGMaas(overlordUid string, cloudConfig *models.V1Overl return *resp.Payload.UID, nil } +// GetPCGManifestMaas retrieves a MAAS PCG manifest by pairing code. func (h *V1Client) GetPCGManifestMaas(pairingCode string) (string, error) { - params := clientV1.NewV1OverlordsMaasManifestParamsWithContext(h.ctx). + params := clientv1.NewV1OverlordsMaasManifestParamsWithContext(h.ctx). WithPairingCode(pairingCode) resp, err := h.Client.V1OverlordsMaasManifest(params) if err != nil { @@ -208,8 +225,9 @@ func (h *V1Client) GetPCGManifestMaas(pairingCode string) (string, error) { return resp.Payload.Manifest, nil } +// GetPCGClusterProfileMaas retrieves a MAAS PCG cluster profile by PCG UID. func (h *V1Client) GetPCGClusterProfileMaas(uid string) (*models.V1ClusterProfile, error) { - params := clientV1.NewV1OverlordsUIDMaasClusterProfileParamsWithContext(h.ctx). + params := clientv1.NewV1OverlordsUIDMaasClusterProfileParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1OverlordsUIDMaasClusterProfile(params) if err != nil { @@ -220,8 +238,9 @@ func (h *V1Client) GetPCGClusterProfileMaas(uid string) (*models.V1ClusterProfil // IP Pool -func (h *V1Client) CreateIpPool(pcgUID string, pool *models.V1IPPoolInputEntity) (string, error) { - params := clientV1.NewV1OverlordsUIDPoolCreateParamsWithContext(h.ctx). +// CreateIPPool creates a new IP pool for a Private Cloud Gateway. +func (h *V1Client) CreateIPPool(pcgUID string, pool *models.V1IPPoolInputEntity) (string, error) { + params := clientv1.NewV1OverlordsUIDPoolCreateParamsWithContext(h.ctx). WithUID(pcgUID). WithBody(pool) resp, err := h.Client.V1OverlordsUIDPoolCreate(params) @@ -231,21 +250,23 @@ func (h *V1Client) CreateIpPool(pcgUID string, pool *models.V1IPPoolInputEntity) return *resp.Payload.UID, nil } -func (h *V1Client) GetIpPool(pcgUid, poolUid string) (*models.V1IPPoolEntity, error) { - pools, err := h.GetIpPools(pcgUid) +// GetIPPool retrieves a PCG's IP pool by pool UID. +func (h *V1Client) GetIPPool(pcgUID, poolUID string) (*models.V1IPPoolEntity, error) { + pools, err := h.GetIPPools(pcgUID) if err != nil { return nil, err } for _, pool := range pools { - if pool.Metadata.UID == poolUid { + if pool.Metadata.UID == poolUID { return pool, nil } } return nil, nil } -func (h *V1Client) GetIpPoolByName(pcgUid, poolName string) (*models.V1IPPoolEntity, error) { - pools, err := h.GetIpPools(pcgUid) +// GetIPPoolByName retrieves a PCG's IP pool by pool name. +func (h *V1Client) GetIPPoolByName(pcgUID, poolName string) (*models.V1IPPoolEntity, error) { + pools, err := h.GetIPPools(pcgUID) if err != nil { return nil, err } @@ -257,9 +278,10 @@ func (h *V1Client) GetIpPoolByName(pcgUid, poolName string) (*models.V1IPPoolEnt return nil, errors.New("ip pool not found: " + poolName) } -func (h *V1Client) GetIpPools(pcgUid string) ([]*models.V1IPPoolEntity, error) { - params := clientV1.NewV1OverlordsUIDPoolsListParamsWithContext(h.ctx). - WithUID(pcgUid) +// GetIPPools retrieves all IP pools for a Private Cloud Gateway. +func (h *V1Client) GetIPPools(pcgUID string) ([]*models.V1IPPoolEntity, error) { + params := clientv1.NewV1OverlordsUIDPoolsListParamsWithContext(h.ctx). + WithUID(pcgUID) resp, err := h.Client.V1OverlordsUIDPoolsList(params) if err != nil { if v1Err := apiutil.ToV1ErrorObj(err); v1Err.Code != "ResourceNotFound" { @@ -269,19 +291,21 @@ func (h *V1Client) GetIpPools(pcgUid string) ([]*models.V1IPPoolEntity, error) { return resp.Payload.Items, nil } -func (h *V1Client) UpdateIpPool(pcgUid, poolUid string, pool *models.V1IPPoolInputEntity) error { - params := clientV1.NewV1OverlordsUIDPoolUpdateParamsWithContext(h.ctx). - WithUID(pcgUid). +// UpdateIPPool updates an existing Private Cloud Gateway IP pool. +func (h *V1Client) UpdateIPPool(pcgUID, poolUID string, pool *models.V1IPPoolInputEntity) error { + params := clientv1.NewV1OverlordsUIDPoolUpdateParamsWithContext(h.ctx). + WithUID(pcgUID). WithBody(pool). - WithPoolUID(poolUid) + WithPoolUID(poolUID) _, err := h.Client.V1OverlordsUIDPoolUpdate(params) return err } -func (h *V1Client) DeleteIpPool(pcgUid, poolUid string) error { - params := clientV1.NewV1OverlordsUIDPoolDeleteParamsWithContext(h.ctx). - WithUID(pcgUid). - WithPoolUID(poolUid) +// DeleteIPPool deletes an existing Private Cloud Gateway IP pool. +func (h *V1Client) DeleteIPPool(pcgUID, poolUID string) error { + params := clientv1.NewV1OverlordsUIDPoolDeleteParamsWithContext(h.ctx). + WithUID(pcgUID). + WithPoolUID(poolUID) _, err := h.Client.V1OverlordsUIDPoolDelete(params) return err } diff --git a/client/project.go b/client/project.go index 86a12ff6..8839e96a 100644 --- a/client/project.go +++ b/client/project.go @@ -3,16 +3,17 @@ package client import ( "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) // CRUDL operations on projects are all tenant scoped. // See: hubble/services/svccore/perms/user_acl.go +// CreateProject creates a new project. func (h *V1Client) CreateProject(body *models.V1ProjectEntity) (string, error) { // ACL scoped to tenant only - params := clientV1.NewV1ProjectsCreateParams(). + params := clientv1.NewV1ProjectsCreateParams(). WithBody(body) resp, err := h.Client.V1ProjectsCreate(params) if err != nil { @@ -21,6 +22,7 @@ func (h *V1Client) CreateProject(body *models.V1ProjectEntity) (string, error) { return *resp.Payload.UID, nil } +// GetProjectUID retrieves an existing project's UID by name. func (h *V1Client) GetProjectUID(projectName string) (string, error) { projects, err := h.GetProjects() if err != nil { @@ -36,9 +38,10 @@ func (h *V1Client) GetProjectUID(projectName string) (string, error) { return "", fmt.Errorf("project '%s' not found", projectName) } +// GetProjectByUID retrieves an existing project by UID. func (h *V1Client) GetProjectByUID(uid string) (*models.V1Project, error) { // ACL scoped to tenant only - params := clientV1.NewV1ProjectsUIDGetParams(). + params := clientv1.NewV1ProjectsUIDGetParams(). WithUID(uid) resp, err := h.Client.V1ProjectsUIDGet(params) if err != nil { @@ -47,9 +50,10 @@ func (h *V1Client) GetProjectByUID(uid string) (*models.V1Project, error) { return resp.Payload, nil } +// GetProjects retrieves all projects' metadata. func (h *V1Client) GetProjects() (*models.V1ProjectsMetadata, error) { // ACL scoped to tenant only - params := clientV1.NewV1ProjectsMetadataParams() + params := clientv1.NewV1ProjectsMetadataParams() resp, err := h.Client.V1ProjectsMetadata(params) if err != nil { return nil, err @@ -57,18 +61,20 @@ func (h *V1Client) GetProjects() (*models.V1ProjectsMetadata, error) { return resp.Payload, nil } +// UpdateProject updates an existing project. func (h *V1Client) UpdateProject(uid string, body *models.V1ProjectEntity) error { // ACL scoped to tenant only - params := clientV1.NewV1ProjectsUIDUpdateParams(). + params := clientv1.NewV1ProjectsUIDUpdateParams(). WithUID(uid). WithBody(body) _, err := h.Client.V1ProjectsUIDUpdate(params) return err } +// DeleteProject deletes an existing project. func (h *V1Client) DeleteProject(uid string) error { // ACL scoped to tenant only - params := clientV1.NewV1ProjectsUIDDeleteParams(). + params := clientv1.NewV1ProjectsUIDDeleteParams(). WithUID(uid) _, err := h.Client.V1ProjectsUIDDelete(params) return err diff --git a/client/registry.go b/client/registry.go index 1d502d2e..68a6a513 100644 --- a/client/registry.go +++ b/client/registry.go @@ -3,15 +3,17 @@ package client import ( "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// SearchPackRegistryCommon retrieves a list of all registries. func (h *V1Client) SearchPackRegistryCommon() ([]*models.V1RegistryMetadata, error) { return h.getRegistryCommon() } +// GetPackRegistryCommonByName retrieves any type of registry by name. func (h *V1Client) GetPackRegistryCommonByName(registryName string) (*models.V1RegistryMetadata, error) { registries, err := h.getRegistryCommon() if err != nil { @@ -26,7 +28,7 @@ func (h *V1Client) GetPackRegistryCommonByName(registryName string) (*models.V1R } func (h *V1Client) getRegistryCommon() ([]*models.V1RegistryMetadata, error) { - params := clientV1.NewV1RegistriesMetadataParamsWithContext(h.ctx). + params := clientv1.NewV1RegistriesMetadataParamsWithContext(h.ctx). WithScope(apiutil.Ptr("")) resp, err := h.Client.V1RegistriesMetadata(params) if err != nil { @@ -35,8 +37,9 @@ func (h *V1Client) getRegistryCommon() ([]*models.V1RegistryMetadata, error) { return resp.Payload.Items, nil } +// GetPackRegistryByName retrieves an existing Pack registry by name. func (h *V1Client) GetPackRegistryByName(registryName string) (*models.V1PackRegistry, error) { - params := clientV1.NewV1RegistriesPackListParamsWithContext(h.ctx) + params := clientv1.NewV1RegistriesPackListParamsWithContext(h.ctx) resp, err := h.Client.V1RegistriesPackList(params) if err != nil { return nil, err @@ -49,8 +52,9 @@ func (h *V1Client) GetPackRegistryByName(registryName string) (*models.V1PackReg return nil, fmt.Errorf("registry '%s' not found", registryName) } +// ListHelmRegistries retrieves a list of all Helm registries, filtered by scope. func (h *V1Client) ListHelmRegistries(scope string) ([]*models.V1HelmRegistrySummary, error) { - params := clientV1.NewV1RegistriesHelmSummaryListParamsWithContext(h.ctx). + params := clientv1.NewV1RegistriesHelmSummaryListParamsWithContext(h.ctx). WithScope(&scope) resp, err := h.Client.V1RegistriesHelmSummaryList(params) if err != nil { @@ -59,8 +63,9 @@ func (h *V1Client) ListHelmRegistries(scope string) ([]*models.V1HelmRegistrySum return resp.Payload.Items, nil } +// GetHelmRegistryByName retrieves an existing Helm registry by name. func (h *V1Client) GetHelmRegistryByName(registryName string) (*models.V1HelmRegistry, error) { - params := clientV1.NewV1RegistriesHelmListParamsWithContext(h.ctx) + params := clientv1.NewV1RegistriesHelmListParamsWithContext(h.ctx) resp, err := h.Client.V1RegistriesHelmList(params) if err != nil { return nil, err @@ -73,9 +78,9 @@ func (h *V1Client) GetHelmRegistryByName(registryName string) (*models.V1HelmReg return nil, fmt.Errorf("registry '%s' not found", registryName) } +// GetHelmRegistry retrieves an existing Helm registry by UID. func (h *V1Client) GetHelmRegistry(uid string) (*models.V1HelmRegistry, error) { - - params := clientV1.NewV1RegistriesHelmUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1RegistriesHelmUIDGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1RegistriesHelmUIDGet(params) if err != nil { @@ -84,8 +89,9 @@ func (h *V1Client) GetHelmRegistry(uid string) (*models.V1HelmRegistry, error) { return resp.Payload, nil } +// CreateHelmRegistry creates a new Helm registry. func (h *V1Client) CreateHelmRegistry(registry *models.V1HelmRegistryEntity) (string, error) { - params := clientV1.NewV1RegistriesHelmCreateParamsWithContext(h.ctx). + params := clientv1.NewV1RegistriesHelmCreateParamsWithContext(h.ctx). WithBody(registry) resp, err := h.Client.V1RegistriesHelmCreate(params) if err != nil { @@ -94,23 +100,26 @@ func (h *V1Client) CreateHelmRegistry(registry *models.V1HelmRegistryEntity) (st return *resp.Payload.UID, nil } +// UpdateHelmRegistry updates an existing Helm registry. func (h *V1Client) UpdateHelmRegistry(uid string, registry *models.V1HelmRegistry) error { - params := clientV1.NewV1RegistriesHelmUIDUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1RegistriesHelmUIDUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(registry) _, err := h.Client.V1RegistriesHelmUIDUpdate(params) return err } +// DeleteHelmRegistry deletes an existing Helm registry. func (h *V1Client) DeleteHelmRegistry(uid string) error { - params := clientV1.NewV1RegistriesHelmUIDDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1RegistriesHelmUIDDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1RegistriesHelmUIDDelete(params) return err } +// ListOCIRegistries retrieves a list of all OCI registries. func (h *V1Client) ListOCIRegistries() ([]*models.V1OciRegistry, error) { - params := clientV1.NewV1OciRegistriesSummaryParamsWithContext(h.ctx) + params := clientv1.NewV1OciRegistriesSummaryParamsWithContext(h.ctx) resp, err := h.Client.V1OciRegistriesSummary(params) if err != nil { return nil, err @@ -118,8 +127,9 @@ func (h *V1Client) ListOCIRegistries() ([]*models.V1OciRegistry, error) { return resp.Payload.Items, nil } +// GetOciRegistryByName retrieves an existing OCI registry by name. func (h *V1Client) GetOciRegistryByName(registryName string) (*models.V1OciRegistry, error) { - params := clientV1.NewV1OciRegistriesSummaryParamsWithContext(h.ctx) + params := clientv1.NewV1OciRegistriesSummaryParamsWithContext(h.ctx) resp, err := h.Client.V1OciRegistriesSummary(params) if err != nil { return nil, err @@ -132,8 +142,9 @@ func (h *V1Client) GetOciRegistryByName(registryName string) (*models.V1OciRegis return nil, fmt.Errorf("registry '%s' not found", registryName) } +// GetOciBasicRegistry retrieves an existing standard/basic OCI registry by UID. func (h *V1Client) GetOciBasicRegistry(uid string) (*models.V1BasicOciRegistry, error) { - params := clientV1.NewV1BasicOciRegistriesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1BasicOciRegistriesUIDGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1BasicOciRegistriesUIDGet(params) if err != nil { @@ -142,8 +153,9 @@ func (h *V1Client) GetOciBasicRegistry(uid string) (*models.V1BasicOciRegistry, return resp.Payload, nil } +// CreateOciBasicRegistry creates a new standard/basic OCI registry. func (h *V1Client) CreateOciBasicRegistry(registry *models.V1BasicOciRegistry) (string, error) { - params := clientV1.NewV1BasicOciRegistriesCreateParamsWithContext(h.ctx). + params := clientv1.NewV1BasicOciRegistriesCreateParamsWithContext(h.ctx). WithBody(registry) resp, err := h.Client.V1BasicOciRegistriesCreate(params) if err != nil { @@ -152,23 +164,26 @@ func (h *V1Client) CreateOciBasicRegistry(registry *models.V1BasicOciRegistry) ( return *resp.Payload.UID, nil } +// UpdateOciBasicRegistry updates an existing standard/basic OCI registry. func (h *V1Client) UpdateOciBasicRegistry(uid string, registry *models.V1BasicOciRegistry) error { - params := clientV1.NewV1BasicOciRegistriesUIDUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1BasicOciRegistriesUIDUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(registry) _, err := h.Client.V1BasicOciRegistriesUIDUpdate(params) return err } +// DeleteOciBasicRegistry deletes an existing standard/basic OCI registry. func (h *V1Client) DeleteOciBasicRegistry(uid string) error { - params := clientV1.NewV1BasicOciRegistriesUIDDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1BasicOciRegistriesUIDDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1BasicOciRegistriesUIDDelete(params) return err } +// GetOciEcrRegistry retrieves an existing ECR OCI registry by UID. func (h *V1Client) GetOciEcrRegistry(uid string) (*models.V1EcrRegistry, error) { - params := clientV1.NewV1EcrRegistriesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1EcrRegistriesUIDGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1EcrRegistriesUIDGet(params) if err != nil { @@ -177,8 +192,9 @@ func (h *V1Client) GetOciEcrRegistry(uid string) (*models.V1EcrRegistry, error) return resp.Payload, nil } +// CreateOciEcrRegistry creates a new ECR OCI registry. func (h *V1Client) CreateOciEcrRegistry(registry *models.V1EcrRegistry) (string, error) { - params := clientV1.NewV1EcrRegistriesCreateParamsWithContext(h.ctx). + params := clientv1.NewV1EcrRegistriesCreateParamsWithContext(h.ctx). WithBody(registry) resp, err := h.Client.V1EcrRegistriesCreate(params) if err != nil { @@ -187,16 +203,18 @@ func (h *V1Client) CreateOciEcrRegistry(registry *models.V1EcrRegistry) (string, return *resp.Payload.UID, nil } -func (h *V1Client) UpdateEcrRegistry(uid string, registry *models.V1EcrRegistry) error { - params := clientV1.NewV1EcrRegistriesUIDUpdateParamsWithContext(h.ctx). +// UpdateOciEcrRegistry updates an existing ECR OCI registry. +func (h *V1Client) UpdateOciEcrRegistry(uid string, registry *models.V1EcrRegistry) error { + params := clientv1.NewV1EcrRegistriesUIDUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(registry) _, err := h.Client.V1EcrRegistriesUIDUpdate(params) return err } +// DeleteOciEcrRegistry deletes an existing ECR OCI registry. func (h *V1Client) DeleteOciEcrRegistry(uid string) error { - params := clientV1.NewV1EcrRegistriesUIDDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1EcrRegistriesUIDDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1EcrRegistriesUIDDelete(params) return err diff --git a/client/role.go b/client/role.go index d22d8914..e13199e4 100644 --- a/client/role.go +++ b/client/role.go @@ -3,16 +3,17 @@ package client import ( "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) // CRUDL operations on roles are all tenant scoped. // See: hubble/services/service/user/internal/service/role/role_acl.go +// GetRole retrieves an existing role by name. func (h *V1Client) GetRole(roleName string) (*models.V1Role, error) { // ACL scoped to tenant only - params := clientV1.NewV1RolesListParams() + params := clientv1.NewV1RolesListParams() resp, err := h.Client.V1RolesList(params) if err != nil { return nil, err diff --git a/client/ssh_key.go b/client/ssh_key.go index 1bf6afae..cdffb2a9 100644 --- a/client/ssh_key.go +++ b/client/ssh_key.go @@ -3,10 +3,11 @@ package client import ( "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// CreateSSHKey creates a new SSH key. func (h *V1Client) CreateSSHKey(body *models.V1UserAssetSSH) (string, error) { sshEntity := &models.V1UserAssetSSHEntity{ Metadata: &models.V1ObjectMetaInputEntity{ @@ -17,7 +18,7 @@ func (h *V1Client) CreateSSHKey(body *models.V1UserAssetSSH) (string, error) { Spec: &models.V1UserAssetSSHSpec{PublicKey: body.Spec.PublicKey}, } - params := clientV1.NewV1UserAssetsSSHCreateParamsWithContext(h.ctx). + params := clientv1.NewV1UserAssetsSSHCreateParamsWithContext(h.ctx). WithBody(sshEntity) resp, err := h.Client.V1UserAssetsSSHCreate(params) if err != nil { @@ -26,8 +27,9 @@ func (h *V1Client) CreateSSHKey(body *models.V1UserAssetSSH) (string, error) { return *resp.Payload.UID, nil } +// GetSSHKeyByName retrieves an existing SSH key by name. func (h *V1Client) GetSSHKeyByName(name string) (*models.V1UserAssetSSH, error) { - params := clientV1.NewV1UsersAssetsSSHGetParamsWithContext(h.ctx) + params := clientv1.NewV1UsersAssetsSSHGetParamsWithContext(h.ctx) resp, err := h.Client.V1UsersAssetsSSHGet(params) if err != nil { return nil, err @@ -40,8 +42,9 @@ func (h *V1Client) GetSSHKeyByName(name string) (*models.V1UserAssetSSH, error) return nil, fmt.Errorf("ssh key '%s' not found", name) } +// GetSSHKeyByUID retrieves an existing SSH key by UID. func (h *V1Client) GetSSHKeyByUID(uid string) (*models.V1UserAssetSSH, error) { - params := clientV1.NewV1UsersAssetSSHGetUIDParamsWithContext(h.ctx). + params := clientv1.NewV1UsersAssetSSHGetUIDParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1UsersAssetSSHGetUID(params) if err != nil { @@ -50,16 +53,18 @@ func (h *V1Client) GetSSHKeyByUID(uid string) (*models.V1UserAssetSSH, error) { return resp.Payload, nil } +// UpdateSSHKey updates an existing SSH key. func (h *V1Client) UpdateSSHKey(uid string, body *models.V1UserAssetSSH) error { - params := clientV1.NewV1UsersAssetSSHUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1UsersAssetSSHUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(body) _, err := h.Client.V1UsersAssetSSHUpdate(params) return err } +// DeleteSSHKey deletes an existing SSH key. func (h *V1Client) DeleteSSHKey(uid string) error { - params := clientV1.NewV1UsersAssetSSHDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1UsersAssetSSHDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1UsersAssetSSHDelete(params) return err diff --git a/client/team.go b/client/team.go index c41a028b..41c16125 100644 --- a/client/team.go +++ b/client/team.go @@ -1,16 +1,17 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) // CRUDL operations on teams are all tenant scoped. // See: hubble/services/svccore/perms/user_acl.go +// CreateTeam creates a new team. func (h *V1Client) CreateTeam(team *models.V1Team) (string, error) { // ACL scoped to tenant only - params := clientV1.NewV1TeamsCreateParams(). + params := clientv1.NewV1TeamsCreateParams(). WithBody(team) resp, err := h.Client.V1TeamsCreate(params) if err != nil { @@ -19,18 +20,20 @@ func (h *V1Client) CreateTeam(team *models.V1Team) (string, error) { return *resp.Payload.UID, nil } +// UpdateTeam updates an existing team. func (h *V1Client) UpdateTeam(uid string, team *models.V1Team) error { // ACL scoped to tenant only - params := clientV1.NewV1TeamsUIDUpdateParams(). + params := clientv1.NewV1TeamsUIDUpdateParams(). WithUID(uid). WithBody(team) _, err := h.Client.V1TeamsUIDUpdate(params) return err } +// GetTeam retrieves an existing team by UID. func (h *V1Client) GetTeam(uid string) (*models.V1Team, error) { // ACL scoped to tenant only - params := clientV1.NewV1TeamsUIDGetParams(). + params := clientv1.NewV1TeamsUIDGetParams(). WithUID(uid) resp, err := h.Client.V1TeamsUIDGet(params) if err != nil { @@ -39,24 +42,27 @@ func (h *V1Client) GetTeam(uid string) (*models.V1Team, error) { return resp.Payload, nil } +// DeleteTeam deletes an existing team by UID. func (h *V1Client) DeleteTeam(uid string) error { // ACL scoped to tenant only - params := clientV1.NewV1TeamsUIDDeleteParams(). + params := clientv1.NewV1TeamsUIDDeleteParams(). WithUID(uid) _, err := h.Client.V1TeamsUIDDelete(params) return err } +// AssociateTeamProjectRole updates a team's project-role associations. func (h *V1Client) AssociateTeamProjectRole(uid string, body *models.V1ProjectRolesPatch) error { - params := clientV1.NewV1TeamsProjectRolesPutParamsWithContext(h.ctx). + params := clientv1.NewV1TeamsProjectRolesPutParamsWithContext(h.ctx). WithUID(uid). WithBody(body) _, err := h.Client.V1TeamsProjectRolesPut(params) return err } +// GetTeamProjectRoleAssociation retrieves a team's project-role associations. func (h *V1Client) GetTeamProjectRoleAssociation(uid string) (*models.V1ProjectRolesEntity, error) { - params := clientV1.NewV1TeamsProjectRolesParamsWithContext(h.ctx). + params := clientv1.NewV1TeamsProjectRolesParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1TeamsProjectRoles(params) if err != nil { @@ -65,16 +71,18 @@ func (h *V1Client) GetTeamProjectRoleAssociation(uid string) (*models.V1ProjectR return resp.Payload, nil } +// AssociateTeamTenantRole updates a team's tenant-role associations. func (h *V1Client) AssociateTeamTenantRole(uid string, body *models.V1TeamTenantRolesUpdate) error { - params := clientV1.NewV1TeamsUIDTenantRolesUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1TeamsUIDTenantRolesUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(body) _, err := h.Client.V1TeamsUIDTenantRolesUpdate(params) return err } +// GetTeamTenantRoleAssociation retrieves a team's tenant-role associations. func (h *V1Client) GetTeamTenantRoleAssociation(uid string) (*models.V1TeamTenantRolesEntity, error) { - params := clientV1.NewV1TeamsUIDTenantRolesGetParamsWithContext(h.ctx). + params := clientv1.NewV1TeamsUIDTenantRolesGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1TeamsUIDTenantRolesGet(params) if err != nil { @@ -83,16 +91,18 @@ func (h *V1Client) GetTeamTenantRoleAssociation(uid string) (*models.V1TeamTenan return resp.Payload, nil } +// AssociateTeamWorkspaceRole updates a team's workspace-role associations. func (h *V1Client) AssociateTeamWorkspaceRole(uid string, body *models.V1WorkspacesRolesPatch) error { - params := clientV1.NewV1TeamsWorkspaceRolesPutParamsWithContext(h.ctx). + params := clientv1.NewV1TeamsWorkspaceRolesPutParamsWithContext(h.ctx). WithTeamUID(uid). WithBody(body) _, err := h.Client.V1TeamsWorkspaceRolesPut(params) return err } +// GetTeamWorkspaceRoleAssociation retrieves a team's workspace-role associations. func (h *V1Client) GetTeamWorkspaceRoleAssociation(uid string) (*models.V1WorkspaceScopeRoles, error) { - params := clientV1.NewV1TeamsWorkspaceGetRolesParamsWithContext(h.ctx). + params := clientv1.NewV1TeamsWorkspaceGetRolesParamsWithContext(h.ctx). WithTeamUID(uid) resp, err := h.Client.V1TeamsWorkspaceGetRoles(params) if err != nil { @@ -101,24 +111,27 @@ func (h *V1Client) GetTeamWorkspaceRoleAssociation(uid string) (*models.V1Worksp return resp.Payload, nil } +// AssociateTeamResourceRole updates a team's resource-role associations. func (h *V1Client) AssociateTeamResourceRole(uid string, body *models.V1ResourceRolesUpdateEntity) error { - params := clientV1.NewV1TeamsUIDResourceRolesCreateParamsWithContext(h.ctx). + params := clientv1.NewV1TeamsUIDResourceRolesCreateParamsWithContext(h.ctx). WithUID(uid). WithBody(body) _, err := h.Client.V1TeamsUIDResourceRolesCreate(params) return err } +// UpdateTeamResourceRole updates a team's resource-role associations. func (h *V1Client) UpdateTeamResourceRole(uid string, body *models.V1ResourceRolesUpdateEntity) error { - params := clientV1.NewV1TeamsResourceRolesUIDUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1TeamsResourceRolesUIDUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(body) _, err := h.Client.V1TeamsResourceRolesUIDUpdate(params) return err } +// GetTeamResourceRole retrieves a resource-role by team UID and role name. func (h *V1Client) GetTeamResourceRole(uid, name string) (*models.V1UIDSummary, error) { - params := clientV1.NewV1TeamsUIDResourceRolesParamsWithContext(h.ctx). + params := clientv1.NewV1TeamsUIDResourceRolesParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1TeamsUIDResourceRoles(params) if err != nil { diff --git a/client/tenant.go b/client/tenant.go index 7823dafa..710f9022 100644 --- a/client/tenant.go +++ b/client/tenant.go @@ -1,5 +1,6 @@ package client +// GetTenantUID retrieves the tenant UID of the authenticated user. func (h *V1Client) GetTenantUID() (string, error) { resp, err := h.GetMe() if err != nil { diff --git a/client/user.go b/client/user.go index 07dd9b59..b55525a7 100644 --- a/client/user.go +++ b/client/user.go @@ -3,13 +3,15 @@ package client import ( "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// Authenticate authenticates a user. +// Returns a JWT token. func (h *V1Client) Authenticate(body *models.V1AuthLogin) (*models.V1UserToken, error) { - params := clientV1.NewV1AuthenticateParams(). + params := clientv1.NewV1AuthenticateParams(). WithBody(body) resp, err := h.Client.V1Authenticate(params) if err != nil { @@ -18,8 +20,9 @@ func (h *V1Client) Authenticate(body *models.V1AuthLogin) (*models.V1UserToken, return resp.Payload, nil } +// GetMe retrieves the authenticated user. func (h *V1Client) GetMe() (*models.V1UserMe, error) { - params := clientV1.NewV1UsersMeGetParamsWithContext(h.ctx) + params := clientv1.NewV1UsersMeGetParamsWithContext(h.ctx) resp, err := h.Client.V1UsersMeGet(params) if err != nil { return nil, err @@ -30,9 +33,10 @@ func (h *V1Client) GetMe() (*models.V1UserMe, error) { // CRUDL operations on users are all tenant scoped. // See: hubble/services/svccore/perms/user_acl.go +// GetUsers retrieves all users. func (h *V1Client) GetUsers() (*models.V1Users, error) { // ACL scoped to tenant only - params := clientV1.NewV1UsersListParams(). + params := clientv1.NewV1UsersListParams(). WithLimit(apiutil.Ptr(int64(0))) resp, err := h.Client.V1UsersList(params) if err != nil { @@ -41,6 +45,7 @@ func (h *V1Client) GetUsers() (*models.V1Users, error) { return resp.Payload, nil } +// GetUserByName retrieves an existing user by name. func (h *V1Client) GetUserByName(name string) (*models.V1User, error) { users, err := h.GetUsers() if err != nil { @@ -54,6 +59,7 @@ func (h *V1Client) GetUserByName(name string) (*models.V1User, error) { return nil, fmt.Errorf("user with name '%s' not found", name) } +// GetUserByEmail retrieves an existing user by email. func (h *V1Client) GetUserByEmail(email string) (*models.V1User, error) { users, err := h.GetUsers() if err != nil { @@ -67,8 +73,9 @@ func (h *V1Client) GetUserByEmail(email string) (*models.V1User, error) { return nil, fmt.Errorf("user with email '%s' not found", email) } +// DeleteUserByUID deletes an existing user by UID. func (h *V1Client) DeleteUserByUID(uid string) error { - params := clientV1.NewV1UsersUIDDeleteParams().WithUID(uid) + params := clientv1.NewV1UsersUIDDeleteParams().WithUID(uid) _, err := h.Client.V1UsersUIDDelete(params) if err != nil { return err @@ -76,6 +83,7 @@ func (h *V1Client) DeleteUserByUID(uid string) error { return nil } +// DeleteUserByName deletes an existing user by name. func (h *V1Client) DeleteUserByName(name string) error { users, err := h.GetUsers() if err != nil { @@ -89,8 +97,9 @@ func (h *V1Client) DeleteUserByName(name string) error { return fmt.Errorf("user with name '%s' not found", name) } +// CreateUser creates a new user. func (h *V1Client) CreateUser(user *models.V1UserEntity) (string, error) { - param := clientV1.NewV1UsersCreateParams().WithBody(user) + param := clientv1.NewV1UsersCreateParams().WithBody(user) resp, err := h.Client.V1UsersCreate(param) if err != nil { return "", err diff --git a/client/virtual_machine.go b/client/virtual_machine.go index 2b366e57..67a90c0d 100644 --- a/client/virtual_machine.go +++ b/client/virtual_machine.go @@ -4,10 +4,11 @@ import ( "errors" "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// CreateVirtualMachine creates a new virtual machine. func (h *V1Client) CreateVirtualMachine(uid string, body *models.V1ClusterVirtualMachine) (*models.V1ClusterVirtualMachine, error) { cluster, err := h.GetCluster(uid) if err != nil { @@ -16,7 +17,7 @@ func (h *V1Client) CreateVirtualMachine(uid string, body *models.V1ClusterVirtua if cluster == nil { return nil, fmt.Errorf("cluster with uid %s not found", uid) } - params := clientV1.NewV1SpectroClustersVMCreateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVMCreateParamsWithContext(h.ctx). WithUID(uid). WithBody(body). WithNamespace(body.Metadata.Namespace) @@ -27,6 +28,7 @@ func (h *V1Client) CreateVirtualMachine(uid string, body *models.V1ClusterVirtua return resp.Payload, nil } +// GetVirtualMachine gets an existing virtual machine, regardless of its status. func (h *V1Client) GetVirtualMachine(uid, namespace, name string) (*models.V1ClusterVirtualMachine, error) { vm, err := h.GetVirtualMachineWithoutStatus(uid, name, namespace) if err != nil { @@ -35,9 +37,10 @@ func (h *V1Client) GetVirtualMachine(uid, namespace, name string) (*models.V1Clu return vm, nil } +// UpdateVirtualMachine updates an existing virtual machine. func (h *V1Client) UpdateVirtualMachine(cluster *models.V1SpectroCluster, vmName string, body *models.V1ClusterVirtualMachine) (*models.V1ClusterVirtualMachine, error) { clusterUID := cluster.Metadata.UID - params := clientV1.NewV1SpectroClustersVMUpdateParams(). + params := clientv1.NewV1SpectroClustersVMUpdateParams(). WithContext(ContextForScope(cluster.Metadata.Annotations[Scope], h.projectUID)). WithUID(clusterUID). WithBody(body). @@ -60,6 +63,7 @@ func (h *V1Client) UpdateVirtualMachine(cluster *models.V1SpectroCluster, vmName return resp.Payload, nil } +// DeleteVirtualMachine deletes an existing virtual machine. func (h *V1Client) DeleteVirtualMachine(uid, namespace, name string) error { cluster, err := h.GetCluster(uid) if err != nil { @@ -68,7 +72,7 @@ func (h *V1Client) DeleteVirtualMachine(uid, namespace, name string) error { if cluster == nil { return fmt.Errorf("cluster with uid %s not found", uid) } - params := clientV1.NewV1SpectroClustersVMDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVMDeleteParamsWithContext(h.ctx). WithUID(uid). WithVMName(name). WithNamespace(namespace) diff --git a/client/virtual_machine_clone.go b/client/virtual_machine_clone.go index 37e0a1e1..b4a15193 100644 --- a/client/virtual_machine_clone.go +++ b/client/virtual_machine_clone.go @@ -3,10 +3,11 @@ package client import ( "errors" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// CloneVirtualMachine clones a virtual machine. func (h *V1Client) CloneVirtualMachine(clusterUID, sourceVMName, cloneVMName, namespace string) error { cluster, err := h.GetCluster(clusterUID) if err != nil { @@ -15,7 +16,7 @@ func (h *V1Client) CloneVirtualMachine(clusterUID, sourceVMName, cloneVMName, na if cluster == nil { return errors.New("cluster not found") } - params := clientV1.NewV1SpectroClustersVMCloneParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVMCloneParamsWithContext(h.ctx). WithUID(clusterUID). WithVMName(sourceVMName). WithNamespace(namespace). diff --git a/client/virtual_machine_common.go b/client/virtual_machine_common.go index 72c123d8..9b70ed84 100644 --- a/client/virtual_machine_common.go +++ b/client/virtual_machine_common.go @@ -1,10 +1,11 @@ package client import ( - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" ) +// IsVMExists checks if a virtual machine exists. func (h *V1Client) IsVMExists(clusterUID, name, namespace string) (bool, error) { vm, err := h.GetVirtualMachine(clusterUID, namespace, name) if err != nil { @@ -16,8 +17,9 @@ func (h *V1Client) IsVMExists(clusterUID, name, namespace string) (bool, error) return false, nil } +// GetVirtualMachineWithoutStatus retrieves a virtual machine, regardless of its status. func (h *V1Client) GetVirtualMachineWithoutStatus(uid, name, namespace string) (*models.V1ClusterVirtualMachine, error) { - params := clientV1.NewV1SpectroClustersVMGetParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVMGetParamsWithContext(h.ctx). WithUID(uid). WithVMName(name). WithNamespace(namespace) @@ -28,8 +30,9 @@ func (h *V1Client) GetVirtualMachineWithoutStatus(uid, name, namespace string) ( return resp.Payload, nil } +// GetVirtualMachines retrieves a list of virtual machines for a given cluster. func (h *V1Client) GetVirtualMachines(cluster *models.V1SpectroCluster) ([]*models.V1ClusterVirtualMachine, error) { - params := clientV1.NewV1SpectroClustersVMListParams(). + params := clientv1.NewV1SpectroClustersVMListParams(). WithContext(ContextForScope(cluster.Metadata.Annotations[Scope], h.projectUID)). WithUID(cluster.Metadata.UID) resp, err := h.Client.V1SpectroClustersVMList(params) diff --git a/client/virtual_machine_lifecycle.go b/client/virtual_machine_lifecycle.go index eafdf446..a26a6a59 100644 --- a/client/virtual_machine_lifecycle.go +++ b/client/virtual_machine_lifecycle.go @@ -3,9 +3,10 @@ package client import ( "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" ) +// StartVirtualMachine starts a virtual machine. func (h *V1Client) StartVirtualMachine(clusterUID, vmName, vmNamespace string) error { cluster, err := h.GetCluster(clusterUID) if err != nil { @@ -14,7 +15,7 @@ func (h *V1Client) StartVirtualMachine(clusterUID, vmName, vmNamespace string) e if cluster == nil { return fmt.Errorf("cluster with uid %s not found", clusterUID) } - params := clientV1.NewV1SpectroClustersVMStartParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVMStartParamsWithContext(h.ctx). WithUID(clusterUID). WithVMName(vmName). WithNamespace(vmNamespace) @@ -22,6 +23,7 @@ func (h *V1Client) StartVirtualMachine(clusterUID, vmName, vmNamespace string) e return err } +// StopVirtualMachine stops a virtual machine. func (h *V1Client) StopVirtualMachine(clusterUID, vmName, vmNamespace string) error { cluster, err := h.GetCluster(clusterUID) if err != nil { @@ -30,7 +32,7 @@ func (h *V1Client) StopVirtualMachine(clusterUID, vmName, vmNamespace string) er if cluster == nil { return fmt.Errorf("cluster with uid %s not found", clusterUID) } - params := clientV1.NewV1SpectroClustersVMStopParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVMStopParamsWithContext(h.ctx). WithUID(clusterUID). WithVMName(vmName). WithNamespace(vmNamespace) @@ -38,6 +40,7 @@ func (h *V1Client) StopVirtualMachine(clusterUID, vmName, vmNamespace string) er return err } +// PauseVirtualMachine pauses a virtual machine. func (h *V1Client) PauseVirtualMachine(clusterUID, vmName, vmNamespace string) error { cluster, err := h.GetCluster(clusterUID) if err != nil { @@ -46,7 +49,7 @@ func (h *V1Client) PauseVirtualMachine(clusterUID, vmName, vmNamespace string) e if cluster == nil { return fmt.Errorf("cluster with uid %s not found", clusterUID) } - params := clientV1.NewV1SpectroClustersVMPauseParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVMPauseParamsWithContext(h.ctx). WithUID(clusterUID). WithVMName(vmName). WithNamespace(vmNamespace) @@ -54,6 +57,7 @@ func (h *V1Client) PauseVirtualMachine(clusterUID, vmName, vmNamespace string) e return err } +// ResumeVirtualMachine resumes a virtual machine. func (h *V1Client) ResumeVirtualMachine(clusterUID, vmName, vmNamespace string) error { cluster, err := h.GetCluster(clusterUID) if err != nil { @@ -62,7 +66,7 @@ func (h *V1Client) ResumeVirtualMachine(clusterUID, vmName, vmNamespace string) if cluster == nil { return fmt.Errorf("cluster with uid %s not found", clusterUID) } - params := clientV1.NewV1SpectroClustersVMResumeParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVMResumeParamsWithContext(h.ctx). WithUID(clusterUID). WithVMName(vmName). WithNamespace(vmNamespace) @@ -70,6 +74,7 @@ func (h *V1Client) ResumeVirtualMachine(clusterUID, vmName, vmNamespace string) return err } +// RestartVirtualMachine restarts a virtual machine. func (h *V1Client) RestartVirtualMachine(clusterUID, vmName, vmNamespace string) error { cluster, err := h.GetCluster(clusterUID) if err != nil { @@ -78,7 +83,7 @@ func (h *V1Client) RestartVirtualMachine(clusterUID, vmName, vmNamespace string) if cluster == nil { return fmt.Errorf("cluster with uid %s not found", clusterUID) } - params := clientV1.NewV1SpectroClustersVMRestartParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVMRestartParamsWithContext(h.ctx). WithUID(clusterUID). WithVMName(vmName). WithNamespace(vmNamespace) diff --git a/client/virtual_machine_migration.go b/client/virtual_machine_migration.go index e3accfec..ae8b2fa5 100644 --- a/client/virtual_machine_migration.go +++ b/client/virtual_machine_migration.go @@ -3,9 +3,10 @@ package client import ( "fmt" - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" ) +// MigrateVirtualMachineNodeToNode migrates a virtual machine from one node to another. func (h *V1Client) MigrateVirtualMachineNodeToNode(clusterUID, vmName, vmNamespace string) error { cluster, err := h.GetCluster(clusterUID) if err != nil { @@ -14,7 +15,7 @@ func (h *V1Client) MigrateVirtualMachineNodeToNode(clusterUID, vmName, vmNamespa if cluster == nil { return fmt.Errorf("cluster with uid %s not found", clusterUID) } - params := clientV1.NewV1SpectroClustersVMMigrateParamsWithContext(h.ctx). + params := clientv1.NewV1SpectroClustersVMMigrateParamsWithContext(h.ctx). WithUID(clusterUID). WithVMName(vmName). WithNamespace(vmNamespace) diff --git a/client/workspace.go b/client/workspace.go index 86cef305..fd89d8f4 100644 --- a/client/workspace.go +++ b/client/workspace.go @@ -1,15 +1,14 @@ package client import ( - "errors" - - clientV1 "github.com/spectrocloud/palette-api-go/client/v1" + clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" ) +// CreateWorkspace creates a new workspace. func (h *V1Client) CreateWorkspace(workspace *models.V1WorkspaceEntity) (string, error) { - params := clientV1.NewV1WorkspacesCreateParamsWithContext(h.ctx). + params := clientv1.NewV1WorkspacesCreateParamsWithContext(h.ctx). WithBody(workspace) resp, err := h.Client.V1WorkspacesCreate(params) if err != nil { @@ -18,8 +17,9 @@ func (h *V1Client) CreateWorkspace(workspace *models.V1WorkspaceEntity) (string, return *resp.Payload.UID, nil } +// GetWorkspace retrieves an existing workspace by UID. func (h *V1Client) GetWorkspace(uid string) (*models.V1Workspace, error) { - params := clientV1.NewV1WorkspacesUIDGetParamsWithContext(h.ctx). + params := clientv1.NewV1WorkspacesUIDGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1WorkspacesUIDGet(params) if apiutil.Is404(err) { @@ -30,8 +30,9 @@ func (h *V1Client) GetWorkspace(uid string) (*models.V1Workspace, error) { return resp.Payload, nil } +// GetWorkspaceByName retrieves an existing workspace by name. func (h *V1Client) GetWorkspaceByName(name string) (*models.V1DashboardWorkspace, error) { - params := clientV1.NewV1DashboardWorkspacesListParamsWithContext(h.ctx) + params := clientv1.NewV1DashboardWorkspacesListParamsWithContext(h.ctx) resp, err := h.Client.V1DashboardWorkspacesList(params) if apiutil.Is404(err) { return nil, nil @@ -46,40 +47,45 @@ func (h *V1Client) GetWorkspaceByName(name string) (*models.V1DashboardWorkspace return nil, nil } +// UpdateWorkspaceResourceAllocation updates an existing workspace's resource allocation. func (h *V1Client) UpdateWorkspaceResourceAllocation(uid string, we *models.V1WorkspaceClusterNamespacesEntity) error { - params := clientV1.NewV1WorkspacesUIDClusterNamespacesUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1WorkspacesUIDClusterNamespacesUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(we) _, err := h.Client.V1WorkspacesUIDClusterNamespacesUpdate(params) return err } -func (h *V1Client) UpdateWorkspaceRBACS(uid, rbacUid string, r *models.V1ClusterRbac) error { - params := clientV1.NewV1WorkspacesUIDClusterRbacUpdateParamsWithContext(h.ctx). +// UpdateWorkspaceRBACS updates an existing workspace's RBAC configuration. +func (h *V1Client) UpdateWorkspaceRBACS(uid, rbacUID string, r *models.V1ClusterRbac) error { + params := clientv1.NewV1WorkspacesUIDClusterRbacUpdateParamsWithContext(h.ctx). WithUID(uid). - WithClusterRbacUID(rbacUid). + WithClusterRbacUID(rbacUID). WithBody(r) _, err := h.Client.V1WorkspacesUIDClusterRbacUpdate(params) return err } +// UpdateWorkspaceBackupConfig updates an existing workspace's backup configuration. func (h *V1Client) UpdateWorkspaceBackupConfig(uid string, config *models.V1WorkspaceBackupConfigEntity) error { - params := clientV1.NewV1WorkspaceOpsBackupUpdateParamsWithContext(h.ctx). + params := clientv1.NewV1WorkspaceOpsBackupUpdateParamsWithContext(h.ctx). WithUID(uid). WithBody(config) _, err := h.Client.V1WorkspaceOpsBackupUpdate(params) return err } +// DeleteWorkspace deletes an existing workspace. func (h *V1Client) DeleteWorkspace(uid string) error { - params := clientV1.NewV1WorkspacesUIDDeleteParamsWithContext(h.ctx). + params := clientv1.NewV1WorkspacesUIDDeleteParamsWithContext(h.ctx). WithUID(uid) _, err := h.Client.V1WorkspacesUIDDelete(params) return err } +// GetWorkspaceBackup retrieves an existing workspace backup by UID. func (h *V1Client) GetWorkspaceBackup(uid string) (*models.V1WorkspaceBackup, error) { - params := clientV1.NewV1WorkspaceOpsBackupGetParamsWithContext(h.ctx). + params := clientv1.NewV1WorkspaceOpsBackupGetParamsWithContext(h.ctx). WithUID(uid) resp, err := h.Client.V1WorkspaceOpsBackupGet(params) if apiutil.Is404(err) { @@ -90,6 +96,6 @@ func (h *V1Client) GetWorkspaceBackup(uid string) (*models.V1WorkspaceBackup, er return resp.Payload, nil } -func (h *V1Client) WorkspaceBackupDelete() error { - return errors.New("not implemented") -} +// func (h *V1Client) WorkspaceBackupDelete() error { +// return errors.New("not implemented") +// }