这是我的模板。我用该模板执行'heat stack-create'命令,它创建一个堆栈和一个带有ip的实例。我可以访问一个界面来管理我的实例。从该界面,我可以创建一个浮动IP,然后将其分配给我新创建的实例。
heat_template_version: 2013-05-23
description: >
Docker generic server
parameters:
image_id: {default: centos-7, description: image, type: string}
instance_type: {default: ug1.medium, description: instance, type: string}
key_name: {default: user, description: Name of an existing key pair to use for the instance, type: string}
resources:
nginx_securitygroup:
properties:
GroupDescription: Generic security group for nginx stack
SecurityGroupIngress:
- {CidrIp: 10.0.0.0/8, FromPort: '80', IpProtocol: TCP, ToPort: '80'}
type: AWS::EC2::SecurityGroup
server_securitygroup:
type: AWS::EC2::SecurityGroup
properties:
GroupDescription: Generic security group from docker nginx
SecurityGroupIngress:
# This is needed to allow pinging the server
- {"CidrIp": "10.0.0.0/8", "FromPort": "-1", "ToPort": "-1", "IpProtocol": "ICMP"}
# Ssh port
- {"CidrIp": "10.0.0.0/8", "FromPort": "22", "ToPort": "22", "IpProtocol": "TCP"}
# Open docker ports
- {"CidrIp": "10.0.0.0/8", "FromPort": "2375", "ToPort": "2375", "IpProtocol": "TCP"}
- {"CidrIp": "10.0.0.0/8", "FromPort": "2376", "ToPort": "2376", "IpProtocol": "TCP"}
docker_server:
type: AWS::EC2::Instance
properties:
ImageId: { get_param: image_id }
InstanceType: { get_param: instance_type }
KeyName: { get_param: key_name }
SecurityGroups:
- Ref: server_securitygroup
- {Ref: nginx_securitygroup}
UserData: |
#!/bin/bash -v
#Do some operations to start the docker container on the instance
outputs:
ipaddress_private:
description: Private ip
value:
"Fn::GetAtt":
- docker_server
- PrivateIp
我的问题是我不想手动将我创建的浮动IP分配给实例,我希望在创建堆栈和实例时自动分配它。我尝试了一些文档,例如:http://blog.oddbit.com/2013/12/06/an-introduction-to-openstack-heat/
但它不起作用。也许是因为它试图将浮动IP分配给另一个现有资源(服务器)。如何使关联工作?
答案 0 :(得分:2)
使用FloatingIPAssociation资源。示例:
association:
type: OS::Nova::FloatingIPAssociation
properties:
floating_ip: { get_param: floatingIpId }
server_id: { get_resource: instance }
NeutronFloatingAssociation的其他例子:
association:
type: OS::Neutron::FloatingIPAssociation
properties:
floatingip_id: { get_param: floatingIpId }
port_id: { get_param: port_id }
答案 1 :(得分:1)
好的,通过反复试验,我发现了该怎么做......
在'参数'部分,添加:
ip_address : {default: x.x.x.x, description : Floating IP address to be associated to the instance, type : string}
在'资源'部分:
IPAssoc :
type : AWS::EC2::EIPAssociation
properties :
InstanceId : { get_resource: docker_server }
EIP : { get_param : ip_address }