vmware / govmomi Goto Github PK
View Code? Open in Web Editor NEWGo library for the VMware vSphere API
License: Apache License 2.0
Go library for the VMware vSphere API
License: Apache License 2.0
https://groups.google.com/forum/#!topic/google-containers/oDBosQySouY
@dougm is taking a look at this.
Instead of file upload going through VC, we can detect which hosts have access to the specified datastore and use one of those to upload to.
See which VMs are being deleted can be useful.
Also consider adding a verbose mode for more commands.
Likely this is a noob error, but I came across the error above and thought I should mention it in case an actual error is warranted instead of a panic here.
fahmed@hasselhoff: ~/src/go$ govc ls vm
/ha-datacenter/vm/fahmed-dcdf30c0-755f-47a3-aa12-2756be3b2506-3
/ha-datacenter/vm/fahmed-dcdf30c0-755f-47a3-aa12-2756be3b2506-2
/ha-datacenter/vm/fahmed-dcdf30c0-755f-47a3-aa12-2756be3b2506-1
/ha-datacenter/vm/fahmed-dcdf30c0-755f-47a3-aa12-2756be3b2506-0
fahmed@hasselhoff: ~/src/go$ govc vm.vnc
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x47ef9f]
goroutine 16 [running]:
runtime.panic(0xe7c2a0, 0x177e313)
/usr/local/go/src/pkg/runtime/panic.c:279 +0xf5
github.com/vmware/govmomi/govc/vm.(*vnc).Run(0xc208025050, 0xc208004a80, 0x0, 0x0)
/home/fahmed/src/go/src/github.com/vmware/govmomi/govc/vm/vnc.go:65 +0xb9f
github.com/vmware/govmomi/govc/cli.Run(0xc20800e010, 0x1, 0x1, 0x7f7b221ae290)
/home/fahmed/src/go/src/github.com/vmware/govmomi/govc/cli/command.go:151 +0x70b
main.main()
/home/fahmed/src/go/src/github.com/vmware/govmomi/govc/main.go:42 +0x69
goroutine 19 [finalizer wait]:
runtime.park(0x412c90, 0x1782e30, 0x1781089)
/usr/local/go/src/pkg/runtime/proc.c:1369 +0x89
runtime.parkunlock(0x1782e30, 0x1781089)
/usr/local/go/src/pkg/runtime/proc.c:1385 +0x3b
runfinq()
/usr/local/go/src/pkg/runtime/mgc0.c:2644 +0xcf
runtime.goexit()
/usr/local/go/src/pkg/runtime/proc.c:1445
goroutine 22 [runnable]:
net/http.(*persistConn).readLoop(0xc2080506e0)
/usr/local/go/src/pkg/net/http/transport.go:868 +0x829
created by net/http.(*Transport).dialConn
/usr/local/go/src/pkg/net/http/transport.go:600 +0x93f
goroutine 23 [select]:
net/http.(*persistConn).writeLoop(0xc2080506e0)
/usr/local/go/src/pkg/net/http/transport.go:885 +0x38f
created by net/http.(*Transport).dialConn
/usr/local/go/src/pkg/net/http/transport.go:601 +0x957
fahmed@hasselhoff: ~/src/go$ set | grep GOVC
GOVC_INSECURE=1
GOVC_URL=https://root:[email protected]/sdk
Currently not supported by the finder/lister in govc.
Doesn't look like we have the ability to add or remove a host to a datacenter from govc or from datacenter.go. Perhaps we could have something like this:
$ govc datacenter.addhost -dc=somedatacenter -hostname=somehost -hostuser=root -hostpassword=password
$ govc datacenter.removehost -dc=somedatacenter -hostname=somehost
I'm working on this now to support my work on the Terraform vSphere plugin. Would be happy to contribute it back upstream if the usage above looks reasonable to you guys.
We can store something in ~/.govmomi if we haven't seen the remote endpoint before.
Weird errors happen if we're talking with a < 5.5 endpoint.
We need to do a little inventory and see if this holds for all commands where we would expect it.
Running the pool.info command just returns the usage text, with no error message:
$ govc pool.info
Usage: govc pool.info [OPTIONS]
-dc=Datacenter Datacenter [GOVC_DATACENTER]
-debug=false Store debug logs [GOVC_DEBUG]
-json=false Enable JSON output
-k=true Skip verification of server certificate [GOVC_INSECURE]
-u=https://vcenter/sdk ESX or vCenter URL [GOVC_URL]
Here's the contents of the debug directory:
$ cat *
POST /sdk HTTP/1.1
Host: vcenter
Content-Type: text/xml; charset="utf-8"
Soapaction: urn:vim25/5.5
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Body><RetrieveProperties xmlns="urn:vim25"><_this type="PropertyCollector">propertyCollector</_this><specSet><propSet><type>SessionManager</type><pathSet>currentSession</pathSet></propSet><objectSet><obj type="SessionManager">SessionManager</obj></objectSet></specSet></RetrieveProperties></Body></Envelope>HTTP/1.1 200 OK
Content-Length: 957
Cache-Control: no-cache
Connection: Keep-Alive
Content-Type: text/xml; charset=utf-8
Date: Mon, 19 Jan 2015 22:49:30 GMT
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<RetrievePropertiesResponse xmlns="urn:vim25"><returnval><obj type="SessionManager">SessionManager</obj><propSet><name>currentSession</name><val xsi:type="UserSession"><key>5238f2f9-a08f-f314-7197-480f3f306b2c</key><userName>_snip_</userName><fullName>_snip_</fullName><loginTime>2015-01-19T22:10:25.078313Z</loginTime><lastActiveTime>2015-01-19T22:46:10.307388Z</lastActiveTime><locale>en</locale><messageLocale>en</messageLocale><extensionSession>false</extensionSession><ipAddress>_snip_</ipAddress><userAgent>Go 1.1 package http</userAgent><callCount>4</callCount></val></propSet></returnval></RetrievePropertiesResponse>
</soapenv:Body>
</soapenv:Envelope>2015-01-19T14-49-31.119709708: 1 took 95ms
Looking at the code, it appears that the command is expecting an argument, so it looks like (at least) the usage statement is incorrect.
When I try passing in a valid resource pool for my datacenter, the command returns a success RC, but no output at all.
A map from strings to reflect.Type is passed to the decoder now. We can avoid having to think about mutation of this map entirely by just passing a function to the decoder. This function can then be implemented and returned from a function in the types package.
When switching from a single ESX host to VC, the finder.VirtualMachine() function doesn't always find existing VMs. I'm currently using SearchIndex().FindChild() as a work around with "ha-datacenter/vm/" as the root folder.
When connected to VC, the finder mechanism seems to only be able to find VMs that appear under "Discovered virtual machine" which is rarely a comprehensive list.
I have done some digging with the help of some users on the IRC channel and noticed that etcd is not running on the master after the build.
"find / -name "etcd" -print" does not return any binary that can be executed... possibly a missing coreos/etcd on the provided vmdk?
Can you confirm the ability to properly deploy a Kubernetes cluster using the current quick start guide for vsphere? I am following everything to the "t" and it won't start up properly.
Add option to detach disks before destroying a VM, defaulting to true. This means that disks that are only referenced by a single VM will not be deleted when that VM is destroyed.
If the VMDK that you're trying to import using "datastore.import" does not exists, there is no error being shown and just says "Uploading" and sits there. It would be nice to have a check to ensure the file exists
└─[0] govc datastore.import kube.vmdk
[04-09-14 20:44:06] Uploading...
I'd be happy to work on the implementation for this request.
Currently templates show up as virtual machines, but nothing is populated for this type, so it isn't really possible (that I have found yet, big caveat) to tell if a virtual machine is a template besides just guessing based on the blank status.
When an govc is interrupted in the middle of an nfc upload, we should call HttpNfcLeaseAbort() to cancel the lease/task(s). Otherwise, UI displays the task(s) at X% complete until the lease timeout.
Is it possible to use this library with the vCloud API v5.5?
I first noticed this when I was using the finder.HostSystem function for my project that's consuming govmomi. I thought it was me, but now I'm not so sure about that given the following output.
$ govc host.info -dc=858c7e1d-89f7-11e4-934e-80e6500a64dc -host.ip=192.168.238.139
Name: 192.168.238.139
Manufacturer: VMware, Inc.
Logical CPUs: 4 CPUs @ 2793MHz
Processor type: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
Memory: 4095MB
Boot time: 2014-12-21 19:20:50.556233 +0000 UTC
$ govc host.info -dc=858c7e1d-89f7-11e4-934e-80e6500a64dc -host=192.168.238.139
Error: no such host
finder.HostSystem is actually not used all that much in the code. In fact, after grepping a bit, the only place I found it was in flags/host_system.go. I'll have to dig in a little more, but I suspect this is something I'll have to fix to address the AddStandaloneHost and Destroy host issue I filed yesterday. In the event that I'm off base on this I'm happy to be corrected in order to save myself the time and trouble. :-D
This makes is more like ls
.
Random things that need some explaining:
Would like the ability to create and destroy a datacenter. I have a patch if you're interested.
localhost:daemon zeey$ govc import.ova ~/Desktop/b2d.ova
panic: field "ovf" in struct "importx.ova" must be a pointer
goroutine 16 [running]:
runtime.panic(0x663760, 0xc208039340)
/usr/local/Cellar/go/1.3/libexec/src/pkg/runtime/panic.c:279 +0xf5
github.com/vmware/govmomi/govc/cli.func·005(0xb74c60, 0xc20801ab40, 0x0, 0x0)
/Users/zeey/go/src/github.com/vmware/govmomi/govc/cli/walk.go:74 +0x596
github.com/vmware/govmomi/govc/cli.Walk(0xb74c60, 0xc20801ab40, 0x15681d8, 0x9389a0, 0xc208111d70, 0x0, 0x0)
/Users/zeey/go/src/github.com/vmware/govmomi/govc/cli/walk.go:107 +0xc1
github.com/vmware/govmomi/govc/cli.RegisterCommand(0x156cfa0, 0xc20801ab40, 0xc2080049c0)
/Users/zeey/go/src/github.com/vmware/govmomi/govc/cli/command.go:54 +0xb1
github.com/vmware/govmomi/govc/cli.Run(0xc20800e010, 0x1, 0x1, 0x156cf68)
/Users/zeey/go/src/github.com/vmware/govmomi/govc/cli/command.go:131 +0x24b
main.main()
/Users/zeey/go/src/github.com/vmware/govmomi/govc/main.go:40 +0x69
Use https://developer.github.com/v3/repos/releases/ to pull down releases/binaries.
It looks like govmomi.Folder.Children() does not support some types.
localhost:govmomi zeey$ govc import.ovf ~/Desktop/b2d.ovf
[13-10-14 13:42:29] Uploading b2d-file1.iso... Error: 403 Forbidden
Error: 403 Forbidden
See #160.
It can populate managed objects if either all properties or a set of top-level properties are requested.
If you request a property like config.hardware
on a VM, it doesn't work.
$ govc about
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x90e71]
goroutine 1 [running]:
runtime.panic(0x61b000, 0x11c6db9)
/Users/pieter/dev/go/src/pkg/runtime/panic.c:266 +0xb6
github.com/vmware/govmomi/govc/flags.(_ClientFlag).sessionFile(0xc21001ec30, 0xc2100f8000, 0xa)
/Users/pieter/dev/godev/src/github.com/vmware/govmomi/govc/flags/client.go:79 +0x31
github.com/vmware/govmomi/govc/flags.(_ClientFlag).loadClient(0xc21001ec30, 0x0, 0x0, 0x0)
/Users/pieter/dev/godev/src/github.com/vmware/govmomi/govc/flags/client.go:86 +0x59
github.com/vmware/govmomi/govc/flags.(_ClientFlag).Client(0xc21001ec30, 0x7769c0, 0x0, 0x0)
/Users/pieter/dev/godev/src/github.com/vmware/govmomi/govc/flags/client.go:160 +0x58
github.com/vmware/govmomi/govc/about.(_about).Run(0xc210000220, 0xc2100ea3f0, 0x0, 0x0)
/Users/pieter/dev/godev/src/github.com/vmware/govmomi/govc/about/command.go:36 +0x38
github.com/vmware/govmomi/govc/cli.Run(0xc21000a010, 0x1, 0x1, 0x1542638)
/Users/pieter/dev/godev/src/github.com/vmware/govmomi/govc/cli/command.go:140 +0x627
main.main()
/Users/pieter/dev/godev/src/github.com/vmware/govmomi/govc/main.go:33 +0x64
Is there a way to access UUID value of a virtual machine object?
Now I have to persist a vm name, this is an unique property, but it can be easily changed and become outdated.
I've been working with the API to walk through our environment, but specifically we would like the ability to change the network a virtual machine's NIC is on. Is this something that can be done with the package as it stands today? If so, how might you do that?
Opened issue in wrong repository.
I currently get the following error on both OSX and Linux for all commands:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x80e7fbc]
goroutine 1 [running]:
runtime.panic(0x8691a20, 0x9584c28)
/usr/lib/golang/src/pkg/runtime/panic.c:266 +0xac
sync/atomic.AddUint64(0x1982eb44, 0x1, 0x0, 0x1980a5e0, 0x0)
/usr/lib/golang/src/pkg/sync/atomic/asm_386.s:118 +0xc
github.com/vmware/govmomi/vim25/soap.(_Client).RoundTrip(0x1982eaf0, 0xb78941a0, 0x1980a5d0, 0xb78941a0, 0x1980a5e0, ...)
/workspace/src/github.com/vmware/govmomi/vim25/soap/client.go:127 +0x11b
github.com/vmware/govmomi/vim25/methods.RetrieveServiceContent(0xb7894188, 0x1982eaf0, 0x1980a5c0, 0x9588790, 0x1, ...)
/workspace/src/github.com/vmware/govmomi/vim25/methods/methods.go:9657 +0x99
github.com/vmware/govmomi.serviceContent(0xb7894188, 0x1982eaf0, 0x9587e70, 0xb7894188, 0x1981cee0, ...)
/workspace/src/github.com/vmware/govmomi/client.go:43 +0x8b
github.com/vmware/govmomi.NewClient(0xbfd5a89f, 0x5, 0x0, 0x0, 0x1981cee0, ...)
/workspace/src/github.com/vmware/govmomi/client.go:79 +0xbe
github.com/vmware/govmomi/govc/flags.(_ClientFlag).newClient(0x1981ce80, 0x0, 0x0, 0x0)
/workspace/src/github.com/vmware/govmomi/govc/flags/client.go:141 +0x61
github.com/vmware/govmomi/govc/flags.(_ClientFlag).Client(0x1981ce80, 0x19800680, 0x196, 0x198a34a4)
/workspace/src/github.com/vmware/govmomi/govc/flags/client.go:207 +0xcf
github.com/vmware/govmomi/govc/about.(_about).Run(0x19800680, 0x198a3680, 0x0, 0x0)
/workspace/src/github.com/vmware/govmomi/govc/about/command.go:42 +0x3a
github.com/vmware/govmomi/govc/cli.Run(0x1980a008, 0x1, 0x1, 0x19800680)
/workspace/src/github.com/vmware/govmomi/govc/cli/command.go:151 +0x4f2
main.main()
/workspace/src/github.com/vmware/govmomi/govc/main.go:42 +0x54
An strace show's it having issues with the session file not existing.
clock_gettime(CLOCK_REALTIME, {1413556864, 473082132}) = 0
open("/root/.govmomi/sessions/[email protected]?insecure=true", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
clock_gettime(CLOCK_REALTIME, {1413556864, 474050323}) = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
rt_sigreturn(0x198010a0) = 140738048
write(2, "panic: ", 7panic: ) = 7
write(2, "runtime error: invalid memory ad"..., 64runtime error: invalid memory address or nil pointer dereference) = 64
/root/.govmomi/sessions/ didn't exist, so I created it, but still get the same error.
I am writing some of my own helper libraries and would love to just use the newReference function in this library instead of having to recreate it. Could you possibly make this an exported function?
Hi Pieter & Doug,
As you might be aware, I am using govc as the underlying tool to do B2D VC interactions. I find that these line of code actually makes it not possible to cross compile to windows binaries:
https://github.com/vmware/govmomi/blob/master/govc/flags/client.go#L133
The reason is that path.Join (http://golang.org/src/pkg/path/path.go?s=3776:3808#L140) and filepath.Join (http://golang.org/src/pkg/path/path.go?s=3776:3808#L140) are different -- the former one is not using the os.Seperator.
Another issue is that:
https://github.com/vmware/govmomi/blob/master/govc/flags/client.go#L132
Windows does not allow "?" in the file name so creating file will fail.
Let me know if you want me to send PR for it :)
$ govc vm.create -on=false -m 1024 foo
Error: please specify a network
The VM is created anyway.
What do you think of adding the managed object reference ID to the vm.info? I've found that I needed it for something and I'd rather use govc as opposed to writing a script using rbVmomi or pySphere. Should be a relatively trivial addition that I could submit a PR for. For example, instead of this...
Gavins-MacBook-Pro:test gavin$ govc vm.info -dc=dc -vm.ipath='/dc/vm/esxi-v51-030'
Name: esxi-v51-030
UUID: 421caf8e-1648-8827-7b66-c834bb7efe41
Guest name: VMware ESXi 5.x
Memory: 32768MB
CPU: 4 vCPU(s)
Power state: poweredOn
Boot time: <nil>
IP address: 10.100.202.30
It'd be something like this:
Gavins-MacBook-Pro:test gavin$ govc vm.info -dc=dc -vm.ipath='/dc/vm/esxi-v51-030'
Name: esxi-v51-030
UUID: 421caf8e-1648-8827-7b66-c834bb7efe41
MOR ID: vm-1989
Guest name: VMware ESXi 5.x
Memory: 32768MB
CPU: 4 vCPU(s)
Power state: poweredOn
Boot time: <nil>
IP address: 10.100.202.30
Running on OS X Yosemite:
~/go/src/github.com/vmware/govmomi/govc > uname -a
Darwin HummaKavula.local 14.0.0 Darwin Kernel Version 14.0.0: Mon Sep 8 05:27:41 PDT 2014; root:xnu-2782.1.96~5/RELEASE_X86_64 x86_64
~/go/src/github.com/vmware/govmomi/govc > go version
go version go1.3 darwin/amd64
Tried both zsh and bash shell:
~/go/src/github.com/vmware/govmomi/govc > govc ls --help
Usage of govc ls:
-dc= Datacenter [GOVC_DATACENTER]
-debug=false Store debug logs [GOVC_DEBUG]
-json=false Enable JSON output
-k=false Skip verification of server certificate [GOVC_INSECURE]
-l=false Long listing format
-u= ESX or vCenter URL [GOVC_URL]
~/go/src/github.com/vmware/govmomi/govc > export GOVC_URL='https://user:pass@vcenter/sdk'
~/go/src/github.com/vmware/govmomi/govc > govc ls --help
Usage of govc ls:
-dc= Datacenter [GOVC_DATACENTER]
-debug=false Store debug logs [GOVC_DEBUG]
-json=false Enable JSON output
-k=false Skip verification of server certificate [GOVC_INSECURE]
-l=false Long listing format
-u=https://vcenter/sdk ESX or vCenter URL [GOVC_URL]
~/go/src/github.com/vmware/govmomi/govc > export GOVC_DATACENTER='Go SDDC'
~/go/src/github.com/vmware/govmomi/govc > govc ls --help
Usage of govc ls:
-dc= Datacenter [GOVC_DATACENTER]
-debug=false Store debug logs [GOVC_DEBUG]
-json=false Enable JSON output
-k=false Skip verification of server certificate [GOVC_INSECURE]
-l=false Long listing format
-u=https://vcenter/sdk ESX or vCenter URL [GOVC_URL]
~/go/src/github.com/vmware/govmomi/govc > govc ls
Error: please specify a datacenter
Env seems correctly set, the only one not picked up correctly is GOVC_DATACENTER.
~/go/src/github.com/vmware/govmomi/govc > env | grep GOVC_
GOVC_DATACENTER=Go SDDC
GOVC_URL=https://user:pass@vcenter/sdk
GOVC_DATASTORE=nfs_fas2020_15k_01
GOVC_RESOURCE_POOL=monster.ad.lab.gosddc.com/Resources
GOVC_GUEST_LOGIN=kube:kube
GOVC_INSECURE=true
See #160.
Both arguments are required, but it is possible to specify a datastore that isn't reachable from the specified resource pool. Ideally, we would auto-detect a resource pool to use. At the very least, we should check if the combination is valid to prevent non-descriptive errors later in the import process.
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.