Skip to content

Commit

Permalink
Merge pull request #143 from NetApp/integration/main
Browse files Browse the repository at this point in the history
Integration/main
  • Loading branch information
wenjun666 authored Dec 7, 2022
2 parents 9b17c9b + 195de39 commit 6a680a4
Show file tree
Hide file tree
Showing 31 changed files with 1,102 additions and 432 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
## 22.12.0
NEW FEATURES:
* resource/cvo_volume: support create and delete onPrem volume.
* resource/cvo_volume: support create snapshot policy for AWS, AZURE and GCP if the snapshot policy is not available.

## 22.11.0
NEW FEATURES:
* resource/cvo_gcp HA: support add, rename and delete SVMs.
* resource/connector_gcp: add `labels` option.

BUG FIXES:
* resource/cvo_gcp: both capacity_tier and tierl_level should be optional.
* cifs_server on resource and data source: CIFS server with workgroup is depreciated. Since creating CIFS server with AD is the only way, updated the param attributes accordingly.

## 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.
* resoruce/cvs for AWS, AZURE and GCP: add `svm_name` an optional parameter. The modification is supported.

NEW ENHANCEMENTS:
* resource/connector_azure: display the deployed virtual machine principal_id in state file on the connector azure creation.
Expand Down
48 changes: 22 additions & 26 deletions cloudmanager/cifs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ import (
)

type cifsRequest struct {
Domain string `structs:"activeDirectoryDomain"`
Username string `structs:"activeDirectoryUsername"`
Password string `structs:"activeDirectoryPassword"`
DNSDomain string `structs:"dnsDomain"`
IPAddresses []string `structs:"ipAddresses"`
NetBIOS string `structs:"netBIOS"`
OrganizationalUnit string `structs:"organizationalUnit"`
WorkingEnvironmentID string `structs:"workingEnvironmentId"`
WorkingEnvironmentType string `structs:"workingEnvironmentType"`
SvmName string `structs:"svmName"`
ServerName string `structs:"serverName,omitempty"`
WorkgroupName string `structs:"workgroupName,omitempty"`
isWorkgroup bool `structs:"IsWorkgroup,omitempty"`
Domain string `structs:"activeDirectoryDomain"`
Username string `structs:"activeDirectoryUsername"`
Password string `structs:"activeDirectoryPassword"`
DNSDomain string `structs:"dnsDomain"`
IPAddresses []string `structs:"ipAddresses"`
NetBIOS string `structs:"netBIOS"`
OrganizationalUnit string `structs:"organizationalUnit"`
WorkingEnvironmentID string `structs:"workingEnvironmentId"`
SvmName string `structs:"svmName,omitempty"`
}

