mirror of
https://github.com/nikdoof/vsphere-influxdb-go.git
synced 2025-12-19 21:49:21 +00:00
add vendoring with go dep
This commit is contained in:
81
vendor/github.com/vmware/govmomi/examples/datastores/main.go
generated
vendored
Normal file
81
vendor/github.com/vmware/govmomi/examples/datastores/main.go
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
This example program shows how the `view` and `property` packages can
|
||||
be used to navigate a vSphere inventory structure using govmomi.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/examples"
|
||||
"github.com/vmware/govmomi/units"
|
||||
"github.com/vmware/govmomi/view"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// Connect and log in to ESX or vCenter
|
||||
c, err := examples.NewClient(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer c.Logout(ctx)
|
||||
|
||||
// Create a view of Datastore objects
|
||||
m := view.NewManager(c.Client)
|
||||
|
||||
v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"Datastore"}, true)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer v.Destroy(ctx)
|
||||
|
||||
// Retrieve summary property for all datastores
|
||||
// Reference: http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.Datastore.html
|
||||
var dss []mo.Datastore
|
||||
err = v.Retrieve(ctx, []string{"Datastore"}, []string{"summary"}, &dss)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Print summary per datastore (see also: govc/datastore/info.go)
|
||||
|
||||
tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
|
||||
fmt.Fprintf(tw, "Name:\tType:\tCapacity:\tFree:\n")
|
||||
|
||||
for _, ds := range dss {
|
||||
fmt.Fprintf(tw, "%s\t", ds.Summary.Name)
|
||||
fmt.Fprintf(tw, "%s\t", ds.Summary.Type)
|
||||
fmt.Fprintf(tw, "%s\t", units.ByteSize(ds.Summary.Capacity))
|
||||
fmt.Fprintf(tw, "%s\t", units.ByteSize(ds.Summary.FreeSpace))
|
||||
fmt.Fprintf(tw, "\n")
|
||||
}
|
||||
|
||||
_ = tw.Flush()
|
||||
}
|
||||
116
vendor/github.com/vmware/govmomi/examples/examples.go
generated
vendored
Normal file
116
vendor/github.com/vmware/govmomi/examples/examples.go
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
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 examples
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi"
|
||||
"github.com/vmware/govmomi/vim25/soap"
|
||||
)
|
||||
|
||||
// getEnvString returns string from environment variable.
|
||||
func getEnvString(v string, def string) string {
|
||||
r := os.Getenv(v)
|
||||
if r == "" {
|
||||
return def
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// getEnvBool returns boolean from environment variable.
|
||||
func getEnvBool(v string, def bool) bool {
|
||||
r := os.Getenv(v)
|
||||
if r == "" {
|
||||
return def
|
||||
}
|
||||
|
||||
switch strings.ToLower(r[0:1]) {
|
||||
case "t", "y", "1":
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
const (
|
||||
envURL = "GOVMOMI_URL"
|
||||
envUserName = "GOVMOMI_USERNAME"
|
||||
envPassword = "GOVMOMI_PASSWORD"
|
||||
envInsecure = "GOVMOMI_INSECURE"
|
||||
)
|
||||
|
||||
var urlDescription = fmt.Sprintf("ESX or vCenter URL [%s]", envURL)
|
||||
var urlFlag = flag.String("url", getEnvString(envURL, "https://username:password@host/sdk"), urlDescription)
|
||||
|
||||
var insecureDescription = fmt.Sprintf("Don't verify the server's certificate chain [%s]", envInsecure)
|
||||
var insecureFlag = flag.Bool("insecure", getEnvBool(envInsecure, false), insecureDescription)
|
||||
|
||||
func processOverride(u *url.URL) {
|
||||
envUsername := os.Getenv(envUserName)
|
||||
envPassword := os.Getenv(envPassword)
|
||||
|
||||
// Override username if provided
|
||||
if envUsername != "" {
|
||||
var password string
|
||||
var ok bool
|
||||
|
||||
if u.User != nil {
|
||||
password, ok = u.User.Password()
|
||||
}
|
||||
|
||||
if ok {
|
||||
u.User = url.UserPassword(envUsername, password)
|
||||
} else {
|
||||
u.User = url.User(envUsername)
|
||||
}
|
||||
}
|
||||
|
||||
// Override password if provided
|
||||
if envPassword != "" {
|
||||
var username string
|
||||
|
||||
if u.User != nil {
|
||||
username = u.User.Username()
|
||||
}
|
||||
|
||||
u.User = url.UserPassword(username, envPassword)
|
||||
}
|
||||
}
|
||||
|
||||
// NewClient creates a govmomi.Client for use in the examples
|
||||
func NewClient(ctx context.Context) (*govmomi.Client, error) {
|
||||
flag.Parse()
|
||||
|
||||
// Parse URL from string
|
||||
u, err := soap.ParseURL(*urlFlag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Override username and/or password as required
|
||||
processOverride(u)
|
||||
|
||||
// Connect and log in to ESX or vCenter
|
||||
return govmomi.NewClient(ctx, u, *insecureFlag)
|
||||
}
|
||||
87
vendor/github.com/vmware/govmomi/examples/hosts/main.go
generated
vendored
Normal file
87
vendor/github.com/vmware/govmomi/examples/hosts/main.go
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
This example program shows how the `view` and `property` packages can
|
||||
be used to navigate a vSphere inventory structure using govmomi.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/examples"
|
||||
"github.com/vmware/govmomi/units"
|
||||
"github.com/vmware/govmomi/view"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// Connect and login to ESX or vCenter
|
||||
c, err := examples.NewClient(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer c.Logout(ctx)
|
||||
|
||||
// Create a view of HostSystem objects
|
||||
m := view.NewManager(c.Client)
|
||||
|
||||
v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"HostSystem"}, true)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer v.Destroy(ctx)
|
||||
|
||||
// Retrieve summary property for all hosts
|
||||
// Reference: http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.HostSystem.html
|
||||
var hss []mo.HostSystem
|
||||
err = v.Retrieve(ctx, []string{"HostSystem"}, []string{"summary"}, &hss)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Print summary per host (see also: govc/host/info.go)
|
||||
|
||||
tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
|
||||
fmt.Fprintf(tw, "Name:\tUsed CPU:\tTotal CPU:\tFree CPU:\tUsed Memory:\tTotal Memory:\tFree Memory\t:\n")
|
||||
|
||||
for _, hs := range hss {
|
||||
totalCPU := int64(hs.Summary.Hardware.CpuMhz) * int64(hs.Summary.Hardware.NumCpuCores)
|
||||
freeCPU := int64(totalCPU) - int64(hs.Summary.QuickStats.OverallCpuUsage)
|
||||
freeMemory := int64(hs.Summary.Hardware.MemorySize) - (int64(hs.Summary.QuickStats.OverallMemoryUsage) * 1024 * 1024)
|
||||
fmt.Fprintf(tw, "%s\t", hs.Summary.Config.Name)
|
||||
fmt.Fprintf(tw, "%d\t", hs.Summary.QuickStats.OverallCpuUsage)
|
||||
fmt.Fprintf(tw, "%d\t", totalCPU)
|
||||
fmt.Fprintf(tw, "%d\t", freeCPU)
|
||||
fmt.Fprintf(tw, "%s\t", units.ByteSize(hs.Summary.QuickStats.OverallMemoryUsage))
|
||||
fmt.Fprintf(tw, "%s\t", units.ByteSize(hs.Summary.Hardware.MemorySize))
|
||||
fmt.Fprintf(tw, "%d\t", freeMemory)
|
||||
fmt.Fprintf(tw, "\n")
|
||||
}
|
||||
|
||||
_ = tw.Flush()
|
||||
}
|
||||
61
vendor/github.com/vmware/govmomi/examples/networks/main.go
generated
vendored
Normal file
61
vendor/github.com/vmware/govmomi/examples/networks/main.go
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
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 main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/vmware/govmomi/examples"
|
||||
"github.com/vmware/govmomi/view"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// Connect and login to ESX or vCenter
|
||||
c, err := examples.NewClient(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer c.Logout(ctx)
|
||||
|
||||
// Create a view of Network types
|
||||
m := view.NewManager(c.Client)
|
||||
|
||||
v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"Network"}, true)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer v.Destroy(ctx)
|
||||
|
||||
// Reference: http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.Network.html
|
||||
var networks []mo.Network
|
||||
err = v.Retrieve(ctx, []string{"Network"}, nil, &networks)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, net := range networks {
|
||||
fmt.Printf("%s: %s\n", net.Name, net.Reference())
|
||||
}
|
||||
}
|
||||
69
vendor/github.com/vmware/govmomi/examples/virtualmachines/main.go
generated
vendored
Normal file
69
vendor/github.com/vmware/govmomi/examples/virtualmachines/main.go
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
This example program shows how the `view` package can
|
||||
be used to navigate a vSphere inventory structure using govmomi.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/vmware/govmomi/examples"
|
||||
"github.com/vmware/govmomi/view"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// Connect and login to ESX or vCenter
|
||||
c, err := examples.NewClient(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer c.Logout(ctx)
|
||||
|
||||
// Create view of VirtualMachine objects
|
||||
m := view.NewManager(c.Client)
|
||||
|
||||
v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"VirtualMachine"}, true)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer v.Destroy(ctx)
|
||||
|
||||
// Retrieve summary property for all machines
|
||||
// Reference: http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.VirtualMachine.html
|
||||
var vms []mo.VirtualMachine
|
||||
err = v.Retrieve(ctx, []string{"VirtualMachine"}, []string{"summary"}, &vms)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Print summary per vm (see also: govc/vm/info.go)
|
||||
|
||||
for _, vm := range vms {
|
||||
fmt.Printf("%s: %s\n", vm.Summary.Config.Name, vm.Summary.Config.GuestFullName)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user