Skip to content

Openstack Servers

To read more about Openstack Servers using the upstream docs.

List and view servers

openstack --os-cloud={cloud name} server list
    [--quote {all,minimal,none,nonnumeric}]
    [--reservation-id <reservation-id>]
    [--ip <ip-address-regex>]
    [--ip6 <ip-address-regex>]
    [--name <name-regex>]
    [--instance-name <server-name>]
    [--status <status>]
    [--flavor <flavor>]
    [--image <image>]
    [--host <hostname>]
    [--all-projects]
    [--project <project>]
    [--project-domain <project-domain>]
    [--user <user>]
    [--user-domain <user-domain>]
    [--long]
    [-n]
    [--marker <server>]
    [--limit <num-servers>]
    [--deleted]
    [--changes-since <changes-since>]

Create a new server

openstack --os-cloud={cloud name} server create
    (--image <image> | --volume <volume>)
    --flavor <flavor>
    [--security-group <security-group>]
    [--key-name <key-name>]
    [--property <key=value>]
    [--file <dest-filename=source-filename>]
    [--user-data <user-data>]
    [--availability-zone <zone-name>]
    [--block-device-mapping <dev-name=mapping>]
    [--nic <net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,port-id=port-uuid,auto,none>]
    [--network <network>]
    [--port <port>]
    [--hint <key=value>]
    [--config-drive <config-drive-volume>|True]
    [--min <count>]
    [--max <count>]
    [--wait]
    <server-name>

Creating a Server with User Data

You can place user data in a local file and pass it through the --user-data parameter at instance creation.

openstack --os-cloud={cloud name} server create --image ubuntu-cloudimage \
                        --flavor 1 \
                        --user-data mydata.file \
                        $INSTANCE_UUID

Creating a Server with Config drives

Config drives are special drives that are attached to an instance when it boots. The instance can mount this drive and read files from it to get information that is normally available through the metadata service.

To enable the config drive for an instance, pass the --config-drive true parameter to the openstack server create command.

The following example enables the config drive and passes a user data file and two key/value metadata pairs, all of which are accessible from the config drive:

openstack --os-cloud={cloud name} server create --config-drive true \
                        --image my-image-name \
                        --flavor 1 \
                        --key-name mykey \
                        --user-data ./my-user-data.txt \
                        --property role=webservers \
                        --property essential=false \
                        $INSTANCE_UUID

Read more about Openstack Config drives using the upstream docs.

Delete a server

openstack --os-cloud={cloud name} server delete [--wait] <server> [<server> ...]

Launch a server from a snapshot

Please visit the Openstack Snapshot page here.

Launch a server from a volume

Please visit the Openstack Volumes page here.

Server Creation Example

Below is a quick example of how one could set up a server.

You will need to get your cloud name from your clouds.yaml. More information on this can be found here. Underneath "clouds:" you will find your cloud name.

First we are going to create our network "my_network"

openstack --os-cloud={cloud name} network create my_network

Second create the subnet "my_subnet"

openstack --os-cloud={cloud name} subnet create --ip-version 4 \
                                          --subnet-range $CIDR \
                                          --network $NETWORK_NAME \
                                          $CIDR

Third create the router "my_router"

openstack --os-cloud={cloud name} router create my_router

Fourth add "my_subnet" to "my_router" and set the router's external gateway using PUBLICNET to allow outbound network access.

openstack --os-cloud={cloud name} router add subnet my_router my_dmz_subnet

Set the external gateway

openstack --os-cloud={cloud name} router set --external-gateway PUBLICNET my_router

Fifth gather the UUIDS for our image, flavor and network to create our server.

openstack --os-cloud={cloud name} image list
openstack --os-cloud={cloud name} flavor list
openstack --os-cloud={cloud name} network list

Lastly create your server!

openstack --os-cloud={cloud name} server create --flavor $FLAVOR_NAME \
                                          --image $IMAGE_NAME \
                                          --boot-from-volume 25 \
                                          --network $NETWORK_NAME \
                                          my_first_server