Skip to content

Commit

Permalink
Merge pull request #205 from NetApp/integration/main
Browse files Browse the repository at this point in the history
Integration/main
  • Loading branch information
wenjun666 authored Nov 4, 2024
2 parents 8fb6f0d + 90f7568 commit f145269
Show file tree
Hide file tree
Showing 11 changed files with 328 additions and 19 deletions.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
## 24.3.0
## 24.11.0
ENHANCEMENTS:
* resource/connector_aws: instance_type default value is set as t3.2xlarge
* resource/connector_azure: virtual_machines_size default value is set as Standard_D8s_v3
* resource/connector_gcp: machine_type default value is set as n2-standard-8

BUG FIXES:
* auth user accesToken: Fix 403 issue with authorizer API token

## 24.5.1
ENHANCEMENTS:
* remove duplicated volume documentation page.
* resource/connector_azure: adding `azure_tag` option, now supports tags.

NEW FEATURES:
* Azure and GCP connectors now support Restricted mode.

## 24.5.0
BUG FIXES:
* resoruce/volume: support `comment` update with adding 3 minutes wait time.

Expand Down
12 changes: 11 additions & 1 deletion cloudmanager/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Client struct {
Auth0Client string
ClientID string
AccountID string
IsSaas bool
Token string
AMIFilter string
AWSAccount string
Expand Down Expand Up @@ -215,7 +216,7 @@ func (c *Client) CallAWSInstanceUpdate(occmDetails createAWSOCCMDetails) error {
return err
}

log.Printf("Updated instance %s", *result.InstanceMetadataOptions, *result.InstanceId)
log.Printf("Updated instance %s, InstanceId %s", *result.InstanceMetadataOptions, *result.InstanceId)
return nil
}

Expand Down Expand Up @@ -310,6 +311,15 @@ func (c *Client) CallDeployAzureVM(occmDetails createOCCMDetails) (string, error
"value": occmDetails.Location,
}

tags := make(map[string]interface{})
if occmDetails.AzureTags != nil {
tags = occmDetails.AzureTags

}
(*params)["tags"] = map[string]interface{}{
"value": tags,
}

