hooklift / govsphere Goto Github PK
View Code? Open in Web Editor NEWGo API for VMware vSphere
License: Mozilla Public License 2.0
Go API for VMware vSphere
License: Mozilla Public License 2.0
Perhaps using https://github.com/op/go-logging
Here is a gist with the log from the panic.
I ran the code with GDB and this was the output.
Here is the code:
package main
import (
"fmt"
vim "govsphere/vim"
)
func main () {
session := vim.NewVSphereSession("https://myhost.com/sdk", "myuser", "mypassword", true)
content, err := session.ServiceInstance.Content()
if err != nil {
panic("unable to get the service content")
}
childs, err := content.RootFolder.ChildEntity() // <------- THIS CALL WILL PANIC
if err != nil {
panic("unable to get the child entities from the RootFolder")
}
for child := range childs {
fmt.Println("child: %v", child)
}
err = session.ServiceContent.SessionManager.Logout()
if err != nil {
panic("unable to logout from the vsphere server")
}
fmt.Println("Done!")
}
Here is the panic log.
Here is the code to reproduce it:
package main
import (
"fmt"
vim "govsphere/vim"
)
func main() {
session := vim.NewVSphereSession("https://myhost.com/sdk", "myuser", "mypass", 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)
}
vms, err := vmfolder.ChildEntity() // <--- THIS WILL PANIC
if err != nil {
fmt.Printf("--> Encountered an error getting childEntity from vmFolder: %#v <--\n", err)
} else {
fmt.Printf("VMs --> %#v\n", vms)
}
}
}
err = session.ServiceContent.SessionManager.Logout()
if err != nil {
fmt.Printf("--> Unable to logout! Error: %#v <--\n", err)
panic(err)
}
fmt.Println("Done!")
}
Let me know if you need more information.
Thanks!
This test:
userAgent := session.UserSession.UserAgent
if !strings.Contains(userAgent, "govsphere") {
t.Errorf("incorrect result\ngot: %#v\nwant: %#v", userAgent, "govsphere")
}
will always fail for versions older than 5.1. The API doc says that the userAgent attribute is available since vSphere API 5.1.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.