github.com/vmware/govmomi@v0.43.0/govc/cluster/draft/commit.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 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/clusters" 27 ) 28 29 type commit struct { 30 *flags.ClientFlag 31 32 clusterId string 33 draftId string 34 } 35 36 func init() { 37 cli.Register("cluster.draft.commit", &commit{}) 38 } 39 40 func (cmd *commit) Register(ctx context.Context, f *flag.FlagSet) { 41 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 42 cmd.ClientFlag.Register(ctx, f) 43 44 f.StringVar(&cmd.clusterId, "cluster-id", "", "The identifier of the cluster.") 45 f.StringVar(&cmd.draftId, "draft-id", "", "The identifier of the software draft.") 46 } 47 48 func (cmd *commit) Process(ctx context.Context) error { 49 return cmd.ClientFlag.Process(ctx) 50 } 51 52 func (cmd *commit) Usage() string { 53 return "CLUSTER" 54 } 55 56 func (cmd *commit) Description() string { 57 return `Commits the provided software draft. 58 59 Execution will block the terminal for the duration of the task. 60 61 Examples: 62 govc cluster.draft.commit -cluster-id=domain-c21 -draft-id=13` 63 } 64 65 func (cmd *commit) Run(ctx context.Context, f *flag.FlagSet) error { 66 rc, err := cmd.RestClient() 67 68 if err != nil { 69 return err 70 } 71 72 dm := clusters.NewManager(rc) 73 74 if taskId, err := dm.CommitSoftwareDraft(cmd.clusterId, cmd.draftId, clusters.SettingsClustersSoftwareDraftsCommitSpec{}); err != nil { 75 return err 76 } else if _, err = tasks.NewManager(rc).WaitForCompletion(ctx, taskId); err != nil { 77 return err 78 } else { 79 return nil 80 } 81 }