Skip to content

Commit

Permalink
Merge pull request #3545 from ericvmw/issue-3542
Browse files Browse the repository at this point in the history
Update library state info to content library API
  • Loading branch information
ericvmw authored Sep 6, 2024
2 parents c1151f8 + 93b97e1 commit d3cb5c6
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
7 changes: 7 additions & 0 deletions vapi/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ type Library struct {
Publication *Publication `json:"publish_info,omitempty"`
SecurityPolicyID string `json:"security_policy_id,omitempty"`
UnsetSecurityPolicyID bool `json:"unset_security_policy_id,omitempty"`
ServerGUID string `json:"server_guid,omitempty"`
StateInfo *StateInfo `json:"state_info,omitempty"`
}

// StateInfo provides the state info of a content library.
type StateInfo struct {
State string `json:"state"`
}

// Subscription info
Expand Down
92 changes: 92 additions & 0 deletions vapi/library/library_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package library_test

import (
"context"
"testing"

"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/simulator"
"github.com/vmware/govmomi/vapi/library"
"github.com/vmware/govmomi/vapi/rest"
"github.com/vmware/govmomi/vim25"

_ "github.com/vmware/govmomi/vapi/simulator"
)

func TestManagerCreateLibrary(t *testing.T) {
simulator.Test(func(ctx context.Context, vc *vim25.Client) {
c := rest.NewClient(vc)

err := c.Login(ctx, simulator.DefaultLogin)
if err != nil {
t.Fatal(err)
}

ds, err := find.NewFinder(vc).DefaultDatastore(ctx)
if err != nil {
t.Fatal(err)
}

m := library.NewManager(c)

libName := "example"
libType := "LOCAL"
id, err := m.CreateLibrary(ctx, library.Library{
Name: libName,
Type: libType,
Storage: []library.StorageBacking{{
DatastoreID: ds.Reference().Value,
Type: "DATASTORE",
}},
})
if err != nil {
t.Fatal(err)
}

l, err := m.GetLibraryByID(ctx, id)
if err != nil {
t.Fatal(err)
}

if l.ID == "" {
t.Fatal("library ID should be generated")
}
if l.ServerGUID == "" {
t.Fatal("library server GUID should be generated")
}
if l.Name != libName {
t.Fatalf("expected library name %s, got %s", libName, l.Name)
}
if l.Type != libType {
t.Fatalf("expected library type %s, got %s", libType, l.Type)
}
if len(l.Storage) == 0 {
t.Fatal("library should have a storage backing")
}
if l.Storage[0].Type != "DATASTORE" {
t.Fatalf("expected library storage type DATASTORE, got %s", l.Storage[0].Type)
}
if l.Storage[0].DatastoreID != ds.Reference().Value {
t.Fatalf("expected library datastore ref %s, got %s", ds.Reference().Value, l.Storage[0].DatastoreID)
}
if l.StateInfo == nil || l.StateInfo.State != "ACTIVE" {
t.Fatal("library should have state ACTIVE")
}
})
}
3 changes: 3 additions & 0 deletions vapi/simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ func (s *handler) library(w http.ResponseWriter, r *http.Request) {

id := uuid.New().String()
spec.Library.ID = id
spec.Library.ServerGUID = uuid.New().String()
spec.Library.CreationTime = types.NewTime(time.Now())
spec.Library.LastModifiedTime = types.NewTime(time.Now())
spec.Library.UnsetSecurityPolicyID = spec.Library.SecurityPolicyID == ""
Expand Down Expand Up @@ -953,6 +954,8 @@ func (s *handler) library(w http.ResponseWriter, r *http.Request) {
}
}

spec.Library.StateInfo = &library.StateInfo{State: "ACTIVE"}

OK(w, id)
}
case http.MethodGet:
Expand Down

0 comments on commit d3cb5c6

Please sign in to comment.