2016-01-19 54 views
1

这是我的模板。我使用该模板执行'heat stack-create'命令,并使用ip创建堆栈和实例。我有权访问一个界面来管理我的实例。从该界面,我可以创建一个浮动IP,然后将其分配给我新创建的实例。使用加热模板将浮动IP分配给OpenStack实例

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分配给另一个现有资源(服务器)。我怎样才能使协会工作?

回答

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 } 
1

使用FloatingIPAssociation资源。例如:

association: 
    type: OS::Neutron::FloatingIPAssociation 
    properties: 
     floatingip_id: { get_param: floatingIpId } 
     port_id: { get_param: port_id } 

association: 
    type: OS::Nova::FloatingIPAssociation 
    properties: 
     floating_ip: { get_param: floatingIpId } 
     server_id: { get_resource: instance } 

与NeutronFloatingAssociation其它示例

相关问题