Skip to content

Commit

Permalink
vcsim: toggle Content Library cached fields in sync and evict calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dougm committed Apr 12, 2024
1 parent 3d03feb commit 7465609
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion vapi/simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,19 @@ func (s *handler) library(w http.ResponseWriter, r *http.Request) {
}
}

func (content *content) cached(val bool) {
for _, item := range content.Item {
item.cached(val)
}
}

func (item *item) cached(val bool) {
item.Cached = val
for _, file := range item.File {
file.Cached = types.NewBool(val)
}
}

func (s *handler) publish(w http.ResponseWriter, r *http.Request, sids []internal.SubscriptionDestination, l *content, vmtx *item) bool {
var ids []string
if len(sids) == 0 {
Expand Down Expand Up @@ -991,10 +1004,14 @@ func (s *handler) libraryID(w http.ResponseWriter, r *http.Request) {
case "sync":
if l.Type == "SUBSCRIBED" {
l.LastSyncTime = types.NewTime(time.Now())
l.cached(true)
OK(w)
} else {
http.NotFound(w, r)
}
case "evict":
l.cached(false)
OK(w)
}
case http.MethodGet:
OK(w, l)
Expand Down Expand Up @@ -1242,8 +1259,9 @@ func (s *handler) libraryItemID(w http.ResponseWriter, r *http.Request) {

OK(w, id)
case "sync":
if l.Type == "SUBSCRIBED" {
if l.Type == "SUBSCRIBED" || l.Publication != nil {
item.LastSyncTime = types.NewTime(time.Now())
item.cached(true)
OK(w)
} else {
http.NotFound(w, r)
Expand All @@ -1255,6 +1273,9 @@ func (s *handler) libraryItemID(w http.ResponseWriter, r *http.Request) {
OK(w)
}
}
case "evict":
item.cached(false)
OK(w, id)
}
case http.MethodGet:
OK(w, item)
Expand Down Expand Up @@ -2309,6 +2330,7 @@ func (s *handler) libraryItemTemplateID(w http.ResponseWriter, r *http.Request)
return
}

item.cached(true)
ref, err := s.cloneVM(item.Template.Value, spec.Name, p, spec.DiskStorage)
if err != nil {
BadRequest(w, err.Error())
Expand Down

0 comments on commit 7465609

Please sign in to comment.