使用命令:nova boot --flavor 1 --key_name mykey--p_w_picpath 9e5c2bee-0373-414c-b4af-b91b0246ad3b --security_group default cirrOS

其中:

flavor是虚拟机的配置,比如说内存大小,硬盘大小等,默认下1为最小,4为最大。

key_name是创建虚拟机使用的密钥,使用以下三条命令创建密钥:

               ssh-keygen       

                cd.ssh

               nova keypair-add --pub_key id_rsa.pub mykey       

p_w_picpath是已上传镜像的ID,使用nova p_w_picpath-list查询。

security_group是安全组。

cirrOS是你所要创建的虚拟机名。

 

 

stack@ustack:/home/stack$ pwd

/home/stack

stack@ustack:/home/stack$ nova keypair-add oskey >oskey.priv

stack@ustack:/home/stack$ chmod 600 oskey.priv

stack@ustack:/home/stack$ 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      |

| 42 | m1.nano   | 64        | 0   | 0         |      | 1    | 1.0         | True      |

| 451 | m1.heat   | 512      | 0    | 0         |     | 1     | 1.0         | True      |

| 5  | m1.xlarge | 16384     | 160  | 0        |      | 8     | 1.0         | True      |

| 84 | m1.micro  | 128       | 0   | 0         |      | 1    | 1.0         | True      |

+-----+-----------+-----------+------+-----------+------+-------+-------------+-----------+

stack@ustack:/home/stack$ nova p_w_picpath-list

+--------------------------------------+---------------------------------+--------+--------+

| ID                                   | Name                            | Status | Server |

+--------------------------------------+---------------------------------+--------+--------+

| 845cae84-3031-47e0-9a76-0d2e1a9acc2d| Fedora-x86_64-20-20140618-sda   |ACTIVE |        |

| fb584b71-ee87-443c-adba-f5b61c10c039 |cirros-0.3.2-x86_64-uec         | ACTIVE|        |

| e54a9f62-f27d-4793-bcef-25cd80d06e62 |cirros-0.3.2-x86_64-uec-kernel  | ACTIVE|        |

| 0fb0e025-2df5-41d1-947f-60ba179d49d5 |cirros-0.3.2-x86_64-uec-ramdisk | ACTIVE |        |

+--------------------------------------+---------------------------------+--------+--------+

使用nova boot命令创建虚拟机

stack@ustack:/home/stack$ nova boot --flavor 2 --key_nameoskey --p_w_picpath 845cae84-3031-47e0-9a76-0d2e1a9acc2d fedora

+--------------------------------------+----------------------------------------------------------------------+

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

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

| config_drive                         |                                                                      |

| created                              |2014-11-27T02:11:02Z                                                |

| flavor                               | m1.small(2)                                                        |

| hostId                               |                                                                     |

| id                                   |9068bbb6-d640-4345-9a67-fad233f01961                                 |

| p_w_picpath                                |Fedora-x86_64-20-20140618-sda (845cae84-3031-47e0-9a76-0d2e1a9acc2d) |

| key_name                             | oskey                                                               |

| metadata                             | {}                                                                   |

| name                                 | fedora                                                              |

| os-extended-volumes:volumes_attached |[]                                                                   |

| progress                             | 0                                                                   |

| security_groups                      | default                                                             |

| status                               | BUILD                                                               |

| tenant_id                            |a32c49a8d4c04936bc436da5ff16379b                                     |

| updated                              | 2014-11-27T02:11:02Z                                                |

| user_id                              |7b313c95e7b044e2b3dc6f0b31672c2f                                     |

+--------------------------------------+----------------------------------------------------------------------+

虚拟机创建完毕,打印虚拟机列表

stack@ustack:/home/stack$ nova list

+--------------------------------------+--------+--------+------------+-------------+--------------------+

| ID                                   | Name   | Status | Task State | Power State |Networks           |

+--------------------------------------+--------+--------+------------+-------------+--------------------+

| fda792f6-92b7-4c7f-adb9-a7e200ef0c7e |cirros | ACTIVE | -          |Running     | private=10.10.10.2 |

| 9068bbb6-d640-4345-9a67-fad233f01961 |fedora | ACTIVE | -          |Running     | private=10.10.10.3 |

+--------------------------------------+--------+--------+------------+-------------+--------------------+

 

添加防火墙规则

stack@ustack:/home/stack$ nova secgroup-add-rule defaulttcp 22 22 0.0.0.0/0

+-------------+-----------+---------+-----------+--------------+

| IP Protocol | From Port | To Port | IPRange  | Source Group |

+-------------+-----------+---------+-----------+--------------+

| tcp         | 22        | 22      | 0.0.0.0/0 |              |

+-------------+-----------+---------+-----------+--------------+

stack@ustack:/home/stack$ nova secgroup-add-rule defaulticmp -1 -1 0.0.0.0/0

+-------------+-----------+---------+-----------+--------------+

| IP Protocol | From Port | To Port | IPRange  | Source Group |

+-------------+-----------+---------+-----------+--------------+

| icmp        | -1        | -1      | 0.0.0.0/0 |              |

+-------------+-----------+---------+-----------+--------------+