Skip to content

Commit

Permalink
Merge pull request #137 from NetApp/integration/main
Browse files Browse the repository at this point in the history
Integration/main
  • Loading branch information
wenjun666 authored Oct 17, 2022
2 parents a63d05d + 27c2604 commit 9b17c9b
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 51 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## 22.9.1
## 22.10.0
NEW FEATURES:
* resource/connector_snapmirror: support fsx as a source for snapmirror relationship with cvo.
* resource/cvo_aws: add `retries` parameter to increase wait time when creating CVO.
* resource/cvo_azure: add `retries` parameter to increase wait time when creating CVO.
* resource/cvo_gcp: add `retries` parameter to increase wait time when creating CVO.

NEW ENHANCEMENTS:
* resource/connector_azure: display the deployed virtual machine principal_id in state file on the connector azure creation.
* resource/cvo_azure: add availability_zone_node1 and availability_zone_node2 to support HA deployment.
* resoruce/cvo_azure: add new support value "Premium_ZRS" in paramter storage_type.

## 22.9.1
NEW FEATURES:
* resource/connector_snapmirror: support fsx as a source for snapmirror relationship with fsx/onprem.

Expand Down
19 changes: 18 additions & 1 deletion cloudmanager/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Client struct {
GCPDeploymentTemplate string
GCPServiceAccountKey string
CVSHostName string
Retries int

initOnce sync.Once
instanceInput *restapi.Client
Expand Down Expand Up @@ -345,13 +346,29 @@ func (c *Client) CallDeployAzureVM(occmDetails createOCCMDetails) (string, error
if err != nil {
return "", err
}

log.Print("Wait for completion...")
err = deploymentFuture.Future.WaitForCompletionRef(context.Background(), deploymentsClient.BaseClient.Client)
if err != nil {
return "", err
}

return "", nil
// get principal id
log.Print("Retrieve the vm...")
vmClient := compute.NewVirtualMachinesClient(occmDetails.SubscriptionID)
vmClient.Authorizer = authorizer
vmFuture, err := vmClient.Get(
context.Background(),
occmDetails.ResourceGroup,
occmDetails.Name,
"",
)
if err != nil {
return "", fmt.Errorf("cannot retrieve vm: %v", err)
}
principalID := *vmFuture.Identity.PrincipalID

return principalID, nil

}

Expand Down
9 changes: 5 additions & 4 deletions cloudmanager/cvo_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,15 @@ func (c *Client) createCVOAWS(cvoDetails createCVOAWSDetails, clientID string) (
}

var baseURL string
var creationWaitTime int
var CreationRetries int

log.Print("retries ", c.Retries)
if cvoDetails.IsHA == false {
baseURL = "/occm/api/vsa/working-environments"
creationWaitTime = 60
CreationRetries = c.Retries
} else if cvoDetails.IsHA == true {
baseURL = "/occm/api/aws/ha/working-environments"
creationWaitTime = 90
CreationRetries = c.Retries + 30
}

hostType := "CloudManagerHost"
Expand All @@ -305,7 +306,7 @@ func (c *Client) createCVOAWS(cvoDetails createCVOAWSDetails, clientID string) (
return cvoResult{}, responseError
}

err = c.waitOnCompletion(onCloudRequestID, "CVO", "create", creationWaitTime, 60, clientID)
err = c.waitOnCompletion(onCloudRequestID, "CVO", "create", CreationRetries, 60, clientID)
if err != nil {
return cvoResult{}, err
}
Expand Down
11 changes: 7 additions & 4 deletions cloudmanager/cvo_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type azureEncryptionParameters struct {
type haParamsAzure struct {
PlatformSerialNumberNode1 string `structs:"platformSerialNumberNode1,omitempty"`
PlatformSerialNumberNode2 string `structs:"platformSerialNumberNode2,omitempty"`
AvailabilityZoneNode1 int `structs:"availabilityZoneNode1,omitempty"`
AvailabilityZoneNode2 int `structs:"availabilityZoneNode2,omitempty"`
EnableHTTPS bool `structs:"enableHttps"`
}

Expand Down Expand Up @@ -240,14 +242,15 @@ func (c *Client) createCVOAzure(cvoDetails createCVOAzureDetails, clientID strin
}

var baseURL string
var creationWaitTime int
var CreationRetries int

log.Print("retries ", c.Retries)
if cvoDetails.IsHA == false {
baseURL = "/occm/api/azure/vsa/working-environments"
creationWaitTime = 60
CreationRetries = c.Retries
} else if cvoDetails.IsHA == true {
baseURL = "/occm/api/azure/ha/working-environments"
creationWaitTime = 90
CreationRetries = c.Retries + 30
}

log.Print(baseURL)
Expand All @@ -266,7 +269,7 @@ func (c *Client) createCVOAzure(cvoDetails createCVOAzureDetails, clientID strin
return cvoResult{}, responseError
}

err = c.waitOnCompletion(onCloudRequestID, "CVO", "create", creationWaitTime, 60, clientID)
err = c.waitOnCompletion(onCloudRequestID, "CVO", "create", CreationRetries, 60, clientID)
if err != nil {
return cvoResult{}, err
}
Expand Down
10 changes: 9 additions & 1 deletion cloudmanager/cvo_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,15 @@ func (c *Client) createCVOGCP(cvoDetails createCVOGCPDetails, clientID string) (
return cvoResult{}, responseError
}

err = c.waitOnCompletion(onCloudRequestID, "CVO", "create", 60, 60, clientID)
log.Print("retries ", c.Retries)
var CreationRetries int
if cvoDetails.IsHA == false {
CreationRetries = c.Retries
} else if cvoDetails.IsHA == true {
CreationRetries = c.Retries + 30
}

err = c.waitOnCompletion(onCloudRequestID, "CVO", "create", CreationRetries, 60, clientID)
if err != nil {
return cvoResult{}, err
}
Expand Down
35 changes: 24 additions & 11 deletions cloudmanager/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,16 @@ func (c *Client) getWorkingEnvironmentDetailForSnapMirror(d *schema.ResourceData
if strings.HasPrefix(WorkingEnvironmentID, "fs-") {
if b, ok := d.GetOk("tenant_id"); ok {
tenantID := b.(string)
_, err := c.getAWSFSX(WorkingEnvironmentID, tenantID)
id, err := c.getAWSFSX(WorkingEnvironmentID, tenantID)
if err != nil {
log.Print("Error getting AWS FSX")
return workingEnvironmentInfo{}, workingEnvironmentInfo{}, err
}

if id != WorkingEnvironmentID {
log.Print("Error getting AWS FSX")
return workingEnvironmentInfo{}, workingEnvironmentInfo{}, fmt.Errorf("Could not find source working environment ID %v", WorkingEnvironmentID)
}
sourceWorkingEnvDetail.PublicID = WorkingEnvironmentID
svmName, err := c.getFSXSVM(WorkingEnvironmentID, clientID)
if err != nil {
Expand Down Expand Up @@ -692,11 +697,13 @@ func (c *Client) getWorkingEnvironmentDetailForSnapMirror(d *schema.ResourceData
return workingEnvironmentInfo{}, workingEnvironmentInfo{}, err
}
sourceWorkingEnvDetail.PublicID = WorkingEnvironmentID
svmName, err := c.getFSXSVM(WorkingEnvironmentID, clientID)
if err != nil {
return workingEnvironmentInfo{}, workingEnvironmentInfo{}, err
if sourceWorkingEnvDetail.PublicID != "" {
svmName, err := c.getFSXSVM(WorkingEnvironmentID, clientID)
if err != nil {
return workingEnvironmentInfo{}, workingEnvironmentInfo{}, err
}
sourceWorkingEnvDetail.SvmName = svmName
}
sourceWorkingEnvDetail.SvmName = svmName
}
}
if err != nil && sourceWorkingEnvDetail.PublicID == "" {
Expand All @@ -713,11 +720,15 @@ func (c *Client) getWorkingEnvironmentDetailForSnapMirror(d *schema.ResourceData
if strings.HasPrefix(WorkingEnvironmentID, "fs-") {
if b, ok := d.GetOk("tenant_id"); ok {
tenantID := b.(string)
_, err := c.getAWSFSX(WorkingEnvironmentID, tenantID)
id, err := c.getAWSFSX(WorkingEnvironmentID, tenantID)
if err != nil {
log.Print("Error getting AWS FSX")
return workingEnvironmentInfo{}, workingEnvironmentInfo{}, err
}
if id != WorkingEnvironmentID {
log.Print("Error getting AWS FSX")
return workingEnvironmentInfo{}, workingEnvironmentInfo{}, fmt.Errorf("Could not find destination working environment ID %v", WorkingEnvironmentID)
}
destWorkingEnvDetail.PublicID = WorkingEnvironmentID
svmName, err := c.getFSXSVM(WorkingEnvironmentID, clientID)
if err != nil {
Expand Down Expand Up @@ -746,12 +757,14 @@ func (c *Client) getWorkingEnvironmentDetailForSnapMirror(d *schema.ResourceData
log.Print("Error getting AWS FSX: ", err)
return workingEnvironmentInfo{}, workingEnvironmentInfo{}, err
}
destWorkingEnvDetail.PublicID = WorkingEnvironmentID
svmName, err := c.getFSXSVM(WorkingEnvironmentID, clientID)
if err != nil {
return workingEnvironmentInfo{}, workingEnvironmentInfo{}, err
if destWorkingEnvDetail.PublicID != "" {
destWorkingEnvDetail.PublicID = WorkingEnvironmentID
svmName, err := c.getFSXSVM(WorkingEnvironmentID, clientID)
if err != nil {
return workingEnvironmentInfo{}, workingEnvironmentInfo{}, err
}
destWorkingEnvDetail.SvmName = svmName
}
destWorkingEnvDetail.SvmName = svmName
}
}
if err != nil && destWorkingEnvDetail.PublicID == "" {
Expand Down
7 changes: 4 additions & 3 deletions cloudmanager/occm_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ type deleteOCCMDetails struct {

// OCCMMResult the users input for creating a occm
type OCCMMResult struct {
ClientID string
AccountID string
InstanceID string
ClientID string
AccountID string
InstanceID string
PrincipalID string
}

// accesTokenRequest the input for requesting a token
Expand Down
8 changes: 5 additions & 3 deletions cloudmanager/occm_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ func (c *Client) createOCCMAzure(occmDetails createOCCMDetails, proxyCertificate
result.ClientID = newClientID
result.AccountID = c.AccountID

instanceID, err := c.CallDeployAzureVM(occmDetails)
principalID, err := c.CallDeployAzureVM(occmDetails)
if err != nil {
return OCCMMResult{}, err
}
result.InstanceID = instanceID
log.Print("VM created - Sleep for 2 minutes")

result.PrincipalID = principalID
log.Print("Sleep for 2 minutes")
time.Sleep(time.Duration(120) * time.Second)

retries := 26
Expand All @@ -149,6 +150,7 @@ func (c *Client) createOCCMAzure(occmDetails createOCCMDetails, proxyCertificate
retries--
}
}

return result, nil
}

Expand Down
23 changes: 17 additions & 6 deletions cloudmanager/resource_netapp_cloudmanager_connector_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ func resourceOCCMAzure() *schema.Resource {
Optional: true,
ForceNew: true,
},
"principal_id": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
},
}
}
Expand Down Expand Up @@ -173,15 +179,15 @@ func resourceOCCMAzureCreate(d *schema.ResourceData, meta interface{}) error {
if occmDetails.ProxyURL != "" {
occmDetails.ProxyUserName = o.(string)
} else {
return fmt.Errorf("Missing proxy_url")
return fmt.Errorf("missing proxy_url")
}
}

if o, ok := d.GetOk("proxy_password"); ok {
if occmDetails.ProxyURL != "" {
occmDetails.ProxyPassword = o.(string)
} else {
return fmt.Errorf("Missing proxy_url")
return fmt.Errorf("missing proxy_url")
}
}

Expand All @@ -191,7 +197,7 @@ func resourceOCCMAzureCreate(d *schema.ResourceData, meta interface{}) error {
// read file
b, err := ioutil.ReadFile(cFile.(string))
if err != nil {
return fmt.Errorf("Cannot read certificate file: %s", err)
return fmt.Errorf("cannot read certificate file: %s", err)
}
// endcode certificate
encodedCertificate := base64.StdEncoding.EncodeToString(b)
Expand Down Expand Up @@ -225,12 +231,17 @@ func resourceOCCMAzureCreate(d *schema.ResourceData, meta interface{}) error {

d.SetId(occmDetails.Name)
log.Print("Set ID: ", occmDetails.Name)

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

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

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

log.Printf("Created occm: %v", res)
Expand Down Expand Up @@ -271,7 +282,7 @@ func resourceOCCMAzureRead(d *schema.ResourceData, meta interface{}) error {
}

if resID != id {
return fmt.Errorf("Expected occm ID %v, Response could not find", id)
return fmt.Errorf("expected occm ID %v, response could not find", id)
}

return nil
Expand Down
7 changes: 7 additions & 0 deletions cloudmanager/resource_netapp_cloudmanager_cvo_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ func resourceCVOAWS() *schema.Resource {
Optional: true,
ForceNew: true,
},
"retries": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Default: 60,
},
},
}
}
Expand All @@ -335,6 +341,7 @@ func resourceCVOAWSCreate(d *schema.ResourceData, meta interface{}) error {

client := meta.(*Client)
clientID := d.Get("client_id").(string)
client.Retries = d.Get("retries").(int)

cvoDetails := createCVOAWSDetails{}

Expand Down
Loading

0 comments on commit 9b17c9b

Please sign in to comment.