Skip to content

Commit

Permalink
protection policies create development
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroon-Dweikat-Ntx committed Dec 30, 2024
1 parent d2551ef commit f118472
Show file tree
Hide file tree
Showing 7 changed files with 622 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
// github.com/nutanix-core/ntnx-api-golang-sdk-internal/vmm-go-client/v16 v16.9.0-9781
// github.com/nutanix-core/ntnx-api-golang-sdk-internal/volumes-go-client/v16 v16.9.0-9552
github.com/nutanix/ntnx-api-golang-clients/clustermgmt-go-client/v4 v4.0.1
github.com/nutanix/ntnx-api-golang-clients/datapolicies-go-client/v4 v4.0.1
github.com/nutanix/ntnx-api-golang-clients/dataprotection-go-client/v4 v4.0.1
github.com/nutanix/ntnx-api-golang-clients/iam-go-client/v4 v4.0.1
github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4 v4.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
github.com/nutanix/ntnx-api-golang-clients/clustermgmt-go-client/v4 v4.0.1 h1:OmOuXNY2DSsR4GUwECV2N6YK5OywXjwEFQSZou6x2HQ=
github.com/nutanix/ntnx-api-golang-clients/clustermgmt-go-client/v4 v4.0.1/go.mod h1:sd4Fnk6MVfEDVY+8WyRoQTmLhi2SgZ3riySWErVHf8E=
github.com/nutanix/ntnx-api-golang-clients/datapolicies-go-client/v4 v4.0.1 h1:hxPJFARcKD2G9WrPhfX8YlzSoL73/MtWdtIfEQopnw4=
github.com/nutanix/ntnx-api-golang-clients/datapolicies-go-client/v4 v4.0.1/go.mod h1:rucOCp3ocrHS9juBpJGQYPfftCiTlI4fXvy5dirKlz8=
github.com/nutanix/ntnx-api-golang-clients/dataprotection-go-client/v4 v4.0.1 h1:IaTTfK9Uy7uUE70b3h8G55/p6LHTwt2lHU33subKyJQ=
github.com/nutanix/ntnx-api-golang-clients/dataprotection-go-client/v4 v4.0.1/go.mod h1:S07bx9/6uUbMOY/OUJsaIUdvZ/LDaE46Kx9VX7Pt7Ek=
github.com/nutanix/ntnx-api-golang-clients/iam-go-client/v4 v4.0.1 h1:zWbA2qtSJt0WsBcEhqqv6FQTSz8pIwBnHA5etaQg4qo=
Expand Down
7 changes: 7 additions & 0 deletions nutanix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nutanix

import (
"fmt"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/datapolicies"

"github.com/terraform-providers/terraform-provider-nutanix/nutanix/client"
era "github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v3/era"
Expand Down Expand Up @@ -111,6 +112,10 @@ func (c *Config) Client() (*Client, error) {
if err != nil {
return nil, err
}
dataPoliciesClient, err := datapolicies.NewDataPoliciesClient(configCreds)
if err != nil {
return nil, err
}
return &Client{
WaitTimeout: c.WaitTimeout,
API: v3Client,
Expand All @@ -126,6 +131,7 @@ func (c *Config) Client() (*Client, error) {
VolumeAPI: volumeClient,
DataProtectionAPI: dataprotectionClient,
VmmAPI: vmmClient,
DataPoliciesAPI: dataPoliciesClient,
}, nil
}

Expand All @@ -145,4 +151,5 @@ type Client struct {
VolumeAPI *volumes.Client
DataProtectionAPI *dataprotection.Client
VmmAPI *vmm.Client
DataPoliciesAPI *datapolicies.Client
}
2 changes: 2 additions & 0 deletions nutanix/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/datapoliciesv2"
"log"
"strings"

Expand Down Expand Up @@ -379,6 +380,7 @@ func Provider() *schema.Provider {
"nutanix_recovery_points_v2": dataprotectionv2.ResourceNutanixRecoveryPointsV2(),
"nutanix_recovery_point_replicate_v2": dataprotectionv2.ResourceNutanixRecoveryPointReplicateV2(),
"nutanix_recovery_point_restore_v2": dataprotectionv2.ResourceNutanixRecoveryPointRestoreV2(),
"nutanix_protection_policy_v2": datapoliciesv2.ResourceNutanixProtectionPoliciesV2(),
"nutanix_vm_revert_v2": vmmv2.ResourceNutanixRevertVMRecoveryPointV2(),
"nutanix_virtual_machine_v2": vmmv2.ResourceNutanixVirtualMachineV2(),
"nutanix_vm_shutdown_action_v2": vmmv2.ResourceNutanixVmsShutdownActionV2(),
Expand Down
35 changes: 35 additions & 0 deletions nutanix/sdks/v4/datapolicies/datapolicies.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package datapolicies

import (
"github.com/nutanix/ntnx-api-golang-clients/datapolicies-go-client/v4/api"
datapolicies "github.com/nutanix/ntnx-api-golang-clients/datapolicies-go-client/v4/client"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/client"
)

type Client struct {
APIClientInstance *datapolicies.ApiClient
ProtectionPolicies *api.ProtectionPoliciesApi
}

func NewDataPoliciesClient(credentials client.Credentials) (*Client, error) {
var baseClient *datapolicies.ApiClient

// check if all required fields are present. Else create an empty client
if credentials.Username != "" && credentials.Password != "" && credentials.Endpoint != "" {
pcClient := datapolicies.NewApiClient()

pcClient.Host = credentials.Endpoint
pcClient.Password = credentials.Password
pcClient.Username = credentials.Username
pcClient.Port = 9440
pcClient.VerifySSL = false

baseClient = pcClient
}

f := &Client{
ProtectionPolicies: api.NewProtectionPoliciesApi(baseClient),
}

return f, nil
}
9 changes: 9 additions & 0 deletions nutanix/services/datapoliciesv2/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package datapoliciesv2

func expandListOfString(list []interface{}) []string {
stringListStr := make([]string, len(list))
for i, v := range list {
stringListStr[i] = v.(string)
}
return stringListStr
}
Loading

0 comments on commit f118472

Please sign in to comment.