Skip to content

Commit

Permalink
Sync bitbucket and GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
carchi8py committed Nov 6, 2020
1 parent c1ff332 commit 52e0110
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 7 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
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"
}
`)
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ require (
github.com/Azure/go-autorest/autorest/azure/auth v0.5.3
github.com/aws/aws-sdk-go v1.35.5
github.com/fatih/structs v1.1.0
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/terraform v0.13.4
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/sirupsen/logrus v1.7.0
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
golang.org/x/tools v0.0.0-20201008025239-9df69603baec // indirect
k8s.io/client-go v11.0.0+incompatible // indirect
)
Loading

0 comments on commit 52e0110

Please sign in to comment.