OpenStack: Deploying Instances using the command line

From Define Wiki
Jump to navigation Jump to search
[root@server2-a ~(keystone_admin)]$ source keystonerc_myuser
  • Create a file which well inject later:
[root@server2-a ~(keystone_myuser)]$ cp /etc/issue /tmp/
[root@server2-a ~(keystone_myuser)]$ echo "Installed using nova command-line" >> /tmp/issue
  • Create a key-pair:
[root@server2-a ~(keystone_myuser)]$ nova keypair-add key1 > /root/key1
  • Create a security group to allow SSH access:
[root@server2-a ~(keystone_myuser)]$ nova secgroup-create mysecgroup "SSH"
+--------------------------------------+------------+-------------+
| Id                                   | Name       | Description |
+--------------------------------------+------------+-------------+
| 12707876-e557-47da-a767-7bb9e4d6b2e2 | mysecgroup | SSH         |
+--------------------------------------+------------+-------------+
  • Add a rule to allow SSH access to that security group:
[root@server2-a ~(keystone_myuser)]$ nova secgroup-add-rule mysecgroup tcp 22 22 0.0.0.0/0
+-------------+-----------+---------+-----------+--------------+
| IP Protocol | From Port | To Port | IP Range  | Source Group |
+-------------+-----------+---------+-----------+--------------+
| tcp         | 22        | 22      | 0.0.0.0/0 |              |
+-------------+-----------+---------+-----------+--------------+
  • List available images (glance image-list would do this too):
[root@server2-a ~(keystone_myuser)]$ nova image-list 
+--------------------------------------+-------+--------+--------+
| ID                                   | Name  | Status | Server |
+--------------------------------------+-------+--------+--------+
| 40f4efd4-8239-481b-a3f4-aafb5455ec20 | small | ACTIVE |        |
+--------------------------------------+-------+--------+--------+
  • List the available flavours:
[root@server2-a ~(keystone_myuser)]$ nova flavor-list 
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| ID | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| 1  | m1.tiny   | 512       | 1    | 0         |      | 1     | 1.0         | True      |
| 2  | m1.small  | 2048      | 20   | 0         |      | 1     | 1.0         | True      |
| 3  | m1.medium | 4096      | 40   | 0         |      | 2     | 1.0         | True      |
| 4  | m1.large  | 8192      | 80   | 0         |      | 4     | 1.0         | True      |
| 5  | m1.xlarge | 16384     | 160  | 0         |      | 8     | 1.0         | True      |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
  • List available networks (private & public):
[root@server2-a ~(keystone_myuser)]$ neutron net-list
+--------------------------------------+---------+------------------------------------------------------+
| id                                   | name    | subnets                                              |
+--------------------------------------+---------+------------------------------------------------------+
| 6077b8ec-6564-49d4-a476-181b2b916ba9 | private | 0ef72eb6-cd4c-4b09-ad60-9a94051b027c 172.25.102.0/24 |
| d7e212ee-f91d-4e84-a802-252833c80940 | public  | 028495a2-e735-4999-8752-687383ed855f                 |
+--------------------------------------+---------+------------------------------------------------------+
  • Boot an instance using information from above:
[root@server2-a ~(keystone_myuser)]$ nova boot --flavor m1.small --image small --key-name key1 --security-groups mysecgroup --nic net-id=6077b8ec-6564-49d4-a476-181b2b916ba9 --file /etc/issue=/tmp/issue test
+--------------------------------------+----------------------------------------------+
| Property                             | Value                                        |
+--------------------------------------+----------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                       |
| OS-EXT-AZ:availability_zone          | nova                                         |
| OS-EXT-STS:power_state               | 0                                            |
| OS-EXT-STS:task_state                | scheduling                                   |
| OS-EXT-STS:vm_state                  | building                                     |
| OS-SRV-USG:launched_at               | -                                            |
| OS-SRV-USG:terminated_at             | -                                            |
| accessIPv4                           |                                              |
| accessIPv6                           |                                              |
| adminPass                            | 7s5F3o3chZhw                                 |
| config_drive                         |                                              |
| created                              | 2015-04-29T10:07:43Z                         |
| flavor                               | m1.small (2)                                 |
| hostId                               |                                              |
| id                                   | eed0482f-eb5e-4c6e-afc9-49b7a402589f         |
| image                                | small (40f4efd4-8239-481b-a3f4-aafb5455ec20) |
| key_name                             | key1                                         |
| metadata                             | {}                                           |
| name                                 | test                                         |
| os-extended-volumes:volumes_attached | []                                           |
| progress                             | 0                                            |
| security_groups                      | mysecgroup                                   |
| status                               | BUILD                                        |
| tenant_id                            | 02f8b026fc754acea4466e5c1e28eecc             |
| updated                              | 2015-04-29T10:07:43Z                         |
| user_id                              | 33ef12bce0ca4658b2a20fe7262bc908             |
+--------------------------------------+----------------------------------------------+
  • After a while, do a nova list to see the state of the instance:
