Skip to content

Models and clients for DP cluster group #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/transport"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/backupschedule"
backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/backupschedule"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/transport"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/dataprotection"
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/dataprotection"
)

const (
Expand Down
106 changes: 106 additions & 0 deletions internal/client/clustergroup/dataprotection/dataprotection_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package clustergroupdataprotectionclient

import (
"net/url"

"github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/transport"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
dataprotectionclustergroupmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/clustergroup/dataprotection"
)

const (
apiVersionAndGroup = "v1alpha1/clustergroups"
dataProtectionPath = "dataprotection"
)

// New creates a new data protection resource service API client.
func New(transport *transport.Client) ClientService {
return &Client{Client: transport}
}

/*
Client for data protection resource service API.
*/
type Client struct {
*transport.Client
}

// ClientService is the interface for Client methods.
type ClientService interface {
ClusterGroupDataProtectionResourceServiceCreate(request *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse, error)

ClusterGroupDataProtectionResourceServiceDelete(fn *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName, destroyBackups bool) error

ClusterGroupDataProtectionResourceServiceList(fn *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse, error)

ClusterGroupDataProtectionResourceServiceUpdate(request *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse, error)
}

/*
ClusterGroupDataProtectionResourceServiceCreate enables data protection on a cluster.
*/
func (c *Client) ClusterGroupDataProtectionResourceServiceCreate(request *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest,
) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse, error) {
response := &dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse{}
requestURL := helper.ConstructRequestURL(apiVersionAndGroup, request.DataProtection.FullName.ClusterGroupName, dataProtectionPath).String()
err := c.Create(requestURL, request, response)

return response, err
}

/*
ClusterGroupDataProtectionResourceServiceDelete disables data protection on a cluster group.
*/
func (c *Client) ClusterGroupDataProtectionResourceServiceDelete(fn *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName, deleteBackups bool) error {
requestURL := helper.ConstructRequestURL(apiVersionAndGroup, fn.ClusterGroupName, dataProtectionPath)
queryParams := url.Values{}

//queryParams.Add("fullName.clusterGroupName", fn.ClusterGroupName)
//queryParams.Add("delete_backups", strconv.FormatBool(deleteBackups))

requestURL = requestURL.AppendQueryParams(queryParams)

return c.Delete(requestURL.String())
}

/*
ClusterGroupDataProtectionResourceServiceList gets data protection details.
*/
func (c *Client) ClusterGroupDataProtectionResourceServiceList(fn *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse, error) {
requestURL := helper.ConstructRequestURL(apiVersionAndGroup, fn.ClusterGroupName, dataProtectionPath)
queryParams := url.Values{}

/*if fn.ManagementClusterName != "" {
queryParams.Add("searchScope.managementClusterName", fn.ManagementClusterName)
}

if fn.ProvisionerName != "" {
queryParams.Add("searchScope.provisionerName", fn.ProvisionerName)
}*/

if len(queryParams) > 0 {
requestURL = requestURL.AppendQueryParams(queryParams)
}

resp := &dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse{}
err := c.Get(requestURL.String(), resp)

return resp, err
}

/*
ClusterGroupDataProtectionResourceServiceUpdate updates a data protection configuration on a cluster.
*/
func (c *Client) ClusterGroupDataProtectionResourceServiceUpdate(request *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest,
) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse, error) {
response := &dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse{}
requestURL := helper.ConstructRequestURL(apiVersionAndGroup, request.DataProtection.FullName.ClusterGroupName, dataProtectionPath).String()
err := c.Update(requestURL, request, response)

return response, err
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package dataprotectionmodels
package dataprotectionclustermodels

import (
"github.com/go-openapi/swag"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package dataprotectionmodels
package dataprotectionclustermodels

import (
"github.com/go-openapi/swag"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package dataprotectionmodels
package dataprotectionclustermodels

import (
"github.com/go-openapi/swag"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package dataprotectionmodels
package dataprotectionclustermodels

import (
"github.com/go-openapi/swag"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package dataprotectionmodels
package dataprotectionclustermodels

import (
"github.com/go-openapi/swag"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package dataprotectionmodels
package dataprotectionclustermodels

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package targetlocationmodels

import (
"encoding/json"
)

// VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode The permissions for a BackupStorageLocation.
//
// - READONLY: The read only access.
// - READWRITE: Read and write access.
//
// swagger:model vmware.tanzu.manage.v1alpha1.cluster.dataprotection.backuplocation.Status.BackupStorageLocationAccessMode.
type VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode string

func NewVmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode(value VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode) *VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode {
return &value
}

// Pointer returns a pointer to a freshly-allocated VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode.
func (m VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode) Pointer() *VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode {
return &m
}

const (

// VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeREADONLY captures enum value "READONLY".
VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeREADONLY VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode = "READONLY"

// VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeREADWRITE captures enum value "READWRITE".
VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeREADWRITE VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode = "READWRITE"
)

// for schema.
var vmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeEnum []interface{}

func init() {
var res []VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode

if err := json.Unmarshal([]byte(`["READONLY","READWRITE"]`), &res); err != nil {
panic(err)
}

for _, v := range res {
vmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeEnum = append(vmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeEnum, v)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package targetlocationmodels

import (
"github.com/go-openapi/swag"

clustermodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster"
clustergroupmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/clustergroup"
)

// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAssignedGroup Group of resources the backup location will be assigned to.
//
// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.AssignedGroup.
type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAssignedGroup struct {

// Full name of a cluster.
Cluster *clustermodel.VmwareTanzuManageV1alpha1ClusterFullName `json:"cluster,omitempty"`

// Full name of a cluster group.
Clustergroup *clustergroupmodel.VmwareTanzuManageV1alpha1ClustergroupFullName `json:"clustergroup,omitempty"`
}

// MarshalBinary interface implementation.
func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAssignedGroup) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}

return swag.WriteJSON(m)
}

// UnmarshalBinary interface implementation.
func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAssignedGroup) UnmarshalBinary(b []byte) error {
var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAssignedGroup

if err := swag.ReadJSON(b, &res); err != nil {
return err
}

*m = res

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package targetlocationmodels

import (
"github.com/go-openapi/swag"

objectmetamodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/objectmeta"
)

// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation A target location for backups.
//
// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.BackupLocation.
type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation struct {

// Full name for the BackupLocation.
FullName *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationFullName `json:"fullName,omitempty"`

// Metadata for the backup location object.
Meta *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectMeta `json:"meta,omitempty"`

// Spec for the backup location.
Spec *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationSpec `json:"spec,omitempty"`

// Status of the backup location.
Status *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatus `json:"status,omitempty"`

// Metadata describing the type of the resource.
Type *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectType `json:"type,omitempty"`
}

// MarshalBinary interface implementation.
func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}

return swag.WriteJSON(m)
}

// UnmarshalBinary interface implementation.
func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation) UnmarshalBinary(b []byte) error {
var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation

if err := swag.ReadJSON(b, &res); err != nil {
return err
}

*m = res

return nil
}
Loading
Loading