add vendoring with go dep

This commit is contained in:
Adrian Todorov
2017-10-25 20:52:40 +00:00
parent 704f4d20d1
commit a59409f16b
1627 changed files with 489673 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
/*
Copyright (c) 2015-2017 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package autostart
import (
"context"
"flag"
"fmt"
"strings"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/vim25/types"
)
type add struct {
*AutostartFlag
// from types.AutoStartPowerInfo
StartOrder int32
StartDelay int32
WaitForHeartbeat string
StartAction string
StopDelay int32
StopAction string
}
func init() {
cli.Register("host.autostart.add", &add{})
}
var waitHeartbeatTypes = []string{
string(types.AutoStartWaitHeartbeatSettingSystemDefault),
string(types.AutoStartWaitHeartbeatSettingYes),
string(types.AutoStartWaitHeartbeatSettingNo),
}
func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
cmd.AutostartFlag, ctx = newAutostartFlag(ctx)
cmd.AutostartFlag.Register(ctx, f)
cmd.StartOrder = -1
cmd.StartDelay = -1
cmd.StopDelay = -1
f.Var(flags.NewInt32(&cmd.StartOrder), "start-order", "Start Order")
f.Var(flags.NewInt32(&cmd.StartDelay), "start-delay", "Start Delay")
f.Var(flags.NewInt32(&cmd.StopDelay), "stop-delay", "Stop Delay")
f.StringVar(&cmd.StartAction, "start-action", "powerOn", "Start Action")
f.StringVar(&cmd.StopAction, "stop-action", "systemDefault", "Stop Action")
f.StringVar(&cmd.WaitForHeartbeat, "wait", waitHeartbeatTypes[0],
fmt.Sprintf("Wait for Hearbeat Setting (%s)", strings.Join(waitHeartbeatTypes, "|")))
}
func (cmd *add) Process(ctx context.Context) error {
if err := cmd.AutostartFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *add) Usage() string {
return "VM..."
}
func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
powerInfo := types.AutoStartPowerInfo{
StartOrder: cmd.StartOrder,
StartDelay: cmd.StartDelay,
WaitForHeartbeat: types.AutoStartWaitHeartbeatSetting(cmd.WaitForHeartbeat),
StartAction: cmd.StartAction,
StopDelay: cmd.StopDelay,
StopAction: cmd.StopAction,
}
return cmd.ReconfigureVMs(f.Args(), powerInfo)
}

View File

@@ -0,0 +1,177 @@
/*
Copyright (c) 2015 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package autostart
import (
"context"
"errors"
"flag"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/mo"
"github.com/vmware/govmomi/vim25/types"
)
type AutostartFlag struct {
*flags.ClientFlag
*flags.DatacenterFlag
*flags.HostSystemFlag
}
func newAutostartFlag(ctx context.Context) (*AutostartFlag, context.Context) {
f := &AutostartFlag{}
f.ClientFlag, ctx = flags.NewClientFlag(ctx)
f.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
f.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
return f, ctx
}
func (f *AutostartFlag) Register(ctx context.Context, fs *flag.FlagSet) {
f.ClientFlag.Register(ctx, fs)
f.DatacenterFlag.Register(ctx, fs)
f.HostSystemFlag.Register(ctx, fs)
}
func (f *AutostartFlag) Process(ctx context.Context) error {
if err := f.ClientFlag.Process(ctx); err != nil {
return err
}
if err := f.DatacenterFlag.Process(ctx); err != nil {
return err
}
if err := f.HostSystemFlag.Process(ctx); err != nil {
return err
}
return nil
}
// VirtualMachines returns list of virtual machine objects based on the
// arguments specified on the command line. This helper is defined in
// flags.SearchFlag as well, but that pulls in other virtual machine flags that
// are not relevant here.
func (f *AutostartFlag) VirtualMachines(args []string) ([]*object.VirtualMachine, error) {
ctx := context.TODO()
if len(args) == 0 {
return nil, errors.New("no argument")
}
finder, err := f.Finder()
if err != nil {
return nil, err
}
var out []*object.VirtualMachine
for _, arg := range args {
vms, err := finder.VirtualMachineList(ctx, arg)
if err != nil {
return nil, err
}
out = append(out, vms...)
}
return out, nil
}
func (f *AutostartFlag) HostAutoStartManager() (*mo.HostAutoStartManager, error) {
ctx := context.TODO()
h, err := f.HostSystem()
if err != nil {
return nil, err
}
var mhs mo.HostSystem
err = h.Properties(ctx, h.Reference(), []string{"configManager.autoStartManager"}, &mhs)
if err != nil {
return nil, err
}
var mhas mo.HostAutoStartManager
err = h.Properties(ctx, *mhs.ConfigManager.AutoStartManager, nil, &mhas)
if err != nil {
return nil, err
}
return &mhas, nil
}
func (f *AutostartFlag) ReconfigureDefaults(template types.AutoStartDefaults) error {
ctx := context.TODO()
c, err := f.Client()
if err != nil {
return err
}
mhas, err := f.HostAutoStartManager()
if err != nil {
return err
}
req := types.ReconfigureAutostart{
This: mhas.Reference(),
Spec: types.HostAutoStartManagerConfig{
Defaults: &template,
},
}
_, err = methods.ReconfigureAutostart(ctx, c, &req)
if err != nil {
return err
}
return nil
}
func (f *AutostartFlag) ReconfigureVMs(args []string, template types.AutoStartPowerInfo) error {
ctx := context.TODO()
c, err := f.Client()
if err != nil {
return err
}
mhas, err := f.HostAutoStartManager()
if err != nil {
return err
}
req := types.ReconfigureAutostart{
This: mhas.Reference(),
Spec: types.HostAutoStartManagerConfig{
PowerInfo: make([]types.AutoStartPowerInfo, 0),
},
}
vms, err := f.VirtualMachines(args)
if err != nil {
return err
}
for _, vm := range vms {
pi := template
pi.Key = vm.Reference()
req.Spec.PowerInfo = append(req.Spec.PowerInfo, pi)
}
_, err = methods.ReconfigureAutostart(ctx, c, &req)
if err != nil {
return err
}
return nil
}

View File

@@ -0,0 +1,62 @@
/*
Copyright (c) 2015 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package autostart
import (
"context"
"flag"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/vim25/types"
)
type configure struct {
*AutostartFlag
types.AutoStartDefaults
}
func init() {
cli.Register("host.autostart.configure", &configure{})
}
func (cmd *configure) Register(ctx context.Context, f *flag.FlagSet) {
cmd.AutostartFlag, ctx = newAutostartFlag(ctx)
cmd.AutostartFlag.Register(ctx, f)
f.Var(flags.NewOptionalBool(&cmd.Enabled), "enabled", "")
f.Var(flags.NewInt32(&cmd.StartDelay), "start-delay", "")
f.StringVar(&cmd.StopAction, "stop-action", "", "")
f.Var(flags.NewInt32(&cmd.StopDelay), "stop-delay", "")
f.Var(flags.NewOptionalBool(&cmd.WaitForHeartbeat), "wait-for-heartbeat", "")
}
func (cmd *configure) Process(ctx context.Context) error {
if err := cmd.AutostartFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *configure) Usage() string {
return ""
}
func (cmd *configure) Run(ctx context.Context, f *flag.FlagSet) error {
return cmd.ReconfigureDefaults(cmd.AutoStartDefaults)
}

View File

@@ -0,0 +1,144 @@
/*
Copyright (c) 2015 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package autostart
import (
"context"
"encoding/json"
"flag"
"fmt"
"io"
"os"
"text/tabwriter"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/mo"
)
type info struct {
cli.Command
*AutostartFlag
*flags.OutputFlag
}
func init() {
cli.Register("host.autostart.info", &info{})
}
func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
cmd.AutostartFlag, ctx = newAutostartFlag(ctx)
cmd.AutostartFlag.Register(ctx, f)
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
cmd.OutputFlag.Register(ctx, f)
}
func (cmd *info) Process(ctx context.Context) error {
if err := cmd.AutostartFlag.Process(ctx); err != nil {
return err
}
if err := cmd.OutputFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *info) Usage() string {
return ""
}
func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
client, err := cmd.Client()
if err != nil {
return err
}
mhas, err := cmd.HostAutoStartManager()
if err != nil {
return err
}
return cmd.WriteResult(&infoResult{client, mhas})
}
type infoResult struct {
client *vim25.Client
mhas *mo.HostAutoStartManager
}
func (r *infoResult) MarshalJSON() ([]byte, error) {
return json.Marshal(r.mhas)
}
// vmPaths resolves the paths for the VMs in the result.
func (r *infoResult) vmPaths() (map[string]string, error) {
ctx := context.TODO()
paths := make(map[string]string)
for _, info := range r.mhas.Config.PowerInfo {
mes, err := mo.Ancestors(ctx, r.client, r.client.ServiceContent.PropertyCollector, info.Key)
if err != nil {
return nil, err
}
path := ""
for _, me := range mes {
// Skip root entity in building inventory path.
if me.Parent == nil {
continue
}
path += "/" + me.Name
}
paths[info.Key.Value] = path
}
return paths, nil
}
func (r *infoResult) Write(w io.Writer) error {
paths, err := r.vmPaths()
if err != nil {
return err
}
tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
fmt.Fprintf(tw, "VM")
fmt.Fprintf(tw, "\tStartAction")
fmt.Fprintf(tw, "\tStartDelay")
fmt.Fprintf(tw, "\tStartOrder")
fmt.Fprintf(tw, "\tStopAction")
fmt.Fprintf(tw, "\tStopDelay")
fmt.Fprintf(tw, "\tWaitForHeartbeat")
fmt.Fprintf(tw, "\n")
for _, info := range r.mhas.Config.PowerInfo {
fmt.Fprintf(tw, "%s", paths[info.Key.Value])
fmt.Fprintf(tw, "\t%s", info.StartAction)
fmt.Fprintf(tw, "\t%d", info.StartDelay)
fmt.Fprintf(tw, "\t%d", info.StartOrder)
fmt.Fprintf(tw, "\t%s", info.StopAction)
fmt.Fprintf(tw, "\t%d", info.StopDelay)
fmt.Fprintf(tw, "\t%s", info.WaitForHeartbeat)
fmt.Fprintf(tw, "\n")
}
_ = tw.Flush()
return nil
}

View File

@@ -0,0 +1,62 @@
/*
Copyright (c) 2015 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package autostart
import (
"context"
"flag"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/vim25/types"
)
type remove struct {
*AutostartFlag
}
func init() {
cli.Register("host.autostart.remove", &remove{})
}
func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) {
cmd.AutostartFlag, ctx = newAutostartFlag(ctx)
cmd.AutostartFlag.Register(ctx, f)
}
func (cmd *remove) Process(ctx context.Context) error {
if err := cmd.AutostartFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *remove) Usage() string {
return "VM..."
}
func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error {
var powerInfo = types.AutoStartPowerInfo{
StartAction: "none",
StartDelay: -1,
StartOrder: -1,
StopAction: "none",
StopDelay: -1,
WaitForHeartbeat: types.AutoStartWaitHeartbeatSettingSystemDefault,
}
return cmd.ReconfigureVMs(f.Args(), powerInfo)
}