Create a customized instance
Cloud users can specify additional data to use when they launch an instance, such as a shell script that the instance runs on boot.
The cloud user can use the following methods to pass data to instances:
- User data
-
Use to include instructions in the instance launch command for
cloud-initto run. - Instance metadata
-
A list of key-value pairs that you can specify when you create or update an instance.
You can access the additional data passed to the instance by using a config drive or the metadata service.
- Config drive
-
You can attach a config drive to an instance when it boots. The config drive is presented to the instance as a read-only drive. The instance can mount this drive and read files from it. You can use the config drive as a source for
cloud-initinformation. Config drives are useful when combined withcloud-initfor server bootstrapping, and when you want to pass large files to your instances. For example, you can configurecloud-initto automatically mount the config drive and run the setup scripts during the initial instance boot. Config drives are created with the volume label ofconfig-2, and attached to the instance when it boots. The contents of any additional files passed to the config drive are added to theuser_datafile in theopenstack/{version}/directory of the config drive.cloud-initretrieves the user data from this file. - Metadata service
-
Provides a REST API to retrieve data specific to an instance. Instances access this service at
169.254.169.254or atfe80::a9fe:a9fe.cloud-initcan use both a config drive and the metadata service to consume the additional data for customizing an instance. Thecloud-initpackage supports several data input formats. Shell scripts and thecloud-configformat are the most common input formats:- Shell scripts: The data declaration begins with
#!orContent-Type: text/x-shellscript. Shell scripts are invoked last in the boot process. cloud-configformat: The data declaration begins with#cloud-configorContent-Type: text/cloud-config.cloud-configfiles must be valid YAML to be parsed and executed bycloud-init.Note cloud-inithas a maximum user data size of 16384 bytes for data passed to an instance. You cannot change the size limit, therefore use gzip compression when you need to exceed the size limit.
- Shell scripts: The data declaration begins with
Vendor-specific data
The administrator can also pass data to instances when they are being created. This data might not be visible to you as the cloud user, for example, a cryptographic token that registers the instance with Active Directory.
The administrator uses the vendordata feature to pass data to instances. Vendordata configuration is read only and is located in one of the following files:
-
/openstack/{version}/vendor_data.json -
/openstack/{version}/vendor_data2.json
You can view these files by using the metadata service or from the config drive on your instance. To access the files by using the metadata service, make a GET request to either 169.254.169.254/openstack/{version}/vendor_data.json or 169.254.169.254/openstack/{version}/vendor_data2.json.
To run openstack client commands on the cloud, you must specify the name of the cloud detailed in your clouds.yaml file. You can specify the name of the cloud by using one of the following methods:
- Use the
--os-cloudoption with each command, for example:$ openstack flavor list --os-cloud <cloud_name>Use this option if you access more than one cloud.
- Create an environment variable for the cloud name in your
bashrcfile:`export OS_CLOUD=<cloud_name>`
Customize an instance by using user data Copy linkLink copied!
Use user data to include instructions in the instance launch command. cloud-init executes these commands to customize the instance as the last step in the boot process.
Before you begin Copy linkLink copied!
- The administrator has created a project for you and they have provided you with a
clouds.yamlfile for you to access the cloud. - You have installed the
python-openstackclientpackage.
Procedure Copy linkLink copied!
Customize an instance by using metadata Copy linkLink copied!
Use instance metadata to specify the properties of an instance in the launch command.
Before you begin Copy linkLink copied!
- The administrator has created a project for you and they have provided you with a
clouds.yamlfile for you to access the cloud. - You have installed the
python-openstackclientpackage.
Procedure Copy linkLink copied!
Customize an instance by using a config drive Copy linkLink copied!
Create a config drive that attaches to an instance during boot. Pass content to the config drive to make configuration data available to the instance.
Before you begin Copy linkLink copied!
- The administrator has created a project for you and they have provided you with a
clouds.yamlfile for you to access the cloud. - You have installed the
python-openstackclientpackage.