Heat Providers

来源:互联网 发布:濮阳市智慧网络 编辑:程序博客网 时间:2024/05/15 02:19

Providers are an extension to our existing internal model, which allows user-definable "resource providers" to be specified via templates.

1. Register “Resource Providers”

For example, use Global Environment to register resource "My::WP::Server":

root@test725:~# cat /etc/heat/environment.d/default.yaml resource_registry:    # allow older templates with Quantum in them.    "OS::Quantum*": "OS::Neutron*"    # Choose your implementation of AWS::CloudWatch::Alarm    #"AWS::CloudWatch::Alarm": "file:///etc/heat/templates/AWS_CloudWatch_Alarm.yaml"    "AWS::CloudWatch::Alarm": "OS::Heat::CWLiteAlarm"    "OS::Metering::Alarm": "OS::Ceilometer::Alarm"    "AWS::RDS::DBInstance": ”file:///etc/heat/templates/AWS_RDS_DBInstance.yaml”    "My::WP::Server": "file:///etc/heat/templates/server.yaml"

Please note that the template resource URL here must end with ”.yaml” or ”.template”, or it will not be treated as a custom template resource.

Here, /etc/heat/templates/server.yaml is customizable template defined by yourself:

heat_template_version: 2013-05-23description: Test Templateparameters:  image:    default: 7a3dcd55-b793-4523-9da9-231433902020     type: string    description: Image use to boot a server  net:    default: e8542140-27cb-4474-8bd1-c726413b20c8     type: string    description: Network ID for the server  flavor:    default: m1.small     type: string    description: Flavor use to boot a server      key_name:    default: demo-key     type: string    description: keypair name use to boot a serverresources:  init:    type: OS::Heat::SoftwareConfig    properties:      group: script       inputs:      - name: welcome_msg       config: |        #!/bin/bash        echo $welcome_msg > ~/welcome.txt  deployment:    type: OS::Heat::SoftwareDeployment    properties:      config:        get_resource: init       server:        get_resource: server      input_values:        welcome_msg: "Hello, world"  server:    type: OS::Nova::Server    properties:      image: {get_param: image}      networks:      - uuid: {get_param: net}      flavor: {get_param: flavor}       key_name: {get_param: key_name}      user_data_format: SOFTWARE_CONFIG outputs:  server_private_ip:    description: IP address of the server in the private network    value: { get_attr: [ server, first_address ] }

Now, restart service heat-engine, you can find similar messages in /var/log/heat/heat-engine.log:

INFO heat.engine.environment [-] Registering My::WP::Server -> file:///etc/heat/templates/server.yaml

And you can verify it by this:

root@test725:~# heat resource-type-list | grep My::WP::Server| My::WP::Server  |


2. Create Stack with providers resource

heat stack-create -f resource_group.yml stack55

Here resource_group.yml is like this, and server_private_ip is the output in server.yaml:

heat_template_version: 2013-05-23description: Test Resource Group Templateresources:  servers:    type: OS::Heat::ResourceGroup    properties:      count: 2      resource_def:        type: My::WP::Server outputs:  server_resources:    description: The actual server details    value: { get_attr: [servers, refs]}  server_0_private_ip:    description: private ip of server 0    value: { get_attr: [servers, resource.0.server_private_ip]}  server_1_private_ip:    description: private ip of server 1    value: { get_attr: [servers, resource.1.server_private_ip]}

Also, you can verify it:


In addition, you can get the nested stack details:




3. References

https://wiki.openstack.org/wiki/Heat/Providers
http://hardysteven.blogspot.com/2013/10/heat-providersenvironments-101-ive.html
http://hardysteven.blogspot.com/2013/08/heat-nested-resource-introspection.html
http://docs.openstack.org/developer/heat/template_guide/environment.html

http://docs.openstack.org/developer/heat/template_guide/openstack.html

0 0
原创粉丝点击