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 AdminOrgVdcStorageProfile for querying #375

Closed
wants to merge 8 commits into from
14 changes: 10 additions & 4 deletions govcd/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ func (vcdCli *VCDClient) GetOrgList() (*types.OrgList, error) {
}

// QueryAdminOrgVdcStorageProfileByID finds a StorageProfile of VDC by ID as admin
func QueryAdminOrgVdcStorageProfileByID(vcdCli *VCDClient, id string) ([]*types.QueryResultAdminOrgVdcStorageProfileRecordType, error) {
func QueryAdminOrgVdcStorageProfileByID(vcdCli *VCDClient, id string) (*types.QueryResultAdminOrgVdcStorageProfileRecordType, error) {
results, err := vcdCli.QueryWithNotEncodedParams(nil, map[string]string{
"type": types.QtAdminOrgVdcStorageProfile,
"filter": fmt.Sprintf("id==%s", url.QueryEscape(id)),
Expand All @@ -986,11 +986,14 @@ func QueryAdminOrgVdcStorageProfileByID(vcdCli *VCDClient, id string) ([]*types.
if err != nil {
return nil, err
}
return results.Results.AdminOrgVdcStorageProfileRecord, nil
if len(results.Results.AdminOrgVdcStorageProfileRecord) != 1 {
return nil, errors.New("error querying storage profile")
}
return results.Results.AdminOrgVdcStorageProfileRecord[0], nil
}

// QueryOrgVdcStorageProfileByID finds a StorageProfile of VDC by ID
func QueryOrgVdcStorageProfileByID(vcdCli *VCDClient, id string) ([]*types.QueryResultOrgVdcStorageProfileRecordType, error) {
func QueryOrgVdcStorageProfileByID(vcdCli *VCDClient, id string) (*types.QueryResultOrgVdcStorageProfileRecordType, error) {
lelvisl marked this conversation as resolved.
Show resolved Hide resolved
results, err := vcdCli.QueryWithNotEncodedParams(nil, map[string]string{
"type": types.QtOrgVdcStorageProfile,
"filter": fmt.Sprintf("id==%s", url.QueryEscape(id)),
Expand All @@ -999,5 +1002,8 @@ func QueryOrgVdcStorageProfileByID(vcdCli *VCDClient, id string) ([]*types.Query
if err != nil {
return nil, err
}
return results.Results.OrgVdcStorageProfileRecord, nil
if len(results.Results.OrgVdcStorageProfileRecord) != 1 {
lelvisl marked this conversation as resolved.
Show resolved Hide resolved
return nil, errors.New("error querying storage profile")
}
return results.Results.OrgVdcStorageProfileRecord[0], nil
}
27 changes: 13 additions & 14 deletions govcd/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,25 +576,24 @@ func (vcd *TestVCD) Test_QueryAdminOrgVdcStorageProfileByID(check *C) {
check.Assert(err, IsNil)
expectedStorageProfileID, err := GetUuidFromHref(ref.HREF, true)
check.Assert(err, IsNil)
vdcStorageProfiles, err := QueryAdminOrgVdcStorageProfileByID(vcd.client, ref.ID)
vdcStorageProfile, err := QueryAdminOrgVdcStorageProfileByID(vcd.client, ref.ID)
check.Assert(err, IsNil)
check.Assert(len(vdcStorageProfiles) > 0, Equals, true)

storageProfileFound := false
for _, vdcStorageProfile := range vdcStorageProfiles {
storageProfileID, err := GetUuidFromHref(vdcStorageProfile.HREF, true)
check.Assert(err, IsNil)
if storageProfileID == expectedStorageProfileID {
storageProfileFound = true
}

if testVerbose {
fmt.Printf("StorageProfile %s\n", vdcStorageProfile.Name)
fmt.Printf("\t href %s\n", vdcStorageProfile.HREF)
fmt.Printf("\t enabled %v\n", vdcStorageProfile.IsEnabled)
fmt.Println("")
}
storageProfileID, err := GetUuidFromHref(vdcStorageProfile.HREF, true)
check.Assert(err, IsNil)
if storageProfileID == expectedStorageProfileID {
storageProfileFound = true
}

if testVerbose {
fmt.Printf("StorageProfile %s\n", vdcStorageProfile.Name)
fmt.Printf("\t href %s\n", vdcStorageProfile.HREF)
fmt.Printf("\t enabled %v\n", vdcStorageProfile.IsEnabled)
fmt.Println("")
}

check.Assert(storageProfileFound, Equals, true)
}

Expand Down