Skip to content

Commit fdb9ec8

Browse files
embano1alexellis
authored andcommitted
Updated README and Deployment File
- Incorporate review feedback for README - Enable OpenFaaS auth in the deployment manifest and describe how to disable if needed Signed-off-by: Michael Gasch <[email protected]>
1 parent 49f38d7 commit fdb9ec8

File tree

2 files changed

+43
-38
lines changed

2 files changed

+43
-38
lines changed

README.md

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# vcenter-connector
22

3-
vcenter-connector is an OpenFaaS event connector built to consume events from vCenter from VMware vSphere.
3+
vcenter-connector is an OpenFaaS event connector built to consume events from vCenter from vCenter.
44

55
With this project your functions can subscribe to events generated by the changes (i.e. events) 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.
66

77
## Status
88

99
This project uses the [OpenFaaS Connector SDK](https://github.com/openfaas-incubator/connector-sdk).
1010

11-
The code is under **active development** and only suitable for early adopters. More examples and instructions for use in Kubernetes are being worked on, including improved handling of secrets (accounts and passwords).
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.
1212

13-
**Note:** Currently only a pre-build 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 supported.
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.
1414

1515
## Example: vCenter Tagging Function
1616

@@ -28,53 +28,55 @@ The code is under **active development** and only suitable for early adopters. M
2828

2929
### How it works:
3030

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.
32-
33-
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"
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.
3432

3533
### Get started with the vCenter Tagging Function example
3634

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+
3737
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.
3838

3939
```bash
40-
# Run pre-build govc Docker image
40+
# Run pre-built govc Docker image
4141
docker run --rm -it embano1/govc:0ee42d3 sh
4242

4343
# Test connection to vCenter, ignore TLS warnings
4444
export GOVC_INSECURE=true
4545
export GOVC_URL='https://vcuser:[email protected]'
4646
./govc tags.ls
4747

48-
# If the connection is successful create a demo category/tag
48+
# If the connection is successful create a demo category/tag to be used by the function
4949
./govc tags.category.create democat1
5050
urn:...
5151
./govc tags.create -c democat1 demotag1
5252
urn:vmomi:InventoryServiceTag:019c0a9e-0672-48f5-ac2a-e394669e2916:GLOBAL
5353
```
54-
2) Take a note of the `urn:...` for `demotag1` as we will need it in a bit
54+
2) Take a note of the `urn:...` for `demotag1` as we will need it for the next steps
5555
3) In a separate terminal download the example function
5656

5757
```bash
5858
git clone https://github.com/embano1/pytagfn
5959
cd pytagfn
6060
```
6161

62-
4) Configure the Python tagging function `stack.yaml`. 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).
62+
4) Configure the Python tagging function `stack.yaml`.
63+
64+
> **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).
6365
6466
```yaml
6567
environment:
66-
VC: vcenter.ip # must be reachable/resolvable from OpenFaaS
67-
VCUSERNAME: VCUSER # WIP: migration to secrets
68-
VCPASSWORD: VCPASSWORD # WIP: migration to secrets
69-
# Replace TAGURN example below with the one you created with govc above
70-
TAGURN: urn:vmomi:InventoryServiceTag:019c0a9e-0672-48f5-ac2a-e394669e2916:GLOBAL
71-
TAGACTION: attach # this function also supports detach
68+
VC: vcenter.ip # FQDN/IP, must be reachable/resolvable from OpenFaaS
69+
VC_USERNAME: VCUSER # WIP: migration to secrets
70+
VC_PASSWORD: VCPASSWORD # WIP: migration to secrets
71+
# Replace TAG_URN example below with the one you created with govc above
72+
TAG_URN: urn:vmomi:InventoryServiceTag:019c0a9e-0672-48f5-ac2a-e394669e2916:GLOBAL
73+
TAG_ACTION: attach # this function also supports detach
7274
```
7375
7476
5) Deploy the function
7577
7678
```bash
77-
faas-cli deploy -f stack.yml
79+
faas-cli deploy
7880
Deploying: pytag-fn.
7981

8082
Deployed. 202 Accepted.
@@ -83,22 +85,26 @@ URL: http://127.0.0.1:8080/function/pytag-fn
8385
8486
6) Download and deploy the OpenFaaS vCenter Connector deployment manifest in a separate
8587
88+
> **Note:** The deployment assumes you have [basic authentication](https://docs.openfaas.com/reference/authentication/#for-the-api-gateway) configured for the OpenFaaS gateway. Thus, the deployment assumes a secret `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 pod.
89+
8690
```bash
8791
git clone https://github.com/openfaas-incubator/vcenter-connector
8892
cd vcenter-connector
8993
90-
# In yaml/kubernetes/connector-dep.yml modify the container args "-vcenter", "-vc-user" and "-vc-pass" accordingly
91-
# Note: OpenFaaS "-gateway" URL should be fine as we assume the connector is deployed in the same namespace and Kubernetes DNS will resolve
94+
# In yaml/kubernetes/connector-dep.yml modify the container args "-vcenter" (following URL scheme), "-vc-user" and "-vc-pass" accordingly
95+
# Note: If you are not running your vCenter connector in the same cluster as OpenFaaS edit the -gateway flag
9296
93-
# Deploy to Kubernetes in the OpenFaaS namespace
97+
# Deploy the connector to Kubernetes
9498
kubectl -n openfaas create -f yaml/kubernetes/connector-dep.yml
9599
96-
# Check the logs of the pod whether it successfully connects to vCenter and OpenFaaS
97-
kubectl -n openfaas logs vcenter-connector-<...> -f
100+
# Check the logs of the pod whether it connected successfully to vCenter and OpenFaaS
101+
kubectl -n openfaas logs deploy/vcenter-connector -f
98102
```
99103

100104
7) Generate a "Power On" event
101105

106+
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.
107+
102108
```bash
103109
# Note: This can be done in vCenter UI or via govc
104110
# Pick a VM that is powered off and does not have already "demotag1", then in the running govc container power on the VM
@@ -111,7 +117,7 @@ VirtualMachine:vm-267
111117

112118
### Troubleshooting
113119

114-
If the tag was not correctly attached, verify:
120+
If your VM did not get the tag attached, verify:
115121

116122
- vCenter IP/username/password
117123
- Permissions of the vCenter user

yaml/kubernetes/connector-dep.yml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@ spec:
1818
image: embano1/faas-vcconnector:0.2
1919
command: ["./connector"]
2020
args: ["-vcenter", "https://vcenter.ip", "-vc-user", "vcuser", "-vc-pass", "vcpass", "-insecure", "-gateway", "http://gateway.openfaas:8080"]
21-
22-
# uncomment and configure accordingly if the OpenFaaS gateway requires authentication
23-
# env:
24-
# - name: basic_auth
25-
# value: "true"
26-
# - name: secret_mount_path
27-
# value: "/var/secrets/"
28-
# volumeMounts:
29-
# - name: auth
30-
# readOnly: true
31-
# mountPath: "/var/secrets/"
32-
# volumes:
33-
# - name: auth
34-
# secret:
35-
# secretName: basic-auth
21+
env:
22+
- name: basic_auth
23+
value: "true"
24+
- name: secret_mount_path
25+
value: "/var/secrets/"
26+
volumeMounts:
27+
- name: auth
28+
readOnly: true
29+
mountPath: "/var/secrets/"
30+
# if you do not have authentication enabled for OpenFaaS comment this out
31+
volumes:
32+
- name: auth
33+
secret:
34+
secretName: basic-auth

0 commit comments

Comments
 (0)