diff --git a/govc/USAGE.md b/govc/USAGE.md index 36486ab63..add6b3532 100644 --- a/govc/USAGE.md +++ b/govc/USAGE.md @@ -217,6 +217,7 @@ but appear via `govc $cmd -h`: - [library.cp](#librarycp) - [library.create](#librarycreate) - [library.deploy](#librarydeploy) + - [library.evict](#libraryevict) - [library.export](#libraryexport) - [library.import](#libraryimport) - [library.info](#libraryinfo) @@ -3549,6 +3550,20 @@ Options: -profile= Storage profile ``` +## library.evict + +``` +Usage: govc library.evict [OPTIONS] LIBRARY NAME | ITEM NAME + +Evict library NAME or item NAME. + +Examples: + govc library.evict subscribed-library + govc library.evict subscribed-library/item + +Options: +``` + ## library.export ``` diff --git a/govc/library/evict.go b/govc/library/evict.go index e676200bd..daf5907aa 100644 --- a/govc/library/evict.go +++ b/govc/library/evict.go @@ -1,5 +1,5 @@ /* -Copyright (c) 2024 VMware, Inc. All Rights Reserved. +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. diff --git a/govc/test/library.bats b/govc/test/library.bats index eff1b415d..fc0cdb2a8 100755 --- a/govc/test/library.bats +++ b/govc/test/library.bats @@ -640,14 +640,20 @@ EOF run govc library.sync subscribed-content/ttylinux-latest assert_success - result=$(govc library.info -l subscribed-content/ttylinux-latest) + # assert cached is false after item sync + result=$(govc library.info -json subscribed-content/ttylinux-latest) echo "$result" - # assert cached is true + cached=$(govc library.info -json subscribed-content/ttylinux-latest | jq '.[].cached' -r) + assert_equal "true" "$cached" - run govc library.evict subscribed-content + run govc library.evict subscribed-content/ttylinux-latest assert_success - # assert cached is false + # assert cached is false after library item evict + result=$(govc library.info -json subscribed-content/ttylinux-latest) + echo "$result" + cached=$(govc library.info -json subscribed-content/ttylinux-latest | jq '.[].cached' -r) + assert_equal "false" "$cached" } diff --git a/vapi/simulator/simulator.go b/vapi/simulator/simulator.go index af1ef9df5..b1d23189f 100644 --- a/vapi/simulator/simulator.go +++ b/vapi/simulator/simulator.go @@ -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 { @@ -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) @@ -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) @@ -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) @@ -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())