github.com/vmware/govmomi@v0.43.0/govc/cluster/draft/baseimage/info.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 draft 18 19 import ( 20 "context" 21 "flag" 22 "io" 23 24 "github.com/vmware/govmomi/govc/cli" 25 "github.com/vmware/govmomi/govc/flags" 26 "github.com/vmware/govmomi/vapi/esx/settings/clusters" 27 ) 28 29 type infoResult clusters.SettingsBaseImageInfo 30 31 func (r infoResult) Write(w io.Writer) error { 32 return nil 33 } 34 35 type info struct { 36 *flags.ClientFlag 37 *flags.OutputFlag 38 39 clusterId string 40 draftId string 41 } 42 43 func init() { 44 cli.Register("cluster.draft.baseimage.info", &info{}) 45 } 46 47 func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) { 48 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 49 cmd.ClientFlag.Register(ctx, f) 50 cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx) 51 52 f.StringVar(&cmd.clusterId, "cluster-id", "", "The identifier of the cluster.") 53 f.StringVar(&cmd.draftId, "draft-id", "", "The identifier of the software draft.") 54 } 55 56 func (cmd *info) Process(ctx context.Context) error { 57 if err := cmd.ClientFlag.Process(ctx); err != nil { 58 return err 59 } 60 if err := cmd.OutputFlag.Process(ctx); err != nil { 61 return err 62 } 63 64 return nil 65 } 66 67 func (cmd *info) Usage() string { 68 return "CLUSTER" 69 } 70 71 func (cmd *info) Description() string { 72 return `Displays the base image version of a software draft. 73 74 Examples: 75 govc cluster.draft.baseimage.info -cluster-id=domain-c21 -draft-id=13` 76 } 77 78 func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error { 79 rc, err := cmd.RestClient() 80 81 if err != nil { 82 return err 83 } 84 85 dm := clusters.NewManager(rc) 86 87 if d, err := dm.GetSoftwareDraftBaseImage(cmd.clusterId, cmd.draftId); err != nil { 88 return err 89 } else { 90 if !cmd.All() { 91 cmd.JSON = true 92 } 93 return cmd.WriteResult(infoResult(d)) 94 } 95 }