github.com/vmware/govmomi@v0.43.0/govc/vlcm/depot/offline/create.go (about) 1 /* 2 Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package offline 18 19 import ( 20 "context" 21 "flag" 22 23 "github.com/vmware/govmomi/govc/cli" 24 "github.com/vmware/govmomi/govc/flags" 25 "github.com/vmware/govmomi/vapi/cis/tasks" 26 "github.com/vmware/govmomi/vapi/esx/settings/depots" 27 ) 28 29 type create struct { 30 *flags.ClientFlag 31 32 spec depots.SettingsDepotsOfflineCreateSpec 33 } 34 35 func init() { 36 cli.Register("vlcm.depot.offline.create", &create{}) 37 } 38 39 func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) { 40 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 41 cmd.ClientFlag.Register(ctx, f) 42 43 f.StringVar(&cmd.spec.Location, "l", "", "The URL to the depot contents. Only applicable when source-type is PULL") 44 f.StringVar(&cmd.spec.Description, "d", "", "An optional description") 45 f.StringVar(&cmd.spec.OwnerData, "owner-data", "", "Optional data about the depot's owner") 46 f.StringVar(&cmd.spec.FileId, "file-id", "", "File identifier. Only used when source-type is PUSH") 47 f.StringVar(&cmd.spec.SourceType, "source-type", string(depots.SourceTypePull), "The depot source type. The default is PULL") 48 } 49 50 func (cmd *create) Process(ctx context.Context) error { 51 return cmd.ClientFlag.Process(ctx) 52 } 53 54 func (cmd *create) Usage() string { 55 return "VLCM" 56 } 57 58 func (cmd *create) Description() string { 59 return `Creates an offline image depot. 60 61 Execution will block the terminal for the duration of the task. 62 63 Examples: 64 govc vlcm.depot.offline.create -l=<https://your.server.com/filepath> 65 govc vlcm.depot.offline.create -l=<https://your.server.com/filepath> -source-type=PULL 66 govc vlcm.depot.offline.create -file-id=<your file identifier> -source-type=PUSH 67 govc vlcm.depot.offline.create -l=<https://your.server.com/filepath> -source-type=PULL -d="This is a depot used for testing" -owner-data="After all, why not? Why shouldn't I keep it?"` 68 } 69 70 func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error { 71 rc, err := cmd.RestClient() 72 73 if err != nil { 74 return err 75 } 76 77 dm := depots.NewManager(rc) 78 79 if taskId, err := dm.CreateOfflineDepot(cmd.spec); err != nil { 80 return err 81 } else if _, err = tasks.NewManager(rc).WaitForCompletion(ctx, taskId); err != nil { 82 return err 83 } else { 84 return nil 85 } 86 }