func Example_2() {
	session := vim.NewVSphereSession("https://172.16.103.128/sdk", "user", "password", true)

	c, err := session.ServiceInstance.Capability()
	if err != nil {
		panic(err)
	}

	fmt.Printf("Capabilities -> %+v\n", c)

	// Supported since vSphere API 5.1 only
	// userAgent := session.UserSession.UserAgent
	// fmt.Printf("User Agent -> %s\n", userAgent)

	err = session.ServiceContent.SessionManager.Logout()
	if err != nil {
		panic(err)
	}

	c, err = session.ServiceInstance.Capability()
	if err != nil {
		panic(err)
	}

	fmt.Printf("There is not an active session, Capabilities -> %+v\n", c)
}
示例#2
0
func Example_1() {

	session := vim.NewVSphereSession("https://172.16.103.128/sdk", "username", "password", true)

	content, err := session.ServiceInstance.Content()

	if err != nil {
		panic("unable to get the service content")
	}

	children, err := content.RootFolder.ChildEntity() // <------- THIS CALL WILL PANIC

	if err != nil {
		panic(err)
	}

	fmt.Printf("--> %#v <--\n", children[0].Type)

	types, err := content.RootFolder.ChildType()
	if err != nil {
		panic(err)
	}
	fmt.Printf("--> %#v <--\n", types)

	err = session.ServiceContent.SessionManager.Logout()
	if err != nil {
		panic("unable to logout from the vsphere server")
	}

	fmt.Println("Done!")
}
示例#3
0
func main() {

	//disable logging.
	log.SetOutput(ioutil.Discard)

	session := vim.NewVSphereSession("https://myhost.com/sdk", "myusername", "mypassword", true)

	content, err := session.ServiceInstance.Content()

	if err != nil {
		fmt.Printf("--> Encountered an error getting content from ServiceInstance: %#v <--\n", err)
		panic(err)
	}

	children, err := content.RootFolder.ChildEntity()

	if err != nil {
		fmt.Printf("--> Encountered an error getting childEntity from vmFolder: %#v <--\n", err)
		panic(err)
	}

	for _, child := range children {

		if child.Type == "Datacenter" {

			datacenter := &vim.Datacenter{
				ManagedEntity: child,
			}

			vmfolder, err := datacenter.VmFolder()
			if err != nil {
				fmt.Printf("--> Encountered an error getting vmFolder from datacenter: %#v <--\n", err)
				panic(err)
			}

			FolderTraverser(vmfolder, "VirtualMachine", ProcessVm)
		}
	}

	err = session.ServiceContent.SessionManager.Logout()

	if err != nil {
		fmt.Printf("--> Unable to logout! Error: %#v <--\n", err)
		panic(err)
	}

	fmt.Println("Done!")
}