Skip to content

Commit

Permalink
Merge pull request #13 from NetApp/integration/main
Browse files Browse the repository at this point in the history
Integration/main
  • Loading branch information
wenjun666 authored Nov 10, 2020
2 parents b65244c + 52e0110 commit 2123639
Show file tree
Hide file tree
Showing 10 changed files with 394 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ cp $GOPATH/bin/terraform-provider-netapp-cloudmanager /tmp/terraform/netapp.com/
#### Local installation - mac

```
mkdir -p /tmp/terraform/netapp.com/netapp/netapp-cloudmanager/20.10.0/darwin_amd64
cp $GOPATH/bin/terraform-provider-netapp-cloudmanager /tmp/terraform/netapp.com/netapp/netapp-cloudmanager/20.10.0/darwin_amd64
mkdir -p ~/.terraform.d/plug-in/netapp.com/netapp/netapp-cloudmanager/20.10.0/darwin_amd64
cp $GOPATH/bin/terraform-provider-netapp-cloudmanager ~/.terraform.d/plug-in/netapp.com/netapp/netapp-cloudmanager/20.10.0/darwin_amd64
```

#### Check the provider can be loaded
Expand Down
46 changes: 43 additions & 3 deletions cloudmanager/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ type deleteAggregateRequest struct {
Name string `structs:"name"`
}

type updateAggregateRequest struct {
WorkingEnvironmentID string `structs:"workingEnvironmentId"`
Name string `structs:"name"`
NumberOfDisks int `structs:"numberOfDisks"`
}

// get aggregate by workingEnvironmentId+aggregate name
func (c *Client) getAggregate(request aggregateRequest, name string) (aggregateResult, error) {
log.Printf("getAggregate %s...", name)
Expand Down Expand Up @@ -165,7 +171,7 @@ func (c *Client) createAggregate(request *createAggregateRequest) (aggregateResu

statusCode, response, onCloudRequestID, err := c.CallAPIMethod("POST", baseURL, params, c.Token, hostType)
if err != nil {
log.Print("CreateAggregate request failed")
log.Print("createAggregate request failed")
return aggregateResult{}, err
}

Expand All @@ -192,7 +198,7 @@ func (c *Client) createAggregate(request *createAggregateRequest) (aggregateResu

// delete aggregate
func (c *Client) deleteAggregate(request deleteAggregateRequest) error {
log.Print("deleteAggregate... ")
log.Print("On deleteAggregate... ")
hostType := "CloudManagerHost"

var baseURL string
Expand All @@ -207,7 +213,7 @@ func (c *Client) deleteAggregate(request deleteAggregateRequest) error {

statusCode, response, onCloudRequestID, err := c.CallAPIMethod("DELETE", baseURL, nil, c.Token, hostType)
if err != nil {
log.Print("DeleteAggregate request failed")
log.Print("deleteAggregate request failed")
return err
}

Expand All @@ -225,6 +231,40 @@ func (c *Client) deleteAggregate(request deleteAggregateRequest) error {
return nil
}

func (c *Client) updateAggregate(request updateAggregateRequest) error {
log.Print("updateAggregate... ")
params := structs.Map(request)
hostType := "CloudManagerHost"

var baseURL string
rootURL, _, err := c.getAPIRoot(request.WorkingEnvironmentID)

if err != nil {
log.Print("updateAggregate: Cannot get API root.")
return err
}
baseURL = fmt.Sprintf("%s/aggregates/%s/%s/disks", rootURL, request.WorkingEnvironmentID, request.Name)

statusCode, response, onCloudRequestID, err := c.CallAPIMethod("POST", baseURL, params, c.Token, hostType)
if err != nil {
log.Print("updateAggregate request failed")
return err
}

responseError := apiResponseChecker(statusCode, response, "updateAggregate")
if responseError != nil {
return responseError
}

log.Print("Wait for aggregate update.")
err = c.waitOnCompletion(onCloudRequestID, "Aggregate", "update", 10, 60)
if err != nil {
return err
}

return nil
}

// flattenCapacity: convert struct size + unit
func flattenCapacity(c capacity) interface{} {
flattened := make(map[string]interface{})
Expand Down
29 changes: 25 additions & 4 deletions cloudmanager/cvo_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// GCPLicenseTypes is the GCP License types
var GCPLicenseTypes = []string{"gcp-cot-standard-paygo", "gcp-cot-explore-paygo", "gcp-cot-premium-paygo", "gcp-cot-premium-byol"}
var GCPLicenseTypes = []string{"gcp-cot-standard-paygo", "gcp-cot-explore-paygo", "gcp-cot-premium-paygo", "gcp-cot-premium-byol", "gcp-ha-cot-standard-paygo", "gcp-ha-cot-premium-paygo", "gcp-ha-cot-explore-paygo", "gcp-ha-cot-premium-byol"}

// createCVOGCPDetails the users input for creating a CVO
type createCVOGCPDetails struct {
Expand All @@ -35,6 +35,8 @@ type createCVOGCPDetails struct {
SerialNumber string `structs:"serialNumber,omitempty"`
GCPLabels []gcpLabels `structs:"gcpLabels,omitempty"`
FirewallRule string `structs:"firewallRule,omitempty"`
IsHA bool
HAParams haParamsGCP `structs:"haParams,omitempty"`
}

// gcpLabels the input for requesting a CVO
Expand All @@ -43,6 +45,25 @@ type gcpLabels struct {
LabelValue string `structs:"labelValue,omitempty"`
}

// haParamsGCP the input for requesting a CVO
type haParamsGCP struct {
Node1Zone string `structs:"node1Zone,omitempty"`
Node2Zone string `structs:"node2Zone,omitempty"`
MediatorZone string `structs:"mediatorZone,omitempty"`
VPC0NodeAndDataConnectivity string `structs:"vpc0NodeAndDataConnectivity,omitempty"`
VPC1ClusterConnectivity string `structs:"vpc1ClusterConnectivity,omitempty"`
VPC2HAConnectivity string `structs:"vpc2HAConnectivity,omitempty"`
VPC3DataReplication string `structs:"vpc3DataReplication,omitempty"`
Subnet0NodeAndDataConnectivity string `structs:"subnet0NodeAndDataConnectivity,omitempty"`
Subnet1ClusterConnectivity string `structs:"subnet1ClusterConnectivity,omitempty"`
Subnet2HAConnectivity string `structs:"subnet2HAConnectivity,omitempty"`
Subnet3DataReplication string `structs:"subnet3DataReplication,omitempty"`
VPC0FirewallRuleName string `structs:"vpc0FirewallRuleName,omitempty"`
VPC1FirewallRuleName string `structs:"vpc1FirewallRuleName,omitempty"`
VPC2FirewallRuleName string `structs:"vpc2FirewallRuleName,omitempty"`
VPC3FirewallRuleName string `structs:"vpc3FirewallRuleName,omitempty"`
}

func (c *Client) createCVOGCP(cvoDetails createCVOGCPDetails) (cvoResult, error) {

log.Print("createCVO")
Expand Down Expand Up @@ -74,7 +95,7 @@ func (c *Client) createCVOGCP(cvoDetails createCVOGCPDetails) (cvoResult, error)
cvoDetails.NssAccount = nssAccount
}

baseURL := "/occm/api/gcp/vsa/working-environments"
baseURL := c.getAPIRootForWorkingEnvironment(cvoDetails.IsHA, "")

hostType := "CloudManagerHost"
params := structs.Map(cvoDetails)
Expand Down Expand Up @@ -104,7 +125,7 @@ func (c *Client) createCVOGCP(cvoDetails createCVOGCPDetails) (cvoResult, error)
return result, nil
}

func (c *Client) deleteCVOGCP(id string) error {
func (c *Client) deleteCVOGCP(id string, isHA bool) error {

log.Print("deleteCVO")

Expand All @@ -115,7 +136,7 @@ func (c *Client) deleteCVOGCP(id string) error {
}
c.Token = accessTokenResult.Token

baseURL := fmt.Sprintf("/occm/api/gcp/vsa/working-environments/%s", id)
baseURL := c.getAPIRootForWorkingEnvironment(isHA, id)

hostType := "CloudManagerHost"

Expand Down
22 changes: 22 additions & 0 deletions cloudmanager/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,25 @@ func (c *Client) getAPIRoot(workingEnvironmentID string) (string, string, error)
log.Printf("API root = %s", baseURL)
return baseURL, workingEnvDetail.CloudProviderName, nil
}

func (c *Client) getAPIRootForWorkingEnvironment(isHA bool, workingEnvironmentID string) string {

var baseURL string

if workingEnvironmentID == "" {
if isHA == true {
baseURL = "/occm/api/gcp/ha/working-environments"
} else {
baseURL = "/occm/api/gcp/vsa/working-environments"
}
} else {
if isHA == true {
baseURL = fmt.Sprintf("/occm/api/gcp/ha/working-environments/%s", workingEnvironmentID)
} else {
baseURL = fmt.Sprintf("/occm/api/gcp/vsa/working-environments/%s", workingEnvironmentID)
}
}

log.Printf("API root = %s", baseURL)
return baseURL
}
43 changes: 41 additions & 2 deletions cloudmanager/resource_netapp_cloudmanager_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func resourceAggregate() *schema.Resource {
Read: resourceAggregateRead,
Delete: resourceAggregateDelete,
Exists: resourceAggregateExists,
Update: resourceAggregateUpdate,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Expand Down Expand Up @@ -42,7 +43,6 @@ func resourceAggregate() *schema.Resource {
"number_of_disks": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
"disk_size_size": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -224,12 +224,50 @@ func resourceAggregateDelete(d *schema.ResourceData, meta interface{}) error {
return nil
}

func resourceAggregateUpdate(d *schema.ResourceData, meta interface{}) error {
log.Printf("Updating Aggregate: %#v", d)
client := meta.(*Client)
client.ClientID = d.Get("client_id").(string)
request := updateAggregateRequest{}

if a, ok := d.GetOk("working_environment_id"); ok {
request.WorkingEnvironmentID = a.(string)
} else if a, ok = d.GetOk("working_environment_name"); ok {
workingEnvDetail, err := client.findWorkingEnvironmentByName(a.(string))
if err != nil {
return fmt.Errorf("Cannot find working environment by working_environment_name %s", a.(string))
}
request.WorkingEnvironmentID = workingEnvDetail.PublicID
} else {
return fmt.Errorf("Cannot find working environment by working_enviroment_id or working_environment_name")
}

request.Name = d.Get("name").(string)

if d.HasChange("number_of_disks") {
currentNumber, expectNumber := d.GetChange("number_of_disks")
if expectNumber.(int) > currentNumber.(int) {
request.NumberOfDisks = expectNumber.(int) - currentNumber.(int)
} else {
d.Set("number_of_disks", currentNumber)
return fmt.Errorf("Aggregate: number_of_disks cannot be reduced")
}
}
updateErr := client.updateAggregate(request)
if updateErr != nil {
return updateErr
}

log.Printf("Updated aggregate; %v", request.Name)

return resourceAggregateRead(d, meta)
}

func resourceAggregateExists(d *schema.ResourceData, meta interface{}) (bool, error) {
log.Printf("Checking existence of Aggregate: %#v", d)
client := meta.(*Client)

client.ClientID = d.Get("client_id").(string)
id := d.Get("name").(string)
aggregate := aggregateRequest{}
if a, ok := d.GetOk("working_environment_id"); ok {
aggregate.WorkingEnvironmentID = a.(string)
Expand All @@ -243,6 +281,7 @@ func resourceAggregateExists(d *schema.ResourceData, meta interface{}) (bool, er
return false, fmt.Errorf("Cannot find working environment by working_enviroment_id or working_environment_name")
}

id := d.Id()
res, err := client.getAggregate(aggregate, id)
if err != nil {
log.Print("Error getting aggregate")
Expand Down
22 changes: 22 additions & 0 deletions cloudmanager/resource_netapp_cloudmanager_aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ func TestAccAggregate_basic(t *testing.T) {
testAccCheckAggregateExists("netapp-cloudmanager_aggregate.cl-aggregate2", &aggregate),
),
},
{
Config: testAccAggregateConfigUpdateAggregate(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAggregateExists("netapp-cloudmanager_aggregate.cl-aggregate2", &aggregate),
resource.TestCheckResourceAttr("netapp-cloudmanager_aggregate.cl-aggregate2", "number_of_disks", "2"),
),
},
},
})
}
Expand Down Expand Up @@ -132,3 +139,18 @@ func testAccAggregateConfigCreateByWorkingEnvironmentName() string {
}
`)
}

func testAccAggregateConfigUpdateAggregate() string {
return fmt.Sprintf(`
resource "netapp-cloudmanager_aggregate" "cl-aggregate2" {
provider = netapp-cloudmanager
name = "acc_test_aggr_2"
provider_volume_type = "gp2"
client_id = "Nw4Q2O1kdnLtvhwegGalFnodEHUfPJWh"
working_environment_name = "testAWS"
number_of_disks = 2
disk_size_size = 100
disk_size_unit = "GB"
}
`)
}
Loading

0 comments on commit 2123639

Please sign in to comment.