8. Launch an instance (by cmd)

 

# 載入權限

source demo-openrc.sh

 

# 建立 ssh key

ssh-keygen

nova keypair-add --pub-key ~/.ssh/id_rsa.pub demo-key

nova keypair-list

+----------+-------------------------------------------------+
| Name     | Fingerprint                                     |
+----------+-------------------------------------------------+
| demo-key | 7f:0c:db:d1:27:8a:c3:28:2d:d4:25:b2:28:8f:61:fc |
+----------+-------------------------------------------------+

# If your host does not contain the public/private key pair created in an earlier step,
# SSH prompts for the default password associated with the cirros user.

 

# 查看可以建立什麼

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      |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+

nova image-list

+--------------------------------------+------------------------------+--------+--------+
| ID                                   | Name                         | Status | Server |
+--------------------------------------+------------------------------+--------+--------+
| dff9056a-81d8-4a21-97ae-f8b6eb20302b | precise-server-cloudimg-i386 | ACTIVE |        |
+--------------------------------------+------------------------------+--------+--------

nova net-list

+--------------------------------------+----------+--------------------+
| ID                                   | Label    | CIDR               |
+--------------------------------------+----------+--------------------+
| 17046477-72c6-4d79-bbf1-2a9291407c10 | demo-net | 192.168.123.128/29 |
+--------------------------------------+----------+--------------------+

nova secgroup-list

+----+---------+-------------+
| Id | Name    | Description |
+----+---------+-------------+
| 1  | default | default     |
+----+---------+-------------+

# 建立

nova boot --flavor m1.tiny --image precise-server-cloudimg-i386 \
                 --nic net-id=17046477-72c6-4d79-bbf1-2a9291407c10  \
                  --security-group default --key-name demo-key demo-instance1

 

--nic <net-id=net-uuid, v4-fixed-ip=ip-addr, port-id=port-uuid>

# block

--block-device-mapping                     # <dev-name>=<id>:<type>:<size(GB)>:<delete-on-terminate>

--block-device key1=value1             

  • id=image_id

  • source=type (image, snapshot, volume or blank) |

  • dest=destination (volume or local)

  • device=name (vda, xda)

  • size=size (GB)

  • format=device (swap, ext3, ntfs)

  • type=device (disk, cdrom)

--poll                                                # Blocks while server builds so progress can be reported.

Output:

+--------------------------------------+---------------------------------------------------------------------+
| Property                             | Value                                                               |
+--------------------------------------+---------------------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                                              |
| OS-EXT-AZ:availability_zone          | nova                                                                |
| OS-EXT-SRV-ATTR:host                 | -                                                                   |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | -                                                                   |
| OS-EXT-SRV-ATTR:instance_name        | instance-00000001                                                   |
| 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                            | ????????????                                                        |
| config_drive                         |                                                                     |
| created                              | 2014-10-03T07:52:21Z                                                |
| flavor                               | m1.tiny (1)                                                         |
| hostId                               |                                                                     |
| id                                   | ce3c3be1-4a4c-4190-8dcb-764ad3b8ef50                                |
| image                                | precise-server-cloudimg-i386 (dff9056a-81d8-4a21-97ae-f8b6eb20302b) |
| key_name                             | demo-key                                                            |
| metadata                             | {}                                                                  |
| name                                 | demo-instance1                                                      |
| os-extended-volumes:volumes_attached | []                                                                  |
| progress                             | 0                                                                   |
| security_groups                      | default                                                             |
| status                               | BUILD                                                               |
| tenant_id                            | 0e61ba054af84f6f99e52766b6ff441f                                    |
| updated                              | 2014-10-03T07:52:22Z                                                |
| user_id                              | 065f59bd572c45e59e68b801f32a5ada                                    |
+--------------------------------------+---------------------------------------------------------------------+

# 查看 instance

nova list

+--------------------------------------+----------------+--------+------------+-------------+----------+
| ID                                   | Name           | Status | Task State | Power State | Networks |
+--------------------------------------+----------------+--------+------------+-------------+----------+
| ce3c3be1-4a4c-4190-8dcb-764ad3b8ef50 | demo-instance1 | ERROR  | -          | NOSTATE     |          |
+--------------------------------------+----------------+--------+------------+-------------+----------+

tiny 注定失敗, 原因:

... virtual size 2361393152 larger than flavor root disk size 1073741824 ...

建決:

nova flavor-create m1.test 11 512 10 1

nova boot --flavor m1.test --image precise-server-cloudimg-i386 \
                 --nic net-id=17046477-72c6-4d79-bbf1-2a9291407c10  \
                  --security-group default --key-name demo-key demo-instance1

 

# Obtain a Virtual Network Computing (VNC) session URL

nova get-vnc-console demo-instance1 novnc

 

# To access your instance remotely

nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
nova secgroup-add-rule default tcp 22 22 0.0.0.0/0

 


Launch instance 過程

 

Build

/var/lib/nova/networks/nova-br100.conf

qemu-img convert -O raw /var/lib/nova/instances/_base/1c93f0b35fd51628d30b35543b291b59e261c65d.part /var/lib/nova/instances/_base/1c93f0b35fd51628d30b35543b291b59e261c65d.converted

Spawning

/usr/libexec/qemu-kvm -name instance-00000016 -S -M rhel6.5.0 -enable-kvm -m 512 -realtime mlock=off -smp 1,sockets=1,cores=1,threads=1 -uuid cfa48f4b-e139-49ff-8bc4-bb7d9fa0e4ac -smbios type=1,manufacturer=Red Hat Inc.,product=OpenStack Nova,version=2014.1.2-1.el6,serial=7ce9d373-9670-2c5a-5c3e-4b2460e86321,uuid=cfa48f4b-e139-49ff-8bc4-bb7d9fa0e4ac -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/instance-00000016.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew -no-kvm-pit-reinjection -no-shutdown -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/var/lib/nova/instances/cfa48f4b-e139-49ff-8bc4-bb7d9fa0e4ac/disk,if=none,id=drive-virtio-disk0,format=qcow2,cache=none -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -netdev tap,fd=27,id=hostnet0,vhost=on,vhostfd=29 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=fa:16:3e:4a:97:ac,bus=pci.0,addr=0x3 -chardev file,id=charserial0,path=/var/lib/nova/instances/cfa48f4b-e139-49ff-8bc4-bb7d9fa0e4ac/console.log -device isa-serial,chardev=charserial0,id=serial0 -chardev pty,id=charserial1 -device isa-serial,chardev=charserial1,id=serial1 -device usb-tablet,id=input0 -vnc 0.0.0.0:1 -k en-us -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

Running

 

 

 

Creative Commons license icon Creative Commons license icon