forked from vmware-archive/dispatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vcenter.go
46 lines (37 loc) · 1.18 KB
/
vcenter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
///////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
///////////////////////////////////////////////////////////////////////
package cmd
import (
"io"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/vmware/dispatch/pkg/event-driver/drivers/vcenter"
)
// NO TESTS
// NewCmdVCenter creates a command object for vCenter driver.
func NewCmdVCenter(out io.Writer, errOut io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "vcenter",
Short: "Run vCenter driver",
RunE: vCenterDriverCmd(out, errOut),
}
cmd.Flags().String("vcenterurl", "https://vcenter.corp.local:443", "URL to vCenter instance")
viper.BindPFlag("vcenterurl", cmd.Flags().Lookup("vcenterurl"))
return cmd
}
func vCenterDriverCmd(out io.Writer, errOut io.Writer) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
consumer, err := vcenter.NewConsumer(viper.GetString("vcenterurl"), true)
if err != nil {
return err
}
driver, err := makeDriver(consumer)
if err != nil {
return err
}
defer driver.Close()
return driver.Run()
}
}