(*params)["adminUsername"] = map[string]string{
"value": occmDetails.AdminUsername,
}
Expand Down
4 changes: 3 additions & 1 deletion cloudmanager/cloudmanager/restapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func (c *Client) Do(baseURL string, hostType string, token string, paramsNil boo
} else if hostType == "GCPCompute" {
host = c.GCPCompute
gcpType = true
} else {
host = hostType
}
httpReq, err := req.BuildHTTPReq(host, token, c.Audience, baseURL, paramsNil, accountID, clientID, gcpType, simulator)
if err != nil {
Expand All @@ -77,7 +79,7 @@ func (c *Client) Do(baseURL string, hostType string, token string, paramsNil boo
}

if res == nil {
return statusCode, res, onCloudRequestID, errors.New("No result returned in REST response")
return statusCode, res, onCloudRequestID, errors.New("no result returned in REST response")
}

statusCode = httpRes.StatusCode
Expand Down
33 changes: 26 additions & 7 deletions cloudmanager/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1331,10 +1331,30 @@ func (c *Client) upgradeOntapVersionAvailable(apiRoot string, id string, ontapVe
return "", fmt.Errorf("working environment %s: no upgrade version availble", id)
}

func (c *Client) setOCCMConfig(request configValuesUpdateRequest, clientID string) error {
func (c *Client) setOCCMConfig(request configValuesUpdateRequest, clientID string, isSAAS bool, occmDetails createOCCMDetails) error {
log.Print("setOCCMConfig: set OCCM configuration")

hostType := "CloudManagerHost"
connectorIP := ""
if !isSAAS {
vm, err := c.getVMInstance(occmDetails, clientID)
if err != nil {
log.Print("Error creating instance")
return err
}
if len(vm["networkInterfaces"].([]interface{})) > 0 {
accessConfigs := vm["networkInterfaces"].([]interface{})[0].(map[string]interface{})["accessConfigs"]
if len(accessConfigs.([]interface{})) > 0 {
connectorIP = vm["networkInterfaces"].([]interface{})[0].(map[string]interface{})["accessConfigs"].([]interface{})[0].(map[string]interface{})["natIP"].(string)
}
}
}

hostType := ""
if isSAAS {
hostType = "CloudManagerHost"
} else {
hostType = "http://" + connectorIP
}
if c.Token == "" {
accesTokenResult, err := c.getAccessToken()
if err != nil {
Expand All @@ -1347,17 +1367,16 @@ func (c *Client) setOCCMConfig(request configValuesUpdateRequest, clientID strin
params := structs.Map(request)
log.Printf("\tparams: %+v", params)
statusCode, response, _, err := c.CallAPIMethod("PUT", baseURL, params, c.Token, hostType, clientID)
if err != nil {
log.Print("setOCCMConfig request failed ", statusCode)
return err
}

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

if err != nil {
log.Print("setOCCMConfig request failed ", statusCode)
return err
}

var result configValuesResponse
if err := json.Unmarshal(response, &result); err != nil {
log.Print("Failed to unmarshall response from setOCCMConfig ", err)
Expand Down
43 changes: 42 additions & 1 deletion cloudmanager/occm_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type createOCCMDetails struct {
EnableTerminationProtection *bool
AwsTags []userTags
Tags []string
AzureTags map[string]interface{}
StorageAccount string
Labels map[string]string
}
Expand Down Expand Up @@ -146,7 +147,7 @@ type accesTokenRequest struct {
Audience string `structs:"audience"`
GrantType string `structs:"grant_type"`
RefreshToken string `structs:"refresh_token"`
ClientSecret string `structs:"client_secret"`
ClientSecret string `structs:"client_secret,omitempty"`
ClientID string `structs:"client_id"`
}

Expand Down Expand Up @@ -193,6 +194,7 @@ type accountResult struct {
type accountIDResult struct {
AccountID string `json:"accountPublicId"`
AccountName string `json:"accountName"`
IsSAAS bool `json:"isSaas"`
}

// listOCCMResult lists the details for given Client ID
Expand Down Expand Up @@ -360,6 +362,45 @@ func (c *Client) getAccount(clientID string) (string, error) {
return result[0].AccountID, nil
}

func (c *Client) getAccountDetails(clientID string) (accountIDResult, error) {

log.Print("getAccountDetails")

baseURL := "/tenancy/account"

hostType := "CloudManagerHost"

statusCode, response, _, err := c.CallAPIMethod("GET", baseURL, nil, c.Token, hostType, clientID)
if err != nil {
log.Print("getAccountDetails request failed ", statusCode)
return accountIDResult{}, err
}

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

var result []accountIDResult
if err := json.Unmarshal(response, &result); err != nil {
log.Print("Failed to unmarshall response from getAccountDetails ", err)
return accountIDResult{}, err
}

if len(result) == 0 {
return accountIDResult{}, fmt.Errorf("no account found: %s", c.AccountID)
}

var resultAccount accountIDResult
for _, account := range result {
if account.AccountID == c.AccountID {
resultAccount = account
}
}

return resultAccount, nil
}

func (c *Client) createAccount(clientID string) (string, error) {

log.Print("createAccount")
Expand Down
11 changes: 11 additions & 0 deletions cloudmanager/occm_azure_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ func (c *Client) callParameters() string {
"location": {
"value": "string"
},
"tags": {
"value": "object"
},
"virtualMachineName": {
"value": "string"
},
Expand Down Expand Up @@ -46,6 +49,9 @@ func (c *Client) callTemplate() string {
"type": "string",
"defaultValue": "eastus"
},
"tags": {
"type": "object"
},
"virtualMachineName": {
"type": "string"
},
Expand Down Expand Up @@ -97,6 +103,7 @@ func (c *Client) callTemplate() string {
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2018-04-01",
"location": "[parameters('location')]",
"tags": "[parameters('tags')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]",
"[concat('Microsoft.Storage/storageAccounts/', variables('diagnosticsStorageAccountName'))]"
Expand Down Expand Up @@ -236,6 +243,9 @@ func (c *Client) callTemplateDisablePublicIP() string {
"type": "string",
"defaultValue": "eastus"
},
"tags": {
"type": "object"
},
"virtualMachineName": {
"type": "string"
},
Expand Down Expand Up @@ -287,6 +297,7 @@ func (c *Client) callTemplateDisablePublicIP() string {
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2018-04-01",
"location": "[parameters('location')]",
"tags": "[parameters('tags')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]",
"[concat('Microsoft.Storage/storageAccounts/', variables('diagnosticsStorageAccountName'))]"
Expand Down
2 changes: 1 addition & 1 deletion cloudmanager/occm_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func (c *Client) setVMInstaceTags(occmDetails createOCCMDetails, fingerprint str
if err != nil {
return err
}
baseURL := fmt.Sprintf("/compute/v1/projects/%s/zones/%s/instances/%s-vm/setTags", occmDetails.GCPProject, occmDetails.Region, occmDetails.Name)
baseURL := fmt.Sprintf("/compute/v1/projects/%s/zones/%s/instances/%s-vm/setTags", occmDetails.GCPProject, occmDetails.Zone, occmDetails.Name)
hostType := "GCPDeploymentManager"
body := make(map[string]interface{})
body["items"] = occmDetails.Tags
Expand Down
2 changes: 1 addition & 1 deletion cloudmanager/resource_netapp_cloudmanager_connector_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func resourceOCCMAWS() *schema.Resource {
"instance_type": {
Type: schema.TypeString,
Optional: true,
Default: "t3.xlarge",
Default: "t3.2xlarge",
ForceNew: true,
},
"subnet_id": {
Expand Down
28 changes: 27 additions & 1 deletion cloudmanager/resource_netapp_cloudmanager_connector_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func resourceOCCMAzure() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "Standard_DS3_v2",
Default: "Standard_D8s_v3",
},
"network_security_group_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -142,6 +142,23 @@ func resourceOCCMAzure() *schema.Resource {
Optional: true,
ForceNew: true,
},
"azure_tag": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tag_key": {
Type: schema.TypeString,
Required: true,
},
"tag_value": {
Type: schema.TypeString,
Required: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -223,6 +240,15 @@ func resourceOCCMAzureCreate(d *schema.ResourceData, meta interface{}) error {
occmDetails.StorageAccount = o.(string)
}

if o, ok := d.GetOk("azure_tag"); ok {
tags := make(map[string]interface{})
for _, v := range o.(*schema.Set).List() {
tag := v.(map[string]interface{})
tags[tag["tag_key"].(string)] = tag["tag_value"].(string)
}
occmDetails.AzureTags = tags
}

res, err := client.createOCCMAzure(occmDetails, proxyCertificates, "")
if err != nil {
log.Print("Error creating instance")
Expand Down
34 changes: 29 additions & 5 deletions cloudmanager/resource_netapp_cloudmanager_connector_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func resourceOCCMGCP() *schema.Resource {
"machine_type": {
Type: schema.TypeString,
Optional: true,
Default: "n2-standard-4",
Default: "n2-standard-8",
ForceNew: true,
},
"subnet_id": {
Expand Down Expand Up @@ -283,16 +283,22 @@ func resourceOCCMGCPCreate(d *schema.ResourceData, meta interface{}) error {
return err
}

account, err := client.getAccountDetails(res.ClientID)
if err != nil {
log.Print("Error creating instance")
return err
}

d.SetId(occmDetails.Name)
if err := d.Set("client_id", res.ClientID); err != nil {
return fmt.Errorf("error reading occm client_id: %s", err)
}

if err := d.Set("account_id", res.AccountID); err != nil {
if err := d.Set("account_id", account.AccountID); err != nil {
return fmt.Errorf("error reading occm account_id: %s", err)
}

if err := client.setOCCMConfig(occmConfig, res.ClientID); err != nil {
if err := client.setOCCMConfig(occmConfig, res.ClientID, account.IsSAAS, occmDetails); err != nil {
return fmt.Errorf("error set occm config: %s", err)
}

Expand Down Expand Up @@ -500,6 +506,10 @@ func resourceOCCMGCPUpdate(d *schema.ResourceData, meta interface{}) error {
}

}
client.GCPServiceAccountKey, err = getGCPServiceAccountKey(d)
if err != nil {
return err
}
occmDetails.Company = d.Get("company").(string)
clientID := d.Get("client_id").(string)
client.AccountID = d.Get("account_id").(string)
Expand All @@ -521,8 +531,18 @@ func resourceOCCMGCPUpdate(d *schema.ResourceData, meta interface{}) error {
if o, ok := d.GetOk("gcp_enable_os_login_sk"); ok {
occmConfig.GcpEnableOsLoginSk = o.(bool)
}
if err := client.setOCCMConfig(occmConfig, clientID); err != nil {
return fmt.Errorf("error set occm config: %s", err)
accesTokenResult, err := client.getAccessToken()
if err != nil {
log.Print("Error Updating OCCM, error in getting access token")
return err
}
log.Print("getAccessToken ", accesTokenResult.Token)
client.Token = accesTokenResult.Token

account, err := client.getAccountDetails(clientID)
if err != nil {
log.Print("Error Updating OCCM, error in getting account details")
return err
}

if d.HasChange("tags") {
Expand Down Expand Up @@ -567,6 +587,10 @@ func resourceOCCMGCPUpdate(d *schema.ResourceData, meta interface{}) error {
}
}

if err := client.setOCCMConfig(occmConfig, clientID, account.IsSAAS, occmDetails); err != nil {
return fmt.Errorf("error set occm config: %s", err)
}

return resourceOCCMGCPRead(d, meta)
}

Expand Down
Loading

0 comments on commit f145269

Please sign in to comment.