Openstack:使每个实例的网络端口都唯一OS :: Heat :: ResourceGroup COUNT

时间:2019-03-03 19:01:00

标签: openstack openstack-heat

问题是,count大于1时将无法建立堆栈。
这样做的原因是因为- port: { get_resource: test_port }并不是每个实例都唯一。

收到的错误代码: CREATE_FAILED冲突:resources.compute_nodes.resources [3]:端口XXX仍在使用中。

问题:如何使每个实例的- port: { get_resource: test_port }唯一?

  compute_nodes:
      type: OS::Heat::ResourceGroup
      properties:
        count: 3
        resource_def:
           type: OS::Nova::Server
           properties:
             name: test-%index%
             key_name: { get_param: key_name }
             image: "Ubuntu Server 18.04 LTS (Bionic Beaver) amd64"
             flavor: m1.small
             networks:
               - port: { get_resource: test_port }


 test_port:
    type: OS::Neutron::Port
    properties:
      network_id: { get_resource: private_net }
      security_groups: { get_param: sec_group_lin }
      fixed_ips:
        - subnet_id: { get_resource: private_subnet }

  test_floating_ip:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network: { get_param: public_net }
      port_id: { get_resource: test_port }

Iterate comma_delimited_list OS::Heat::ResourceGroup

2 个答案:

答案 0 :(得分:0)

利用“ depends_on ”调整模板的执行流程

 compute_nodes:
  type: OS::Heat::ResourceGroup
  depends_on: [test_port, test_floating_ip]
  properties:
    count: 3
    resource_def:
       type: OS::Nova::Server
       properties:
         name: test-%index%
         key_name: { get_param: key_name }
         image: "Ubuntu Server 18.04 LTS (Bionic Beaver) amd64"
         flavor: m1.small
         networks:
           - port: { get_resource: test_port }


test_port:
  type: OS::Neutron::Port
  properties:
    network_id: { get_resource: private_net }
    security_groups: { get_param: sec_group_lin }
    fixed_ips:
      - subnet_id: { get_resource: private_subnet }

test_floating_ip:
  type: OS::Neutron::FloatingIP
  depends_on: [test_port]
  properties:
    floating_network: { get_param: public_net }
    port_id: { get_resource: test_port }

答案 1 :(得分:0)

您的堆栈尝试将同一端口连接到其他Nova服务器,因此失败。 解决方案是创建一个嵌套堆栈,该堆栈将创建您的3种资源(Nova服务器,Neutron端口和Neutron浮动IP),然后您的主堆栈将实现一个资源组来“扩展”您的服务器:

嵌套堆栈:nested_stack.yaml

parameter:
  index:
    type: number

  sec_group_lin:
    type: string

  key_name:
    type: string

  public_net:
    type: string


resources:

  compute_nodes:
    type: OS::Nova::Server
    depends_on: [test_port, test_floating_ip]
    properties:
      name: { list-join: ['-', ['test', {get_param: index} ] ] }
      key_name: { get_param: key_name }
      image: "Ubuntu Server 18.04 LTS (Bionic Beaver) amd64"
      flavor: m1.small
      networks:
        - port: { get_resource: test_port }

  test_port:
    type: OS::Neutron::Port
    properties:
      network_id: { get_resource: private_net }
      security_groups: { get_param: sec_group_lin }
      fixed_ips:
        - subnet_id: { get_resource: private_subnet }

test_floating_ip:
  type: OS::Neutron::FloatingIP
  depends_on: [test_port]
  properties:
    floating_network: { get_param: public_net }
    port_id: { get_resource: test_port }

然后您的主堆栈如下:

parameters:

  key_name:
    type: string
  public_net:
    type: string
  sec_group_lin:
    type: string

resources:
 compute_nodes:
  type: OS::Heat::ResourceGroup
  properties:
    count: 3
    resource_def:
       type: nested_stack.yaml
       properties:
         index: %index%
         key_name: {get_param: key_name}
         public_net: { get_param: public_net }
         sec_group_lin: { get_param: sec_group_lin }

这将创建x个服务器(这里的x = 3,因为您的计数设置为3),每个服务器都有自己的测试端口和测试浮动IP。