You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Many important vCenter events supported now
- Split event handling in separate pkg
- JSON key in outbound Message is now `ManagedObjectReference` for functions to check
- Robust vCenter client connection/error handling
- Clean shutdown via `os.Signal`
- Fixed a bug where `-insecure` was never populated
- Improved error handling and logging (removed panics)
- More comments in the code
- Dockerfiles updated
- `dep ensure` was out of sync
- README fixes and updates reflecting new events supported
- New `docs` section for examples
- Bumped Docker image version for the connector to `0.4` (until official
OpenFaaS builds are used)
- Updated external examples (gotagfn, pytagfn) to use new JSON key
- Tested with:
- vCenter 6.5
- Kubernetes: kindest/node:v1.13.3 (kind version 0.2.0-alpha)
- OpenFaaS: faas-netes (Commit 07bca00)
- Python demo function [pytagfn](https://github.com/embano1/pytagfn) (Commit 99e2eea)
- Improvements for further PRs:
- Migrate to latest openfaas-sdk version
- Add code examples to repo instead personal repo
- Switch to official builds in YAML
- When govmomi ships govc/vcsim Docker images, use them
Signed-off-by: Michael Gasch <[email protected]>
@@ -10,143 +10,21 @@ This project uses the [OpenFaaS Connector SDK](https://github.com/openfaas-incub
10
10
11
11
The code is under **active development** and only suitable for early adopters. For the initial version the vCenter user credentials need to be stored in plain-text in your YAML files, but this will move to using [OpenFaaS secrets](https://docs.openfaas.com/reference/secrets/) in the next version.
12
12
13
-
**Note:** Currently only a pre-built Docker image is available (based on [PR#11](https://github.com/openfaas-incubator/vcenter-connector/pull/11)) and only [VM events](https://code.vmware.com/doc/preview?id=4206#/doc/vim.event.VmEvent.html) are reportable for now.
13
+
## Supported Events
14
14
15
-
## Example: vCenter Tagging Function
15
+
The following event types (incl. their subtypes) are supported and can be used to trigger functions:
16
16
17
-
### Pre-reqs:
17
+
- Alarm Event, e.g. `AlarmCreatedEvent`
18
+
- Datastore Event, e.g. `DatastoreDestroyedEvent`
19
+
- Host Event, e.g. `HostDisconnectedEvent`
20
+
- Resource Pool Event, e.g. `ResourcePoolCreatedEvent`
21
+
- VM Event, e.g. `VmPoweredOnEvent`
18
22
19
-
*[OpenFaaS](https://docs.openfaas.com/) running on a local or remote Kubernetes cluster (e.g. [kind](https://blog.alexellis.io/get-started-with-openfaas-and-kind/))
20
-
* An installation of vCenter (tested against 6.5)
21
-
* A vCenter user/service account with sufficient rights to perform the (tagging) action of the example function
22
-
*`docker` to run tools like `govc` if not installed on your machine already
23
-
*`git` to clone the function example
24
-
*`faas-cli` to deploy the function
25
-
*`kubectl` to deploy the connector
23
+
For further details and naming see the [vSphere Web Services API](https://code.vmware.com/apis/358/vsphere#/doc/vim.event.Event.html) documentation.
26
24
27
-
**Note:** Make sure that your OpenFaaS environment can reach vCenter as the tagging function performs API calls against vCenter.
25
+
## Example
28
26
29
-
### How it works:
30
-
31
-
Functions can subscribe to events in vCenter through the "topic" [annotations](https://docs.openfaas.com/reference/yaml/#function-annotations) applied through your `stack.yml` file. Based on these events a function can take action, e.g. tag a VM, run post-processing scripts, audit to an external system, etc.
32
-
33
-
### Get started with the vCenter Tagging Function example
34
-
35
-
In the following example we will subscribe to the event "vm.powered.on" by adding an annotation to our function of "vm.powered.on". The function will then add a specific tag to any VM when it is powered on.
36
-
37
-
**Note:** In a DRS-enabled cluster the event is called `drs...` and the example would not work as it's a different event type. If you run this example in a DRS cluster you can use `vm.powered.off` throughout the example below as a workaround.
38
-
39
-
1) Create a category/tag to be attached to a VM when it is powered on. Since we need the unique tag ID (i.e. vSphere URN) we will use [govc](https://github.com/vmware/govmomi/tree/master/govc) for this job. You can also use vSphere APIs (REST/SOAP) to retrieve the URN.
2) Take a note of the `urn:...` for `demotag1` as we will need it for the next steps
57
-
3) In a separate terminal download the example function
58
-
59
-
```bash
60
-
git clone https://github.com/embano1/pytagfn
61
-
cd pytagfn
62
-
```
63
-
64
-
4) Configure the Python tagging function `stack.yaml`.
65
-
66
-
> **Note:** The example cloned from Github already has the annotation to subscribe to VM power on events. More details in the [README](https://github.com/embano1/pytagfn/blob/master/README.md).
67
-
68
-
```yaml
69
-
environment:
70
-
VC: vcenter.ip # FQDN/IP, must be reachable/resolvable from OpenFaaS
71
-
VC_USERNAME: VCUSER # WIP: migration to secrets
72
-
VC_PASSWORD: VCPASSWORD # WIP: migration to secrets
73
-
# Replace TAG_URN example below with the one you created with govc above
TAG_ACTION: attach # this function also supports detach
76
-
```
77
-
78
-
5) Deploy the function
79
-
80
-
```bash
81
-
faas-cli deploy
82
-
Deploying: pytag-fn.
83
-
84
-
Deployed. 202 Accepted.
85
-
URL: http://127.0.0.1:8080/function/pytag-fn
86
-
```
87
-
88
-
6) Download and deploy the OpenFaaS vCenter Connector deployment manifest in a separate
89
-
90
-
> **Note:** The deployment assumes you have basic authentication configured for OpenFaaS on Kubernetes as per [this guide](https://github.com/openfaas/faas-netes/blob/67f61a468bc73833e53b626fa5243f5d539a9e00/yaml/README.md#L5). Thus, the deployment assumes a secret `gateway-basic-auth` to be available (`volumes` section in the YAML). If you don't use authentication for the gateway, remove the volumes section as the deployment would fail, not being able to mount the secret to the deployment.
In the next step we will power on a VM to trigger an event in vCenter ("VM powered on..."). This event will be received by the connector and forwarded to the OpenFaaS function subscribed to the corresponding event type (`vm.powered.on`). The function will then add the tag we created above (`demotag1`) to the VM.
109
-
110
-
```bash
111
-
# Note: This can be done in vCenter UI or via govc
112
-
# Pick a VM that is powered off and does not have already "demotag1", then in the running govc container power on the VM
*[OpenFaaS](https://docs.openfaas.com/) running on a local or remote Kubernetes cluster (e.g. [kind](https://blog.alexellis.io/get-started-with-openfaas-and-kind/))
6
+
* An installation of vCenter (tested against 6.5) or the vCenter simulator [vcsim](https://github.com/vmware/govmomi/tree/master/vcsim)
7
+
* A vCenter user/service account with sufficient rights to perform the (tagging) action of the example function
8
+
*`docker` to run tools like `govc` if not installed on your machine already
9
+
*`git` to clone the function example
10
+
*`faas-cli` to deploy the function
11
+
*`kubectl` to deploy the connector
12
+
13
+
**Note:** Make sure that your OpenFaaS environment can reach vCenter as the tagging function performs API calls against vCenter.
14
+
15
+
### How it works:
16
+
17
+
Functions can subscribe to events in vCenter through the "topic" [annotations](https://docs.openfaas.com/reference/yaml/#function-annotations) applied through your `stack.yml` file. Based on these events a function can take action, e.g. tag a VM, run post-processing scripts, audit to an external system, etc.
18
+
19
+
For example, a `VmPoweredOnEvent` from vCenter would have a function annotation `vm.powered.on`.
20
+
21
+
### Get started with the vCenter Tagging Function example
22
+
23
+
In the following example we will subscribe to the `VmPoweredOnEvent` by adding an annotation to our function of `vm.powered.on`. The function will then add a specific tag to any VM when it is powered on.
24
+
25
+
**Note:** In a DRS-enabled cluster the annotation would be `drs.vm.powered.on`.
26
+
27
+
1) Create a category/tag to be attached to a VM when it is powered on. Since we need the unique tag ID (i.e. vSphere URN) we will use [govc](https://github.com/vmware/govmomi/tree/master/govc) for this job. You can also use vSphere APIs (REST/SOAP) to retrieve the URN.
28
+
29
+
```bash
30
+
# Run pre-built govc Docker image if you don't have govc already installed on your machine
TAG_ACTION: attach # alternatively, this Python function also supports detach
64
+
65
+
# Enable debugging in case something goes wrong
66
+
write_debug: true
67
+
read_debug: true
68
+
69
+
annotations:
70
+
topic: vm.powered.on
71
+
```
72
+
73
+
5) Deploy the function
74
+
75
+
```bash
76
+
faas-cli template pull
77
+
faas-cli deploy
78
+
Deploying: pytag-fn.
79
+
80
+
Deployed. 202 Accepted.
81
+
URL: http://127.0.0.1:8080/function/pytag-fn
82
+
```
83
+
84
+
6) Download and deploy the OpenFaaS vCenter Connector
85
+
86
+
> **Note:** The deployment assumes you have basic authentication configured for OpenFaaS on Kubernetes as per [this guide](https://github.com/openfaas/faas-netes/blob/67f61a468bc73833e53b626fa5243f5d539a9e00/yaml/README.md#L5). Thus, the deployment requires a secret `gateway-basic-auth` to be available (`volumes` section in the YAML).
87
+
>
88
+
> If you **don't** use authentication for the gateway, edit `yaml/kubernetes/connector-dep.yml` as per instructions in the file.
# In yaml/kubernetes/connector-dep.yml modify the container args "-vcenter" (incl. protocol, i.e. "https://"), "-vc-user" and "-vc-pass" accordingly. If vCenter port != 443, please specify (e.g. "https://vcsim.openfaas:8989").
> Note: If you are not running your vCenter connector in the same cluster as OpenFaaS also edit the `-gateway` flag in the connector deployment manifest accordingly (default: `http://gateway.openfaas:8080`, i.e. OpenFaaS in a Kubernetes namespace `openfaas`).
104
+
105
+
7) Generate a "Power On" event
106
+
107
+
In the next step we will power on a VM to trigger an event in vCenter ("VM powered on..."). This event will be received by the connector and forwarded to the OpenFaaS function(s) subscribed to the corresponding event type (`vm.powered.on`). The function will then add the tag we created above (`demotag1`) to the VM.
108
+
109
+
```bash
110
+
# Note: This can be done in vCenter UI or via govc
111
+
# Pick a VM that is powered off and does not have already "demotag1", then in the running govc container power on the VM
0 commit comments