Skip to content

Commit

Permalink
Add GetProfileNameByID functionality to PBM
Browse files Browse the repository at this point in the history
  • Loading branch information
BaluDontu committed Apr 20, 2020
1 parent a340b69 commit 409279f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
25 changes: 25 additions & 0 deletions pbm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,28 @@ func (c *Client) FetchCapabilityMetadata(ctx context.Context, rtype *types.PbmPr

return res.Returnval, nil
}

// GetProfileNameByID gets storage profile name by ID
func (c *Client) GetProfileNameByID(ctx context.Context, profileID string) (string, error) {
resourceType := types.PbmProfileResourceType{
ResourceType: string(types.PbmProfileResourceTypeEnumSTORAGE),
}
category := types.PbmProfileCategoryEnumREQUIREMENT
ids, err := c.QueryProfile(ctx, resourceType, string(category))
if err != nil {
return "", err
}

profiles, err := c.RetrieveContent(ctx, ids)
if err != nil {
return "", err
}

for i := range profiles {
profile := profiles[i].GetPbmProfile()
if profile.ProfileId.UniqueId == profileID {
return profile.Name, nil
}
}
return "", fmt.Errorf("no pbm profile found with id: %q", profileID)
}
19 changes: 16 additions & 3 deletions pbm/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,30 @@ func TestClient(t *testing.T) {
t.Logf("VSAN-SIOC Profile: %q successfully created", vsansiocProfileID.UniqueId)

// 9. Get ProfileID by Name
profileID, err := pc.ProfileIDByName(ctx, "Kubernetes-VSAN-SIOC-TestPolicy")
profileID, err := pc.ProfileIDByName(ctx, pbmCreateSpecVSANandSIOC.Name)
if err != nil {
t.Fatal(err)
}

if vsansiocProfileID.UniqueId != profileID {
t.Errorf("vsan-sioc profile: %q and retrieved profileID: %q successfully matched", vsansiocProfileID.UniqueId, profileID)
t.Errorf("vsan-sioc profile: %q and retrieved profileID: %q did not match", vsansiocProfileID.UniqueId, profileID)
}

t.Logf("VSAN-SIOC profile: %q and retrieved profileID: %q successfully matched", vsansiocProfileID.UniqueId, profileID)

// 10. Delete VSAN and VSAN-SIOC profile.
// 10. Get ProfileName by ID
profileName, err := pc.GetProfileNameByID(ctx, profileID)
if err != nil {
t.Fatal(err)
}

if profileName != pbmCreateSpecVSANandSIOC.Name {
t.Errorf("vsan-sioc profile: %q and retrieved profileName: %q did not match", pbmCreateSpecVSANandSIOC.Name, profileName)
}

t.Logf("vsan-sioc profile: %q and retrieved profileName: %q successfully matched", pbmCreateSpecVSANandSIOC.Name, profileName)

// 11. Delete VSAN and VSAN-SIOC profile.
_, err = pc.DeleteProfile(ctx, []types.PbmProfileId{*vsanProfileID, *vsansiocProfileID})
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 409279f

Please sign in to comment.