[root@server2-a ~(keystone_myuser)]$ nova list
+--------------------------------------+------+--------+------------+-------------+-----------------------+
| ID                                   | Name | Status | Task State | Power State | Networks              |
+--------------------------------------+------+--------+------------+-------------+-----------------------+
| eed0482f-eb5e-4c6e-afc9-49b7a402589f | test | ACTIVE | -          | Running     | private=172.25.102.26 |
+--------------------------------------+------+--------+------------+-------------+-----------------------+
  • Get the UID of the private port:
[root@server2-a ~(keystone_myuser)]$ neutron port-list | grep 172.25.102.26 | cut -f 2 -d "|"
 4fd4d340-6cff-4292-b0a3-6ceba7a30404
  • Get the UID of the floating IP:
[root@server2-a ~(keystone_myuser)]$ neutron floatingip-list  | grep 172.25.2.26 | cut -f 2 -d "|"
 787c484c-1497-4b6d-a0ac-617d5cce4e06
  • Associate the floating IP (UID) to the private port (UID)
[root@server2-a ~(keystone_myuser)]$ neutron floatingip-associate 787c484c-1497-4b6d-a0ac-617d5cce4e06 4fd4d340-6cff-4292-b0a3-6ceba7a30404
Associated floatingip 787c484c-1497-4b6d-a0ac-617d5cce4e06
  • Confirm the associated public IP:
[root@server2-a ~(keystone_myuser)]$ nova list
+--------------------------------------+------+--------+------------+-------------+------------------------------------+
| ID                                   | Name | Status | Task State | Power State | Networks                           |
+--------------------------------------+------+--------+------------+-------------+------------------------------------+
| eed0482f-eb5e-4c6e-afc9-49b7a402589f | test | ACTIVE | -          | Running     | private=172.25.102.26, 172.25.2.26 |
+--------------------------------------+------+--------+------------+-------------+------------------------------------+
  • You should be able to SSH to the instance now:
[root@server2-a ~(keystone_myuser)]$ ssh 172.25.2.26
The authenticity of host '172.25.2.26 (172.25.2.26)' can't be established.
RSA key fingerprint is a3:65:f8:8e:b3:f0:f9:38:49:d8:e0:31:a9:43:f9:26.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.25.2.26' (RSA) to the list of known hosts.
root@172.25.2.26's password: 
Last login: Wed Apr 29 06:12:04 2015
[root@host-172-25-102-26 ~]# exit
logout
Connection to 172.25.2.26 closed.
[root@server2-a ~(keystone_myuser)]$ nova keypair-show key1 | grep Public | cut -f 2 -d ":" > /root/key1.pub
[root@server2-a ~(keystone_myuser)]$ ssh-copy-id -i /root/key1.pub root@172.25.2.26
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.25.2.26's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@172.25.2.26'"
and check to make sure that only the key(s) you wanted were added.
[root@server2-a ~(keystone_myuser)]$ chmod 600 /root/key1
[root@server2-a ~(keystone_myuser)]$ ssh -i /root/key1 root@172.25.2.26
Last login: Wed Apr 29 06:17:31 2015 from 172.25.2.10
[root@host-172-25-102-26 ~]#
  • On another terminal:
[root@server2-a ~]# source /root/keystonerc_myuser 
[root@server2-a ~(keystone_myuser)]$ cinder create --display-name vol1 2
+---------------------+--------------------------------------+
|       Property      |                Value                 |
+---------------------+--------------------------------------+
|     attachments     |                  []                  |
|  availability_zone  |                 nova                 |
|       bootable      |                false                 |
|      created_at     |      2015-04-29T10:26:43.346741      |
| display_description |                 None                 |
|     display_name    |                 vol1                 |
|      encrypted      |                False                 |
|          id         | e004c30a-64ff-45f8-b957-da04192cdad4 |
|       metadata      |                  {}                  |
|         size        |                  2                   |
|     snapshot_id     |                 None                 |
|     source_volid    |                 None                 |
|        status       |               creating               |
|     volume_type     |                 None                 |
+---------------------+--------------------------------------+
[root@server2-a ~(keystone_myuser)]$ cinder list
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
|                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
| e004c30a-64ff-45f8-b957-da04192cdad4 | available |     vol1     |  2   |     None    |  false   |             |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
[root@server2-a ~(keystone_myuser)]$ nova volume-attach test e004c30a-64ff-45f8-b957-da04192cdad4 auto
+----------+--------------------------------------+
| Property | Value                                |
+----------+--------------------------------------+
| device   | /dev/vdb                             |
| id       | e004c30a-64ff-45f8-b957-da04192cdad4 |
| serverId | eed0482f-eb5e-4c6e-afc9-49b7a402589f |
| volumeId | e004c30a-64ff-45f8-b957-da04192cdad4 |
+----------+--------------------------------------+
[root@server2-a ~(keystone_myuser)]$ cinder list
+--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+
|                  ID                  | Status | Display Name | Size | Volume Type | Bootable |             Attached to              |
+--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+
| e004c30a-64ff-45f8-b957-da04192cdad4 | in-use |     vol1     |  2   |     None    |  false   | eed0482f-eb5e-4c6e-afc9-49b7a402589f |
+--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+
  • Back in the original terminal (still SSH'd into the new instance):
[root@host-172-25-102-26 ~]# fdisk -cul /dev/vdb

Disk /dev/vdb: 2147 MB, 2147483648 bytes
16 heads, 63 sectors/track, 4161 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000