Skip to content

Commit 6757fe3

Browse files
Added documentation for the first class resource userdata (#273)
* Added documentation for the userdata, which can be treated as a first class resource * Added content to explain the usage of variables in userdata during registration and vm deployment * fixed a code snippet in userdata section
1 parent a46c419 commit 6757fe3

9 files changed

Lines changed: 143 additions & 32 deletions
27.4 KB
Loading
31.3 KB
Loading
30.4 KB
Loading
32.6 KB
Loading
20.5 KB
Loading
11.1 KB
Loading
63.3 KB
Loading

source/adminguide/templates.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@ To upload a template:
268268
selecting an OS Type when registering a template if the option 'Read VM settings from OVA' is selected. In this case, the OS Type is
269269
obtained from the template after it is registered.
270270

271+
- **Userdata**: The registered Userdata are listed. Select the
272+
desired one.
273+
274+
- **Userdata link policy**: Select the userdata override policy as required.
275+
For more information on userdata and override link policy, please check `Userdata section <virtual_machines.html#user-data-and-meta-data>`_.
276+
277+
271278
- **Hypervisor**: The supported hypervisors are listed. Select the
272279
desired one.
273280

source/adminguide/virtual_machines/user-data.rst

Lines changed: 136 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,113 @@
1717
User-Data and Meta-Data
1818
-----------------------
1919

20-
CloudStack provides APIs to attach up to 32KB of user-data to a deployed VM.
20+
Users can register userdata in CloudStack and refer the registered userdata while
21+
deploying or editing or reset userdata on a VM. The userdata content can also be
22+
directly provided while deploying the VM. Userdata content length can be up to 32kb.
2123

22-
There are two CloudStack APIs that can be used to store user-data:
23-
`deployVirtualMachine <https://cloudstack.apache.org/docs/api/apidocs-4.14/user/deployVirtualMachine.html>`_
24-
and
25-
`updateVirtualMachine <https://cloudstack.apache.org/docs/api/apidocs-4.14/user/updateVirtualMachine.html>`_
26-
They both support the parameter ``userdata=``. The value for this parameter
27-
must be a `base64 <https://www.base64encode.org/>`_-encoded multi-part MIME
28-
message. See further below for an example of what this should look like.
24+
To register a new userdata:
25+
26+
#. Log in to the CloudStack UI.
27+
28+
#. In the left navigation bar, click Compute and then User Data.
29+
30+
#. Click Register a userdata.
31+
32+
#. In the dialog, make the following choices:
33+
34+
- **Name**: Any desired name for the userdata.
35+
36+
- **Userdata**: Plain userdata content. CloudStack UI does base64 encoding.
37+
38+
- **Userdata parameters**: Comma separated list of variables which (if any) declared
39+
in userdata content.
40+
41+
- **Domain**: An optional domain for the userdata.
42+
43+
- **Account**: An optional account for the userdata.
44+
45+
.. image:: /_static/images/register_userdata.png
46+
:width: 400px
47+
:align: center
48+
:alt: Regiser userdata dialog box
49+
50+
If userdata content has variables declared in it, user can register the Userdata
51+
with userdata parameters.
52+
53+
For example, if userdata content is like below having a custom variable "variable1"
54+
55+
.. code:: bash
56+
57+
## template: jinja
58+
#cloud-config
59+
runcmd:
60+
- echo 'TestVariable {{ ds.meta_data.variable1 }}' >> /tmp/variable
61+
- echo 'Hostname {{ ds.meta_data.public_hostname }}' > /tmp/hostname
62+
63+
Userdata has to be registered with userdata parameter "variable1" like below
64+
65+
.. image:: /_static/images/register_userdata_with_variables.png
66+
:width: 400px
67+
:align: center
68+
:alt: Regiser userdata with variables dialog box
69+
70+
If the variables in userdata content are of a predefined metadata like "public_hostname"
71+
or "instance_id", then userdata parameters should not declare these variables. That is
72+
the reason in the above example "public_hostname" is not declared.
73+
74+
There are three CloudStack APIs that can be used to provide user-data to VM:
75+
deployVirtualMachine, updateVirtualMachine and resetUserDataForVirtualMachine.
76+
These APIs accepts parameters ``userdataid`` and ``userdatadetails``.
77+
userdatadetails is to specify the custom values for the variables which are declared
78+
in userdata in a key value parameter map details.
79+
80+
.. image:: /_static/images/deployvm_userdata.png
81+
:width: 400px
82+
:align: center
83+
:alt: Provide userdata id or userdata text dialog box
84+
85+
If the userdata contains variables that are declared during registration then those values
86+
has to be specified like below,
87+
88+
.. image:: /_static/images/deployvm_userdata_with_variables.png
89+
:width: 400px
90+
:align: center
91+
:alt: Provide userdata id or userdata with variables text dialog box
92+
93+
These details will be saved as meta-data file(s) in both config drive and virtual router,
94+
which in turn support jinja based instance meta-data feature of cloud-init,
95+
refer to https://cloudinit.readthedocs.io/en/latest/topics/instancedata.html.
96+
97+
These APIs also support the parameter ``userdata=`` to provide the userdata content
98+
directly. The value for this parameter must be a `base64 <https://www.base64encode.org/>`_-encoded
99+
multi-part MIME message. See further below for an example of what this should look like.
100+
101+
The registered UserData can be linked to a template or ISO on registration/upload/editing
102+
using linkUserDataToTemplate API. The same API can be used to unlink the mapping of userdata and template.
103+
104+
While linking userData to a template/ISO userdata override policy has to be specified.
105+
Following are the override policies available:
106+
107+
Allow Override: Allow users to override UserData for the template during VM deployment or on reset.
108+
This is the default override policy if not specified
109+
110+
Deny Override: Override of UserData isn’t allowed during VM deployment or on reset.
111+
112+
Append Only: Don’t allow users to override linked UserData but allow users to pass userdata content
113+
or ID that should be appended to the linked UserData of the template.
114+
115+
This is how it looks like in template/ISO register/upload/edit forms.
116+
117+
.. image:: /_static/images/userdata_template_link.png
118+
:width: 400px
119+
:align: center
120+
:alt: Linking userdata to template/ISO
121+
122+
Based on these override policies, "Add Instance" UI form provides relevant options to either
123+
override or append. If it is "Deny Override" then "Add Instance" will not allow adding user specific userdata
124+
125+
Storing and accessing userdata
126+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29127

30128
HTTP GET parameters are limited to a length of 2048 bytes, but it is possible
31129
to store larger user-data blobs by sending them in the body via HTTP POST
@@ -124,36 +222,42 @@ Custom user-data example
124222

125223
This example uses cloud-init to automatically update all OS packages on the first launch.
126224

127-
#. Create user-data, wrapped into a multi-part MIME message and encoded in base64:
225+
#. Register the following user-data in CloudStack. If APIs are used to register userdata or to
226+
provide direct userdata text then userdata needs to be wrapped into a multi-part MIME message
227+
and encoded in base64:
128228

129-
.. code:: bash
229+
.. code:: bash
130230
131-
base64 <<EOF
132-
Content-Type: multipart/mixed; boundary="//"
133-
MIME-Version: 1.0
134-
135-
--//
136-
Content-Type: text/cloud-config; charset="us-ascii"
137-
MIME-Version: 1.0
138-
Content-Transfer-Encoding: 7bit
139-
Content-Disposition: attachment; filename="cloud-config.txt"
140-
141-
#cloud-config
231+
base64 <<EOF
232+
Content-Type: multipart/mixed; boundary="//"
233+
MIME-Version: 1.0
234+
235+
--//
236+
Content-Type: text/cloud-config; charset="us-ascii"
237+
MIME-Version: 1.0
238+
Content-Transfer-Encoding: 7bit
239+
Content-Disposition: attachment; filename="cloud-config.txt"
240+
241+
#cloud-config
242+
243+
# Upgrade the instance on first boot
244+
# (ie run apt-get upgrade)
245+
#
246+
# Default: false
247+
# Aliases: apt_upgrade
248+
package_upgrade: true
249+
EOF
142250
143-
# Upgrade the instance on first boot
144-
# (ie run apt-get upgrade)
145-
#
146-
# Default: false
147-
# Aliases: apt_upgrade
148-
package_upgrade: true
149-
EOF
150-
151-
#. Deploy a VM with this user-data:
251+
#. Deploy a VM with this user-data either by providing the UUID of the registerd userdata
252+
or by providing base64 encoded userdata:
152253
153-
.. code:: bash
254+
.. code:: bash
154255
155-
cmk deploy virtualmachine name=..... userdata=Q29udGVudC1UeXBlOiBtdWx0aXBhcnQvbWl4ZWQ7IGJvdW5kYXJ5PSIvLyIKTUlNRS1WZXJzaW9uOiAxLjAKCi0tLy8KQ29udGVudC1UeXBlOiB0ZXh0L2Nsb3VkLWNvbmZpZzsgY2hhcnNldD0idXMtYXNjaWkiCk1JTUUtVmVyc2lvbjogMS4wCkNvbnRlbnQtVHJhbnNmZXItRW5jb2Rpbmc6IDdiaXQKQ29udGVudC1EaXNwb3NpdGlvbjogYXR0YWNobWVudDsgZmlsZW5hbWU9ImNsb3VkLWNvbmZpZy50eHQiCgojY2xvdWQtY29uZmlnCgojIFVwZ3JhZGUgdGhlIGluc3RhbmNlIG9uIGZpcnN0IGJvb3QKIyAoaWUgcnVuIGFwdC1nZXQgdXBncmFkZSkKIwojIERlZmF1bHQ6IGZhbHNlCiMgQWxpYXNlczogYXB0X3VwZ3JhZGUKcGFja2FnZV91cGdyYWRlOiB0cnVlCg==
256+
cmk deploy virtualmachine name=..... userdata=Q29udGVudC1UeXBlOiBtdWx0aXBhcnQvbWl4ZWQ7IGJvdW5kYXJ5PSIvLyIKTUlNRS1WZXJzaW9uOiAxLjAKCi0tLy8KQ29udGVudC1UeXBlOiB0ZXh0L2Nsb3VkLWNvbmZpZzsgY2hhcnNldD0idXMtYXNjaWkiCk1JTUUtVmVyc2lvbjogMS4wCkNvbnRlbnQtVHJhbnNmZXItRW5jb2Rpbmc6IDdiaXQKQ29udGVudC1EaXNwb3NpdGlvbjogYXR0YWNobWVudDsgZmlsZW5hbWU9ImNsb3VkLWNvbmZpZy50eHQiCgojY2xvdWQtY29uZmlnCgojIFVwZ3JhZGUgdGhlIGluc3RhbmNlIG9uIGZpcnN0IGJvb3QKIyAoaWUgcnVuIGFwdC1nZXQgdXBncmFkZSkKIwojIERlZmF1bHQ6IGZhbHNlCiMgQWxpYXNlczogYXB0X3VwZ3JhZGUKcGFja2FnZV91cGdyYWRlOiB0cnVlCg==
257+
258+
.. code:: bash
156259
260+
cmk deploy virtualmachine name=..... userdataid=<Userdata UUID>
157261
158262
Disclaimer
159263
~~~~~~~~~~

0 commit comments

Comments
 (0)