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

New functions for getting and updating Org vDC #206

Merged
merged 12 commits into from
Jul 1, 2019
2 changes: 1 addition & 1 deletion govcd/org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func (vcd *TestVCD) Test_UpdateVdc(check *C) {
}
quota := 111
vCpu := int64(1000)
guaranteed := float64(0.6)
guaranteed := "0.6"
adminVdc.AdminVdc.Description = updateDescription
adminVdc.AdminVdc.ComputeCapacity = computeCapacity
adminVdc.AdminVdc.IsEnabled = false
Expand Down
15 changes: 15 additions & 0 deletions govcd/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"github.com/vmware/go-vcloud-director/v2/types/v56"
"github.com/vmware/go-vcloud-director/v2/util"
)

// Simple structure to pass Edge Gateway creation parameters.
Expand Down Expand Up @@ -500,3 +501,17 @@ func QueryProviderVdcByName(vcdCli *VCDClient, name string) ([]*types.QueryResul

return results.Results.VMWProviderVdcRecord, nil
}

// GetNetworkPoolByHREF functions fetches an network pool using VDC client and network pool href
func GetNetworkPoolByHREF(client *VCDClient, href string) (*types.VMWNetworkPool, error) {
util.Logger.Printf("[TRACE] Get network pool by HREF: %s\n", href)

networkPool := &types.VMWNetworkPool{}

_, err := client.Client.ExecuteRequest(href, http.MethodGet,
"", "error fetching network ppol: %s", nil, networkPool)

// Return the disk
return networkPool, err

}
22 changes: 22 additions & 0 deletions govcd/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ func (vcd *TestVCD) Test_FindBadlyNamedStorageProfile(check *C) {
check.Assert(err.Error(), Matches, reNotFound)
}

// Test getting network pool by href and vdc client
func (vcd *TestVCD) Test_GetNetworkPoolByHREF(check *C) {
if vcd.config.VCD.ProviderVdc.NetworkPool == "" {
check.Skip("Skipping test because network pool is not configured")
}

fmt.Printf("Running: %s\n", check.TestName())

adminOrg, err := GetAdminOrgByName(vcd.client, vcd.config.VCD.Org)
check.Assert(adminOrg, Not(Equals), AdminOrg{})
check.Assert(err, IsNil)

adminVdc, err := adminOrg.GetAdminVdcByName(vcd.config.VCD.Vdc)
check.Assert(adminVdc, Not(Equals), AdminVdc{})
check.Assert(err, IsNil)

// Get network pool by href
foundNetworkPool, err := GetNetworkPoolByHREF(vcd.client, adminVdc.AdminVdc.NetworkPoolReference.HREF)
check.Assert(err, IsNil)
check.Assert(foundNetworkPool, Not(Equals), types.VMWNetworkPool{})
}

// longer than the 128 characters so nothing can be named this
var INVALID_NAME = `*******************************************INVALID
****************************************************
Expand Down
17 changes: 15 additions & 2 deletions types/v56/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ type AdminVdc struct {
Xmlns string `xml:"xmlns,attr"`
Vdc

ResourceGuaranteedMemory float64 `xml:"ResourceGuaranteedMemory,omitempty"`
ResourceGuaranteedCpu float64 `xml:"ResourceGuaranteedCpu,omitempty"`
ResourceGuaranteedMemory string `xml:"ResourceGuaranteedMemory,omitempty"`
Didainius marked this conversation as resolved.
Show resolved Hide resolved
ResourceGuaranteedCpu string `xml:"ResourceGuaranteedCpu,omitempty"`
VCpuInMhz int64 `xml:"VCpuInMhz,omitempty"`
IsThinProvision bool `xml:"IsThinProvision,omitempty"`
NetworkPoolReference *Reference `xml:"NetworkPoolReference,omitempty"`
Expand Down Expand Up @@ -2461,3 +2461,16 @@ type QueryResultOrgVdcNetworkRecordType struct {
IsIpScopeInherited bool `xml:"isIpScopeInherited,attr,omitempty"`
Link []*Link `xml:"Link,omitempty"`
}

// Represents org VDC Network
// Reference: vCloud API 27.0 - Network Pool
// https://code.vmware.com/apis/72/vcloud-director#/doc/doc/types/VMWNetworkPoolType.html
type VMWNetworkPool struct {
HREF string `xml:"href,attr,omitempty"`
Id string `xml:"id,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
Name string `xml:"name,attr"`
Status int `xml:"status,attr,omitempty"`
Description string `xml:"netmask,omitempty"`
Tasks *TasksInProgress `xml:"Tasks,omitempty"`
}