type cifsResponse struct {
Expand All @@ -34,18 +30,19 @@ type cifsResponse struct {
OrganizationalUnit string `json:"organizationalUnit"`
}

type cifsDeleteRequest struct {
Username string `structs:"activeDirectoryUsername,omitempty"`
Password string `structs:"activeDirectoryPassword,omitempty"`
SvmName string `structs:"svmName,omitempty"`
}

func (c *Client) createCIFS(cifs cifsRequest, clientID string) error {
baseURL, _, err := c.getAPIRoot(cifs.WorkingEnvironmentID, clientID)
hostType := "CloudManagerHost"
if err != nil {
return err
}
// cifs-workgroup
if cifs.isWorkgroup {
baseURL = fmt.Sprintf("%s/working-environments/%s/cifs-workgroup", baseURL, cifs.WorkingEnvironmentID)
} else {
baseURL = fmt.Sprintf("%s/working-environments/%s/cifs", baseURL, cifs.WorkingEnvironmentID)
}
baseURL = fmt.Sprintf("%s/working-environments/%s/cifs", baseURL, cifs.WorkingEnvironmentID)
param := structs.Map(cifs)
statusCode, response, onCloudRequestID, err := c.CallAPIMethod("POST", baseURL, param, c.Token, hostType, clientID)
if err != nil {
Expand All @@ -70,11 +67,10 @@ func (c *Client) getCIFS(cifs cifsRequest, clientID string) ([]cifsResponse, err
if err != nil {
return result, err
}
if cifs.isWorkgroup {
return result, nil
}
baseURL = fmt.Sprintf("%s/working-environments/%s/cifs", baseURL, cifs.WorkingEnvironmentID)

if cifs.SvmName != "" {
baseURL += "?svm=" + cifs.SvmName
}
hostType := "CloudManagerHost"
statusCode, response, _, err := c.CallAPIMethod("GET", baseURL, nil, c.Token, hostType, clientID)
if err != nil {
Expand All @@ -92,13 +88,13 @@ func (c *Client) getCIFS(cifs cifsRequest, clientID string) ([]cifsResponse, err
return result, nil
}

func (c *Client) deleteCIFS(cifs cifsRequest, clientID string) error {
baseURL, _, err := c.getAPIRoot(cifs.WorkingEnvironmentID, clientID)
func (c *Client) deleteCIFS(cifs cifsDeleteRequest, workingEnvironmentID, clientID string) error {
baseURL, _, err := c.getAPIRoot(workingEnvironmentID, clientID)
hostType := "CloudManagerHost"
if err != nil {
return err
}
baseURL = fmt.Sprintf("%s/working-environments/%s/delete-cifs", baseURL, cifs.WorkingEnvironmentID)
baseURL = fmt.Sprintf("%s/working-environments/%s/delete-cifs", baseURL, workingEnvironmentID)
param := structs.Map(cifs)
statusCode, response, _, err := c.CallAPIMethod("POST", baseURL, param, c.Token, hostType, clientID)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cloudmanager/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Client struct {
AWSAccount string
AzureEnvironmentForOCCM string
GCPDeploymentManager string
GCPCompute string
GCPImageProject string
GCPImageFamily string
GCPDeploymentTemplate string
Expand Down Expand Up @@ -809,6 +810,7 @@ func (c *Client) init() {
Audience: c.Audience,
GCPDeploymentManager: c.GCPDeploymentManager,
CVSHostName: c.CVSHostName,
GCPCompute: c.GCPCompute,
}
}

Expand Down
5 changes: 4 additions & 1 deletion cloudmanager/cloudmanager/restapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Client struct {
Audience string
GCPDeploymentManager string
CVSHostName string
GCPCompute string

httpClient http.Client
}
Expand Down Expand Up @@ -46,13 +47,15 @@ func (c *Client) Do(baseURL string, hostType string, token string, paramsNil boo
gcpType = true
} else if hostType == "CVSHost" {
host = c.CVSHostName
} else if hostType == "GCPCompute" {
host = c.GCPCompute
gcpType = true
}

httpReq, err := req.BuildHTTPReq(host, token, c.Audience, baseURL, paramsNil, accountID, clientID, gcpType, simulator)
if err != nil {
return statusCode, res, onCloudRequestID, err
}

httpRes, err := c.httpClient.Do(httpReq)
if err != nil {
log.Print("HTTP req failed")
Expand Down
2 changes: 2 additions & 0 deletions cloudmanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (c *configStruct) clientFun() (*Client, error) {
AMIFilter: "Setup-As-Service-AMI-Prod*",
AWSAccount: "952013314444",
GCPDeploymentManager: "https://www.googleapis.com",
GCPCompute: "https://compute.googleapis.com",
GCPImageProject: "netapp-cloudmanager",
GCPImageFamily: "cloudmanager",
CVSHostName: "https://api.services.cloud.netapp.com",
Expand All @@ -47,6 +48,7 @@ func (c *configStruct) clientFun() (*Client, error) {
AMIFilter: "Setup-As-Service-AMI-*",
AWSAccount: "282316784512",
GCPDeploymentManager: "https://www.googleapis.com",
GCPCompute: "https://compute.googleapis.com",
GCPImageProject: "tlv-automation",
GCPImageFamily: "occm-automation",
AzureEnvironmentForOCCM: "stage",
Expand Down
40 changes: 1 addition & 39 deletions cloudmanager/cvo_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type createCVOAWSDetails struct {
Region string `structs:"region"`
VpcID string `structs:"vpcId,omitempty"`
SvmPassword string `structs:"svmPassword"`
SvmName string `structs:"svmName,omitempty"`
VsaMetadata vsaMetadata `structs:"vsaMetadata"`
EbsVolumeSize ebsVolumeSize `structs:"ebsVolumeSize"`
EbsVolumeType string `structs:"ebsVolumeType"`
Expand Down Expand Up @@ -145,45 +146,6 @@ func (c *Client) getTenant(clientID string) (string, error) {
return result[0].PublicID, nil
}

func (c *Client) getCVOAWSByID(id string, clientID string) (map[string]interface{}, error) {

log.Print("getCVOAWSByID")

baseURL, _, err := c.getAPIRoot(id, clientID)
if err != nil {
return nil, err
}

accessTokenResult, err := c.getAccessToken()
if err != nil {
log.Print("in getCVOAWSByID request, failed to get AccessToken")
return nil, err
}
c.Token = accessTokenResult.Token

baseURL = fmt.Sprintf("%s/working-environments/%s?fields=*", baseURL, id)

hostType := "CloudManagerHost"

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

responseError := apiResponseChecker(statusCode, response, "getCVOAWSByID")
if responseError != nil {
return nil, responseError
}
var result map[string]interface{}
if err := json.Unmarshal(response, &result); err != nil {
log.Print("Failed to unmarshall response from getCVOAWSByID ", err)
return nil, err
}

return result, nil
}

func (c *Client) getCVOAWS(id string, clientID string) (string, error) {

log.Print("getCVOAWS")
Expand Down
30 changes: 1 addition & 29 deletions cloudmanager/cvo_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type createCVOAzureDetails struct {
SubscriptionID string `structs:"subscriptionId"`
VnetID string `structs:"vnetId,omitempty"`
SvmPassword string `structs:"svmPassword"`
SvmName string `structs:"svmName,omitempty"`
VsaMetadata vsaMetadata `structs:"vsaMetadata"`
DiskSize diskSize `structs:"diskSize"`
StorageType string `structs:"storageType"`
Expand Down Expand Up @@ -122,35 +123,6 @@ func (c *Client) getNSS(clientID string) (string, error) {
return result.NssAccounts[0].PublicID, nil
}

func (c *Client) getCVOAzureByID(id string, clientID string) error {

log.Print("getCVOAzureByID")

accessTokenResult, err := c.getAccessToken()
if err != nil {
log.Print("in getCVOAzureByID request, failed to get AccessToken")
return err
}
c.Token = accessTokenResult.Token

baseURL := fmt.Sprintf("/occm/api/working-environments/%s", id)

hostType := "CloudManagerHost"

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

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

return nil
}

func (c *Client) getCVOAzure(id string, clientID string) (string, error) {

log.Print("getCVOAzure")
Expand Down
92 changes: 90 additions & 2 deletions cloudmanager/cvo_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ type createCVOGCPDetails struct {
GCPServiceAccount string `structs:"gcpServiceAccount"`
VpcID string `structs:"vpcId"`
SvmPassword string `structs:"svmPassword"`
SvmName string `structs:"svmName,omitempty"`
VsaMetadata vsaMetadata `structs:"vsaMetadata"`
GCPVolumeSize diskSize `structs:"gcpVolumeSize"`
GCPVolumeType string `structs:"gcpVolumeType"`
SubnetID string `structs:"subnetId"`
SubnetPath string `structs:"subnetPath"`
Project string `structs:"project"`
CapacityTier string `structs:"capacityTier"`
TierLevel string `structs:"tierLevel"`
CapacityTier string `structs:"capacityTier,omitempty"`
TierLevel string `structs:"tierLevel,omitempty"`
NssAccount string `structs:"nssAccount,omitempty"`
WritingSpeedState string `structs:"writingSpeedState,omitempty"`
SerialNumber string `structs:"serialNumber,omitempty"`
Expand All @@ -50,6 +51,12 @@ type gcpLabels struct {
LabelValue string `structs:"labelValue,omitempty"`
}

// gcpSVMs the input for adding SVMs to a CVO HA
type gcpSVM struct {
SvmName string `structs:"svmName"`
// more parameters might be added in the future
}

// gcpEncryptionParameters the input for requesting a CVO
type gcpEncryptionParameters struct {
Key string `structs:"key,omitempty"`
Expand Down Expand Up @@ -138,6 +145,7 @@ func (c *Client) createCVOGCP(cvoDetails createCVOGCPDetails, clientID string) (

var result cvoResult
if err := json.Unmarshal(response, &result); err != nil {
log.Printf("Response: %#v", response)
log.Print("Failed to unmarshall response from createCVO ", err)
return cvoResult{}, err
}
Expand Down Expand Up @@ -179,6 +187,73 @@ func (c *Client) deleteCVOGCP(id string, isHA bool, clientID string) error {
return nil
}

// This is used on GCP CVO HA only
func (c *Client) addSVMtoCVO(id string, clientID string, svmName string) error {
log.Printf("addSVMtoCVO: id %s client %s svm %s", id, clientID, svmName)

accessTokenResult, err := c.getAccessToken()
if err != nil {
log.Print("In addSVMtoCVO request, failed to get AccessToken")
return err
}
c.Token = accessTokenResult.Token

// GCP CVO SVM add and deletion only support HA
baseURL := getAPIRootForWorkingEnvironment(true, id) + "/svm"
hostType := "CloudManagerHost"

var svm gcpSVM
svm.SvmName = svmName
params := structs.Map(svm)
log.Printf("\taddSVMtoCVO params: %#v", params)
statusCode, response, onCloudRequestID, err := c.CallAPIMethod("POST", baseURL, params, c.Token, hostType, clientID)
if err != nil {
log.Print("addSVMtoCVO request failed ", statusCode)
return err
}

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

err = c.waitOnCompletion(onCloudRequestID, "CVO_SVM", "add", 60, 60, clientID)

return err
}

func (c *Client) deleteSVMfromCVO(id string, clientID string, svmName string) error {
log.Printf("deleteSVMfromCVO: id %s client %s svm %s", id, clientID, svmName)

accessTokenResult, err := c.getAccessToken()
if err != nil {
log.Print("In deleteSVMfromCVO request, failed to get AccessToken")
return err
}
c.Token = accessTokenResult.Token

// GCP CVO SVM add and deletion only support HA
baseURL := getAPIRootForWorkingEnvironment(true, id)
baseURL = fmt.Sprintf("%s/svm/%s", baseURL, svmName)
log.Print("\tDelete svm url: ", baseURL)
hostType := "CloudManagerHost"

statusCode, response, onCloudRequestID, err := c.CallAPIMethod("DELETE", baseURL, nil, c.Token, hostType, clientID)
if err != nil {
log.Printf("deleteSVMfromCVO %s request failed %#v", id, statusCode)
return err
}

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

err = c.waitOnCompletion(onCloudRequestID, "CVO_SVM", "delete", 40, 60, clientID)

return err
}

// expandGCPLabels converts set to gcpLabels struct
func expandGCPLabels(set *schema.Set) []gcpLabels {
labels := []gcpLabels{}
Expand All @@ -193,6 +268,19 @@ func expandGCPLabels(set *schema.Set) []gcpLabels {
return labels
}

// expandGCPLabels converts set to gcpLabels struct
func expandGCPSVMs(set *schema.Set) []gcpSVM {
svms := []gcpSVM{}

for _, v := range set.List() {
svm := v.(map[string]interface{})
gcpSVM := gcpSVM{}
gcpSVM.SvmName = svm["svm_name"].(string)
svms = append(svms, gcpSVM)
}
return svms
}

// expandGCPLabelsToUseTags
func expandGCPLabelsToUserTags(set *schema.Set) []userTags {
tags := []userTags{}
Expand Down
Loading

0 comments on commit 6a680a4

Please sign in to comment.