OpenStack Heat 模板学习


Date:2014/03/28

Author:berlin

System:Ubuntu 12.04 Server

What's heat

Heat is the main project in the OpenStack Orchestration program. It implements an orchestration engine to launch multiple composite cloud applications based on templates in the form of text files that can be treated like code. A native Heat template format is evolving, but Heat also endeavours to provide compatibility with the AWS CloudFormation template format, so that many existing CloudFormation templates can be launched on OpenStack. Heat provides both an OpenStack-native ReST API and a CloudFormation-compatible Query API.

 

Heat 类似于AWS的CloudFormation, 是OpenStack Orchestration进程的一个项目,OpenStack Orchestration旨在创建一个人性化的服务去管理整个云架构,服务和应用的生命周期。heat实现了一种自动化的通过简单定义和配置就能实现的云部署方式。可以在heat模板中定义连串相关任务(例如用某配置开几台虚拟机,然后再去在其中一台中安装一个mysql服务,设定相关数据库属性,然后再配置几台虚拟机安装web服务集群等等),然后交由heat,由heat按照一定的顺序执行heat模板中定义的一连串任务。利用heat还可以连接到neutron来帮助编排负载均衡和其他网络功能。

 

How it works

学习heat主要学习heat的template,heat的template描述了所用的所有组件资源以及组件资源之间的关系。 这些资源包括:servers,floating ips, volumes, security groups, users and others. Heat管理这些组件的生命周期,当你需要对现在的部署做一些修改的时候,你只需要对template做一些修改即可。Heat还可以与其他软件管理工具集成比如Puppet以及chef。

 

Getting Started Guides

Install Heat with Devstack

选择一个VM镜像,可以选择 http://cloud.fedoraproject.org/fedora-20.x86_64.qcow2F20,它包含了heat-cfntools包,当运行./stack.sh的时候Heat将会被加载到screen中前缀是h-. 假如需要使用Ceilometer Alarms功能你需要添加Ceilometer功能。需要做的是在devstack的localrc文件中添加如下:

CEILOMETER_BACKEND=mysql

enable_service ceilometer-acompute ceilometer-acentral ceilometer-collector ceilometer-api

enable_service ceilometer-alarm-notifier ceilometer-alarm-evaluator

 

#sudo apt-get install gitgit-review ctags

首先下载devstack

#git clone https://github.com/openstack-dev/devstack.git

