在包含Orchestration服务的环境中,可以创建启动实例的堆栈
创建yam文件
heat_template_version: 2015-10-15
description: Launch a basic instance with CirrOS image using the
``m1.tiny`` flavor, ``mykey`` key, and one network.
parameters:
NetID:
type: string
description: Network ID to use for the instance.
resources:
server:
type: OS::Nova::Server
properties:
image: cirros_test
flavor: m1.tiny
key_name: demo
networks:
- network: { get_param: NetID }
outputs:
instance_name:
description: Name of the instance.
value: { get_attr: [ server, name ] }
instance_ip:
description: IP address of the instance.
value: { get_attr: [ server, first_address ] }
[root@armstrong ~]# source keystone_demo 注意,yam文件里的image,flavor,key_name可以利用openstack CLI获取 [root@armstrong ~(keystone_demo)]# openstack flavor list +----+-----------+-------+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +----+-----------+-------+------+-----------+-------+-----------+ | 1 | m1.tiny | 512 | 1 | 0 | 1 | True | | 2 | m1.small | 2048 | 20 | 0 | 1 | True | | 3 | m1.medium | 4096 | 40 | 0 | 2 | True | | 4 | m1.large | 8192 | 80 | 0 | 4 | True | | 5 | m1.xlarge | 16384 | 160 | 0 | 8 | True | +----+-----------+-------+------+-----------+-------+-----------+ [root@armstrong ~(keystone_demo)]# openstack image list +--------------------------------------+----------------+--------+ | ID | Name | Status | +--------------------------------------+----------------+--------+ | 9d3a6eba-2e28-422c-950a-d62240a14257 | cirros_test | active | | 9fee7ec6-6cce-4df0-9017-c9d94153fb98 | test_armstrong | active | +--------------------------------------+----------------+--------+ [root@armstrong ~(keystone_demo)]# openstack keypair create demo [root@armstrong ~(keystone_demo)]# openstack keypair list +------+-------------------------------------------------+ | Name | Fingerprint | +------+-------------------------------------------------+ | demo | f6:27:ea:aa:8a:f9:bc:48:a0:86:17:90:e1:f7:64:fa | +------+-------------------------------------------------+ [root@armstrong ~(keystone_demo)]# export NET_ID=$(openstack network list | awk '/ private / { print $2 }') [root@armstrong ~(keystone_demo)]# openstack stack create -t demo-template.yml --parameter "NetID=$NET_ID" stack +---------------------+----------------------------------------------------------------------------------------------------------+ | Field | Value | +---------------------+----------------------------------------------------------------------------------------------------------+ | id | a98a9958-088d-4882-8102-f7698884ce40 | | stack_name | stack | | description | Launch a basic instance with CirrOS image using the ``m1.tiny`` flavor, ``mykey`` key, and one network. | | creation_time | 2018-06-13T07:12:37Z | | updated_time | None | | stack_status | CREATE_IN_PROGRESS | | stack_status_reason | Stack CREATE started | +---------------------+----------------------------------------------------------------------------------------------------------+ [root@armstrong ~(keystone_demo)]# openstack stack list +--------------------------------------+------------+--------------------+----------------------+--------------+ | ID | Stack Name | Stack Status | Creation Time | Updated Time | +--------------------------------------+------------+--------------------+----------------------+--------------+ | a98a9958-088d-4882-8102-f7698884ce40 | stack | CREATE_IN_PROGRESS | 2018-06-13T07:12:37Z | None | +--------------------------------------+------------+--------------------+----------------------+--------------+ 虚机启动后会变为COMPLETE [root@armstrong ~(keystone_demo)]# openstack stack list +--------------------------------------+------------+-----------------+----------------------+--------------+ | ID | Stack Name | Stack Status | Creation Time | Updated Time | +--------------------------------------+------------+-----------------+----------------------+--------------+ | a98a9958-088d-4882-8102-f7698884ce40 | stack | CREATE_COMPLETE | 2018-06-13T07:12:37Z | None | +--------------------------------------+------------+-----------------+----------------------+--------------+ [root@armstrong ~(keystone_demo)]# openstack stack show stack +-----------------------+---------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +-----------------------+---------------------------------------------------------------------------------------------------------------------------+ | id | a98a9958-088d-4882-8102-f7698884ce40 | | stack_name | stack | | description | Launch a basic instance with CirrOS image using the ``m1.tiny`` flavor, ``mykey`` key, and one network. | | creation_time | 2018-06-13T07:12:37Z | | updated_time | None | | stack_status | CREATE_COMPLETE | | stack_status_reason | Stack CREATE completed successfully | | parameters | NetID: c53a005b-03af-4801-b92e-2fd2acedcd1d | | | OS::project_id: 5a55ee4fa9474c31a372e3dc8a951cf6 | | | OS::stack_id: a98a9958-088d-4882-8102-f7698884ce40 | | | OS::stack_name: stack | | | | | outputs | - description: Name of the instance. | | | output_key: instance_name | | | output_value: stack-server-m4qegurg52pm | | | - description: IP address of the instance. | | | output_key: instance_ip | | | output_value: 10.0.0.8 | | | | | links | - href: http://192.168.122.209:8004/v1/5a55ee4fa9474c31a372e3dc8a951cf6/stacks/stack/a98a9958-088d-4882-8102-f7698884ce40 | | | rel: self | | | | | parent | None | | disable_rollback | True | | deletion_time | None | | stack_user_project_id | 932859b5db654e1bae13956d90b45a63 | | capabilities | [] | | notification_topics | [] | | stack_owner | None | | timeout_mins | None | | tags | None | +-----------------------+---------------------------------------------------------------------------------------------------------------------------+ 显示实例的名称和IP地址,并与OpenStack客户端的输出进行比较 [root@armstrong ~(keystone_demo)]# openstack stack output show --all stack +---------------+-------------------------------------------------+ | Field | Value | +---------------+-------------------------------------------------+ | instance_name | { | | | "output_value": "stack-server-m4qegurg52pm", | | | "output_key": "instance_name", | | | "description": "Name of the instance." | | | } | | instance_ip | { | | | "output_value": "10.0.0.8", | | | "output_key": "instance_ip", | | | "description": "IP address of the instance." | | | } | +---------------+-------------------------------------------------+ [root@armstrong ~(keystone_demo)]# openstack server list +--------------------------------------+---------------------------+--------+------------------+-------------+---------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+---------------------------+--------+------------------+-------------+---------+ | f6879d35-7c12-4ddf-bb4a-c51f501a7328 | stack-server-m4qegurg52pm | ACTIVE | private=10.0.0.8 | cirros_test | m1.tiny | +--------------------------------------+---------------------------+--------+------------------+-------------+---------+
但谈何容易。