Ask Your Question
0

How to read attributes of existing keypair in Heat template

asked 2015-03-04 03:51:06 -0500

hartapani gravatar image

updated 2015-03-04 05:13:36 -0500

cli:

[root@localhost ~(keystone_admin)]# nova keypair-list
+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| ssh_key | 8c:f1:b1:ab:c1:5f:6e:86:45:e1:35:2a:20:fc:34:d1 |
+-------+-------------------------------------------------+

yaml:

...
  server1:
    type: OS::Nova::Server
    properties:
      name: abc1
      image: { get_param: image }
      flavor: { get_param: flavor }
      key_name: { get_param: key_name }
      networks:
        - port: { get_resource: server1_port1 }
      user_data:
        str_replace:
          template: |
            ssh-key:$ssh_keys
      params:
        $ssh_key:                { get_attr: [ssh_key, public_key] }

Is it possible to "get_attr" from resource which is not defined in same yaml? Above example is not working. (Nova keypair is not defined in the yaml. Keypair created from cli before stack creation, nova keypair-add...)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-02-12 10:33:37 -0500

spartacle gravatar image

updated 2017-02-12 10:37:03 -0500

I know this a quite old but when searching google for heat template existing keypair this question is the top result, so hopefully this answer will help some people out.

This is my existing key

 ~ > supernova mynova keypair-list
[SUPERNOVA] Running nova against mynova...
+----------+-------------------------------------------------+
| Name     | Fingerprint                                     |
+----------+-------------------------------------------------+
| Public01 | 1a:f7:c0:be:00:f0:eb:7f:90:61:cc:7c:4d:1c:b9:79 |
+----------+-------------------------------------------------+

In the template I set a parameter called this 'KeyName' and set a custom constraint to ensure that this resource exists in the backend, the rest is the optional and makes it look good in the control panel

parameters:
   KeyName:
    type: string
    default: Public01
    description: Name of an existing key pair to use for the instance
    constraints:
      - custom_constraint: nova.keypair
        description: Must name a public key (pair) known to Nova

Then simply retrieve the parameter when creating the server as you would any other parameter.

resources:  
server:
    type: "OS::Nova::Server"
    properties:
      name: { get_param: "OS::stack_name" }
      flavor: { get_param: server_flavor }
      image: { get_param: server_image }
      key_name: { get_param: KeyName }
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

2 followers

Stats

Asked: 2015-03-04 03:51:06 -0500

Seen: 1,371 times

Last updated: Feb 12 '17