Sample workflow - Automatically adding a host to an external VMWare VCenter¶
This example shows how to create a custom workflow in order to add a host to a vmware vcenter system.
We will be using the CLI for this and some familiarity with it is required. Please follow Using the CLI guide to setup the CLI.
Warning
Tested using VMWare vCenter 6.7.0 and might not work with future versions of the API
Documentation for vCenter REST API is available here. We’re calling host create.
Creating a Task for enroll into vCenter¶
Create a variable for the host of the vcenter
echo "https://172.17.108.75/" | metalcloud-cli variable create --name vcenter --pipe
Create a secret for the credentials
echo "Basic YWRtaW5pc3RyYXRvckB2c3BoZXJlLmxvY2FsOkRlbGxSMGNrcyE=" | metalcloud-cli secret create --name vcenter-creds --pipe
Create a stage definition to login
metalcloud-cli stage-definition create --label "vcenter-login" --title "vcenter-login" --type "HTTPRequest" --http-request-method GET --http_request_url='{{vcenter}}/rest/com/vmware/cis/session' --vars "vcenter"
Create a stage definition to add the host to the vmware. Notice the IP obtained from the context
{{vmware_ipv4_address_0_0}}
echo '{{vmware_ipv4_address_0_0}}' | ./metalcloud-cli stage-definition create --label "vcenter-host-add" --title "vcenter-host-add" --type "HTTPRequest" --http-request-method GET --http-request-url='{{vcenter}}/rest/vcenter/host' --http-request-header-authorization '{{vcenter_creds}}' --vars "vcenter,vcenter_creds,vmware_ipv4_0" --http-request-body-from-pipe
Create a workflow¶
$ metalcloud-cli workflow create --label "vmware" --title "Add host to vCenter" --usage infrastructure
Add stages to workflow¶
$ metalcloud-cli stage-definition add-to-workflow --id vcenter-login --workflow vmware --runlevel 1
$ metalcloud-cli stage-definition add-to-workflow --id 'vcenter-host-add' --workflow vmware --runlevel 2
Verify the stages¶
metalcloud-cli workflow list --id wmware
Stage Definitions:
+-------+---------------+------------------+-------------+----------+---------------------+
| ID | INFRASTRUCTRE | STAGE | TYPE | RUNLEVEL | OUTPUT |
+-------+---------------+------------------+-------------+----------+---------------------+
| 816 | vmware | vcenter-login | post_deploy | 1 | |
| 818 | vmware | vcenter-host-add | post_deploy | 2 | |
+-------+---------------+------------------+-------------+----------+---------------------+
Total: 2
Add workflow to infrastructure¶
We add the workflow to the infrastructure using a reference stage definition which instructs the system to call a workflow.
metalcloud-cli stage-definition create --title "ref VMWARE" --label refvmware --type WorkflowReference --workflow add-host-to-vcenter
Deploy infrastructure¶
metalcloud-cli infrastructure deploy --id vmware --autoconfirm