然后准备localrc如下,灵活选择你感兴趣的项目,做减法处理。注意假如你的环境在proxy后面,而proxy又不支持git时,可以将stackrc中的GIT_BASE=${GIT_BASE:-git://git.openstack.org}改为GIT_BASE=${GIT_BASE:-https://github.com}

#The localrc is used to deploy a Neutron+OVS+heat+ceilometer+tempest development env

#OFFLINE True if no need to pull necessary packages again

#OFFLINE=True

#RECLONE True if all need a fresh repo environment

#RECLONE=True

ADMIN_PASSWORD=123

MYSQL_PASSWORD=123

RABBIT_PASSWORD=123

SERVICE_PASSWORD=123

SERVICE_TOKEN=123

Q_PLUGIN=openvswitch

disable_service n-net

#enable necessary network comps

ENABLED_SERVICES+=,neutron,q-svc,q-agt,q-dhcp,q-l3,q-meta

#enable advanced services

enable_service q-vpn q-lbaas q-fwaas

#enable tempest for learning tempest

enable_service tempest

#enable heat

enable_service heat h-api h-api-cfn h-api-cw h-eng

#enable ceilometer for Ceilometer Alarms

CEILOMETER_BACKEND=mysql

enable_service ceilometer-acompute ceilometer-acentral ceilometer-collector ceilometer-anotification

enable_service ceilometer-api

enable_service ceilometer-alarm-notifier ceilometer-alarm-evaluator

 

HOST_IP=<Host-IP>

#VM images

IMAGE_URLS="http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-i386-uec.tar.gz"

#IMAGE_URLS+=",http://uec-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img"

IMAGE_URLS+=",http://cloud.fedoraproject.org/fedora-20.x86_64.qcow2"

 

http_proxy=<http-proxy>

https_proxy=<https-proxy>

no_proxy=localhost,<Host-IP>

 

#for IPSec VPNaaS

IPSEC_PACKAGE=openswan

 

#LOG configure

SCREEN_LOGDIR=/opt/stack/screen-logs

SYSLOG=True

 

#DEST=/opt/stack/project

一切准备就绪,最好先update&upgrade一下,然后运行./stack.sh 可以部署openstack环境了。

模板

https://github.com/openstack/heat-templates 提供一些templates参考例子来展示heat的一些核心功能。heat目前支持两种模板: 与CloudFormatior兼容的cnf目录下的模板以及自研的在hot目录下的HOT模板。 HOT模板基于YAML来展示,下面仅研究HOT模板。

写一个HOT hello world 模板

hello template file:

heat_template_version: 2013-05-23

 

description: Simple template to deploy a single compute instance

 

resources:

  my_instance:

    type: OS::Nova::Server

    properties:

      key_name: heat_key

      image: cirros-0.3.0-i386-uec

      flavor: m1.tiny

“heat_template_version: 2013-05-23” 是必须制定的,标识当前heat的模板版本。Resources是必须的,其中一个resources内必须至少包含一个resource定义,在该例子中的key_name, image以及flavor都是hardcoded,该问题可以通过input parameters解决。

查找上面模板相关参数的CLI过程如下:

stack@vm:~/devstack$ . openrc admin admin

stack@vm:~/devstack$ cd

stack@vm:~$ nova keypair-add heat_key

-----BEGIN RSA PRIVATE KEY-----

MIIEpAIBAAKCAQEA5bONIrtYZju6CYa+QB8z+cV+6yDHwW1FH5KpMrHhK317b05D

G2q3gkE3TWZE5pHNlDDIOyG+6XVu+paFgkjsigsu5c3y4/43ArdSL/l47rauaQOb

/Lg/hpxe09P30IszhRIicl8sRYMceCpCmdnE+d4NHBqD8AEvFzZU+CVLuLimmkxj

TbcapVKbdGe0CBEypTifxDY/DXhlMlnGqMemP9rMig9SWxh1JS+EdsLfIBQ1NjTO

f8b6QnIiAx18RZc9LRjfQy63mPNKJEiyjPGdqkVDwVaM6QHaNblen5yTv17AoOi9

EZlN1FIGBH0LamUBn8FCCKvY0zgjhrlE5a5viQIDAQABAoIBAQC2mjUxjiNpKkPr

fM1TZjrIbaNGwglqkDYqMkoFffkVvKxawKmCayS1DKktA4b0kKYQD3Ot5lbBetSd

qvk5qEU6PEes8jsL2jTbGObiMn1br6gY3YCst7/wf/C2jsRraa2sNM1jhJtKKz9/

m4DUk5UOWeKsG7wVGKvZ1RxZJDT9A3OPqoNlKPcVXPfkZgyr9MujfNaBmGMwnJ5u

Kulu0CWPV1Q66/BOPJP6sy2iMBatvxAl6bJW8MG2kmaroy697kUs88pJQkOX6XAQ

BxW4pgBvE70sBNKGB3Q5krQAflF00k0JD73JSzEEnfYf/qiiliVVErlIxCX0m8q+

AvnDswgBAoGBAP7VIP7GkGEOw1OF1dLwJQw+sLmzmx1cRsR6atN4aebs97ELbqwR

iQdkjwi7QcloGSPvwNci9m69n5b4MDORfnyg6iEjnufjx0ETdU+WAYuHVKzo0jQc

CYscCInOWDDwfIQiKLaxJ8PHsr6PnLluVpqRYZj58OfmK8rg5A4pvJyJAoGBAObA

8sB9ZpKZ3cqKsFvWk9ZxatWEqyqILhHvxXDYDxEnjbbEW3pc22YSKNUixHjnKJ0A

ff+z8v3sZK+Ut9wyuSZ2RcChCR8+yRpH93+uhArRzvkmoCLfkEeCLnAenMn7Gn/G

5PtUnINc1/1aWR76nNoNCC38be4CJ2ZGRa4f3HsBAoGACyffYufkaCtSR7TDMJHM

vWV9LRP8xWNFwdIuHQXXdQGIslpyxNubqRQw4sv3zE5fU2Bqi8B/E0f/1YcV7RwA

copE1aCOk044adPlPc+uT6JkBZHHqfpUPJ/Ei+vZloLgoJQyPhUxTXPPkmINFV0M

M4YLxLukXTKJVj9UHH6dQCkCgYEAgZbYfXuvUCNzKF0s39ao3eSCD/laux8RaGdU

ZaQhCgxBjOPHT/e4CyGlptTIq/F9oHZ3TFP94daRUP3fJ52g11XSpHSLj+2NuOGz

wBP8+aqMZuXnRs5w04frlnHKsbAAWMQVMoR5BVjtv82ugTRTRC3Payv5fJHfGJPc

bAZepwECgYBdqWrp5vkF5ZWkWv/mAFs9FJ9l/U9Ac6Mwf70YWD2XaumeRHcbT7lN

K4Yb9yguT3tG39t7DcRxj/QopgIrI/eItiLI1UD2QiieFpT4NWSmRuBKJ24qlL2F

4ehCUJa0Pw1NVoTBsi3qjxqEHp41wJ5LDea5D8qltdA5Qln7wtbdBA==

-----END RSA PRIVATE KEY-----

stack@vm:~$ nova image-list

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

| ID                                   | Name                          | Status | Server |

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

| cd8dc967-6dea-4963-806a-715d52fb2721 | cirros-0.3.0-i386-uec         | ACTIVE |        |

| bbb040e9-2d35-403a-bf40-27b7213c0e1f | cirros-0.3.0-i386-uec-kernel  | ACTIVE |        |

| 31425245-56d6-424f-8089-cd363a90d210 | cirros-0.3.0-i386-uec-ramdisk | ACTIVE |        |

| 851fd3d9-ac4b-41b8-84a5-2fd169052d68 | fedora-20.x86_64              | ACTIVE |        |

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

stack@vm:~$ 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      |

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

 

部署模板的CLI过程如下:

stack@vm:~/hot-files$ heat stack-create -f ./hello hello-stack

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

| id                                   | stack_name  | stack_status       | creation_time        |

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

| 2652f7da-aeb7-46a9-8832-a834142af6d4 | hello-stack | CREATE_IN_PROGRESS | 2014-03-31T07:52:19Z |

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

stack@vm:~/hot-files$ heat stack-list

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

| id                                   | stack_name  | stack_status    | creation_time        |

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

| 2652f7da-aeb7-46a9-8832-a834142af6d4 | hello-stack | CREATE_COMPLETE | 2014-03-31T07:52:19Z |

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

stack@vm:~/hot-files$ heat event-list hello-stack

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

| resource_name | id                                   | resource_status_reason | resource_status    | event_time           |

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

| my_instance   | 871b7361-fed2-4083-bd09-086e128cc6df | state changed          | CREATE_COMPLETE    | 2014-03-31T07:52:43Z |

| my_instance   | 9c192721-a7e3-4a0b-a4b1-a0131012d9fa | state changed          | CREATE_IN_PROGRESS | 2014-03-31T07:52:19Z |

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

stack@vm:~/hot-files$ heat stack-show hello-stack

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

| Property             | Value                                                                                                               |

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

| capabilities         | []                                                                                                                  |

| creation_time        | 2014-03-31T07:52:19Z                                                                                                |

| description          | Simple template to deploy a single compute instance                                                                 |

| disable_rollback     | True                                                                                                                |

| id                   | 2652f7da-aeb7-46a9-8832-a834142af6d4                                                                                |

| links                | http://10.117.4.58:8004/v1/dee53de0a4ff46a498a916edf328d13f/stacks/hello-stack/2652f7da-aeb7-46a9-8832-a834142af6d4 |

| notification_topics  | []                                                                                                                  |

| outputs              | []                                                                                                                  |

| parameters           | {                                                                                                                   |

|                      |   "OS::stack_name": "hello-stack",                                                                                  |

|                      |   "OS::stack_id": "2652f7da-aeb7-46a9-8832-a834142af6d4"                                                            |

|                      | }                                                                                                                   |

| stack_name           | hello-stack                                                                                                         |

| stack_status         | CREATE_COMPLETE                                                                                                     |

| stack_status_reason  | Stack CREATE completed successfully                                                                                 |

| template_description | Simple template to deploy a single compute instance                                                                 |

| timeout_mins         | 60                                                                                                                  |

| updated_time         | None                                                                                                                |

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

 

Template input parameters

去硬编码,使模板更加灵活,需要加入parameters属性,这样调用模板时,可以输入相关参数,hello带input的模板如下:

heat_template_version: 2013-05-23

 

description: Simple template to deploy a single compute instance

 

parameters:

  key_name:

    type: string

    label: Key Name

    description: Name of key-pair to be used for compute instance

  image_name:

    type: string   

    label: Image Name

    description: Image to be used for compute instance

  instance_type:

    type: string

    label: Instance Type

    description: Type of instance (flavor) to be used

 

outputs:

    instance_ip:

        description: the ip addresss of the deployed instance_type

        value: {get_attr: [my_instance, first_address]}

 

resources:

  my_instance:

    type: OS::Nova::Server

    properties:

      key_name: { get_param: key_name }

      image: { get_param: image_name }

      flavor: { get_param: instance_type }

执行如下:

stack@vm:~/hot-files$ heat stack-create -f ./hello_input -P "key_name=heat_key;instance_type=m1.tiny;image_name=cirros-0.3.0-i386-uec" stack-vm2

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

| id                                   | stack_name  | stack_status       | creation_time        |

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

| 2652f7da-aeb7-46a9-8832-a834142af6d4 | hello-stack | CREATE_COMPLETE    | 2014-03-31T07:52:19Z |

| 73f79f9d-f5a4-46a4-a4d0-db0da7c646b2 | stack-vm2   | CREATE_IN_PROGRESS | 2014-03-31T08:36:36Z |

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

stack@vm:~/hot-files$ heat stack-list

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

| id                                   | stack_name  | stack_status    | creation_time        |

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

| 2652f7da-aeb7-46a9-8832-a834142af6d4 | hello-stack | CREATE_COMPLETE | 2014-03-31T07:52:19Z |

| 73f79f9d-f5a4-46a4-a4d0-db0da7c646b2 | stack-vm2   | CREATE_COMPLETE | 2014-03-31T08:36:36Z |

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

理解好了上面的两个例子,然后接下来就可以看【9】HOT的spec文档了,包括Structure,PGS,PS,RS,OS以及Intrinsic Functions

现在Heat支持的Resource类型可以在http://docs.openstack.org/developer/heat/template_guide/openstack.html上找到,下面主要探索advancedservices(LB,FW,VPN)的相关模板,需要在阅读[7]OpenStack Resource Types 以及[9]的前提下,才能了解下面模板的具体含义。

Loadbalancer 模板

接下来首先根据[13]下手做一个Loadbalancer模板,网络拓扑图如下:



“””如上图所示,我们的服务器网络的网址范围为10.0.0.0/24,负载均衡器网络的网址范围是192.168.40.0/24,public网络链接办公网络,网址范围是192.168.10.224/28。路由器链接了所有三个网络。public网络和路由器是通过路由器的网关臂(NeutronAPIroutergateway相连的。路由器把服务器网络和负载均衡器网络的IP地址SNAT成路由器的网关臂public网络的地址。这样他们就可以访问办公网络的IP啦。但是如果要想从办公网络访问服务器网络和负载均衡器网络,我们还需要动态地址(FloatingIP).”””引自[13]

Network 设备及拓扑

public_net: 192.168.10.224/28

lb_net:  192.168.40.0/24

server_net: 10.0.0.0/24

router: {

gateway: <from public_net>,

interface1: lb_net,

interface2: server_net

}

Router resource 要depends on public_net, lb_net以及server_net

根据以上信息:设置LB网络拓扑图模板network_topology.template如下,注意在这之前你可能需要清理网络拓扑环境,然后设置合适的br-ex配置(sudo ifconfig br-ex 192.168.10.225netmask 255.255.224.0 up),式能够访问public_net:

heat_template_version: 2013-05-23

 

description: >

    network topology deployment HOT template reference to

    http://www.ustack.com/blog/neutron_loadbalance/

 

parameters:

    public_net_name:

        type: string

        label: Public Network Name

        default: public_net

    lb_net_name:

        type: string

        label: Loadbalancer Network Name

        default: lb_net

    server_net_name:

        type: string

        label: Web Servers Network Name

        default: server_net

    public_subnet_name:

        type: string

        label: Public Subnet Name

        default: public_subnet

    public_subnet_cidr:

        type: string

        label: Public Subnet CIDR

        default: 192.168.10.224/28

    lb_subnet_name:

        type: string

        label: Loadbalancer Subnet Name

        default: lb_subnet

    lb_subnet_cidr:

        type: string

        label: Loadbalancer Subnet CIDR

        default: 192.168.40.0/24

    server_subnet_name:

        type: string

        label: Web Servers Subnet Name

        default: server_subnet

    server_subnet_cidr:

        type: string

        label: Web Servers Subnet CIDR

        default: 10.0.0.0/24

    router_name:

        type: string

        label: The Router Name

        default: router

 

outputs:

    lb_subnet_gateway:

        description: Loadbalancer Subnet Gateway

        value: {get_attr: [lb_subnet, gateway_ip]}

    lb_subnet_cidr:

        description: Loadbalancer Subnet CIDR

        value: {get_attr: [lb_subnet, cidr]}

    server_subnet_gateway:

        description: Web Servers Subnet Gateway

        value: {get_attr: [server_subnet, gateway_ip]}

    server_subnet_cidr:

        description: Web Servers Subnet CIDR

        value: {get_attr: [server_subnet, cidr]}

    

 

resources:

    public_net:

        type: OS::Neutron::Net

        properties:

            name: {get_param: public_net_name}

            shared: True

            value_specs: {"router:external": True}

    lb_net:

        type: OS::Neutron::Net

        properties:

            name: {get_param: lb_net_name}

    server_net:

        type: OS::Neutron::Net

        properties:

            name: {get_param: server_net_name}

    public_subnet:

        type: OS::Neutron::Subnet

        depends_on: public_net

        properties:

            name: {get_param: public_subnet_name}

            cidr: {get_param: public_subnet_cidr}

            network_id: {get_resource: public_net}

            enable_dhcp: False

    lb_subnet:

        type: OS::Neutron::Subnet

        depends_on: lb_net

        properties:

            name: {get_param: lb_subnet_name}

            cidr: {get_param: lb_subnet_cidr}

            network_id: {get_resource: lb_net}

    server_subnet:

        type: OS::Neutron::Subnet

        depends_on: server_net

        properties:

            name: {get_param: server_subnet_name}

            cidr: {get_param: server_subnet_cidr}

            network_id: {get_resource: server_net}

    router:

        type: OS::Neutron::Router

        depends_on: [public_net, public_subnet]

        properties:

            name: {get_param: router_name}

            external_gateway_info: {"network": {get_resource: public_net}}

    lb_interface:

        type: OS::Neutron::RouterInterface

        depends_on: [lb_subnet, router]

        properties:

            router_id: {get_resource: router}

            subnet_id: {get_resource: lb_subnet}

    server_interface:

        type: OS::Neutron::RouterInterface

        depends_on: [server_subnet, router]

        properties:

            router_id: {get_resource: router}

            subnet_id: {get_resource: server_subnet}

然后运行如下CLI命令,则自动生成相应的网络拓扑,省去不少命令行敲字,而且实验结束,直接heatstack-delete 掉即可。

#heat template-validate--template-file ./network_topology.template

#heat stack-create -f./network_topology.template lb-net-topology

网络拓扑用到的Resource资源如下:

OS::Neutron::Net: http://docs.openstack.org/developer/heat/template_guide/openstack.html#OS::Neutron::Net

OS::Neutron::Subnet:

http://docs.openstack.org/developer/heat/template_guide/openstack.html#OS::Neutron::Subnet

OS::Neutron::Router:

http://docs.openstack.org/developer/heat/template_guide/openstack.html#OS::Neutron::Router

接下来开始部署LB了, 主要有下面个资源:

Pool:

VIP:

Floating IP for VIP

HealthMonitor:

2 Pool Member instances (内部运行简单的web server):

根据以上信息设计LB模板如下:

heat_template_version: 2013-05-23

 

description: >

    LB service deployment HOT template reference to

    http://www.ustack.com/blog/neutron_loadbalance/

 

parameters:

    image_name:

        type: string   

        label: Image Name

        description: Image to be used for compute instance

        default: cirros-0.3.0-i386-uec

    instance_type:

        type: string

        label: Instance Type

        description: Type of instance (flavor) to be used

        default: m1.tiny

    health_monitor_type:

        type: string

        label: Type of HealthMonitor

        constraints:

            - allowed_values: [PING, TCP, HTTP, HTTPS]

        default: HTTP

    pool_name:

        type: string

        label: The Name of Pool

        default: pool

    lb_method:

        type: string

        label: The Algorithm used to distribute load between the memebers of pool

        constraints:

            - allowed_values: [ROUND_ROBIN, LEAST_CONNECTIONS, SOURCE_IP]

        default: ROUND_ROBIN

    pool_protocol:

        type: string

        label: Protocol for Pool Balancing

        constraints:

            - allowed_values: [HTTP, HTTPS, TCP]

        default: HTTP

    lb_subnet_id:

        type: string

        label: Loadbalancer Subnet uuid

    vip_name:

        type: string

        label: Name of VIP

        default: vip

    vip_address:

        type: string

        label: Address of VIP which must be within lb_subnet

    session_persistence_type:

        type: string

        label: Session Persistence Type

        constraints:

            - allowed_values: [SOURCE_IP, HTTP_COOKIE, APP_COOKIE]

        default: HTTP_COOKIE

    vip_protocol_port:

        type: number

        label: VIP protocol port

        default: 8080

    member_protocol_port:

        type: number

        label: Member protocol port

        default: 8080

    public_net_id:

        type: string

        label: Public Network uuid

    server_net_id:

        type: string

        label: Web Servers Network uuid

 

 

outputs:

    vip_floating_ip:

        description: FloatingIP of VIP

        value: {get_attr: [floatingip, floating_ip_address]}

    member1_ip_address:

        description: IP address of member1

        value: {get_attr: [member1, first_address]}

    member2_ip_address:

        description: IP address of member2

        value: {get_attr: [member2, first_address]}

    vip:

        description: VIP info

        value: {get_attr: [pool, vip]}

    lb_keypair_private_key:

        description: private key of KeyPair for 'ssh-add use'

        value: {get_attr: [lb_keypair, private_key]}

    

 

resources:

    lb_keypair:

        type: OS::Nova::KeyPair

        properties:

            name: lb_keypair

            save_private_key: True

    health_monitor:

        type: OS::Neutron::HealthMonitor

        properties:

            delay: 10

            expected_codes: "200"

            http_method: GET

            max_retries: 3

            timeout: 20

            type: {get_param: health_monitor_type}

            url_path: /

    pool:

        type: OS::Neutron::Pool

        depends_on: health_monitor

        properties:

            admin_state_up: False

            name: {get_param: pool_name}

            lb_method: {get_param: lb_method}

            protocol: {get_param: pool_protocol}

            monitors: [{get_resource: health_monitor}]

            subnet_id: {get_param: lb_subnet_id}

            vip:

                session_persistence:

                    type: {get_param: session_persistence_type}

                name: {get_param: vip_name}

                address: {get_param: vip_address}

                protocol_port: {get_param: vip_protocol_port}

    member1:

        type: OS::Nova::Server

        properties:

            name: server1

            key_name: {get_resource: lb_keypair}

            image: {get_param: image_name}

            flavor: {get_param: instance_type}

            networks:

                - {network: {get_param: server_net_id}}

    member2:

        type: OS::Nova::Server

        properties:

            name: server2

            key_name: {get_resource: lb_keypair}

            image: {get_param: image_name}

            flavor: {get_param: instance_type}

            networks:

                - {network: {get_param: server_net_id}}

    pool_member1:

        type: OS::Neutron::PoolMember

        depends_on: [pool, member1]

        properties:

            address: {get_attr: [member1, first_address]}

            pool_id: {get_resource: pool}

            protocol_port: {get_param: member_protocol_port}

            weight: 100

    pool_member2:

        type: OS::Neutron::PoolMember

        depends_on: [pool, member2]

        properties:

            address: {get_attr: [member2, first_address]}

            pool_id: {get_resource: pool}

            protocol_port: {get_param: member_protocol_port}

            weight: 100

    floatingip:

        type: OS::Neutron::FloatingIP

        depends_on: pool

        properties:

            fixed_ip_address: {get_param: vip_address}

            floating_network_id: {get_param: public_net_id}

            port_id: {get_attr: [pool, vip, port_id]}

然后运行如下命令部署lb模板:

stack@vm:~/hot-files$  heat stack-create lbaas -f ./lbaas.template -P"public_net_id=842a7996-b8ca-4f75-8bfa-72d930780694;lb_subnet_id=f33b03a9-0f39-4c25-a9fa-94d63042f206;server_net_id=33c2e2db-121f-489e-bdc0-06d091472727;vip_address=192.168.40.3"

Note: 可能注意到了现在Poo的admin_state_up是False状态,这是由于LBaaS Haproxy的一个bug,如果不设置,会导致vip直接返回Error,导致Heat模板运行中断,所以暂时设置为False,等部署好后,再打开admin_state_up,打开后发现Member是INACTIVE状态的,因为现在member还没有开启web server,我用很多方法试图用String,template,以及get_file将user_data注入到VM中,但不知道为什么都失败了,所以你只能自己进到VM中启动一个简单的web服务器了,我的如下所示:

$ while true

> do

> echo -e 'HTTP/1.0 200 OK\r\n\r\n<serverX>' | nc -l -p 8080

> done

启动后就看到Member变为ACTIVE状态了。

拿到VIP的floatingIP,然后就可以测试LB的运行状态了,结果如下:


LB成功运行!

 

另外: Keypair的用法:你可以import a keypair,将你的操作console的public key引入,也可以像上面lb模板创建一个keypair,然后将lb_private_key保存到一个文件(lb_private_key.pem)中,然后给VM加一个floatingIP

#eval `ssh-agent`

#ssh-add lb_private_key.pem

然后你就可以通过ssh访问VM了,其他可以进noVNC界面对VM进行相关操作。

LB模板用到的resources有: OS::Nova::Server, OS::Nova::KeyPair, OS::Neutron::Pool, OS::Neutron::PoolMember, OS::Neutron::HealthMonitor, OS::Neutron::FloatingIP

VPNaaS模板

未完待续。。。

FWaaS模板

未完待续。。。

用到的不方便的地方

1.      Template查错功能有待提高,阐释不清楚或者错误张冠李戴

2.      没有类似于action-continue –force的功能,比如LBaaS创建的VIP状态返回error是由于haproxy内部的一个bug,这类人类可控的错误希望能够just 忽略掉然后继续运行。

3.      不知道为什么,用heat一直不能把user_data注入VM中

Link

[1] Heat Wiki:https://wiki.openstack.org/wiki/Heat

[2] OpenStack G 版孵化项目heat介绍:http://blog.csdn.net/wangyish201201/article/details/8933581

[3] OpenStack Heat进阶:http://blog.csdn.net/lynn_kong/article/details/17195047

[4] OpenStack heat getting started guides: http://docs.openstack.org/developer/heat/getting_started/index.html

介绍安装heat的几种方法以及如何构建JEOS镜像(os with heat-cfntools package)

[5] *Heat 开发者文档:http://docs.openstack.org/developer/heat/

[6] Heat 术语表:http://docs.openstack.org/developer/heat/glossary.html

[7] *template Guide: http://docs.openstack.org/developer/heat/template_guide/index.html

[8] HOT template Guide: http://docs.openstack.org/developer/heat/template_guide/hot_guide.html

[9] *HOT template spec in detail: http://docs.openstack.org/developer/heat/template_guide/hot_spec.html

[10] Yaml: http://www.ibm.com/developerworks/cn/xml/x-1103linrr/

[11] My first OpenStack heat template: http://openstack.prov12n.com/my-first-openstack-heat-template/

[12] 龚永生:Neutron防火墙:http://www.ustack.com/blog/neutron-firewall/

[13] 龚永生: Neutron负载均衡:http://www.ustack.com/blog/neutron_loadbalance/

[14] CirrOS: https://www.eucalyptus.com/blog/2014/02/02/cirros-perfect-machine-image-eucalyptus-cloud-debugging

相关内容

    暂无相关文章