Skip to content

Commit

Permalink
PCCM-101404: Directly access morpheus (#280)
Browse files Browse the repository at this point in the history
* PCCM-101404: Directly access morpheus

* Add storage controller page

* update testcase

* update doc
  • Loading branch information
mahesh-hpe authored Jan 16, 2025
1 parent ec03ab2 commit 7fc92d6
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 15 deletions.
8 changes: 4 additions & 4 deletions acc-testcases/resources/network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ acc:
description = "Network created using tf"
group_id = "shared"
scope_id = "/infra/sites/default/enforcement-points/default/transport-zones/2cc8e542-8c53-456d-b058-9fb00a5fae70"
cidr = "10.200.40.1/24"
gateway = "10.200.40.1"
cidr = "10.200.42.1/24"
gateway = "10.200.42.1"
scan_network = false
active = true
connected_gateway = "/infra/tier-1s/d3561ba7-01c9-4fa7-a7c5-bac401fd8f75"
Expand All @@ -18,5 +18,5 @@ acc:
pool_id = 25
}
validations:
tf.cidr = "10.200.40.1/24"
tf.gateway = "10.200.40.1"
tf.cidr = "10.200.42.1/24"
tf.gateway = "10.200.42.1"
13 changes: 10 additions & 3 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"os"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

Expand Down Expand Up @@ -106,9 +107,15 @@ func (i InitialiseClient) NewClient(r *schema.ResourceData) (interface{}, error)
}
}
apiClient := api_client.NewAPIClient(&cfg)
err = utils.SetCMPVars(apiClient, brokerApiClient, &cfg)
if err != nil {
return nil, fmt.Errorf("[ERROR]: unable to set cmp metadata %v", err)
morpheus_url := strings.TrimSpace(vmaasProviderSettings[constants.MORPHEUS_URL].(string))
morpheus_token := strings.TrimSpace(vmaasProviderSettings[constants.MORPHEUS_TOKEN].(string))
if morpheus_url != "" && morpheus_token != "" {
utils.SetMorpheusVars(apiClient, &cfg, morpheus_url, morpheus_token)
} else {
err = utils.SetCMPVars(apiClient, brokerApiClient, &cfg)
if err != nil {
return nil, fmt.Errorf("[ERROR]: unable to set cmp metadata %v", err)
}
}
client.CmpClient = cmp_client.NewClient(apiClient, cfg)
utils.SetMetaFnAndVersion(brokerApiClient, r, apiClient.GetSCMVersion())
Expand Down
18 changes: 10 additions & 8 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ const (
IamGlcs string = "glcs"
TenantID string = "tenant_id"

LOCATION = "location"
SPACENAME = "space_name"
APIURL = "api_url"
BROKERRURL = "broker_url"
INSECURE = "allow_insecure"
SpaceKey = "space"
TenantIDKey = "tenantID"
LocationKey = "location"
LOCATION = "location"
SPACENAME = "space_name"
APIURL = "api_url"
BROKERRURL = "broker_url"
INSECURE = "allow_insecure"
MORPHEUS_URL = "morpheus_url"
MORPHEUS_TOKEN = "morpheus_token"
SpaceKey = "space"
TenantIDKey = "tenantID"
LocationKey = "location"

MockIAMKey = "TF_ACC_MOCK_IAM"
CmpSubjectKey = "TF_ACC_CMP_SUBJECT"
Expand Down
12 changes: 12 additions & 0 deletions pkg/resources/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ func (r Registration) ProviderSchemaEntry() *schema.Resource {
DefaultFunc: schema.EnvDefaultFunc("HPEGL_VMAAS_BROKER_URL", constants.BrokerURL),
Description: "The URL to use for the VMaaS Broker API, can also be set with the HPEGL_VMAAS_BROKER_URL env var",
},
constants.MORPHEUS_URL: {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("HPEGL_MORPHEUS_URL", ""),
Description: "The Morpheus URL, can also be set with the HPEGL_MORPHEUS_URL env var",
},
constants.MORPHEUS_TOKEN: {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("HPEGL_MORPHEUS_TOKEN", ""),
Description: "The Morpheus token, can also be set with the HPEGL_MORPHEUS_TOKEN env var",
},
constants.INSECURE: {
Type: schema.TypeBool,
Optional: true,
Expand Down
21 changes: 21 additions & 0 deletions pkg/utils/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,24 @@ func SetCMPVars(apiClient, brokerClient *client.APIClient, cfg *client.Configura

return err
}

func SetMorpheusVars(apiClient *client.APIClient, cfg *client.Configuration, url, token string) (err error) {
apiClient.SetHost(url)
apiClient.CMPToken = token
apiClient.TokenExpiry = 15 * 60 * 1000 // Not being used
apiClient.SetMetaFnAndVersion(nil, 0, func(ctx *context.Context, meta interface{}) {
// Initialise token handler

*ctx = context.WithValue(*ctx, client.ContextAccessToken, apiClient.CMPToken)
})
ctx := context.Background()
ctx = context.WithValue(ctx, client.ContextAccessToken, token)
err = apiClient.SetCMPVersion(ctx)
if err != nil {
log.Printf("[ERROR] Unable to set CMP version client: %s", err)
return
}
cfg.Host = url

return err
}
23 changes: 23 additions & 0 deletions templates/data-sources/vmaas_instance_storage_controller.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
layout: ""
page_title: "hpegl_vmaas_instance_storage_controller Data-source - vmaas-terraform-data-sources"
subcategory: {{ $arr := split .Name "_" }}"{{ index $arr 1 }}"
description: |-
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
---

-> Compatible version >= 5.2.4

# Data-source hpegl_vmaas_instance_storage_controller

{{ .Description | trimspace }}

## Example usage

{{tffile "examples/data-sources/hpegl_vmaas_instance_storage_controller/data-source.tf"}}

- During volume addition for an instance, if the interface or bus details are wrong, then TF will exit with VM as unknow state.
- During creation of an instance, the first volume will always be `SCSI VMware Paravirtual - SCSI 0:0`.
- Controller of a created volume cannot be modified. But volume can be deleted and re-created with correct virtual adaptor info.

{{ .SchemaMarkdown | trimspace }}

0 comments on commit 7fc92d6

Please sign in to comment.