1
0
mirror of https://github.com/Oxalide/vsphere-influxdb-go.git synced 2023-10-10 11:36:51 +00:00

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

244
vendor/github.com/vmware/govmomi/govc/object/collect.go generated vendored Normal file
View File

@@ -0,0 +1,244 @@
/*
Copyright (c) 2016 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 object
import (
"context"
"encoding/json"
"flag"
"fmt"
"io"
"reflect"
"strings"
"text/tabwriter"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/property"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/types"
)
type collect struct {
*flags.DatacenterFlag
single bool
simple bool
n int
}
func init() {
cli.Register("object.collect", &collect{})
}
func (cmd *collect) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
cmd.DatacenterFlag.Register(ctx, f)
f.BoolVar(&cmd.simple, "s", false, "Output property value only")
f.IntVar(&cmd.n, "n", 0, "Wait for N property updates")
}
func (cmd *collect) Usage() string {
return "[MOID] [PROPERTY]..."
}
func (cmd *collect) Description() string {
return `Collect managed object properties.
MOID can be an inventory path or ManagedObjectReference.
MOID defaults to '-', an alias for 'ServiceInstance:ServiceInstance'.
By default only the current property value(s) are collected. Use the '-n' flag to wait for updates.
Examples:
govc object.collect - content
govc object.collect -s HostSystem:ha-host hardware.systemInfo.uuid
govc object.collect -s /ha-datacenter/vm/foo overallStatus
govc object.collect -json -n=-1 EventManager:ha-eventmgr latestEvent | jq .
govc object.collect -json -s $(govc object.collect -s - content.perfManager) description.counterType | jq .`
}
func (cmd *collect) Process(ctx context.Context) error {
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
return err
}
return nil
}
var stringer = reflect.TypeOf((*fmt.Stringer)(nil)).Elem()
type change struct {
cmd *collect
PropertyChange []types.PropertyChange
}
func (pc *change) MarshalJSON() ([]byte, error) {
return json.Marshal(pc.PropertyChange)
}
func (pc *change) output(name string, rval reflect.Value, rtype reflect.Type) {
s := "..."
kind := rval.Kind()
if kind == reflect.Ptr || kind == reflect.Interface {
if rval.IsNil() {
s = ""
} else {
rval = rval.Elem()
kind = rval.Kind()
}
}
switch kind {
case reflect.Ptr, reflect.Interface:
case reflect.Slice:
if rval.Len() == 0 {
s = ""
break
}
etype := rtype.Elem()
if etype.Kind() != reflect.Interface && etype.Kind() != reflect.Struct || etype.Implements(stringer) {
var val []string
for i := 0; i < rval.Len(); i++ {
v := rval.Index(i).Interface()
if fstr, ok := v.(fmt.Stringer); ok {
s = fstr.String()
} else {
s = fmt.Sprintf("%v", v)
}
val = append(val, s)
}
s = strings.Join(val, ",")
}
case reflect.Struct:
if rtype.Implements(stringer) {
s = rval.Interface().(fmt.Stringer).String()
}
default:
s = fmt.Sprintf("%v", rval.Interface())
}
if pc.cmd.simple {
fmt.Fprintln(pc.cmd.Out, s)
return
}
fmt.Fprintf(pc.cmd.Out, "%s\t%s\t%s\n", name, rtype, s)
}
func (pc *change) writeStruct(name string, rval reflect.Value, rtype reflect.Type) {
for i := 0; i < rval.NumField(); i++ {
fval := rval.Field(i)
field := rtype.Field(i)
if field.Anonymous {
pc.writeStruct(name, fval, fval.Type())
continue
}
fname := fmt.Sprintf("%s.%s%s", name, strings.ToLower(field.Name[:1]), field.Name[1:])
pc.output(fname, fval, field.Type)
}
}
func (pc *change) Write(w io.Writer) error {
tw := tabwriter.NewWriter(pc.cmd.Out, 4, 0, 2, ' ', 0)
pc.cmd.Out = tw
for _, c := range pc.PropertyChange {
if c.Val == nil {
// type is unknown in this case, as xsi:type was not provided - just skip for now
continue
}
rval := reflect.ValueOf(c.Val)
rtype := rval.Type()
if strings.HasPrefix(rtype.Name(), "ArrayOf") {
rval = rval.Field(0)
rtype = rval.Type()
}
if pc.cmd.single && rtype.Kind() == reflect.Struct && !rtype.Implements(stringer) {
pc.writeStruct(c.Name, rval, rtype)
continue
}
pc.output(c.Name, rval, rtype)
}
return tw.Flush()
}
func (cmd *collect) Run(ctx context.Context, f *flag.FlagSet) error {
client, err := cmd.Client()
if err != nil {
return err
}
finder, err := cmd.Finder()
if err != nil {
return err
}
ref := methods.ServiceInstance
arg := f.Arg(0)
switch arg {
case "", "-":
default:
if !ref.FromString(arg) {
l, ferr := finder.ManagedObjectList(ctx, arg)
if ferr != nil {
return err
}
switch len(l) {
case 0:
return fmt.Errorf("%s not found", arg)
case 1:
ref = l[0].Object.Reference()
default:
return flag.ErrHelp
}
}
}
p := property.DefaultCollector(client)
var props []string
if f.NArg() > 1 {
props = f.Args()[1:]
cmd.single = len(props) == 1
}
return property.Wait(ctx, p, ref, props, func(pc []types.PropertyChange) bool {
_ = cmd.WriteResult(&change{cmd, pc})
cmd.n--
return cmd.n == -1
})
}

View File

@@ -0,0 +1,90 @@
/*
Copyright (c) 2016 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 object
import (
"context"
"flag"
"fmt"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/object"
)
type destroy struct {
*flags.DatacenterFlag
}
func init() {
cli.Register("object.destroy", &destroy{})
}
func (cmd *destroy) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
cmd.DatacenterFlag.Register(ctx, f)
}
func (cmd *destroy) Usage() string {
return "PATH..."
}
func (cmd *destroy) Description() string {
return `Destroy managed objects.
Examples:
govc object.destroy /dc1/network/dvs /dc1/host/cluster`
}
func (cmd *destroy) Process(ctx context.Context) error {
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *destroy) Run(ctx context.Context, f *flag.FlagSet) error {
if f.NArg() == 0 {
return flag.ErrHelp
}
c, err := cmd.Client()
if err != nil {
return err
}
objs, err := cmd.ManagedObjects(ctx, f.Args())
if err != nil {
return err
}
for _, obj := range objs {
task, err := object.NewCommon(c, obj).Destroy(ctx)
if err != nil {
return err
}
logger := cmd.ProgressLogger(fmt.Sprintf("destroying %s... ", obj))
_, err = task.WaitForResult(ctx, logger)
logger.Wait()
if err != nil {
return err
}
}
return nil
}

320
vendor/github.com/vmware/govmomi/govc/object/find.go generated vendored Normal file
View File

@@ -0,0 +1,320 @@
/*
Copyright (c) 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 object
import (
"bytes"
"context"
"flag"
"fmt"
"strings"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/property"
"github.com/vmware/govmomi/view"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/types"
)
type find struct {
*flags.DatacenterFlag
ref bool
kind kinds
name string
maxdepth int
}
var alias = []struct {
name string
kind string
}{
{"a", "VirtualApp"},
{"c", "ClusterComputeResource"},
{"d", "Datacenter"},
{"f", "Folder"},
{"g", "DistributedVirtualPortgroup"},
{"h", "HostSystem"},
{"m", "VirtualMachine"},
{"n", "Network"},
{"o", "OpaqueNetwork"},
{"p", "ResourcePool"},
{"r", "ComputeResource"},
{"s", "Datastore"},
{"w", "DistributedVirtualSwitch"},
}
func aliasHelp() string {
var help bytes.Buffer
for _, a := range alias {
fmt.Fprintf(&help, " %s %s\n", a.name, a.kind)
}
return help.String()
}
type kinds []string
func (e *kinds) String() string {
return fmt.Sprint(*e)
}
func (e *kinds) Set(value string) error {
*e = append(*e, e.alias(value))
return nil
}
func (e *kinds) alias(value string) string {
if len(value) != 1 {
return value
}
for _, a := range alias {
if a.name == value {
return a.kind
}
}
return value
}
func (e *kinds) wanted(kind string) bool {
if len(*e) == 0 {
return true
}
for _, k := range *e {
if kind == k {
return true
}
}
return false
}
func init() {
cli.Register("find", &find{})
}
func (cmd *find) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
cmd.DatacenterFlag.Register(ctx, f)
f.Var(&cmd.kind, "type", "Resource type")
f.StringVar(&cmd.name, "name", "*", "Resource name")
f.IntVar(&cmd.maxdepth, "maxdepth", -1, "Max depth")
f.BoolVar(&cmd.ref, "i", false, "Print the managed object reference")
}
func (cmd *find) Usage() string {
return "[ROOT] [KEY VAL]..."
}
func (cmd *find) Description() string {
atable := aliasHelp()
return fmt.Sprintf(`Find managed objects.
ROOT can be an inventory path or ManagedObjectReference.
ROOT defaults to '.', an alias for the root folder or DC if set.
Optional KEY VAL pairs can be used to filter results against object instance properties.
The '-type' flag value can be a managed entity type or one of the following aliases:
%s
Examples:
govc find
govc find /dc1 -type c
govc find vm -name my-vm-*
govc find . -type n
govc find . -type m -runtime.powerState poweredOn
govc find . -type m -datastore $(govc find -i datastore -name vsanDatastore)
govc find . -type s -summary.type vsan
govc find . -type h -hardware.cpuInfo.numCpuCores 16`, atable)
}
func (cmd *find) Process(ctx context.Context) error {
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
return err
}
return nil
}
// rootMatch returns true if the root object path should be printed
func (cmd *find) rootMatch(ctx context.Context, root object.Reference, client *vim25.Client, filter property.Filter) bool {
ref := root.Reference()
if !cmd.kind.wanted(ref.Type) {
return false
}
if len(filter) == 1 && filter["name"] == "*" {
return true
}
var content []types.ObjectContent
pc := property.DefaultCollector(client)
_ = pc.RetrieveWithFilter(ctx, []types.ManagedObjectReference{ref}, filter.Keys(), &content, filter)
return content != nil
}
func (cmd *find) Run(ctx context.Context, f *flag.FlagSet) error {
client, err := cmd.Client()
if err != nil {
return err
}
finder, err := cmd.Finder()
if err != nil {
return err
}
root := client.ServiceContent.RootFolder
rootPath := "/"
arg := f.Arg(0)
props := f.Args()
if len(props) > 0 {
if strings.HasPrefix(arg, "-") {
arg = "."
} else {
props = props[1:]
}
}
if len(props)%2 != 0 {
return flag.ErrHelp
}
switch arg {
case rootPath:
case "", ".":
dc, _ := cmd.DatacenterIfSpecified()
if dc == nil {
arg = rootPath
} else {
arg = "."
root = dc.Reference()
rootPath = dc.InventoryPath
}
default:
l, ferr := finder.ManagedObjectList(ctx, arg)
if ferr != nil {
return err
}
switch len(l) {
case 0:
return fmt.Errorf("%s not found", arg)
case 1:
root = l[0].Object.Reference()
rootPath = l[0].Path
default:
return flag.ErrHelp
}
}
filter := property.Filter{}
for i := 0; i < len(props); i++ {
key := props[i]
if !strings.HasPrefix(key, "-") {
return flag.ErrHelp
}
key = key[1:]
i++
val := props[i]
if xf := f.Lookup(key); xf != nil {
// Support use of -flag following the ROOT arg (flag package does not do this)
if err = xf.Value.Set(val); err != nil {
return err
}
} else {
filter[key] = val
}
}
filter["name"] = cmd.name
printPath := func(o types.ManagedObjectReference, p string) {
if cmd.ref {
fmt.Fprintln(cmd.Out, o)
return
}
path := strings.Replace(p, rootPath, arg, 1)
fmt.Fprintln(cmd.Out, path)
}
recurse := false
switch cmd.maxdepth {
case -1:
recurse = true
case 0:
case 1:
default:
return flag.ErrHelp // TODO: ?
}
if cmd.rootMatch(ctx, root, client, filter) {
printPath(root, arg)
}
if cmd.maxdepth == 0 {
return nil
}
m := view.NewManager(client)
v, err := m.CreateContainerView(ctx, root, cmd.kind, recurse)
if err != nil {
return err
}
defer v.Destroy(ctx)
objs, err := v.Find(ctx, cmd.kind, filter)
if err != nil {
return err
}
for _, o := range objs {
var path string
if !cmd.ref {
e, err := finder.Element(ctx, o)
if err != nil {
return err
}
path = e.Path
}
printPath(o, path)
}
return nil
}

104
vendor/github.com/vmware/govmomi/govc/object/method.go generated vendored Normal file
View File

@@ -0,0 +1,104 @@
/*
Copyright (c) 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 object
import (
"context"
"flag"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/object"
)
type method struct {
*flags.DatacenterFlag
name string
reason string
source string
enable bool
}
func init() {
cli.Register("object.method", &method{})
}
func (cmd *method) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
cmd.DatacenterFlag.Register(ctx, f)
f.StringVar(&cmd.name, "name", "", "Method name")
f.StringVar(&cmd.reason, "reason", "", "Reason for disabling method")
f.StringVar(&cmd.source, "source", "govc", "Source ID")
f.BoolVar(&cmd.enable, "enable", true, "Enable method")
}
func (cmd *method) Usage() string {
return "PATH..."
}
func (cmd *method) Description() string {
return `Enable or disable methods for managed objects.
Examples:
govc object.method -name Destroy_Task -enable=false /dc1/vm/foo
govc object.collect /dc1/vm/foo disabledMethod | grep --color Destroy_Task
govc object.method -name Destroy_Task -enable /dc1/vm/foo`
}
func (cmd *method) Process(ctx context.Context) error {
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *method) Run(ctx context.Context, f *flag.FlagSet) error {
if f.NArg() == 0 {
return flag.ErrHelp
}
if cmd.name == "" {
return flag.ErrHelp
}
c, err := cmd.Client()
if err != nil {
return err
}
objs, err := cmd.ManagedObjects(ctx, f.Args())
if err != nil {
return err
}
m := object.NewAuthorizationManager(c)
if cmd.enable {
return m.EnableMethods(ctx, objs, []string{cmd.name}, cmd.source)
}
method := []object.DisabledMethodRequest{
{
Method: cmd.name,
Reason: cmd.reason,
},
}
return m.DisableMethods(ctx, objs, method, cmd.source)
}

92
vendor/github.com/vmware/govmomi/govc/object/mv.go generated vendored Normal file
View File

@@ -0,0 +1,92 @@
/*
Copyright (c) 2016 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 object
import (
"context"
"flag"
"fmt"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
)
type mv struct {
*flags.DatacenterFlag
}
func init() {
cli.Register("object.mv", &mv{})
}
func (cmd *mv) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
cmd.DatacenterFlag.Register(ctx, f)
}
func (cmd *mv) Usage() string {
return "PATH... FOLDER"
}
func (cmd *mv) Description() string {
return `Move managed entities to FOLDER.
Examples:
govc folder.create /dc1/host/example
govc object.mv /dc2/host/*.example.com /dc1/host/example`
}
func (cmd *mv) Process(ctx context.Context) error {
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *mv) Run(ctx context.Context, f *flag.FlagSet) error {
if f.NArg() < 2 {
return flag.ErrHelp
}
finder, err := cmd.Finder()
if err != nil {
return err
}
n := f.NArg() - 1
folder, err := finder.Folder(ctx, f.Arg(n))
if err != nil {
return err
}
objs, err := cmd.ManagedObjects(ctx, f.Args()[:n])
if err != nil {
return err
}
task, err := folder.MoveInto(ctx, objs)
if err != nil {
return err
}
logger := cmd.ProgressLogger(fmt.Sprintf("moving %d objects to %s... ", len(objs), folder.InventoryPath))
_, err = task.WaitForResult(ctx, logger)
logger.Wait()
return err
}

88
vendor/github.com/vmware/govmomi/govc/object/reload.go generated vendored Normal file
View File

@@ -0,0 +1,88 @@
/*
Copyright (c) 2016 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 object
import (
"context"
"flag"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/types"
)
type reload struct {
*flags.DatacenterFlag
}
func init() {
cli.Register("object.reload", &reload{})
}
func (cmd *reload) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
cmd.DatacenterFlag.Register(ctx, f)
}
func (cmd *reload) Usage() string {
return "PATH..."
}
func (cmd *reload) Description() string {
return `Reload managed object state.
Examples:
govc datastore.upload $vm.vmx $vm/$vm.vmx
govc object.reload /dc1/vm/$vm`
}
func (cmd *reload) Process(ctx context.Context) error {
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *reload) Run(ctx context.Context, f *flag.FlagSet) error {
if f.NArg() == 0 {
return flag.ErrHelp
}
c, err := cmd.Client()
if err != nil {
return err
}
objs, err := cmd.ManagedObjects(ctx, f.Args())
if err != nil {
return err
}
for _, obj := range objs {
req := types.Reload{
This: obj,
}
_, err = methods.Reload(ctx, c, &req)
if err != nil {
return err
}
}
return nil
}

85
vendor/github.com/vmware/govmomi/govc/object/rename.go generated vendored Normal file
View File

@@ -0,0 +1,85 @@
/*
Copyright (c) 2016 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 object
import (
"context"
"flag"
"fmt"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/object"
)
type rename struct {
*flags.DatacenterFlag
}
func init() {
cli.Register("object.rename", &rename{})
}
func (cmd *rename) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
cmd.DatacenterFlag.Register(ctx, f)
}
func (cmd *rename) Usage() string {
return "PATH NAME"
}
func (cmd *rename) Description() string {
return `Rename managed objects.
Examples:
govc object.rename /dc1/network/dvs1 Switch1`
}
func (cmd *rename) Process(ctx context.Context) error {
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *rename) Run(ctx context.Context, f *flag.FlagSet) error {
if f.NArg() != 2 {
return flag.ErrHelp
}
c, err := cmd.Client()
if err != nil {
return err
}
objs, err := cmd.ManagedObjects(ctx, f.Args()[:1])
if err != nil {
return err
}
task, err := object.NewCommon(c, objs[0]).Rename(ctx, f.Arg(1))
if err != nil {
return err
}
logger := cmd.ProgressLogger(fmt.Sprintf("renaming %s... ", objs[0]))
_, err = task.WaitForResult(ctx, logger)
logger.Wait()
return err
}