Last active
August 29, 2015 14:13
-
-
Save jmmcatee/f2f77184d20cc86e96b3 to your computer and use it in GitHub Desktop.
govmomi Template as VirtualMachine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/jmmcatee/go-vsphere-utils" | |
"github.com/vmware/govmomi" | |
"github.com/vmware/govmomi/vim25/mo" | |
"net/url" | |
) | |
func main() { | |
vCenterURL, err := url.Parse("https://url/sdk") | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
vClient, err := govmomi.NewClient(*vCenterURL, true) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
// This returns a map[string][]govmomi.Reference{} where the string is the Reference.Type() | |
m, err := govsphereutils.InventoryMap(vClient) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
for key, value := range m { | |
for _, v := range value { | |
if key == "VirtualMachine" { | |
var vm mo.VirtualMachine | |
vClient.Properties(v.Reference(), nil, &vm) | |
if vm.Name == "" { | |
fmt.Printf("%v\n", vm) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment