vcenter-connector is an OpenFaaS event connector built to consume events from vCenter from VMware
With this project your functions can subscribe to events generated by the changes in your vCenter installation - for instance a VM being created, turned on or deleted. This allows you to extend vCenter's functionality by writing functions to execute each time an event is fired. An example may be tagging a VM with the date it was last turned on or applying a tag showing which user made a change to an object.
This project uses the OpenFaaS Connector SDK.
The code is under active development and only suitable for early adopters. More examples and instructions for use in Kubernetes are being worked on.
How it works:
Functions can subscribe to events in vCenter through the "topic" annotations applied through your
I.e. in the following example we will subscribe to the event "vm.powered.on" by adding an annotation to our function of "vm.powered.on"
Get started with the example
- Run the vCenter Simulator
# Note: the following steps assume a correctly configured GO environment (using GOPATH) go get -u -d github.com/vmware/govmomi cd $GOPATH/src/github.com/vmware/govmomi/vcsim go build -o vcsim main.go ./vcsim -tls=false
- Run the connector
export OPENFAAS_URL=http://127.0.0.1:31112 go run main.go -vcenter-url="http://user:email@example.com:8989/sdk" -insecure
Deploy an echo function that subscribes to the event of "vm.powered.on"
export OPENFAAS_URL=http://127.0.0.1:31112 git clone https://github.com/alexellis/echo-fn cd echo-fn faas-cli template store pull golang-http faas-cli deploy
stack.yml contains an annotation of
topic=vm.powered.on, to change this edit the file and run
faas-cli deploy. To edit the code in the handler change the code and
image field then run
- Generate some events:
# Note: the following steps assume you have already downloaded the govmomi sources as described above in the vcsim section cd $GOPATH/src/github.com/vmware/govmomi/govc go build -o govc main.go # turn all VMs off GOVC_INSECURE=true GOVC_URL=http://user:firstname.lastname@example.org:8989/sdk ./govc vm.power -off '*' # turn all VMs back on to trigger the event GOVC_INSECURE=true GOVC_URL=http://user:email@example.com:8989/sdk ./govc vm.power -on '*'
- Check the logs of the
# on Kubernetes kubectl logs -n openfaas-fn deploy/echo-fn # or on Swarm docker service logs echo-fn
Thanks to Karol Stępniewski for showing me a demo of events being consumed in OpenFaaS via vCenter over a year ago at KubeCon in Austin. Parts of his "event-driver" originally developed in the Dispatch project have been adapted for this OpenFaaS event-connector including a method to convert camel case event names into names separated by a dot. I wanted to include this for compatibility between the two systems.