Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StoragePolicy and ContentLibrary when creating VC Namespace #975

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions test/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,23 @@ func (data *TestData) createVCNamespace(namespace string) error {
}()

svID, _ := data.vcClient.getSupervisorID()
storagePolicyID, _ := data.vcClient.getStoragePolicyID()
log.Info("", "storagePolicyID", storagePolicyID)
contentLibraryID, _ := data.vcClient.getContentLibraryID()
log.Info("", "contentLibraryID", contentLibraryID)
vcNamespace := &VCNamespaceCreateSpec{
Supervisor: svID,
Namespace: namespace,
StorageSpecs: []InstancesStorageSpec{
{
Policy: storagePolicyID,
},
},
ContentLibraries: []InstancesContentLibrarySpec{
{
ContentLibrary: contentLibraryID,
},
},
NetworkSpec: InstancesNetworkConfigInfo{
NetworkProvider: "NSX_VPC",
VpcNetwork: InstancesVpcNetworkInfo{
Expand Down
72 changes: 69 additions & 3 deletions test/e2e/vclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net/http"
"net/url"
"strings"
"sync"
"time"

Expand All @@ -27,6 +28,16 @@ type supervisorInfo struct {
K8sStatus string `json:"kubernetes_status"`
}

type storagePolicyInfo struct {
Name string `json:"name"`
Description string `json:"description"`
Policy string `json:"policy"`
}

type contentLibraryInfo struct {
ID string `json:"policy"`
}

type supervisorSummary struct {
ID string `json:"supervisor"`
Info supervisorInfo `json:"info"`
Expand All @@ -52,10 +63,23 @@ type InstancesNetworkConfigInfo struct {
VpcNetwork InstancesVpcNetworkInfo `json:"vpc_network"`
}

type InstancesStorageSpec struct {
Policy string
Limit *int64
}

type InstancesContentLibrarySpec struct {
ContentLibrary string
Writable *bool
AllowImport *bool
}

type VCNamespaceCreateSpec struct {
Supervisor string `json:"supervisor"`
Namespace string `json:"namespace"`
NetworkSpec InstancesNetworkConfigInfo `json:"network_spec"`
Supervisor string `json:"supervisor"`
Namespace string `json:"namespace"`
NetworkSpec InstancesNetworkConfigInfo `json:"network_spec"`
StorageSpecs []InstancesStorageSpec `json:"storage_specs"`
ContentLibraries []InstancesContentLibrarySpec `json:"content_libraries"`
}

type VCNamespaceGetInfo struct {
Expand Down Expand Up @@ -150,6 +174,48 @@ func (c *vcClient) getSupervisorID() (string, error) {
return "", fmt.Errorf("no valid supervisor found on vCenter")
}

func (c *vcClient) getStoragePolicyID() (string, error) {
urlPath := "/api/vcenter/storage/policies"
request, err := c.prepareRequest(http.MethodGet, urlPath, nil)
if err != nil {
return "", err
}
var response struct {
Items []storagePolicyInfo `json:"items"`
}
if _, err = c.handleRequest(request, &response); err != nil {
return "", err
}

for _, po := range response.Items {
if strings.Contains(po.Name, "global") || strings.Contains(po.Name, "local") {
return po.Name, nil
}
}
return "", fmt.Errorf("no valid storage policy found on vCenter")
}

func (c *vcClient) getContentLibraryID() (string, error) {
urlPath := "/api/vcenter/content/library"
request, err := c.prepareRequest(http.MethodGet, urlPath, nil)
if err != nil {
return "", err
}
var response struct {
Items []contentLibraryInfo `json:"items"`
}
if _, err = c.handleRequest(request, &response); err != nil {
return "", err
}

for _, cl := range response.Items {
if cl.ID != "" {
return cl.ID, nil
}
}
return "", fmt.Errorf("no valid content library found on vCenter")
}

func (c *vcClient) createNamespaceWithPreCreatedVPC(namespace string, vpcPath string, supervisorID string) error {
vcNamespace := createVCNamespaceSpec(namespace, supervisorID, vpcPath)
data, err := json.Marshal(vcNamespace)
Expand Down
Loading