[Openstack] [Heat] Customize server names in AutoScalingGroup

Phil Clay pilf_b at yahoo.com
Mon Apr 10 18:15:55 UTC 2017


Hi,
I want to customize the names of the OS::Nova::Server resources that are part of a OS::Heat::AutoScalingGroup resource.
Ideally, I want to use something like:
    <prefix>-<uniqueId>

If I do not specify the name, then the name will default to this pattern:
    <stackName>-<serverResourceName>-<serverResourceShortId>
I could, in theory, get close to what I want by just customizing the stackName.  However, in reality, the stackname to which the server belongs will be super long, because the AutoScalingGroup creates nested stacks.  So for example, if my top level stack name is myawesomestack, the server will belong to a nested stack whose name is something like:
    myawesomestack-asg-lcu5abqafob2-q2lhhye4iux5-kezgqb5ub5k4
Then, the servers will be created with a name that looks like this  (note the stackname is shortened by using the first two characters, and the last X digits to keep it under a certain length):
    my-fob2-bods7udv2y6o-mowdcx2ewaiz-server-f4quplsegdiw



Therefore, the default naming pattern does not meet my needs.

In order to get the pattern I want, I must figure out what to specify for the name value.  I tried a few things...
A) First, I just tried a static name, hoping that Heat would auto-append something.  Unfortunately, Heat doesn't do that, and all the servers end up with the same name.  This does not work for me.
B) Then, I tried using a OS::Heat::RandomString to generate a unique suffix like this:
  server_name_suffix:    type: OS::Heat::RandomString    properties:      character_classes:        - class: lowercase        - class: digits        server:    type: OS::Nova::Server    properties:      name:        str_replace:          template: $prefix-$suffix          params:            $prefix: {get_param: name_prefix}            $suffix: {get_resource: server_name_suffix}
This results in the servers having unique names that follow the pattern I want.  However, when I perform a rolling update by changing something on the server (e.g. user_data or something), the RandomString resources do NOT change.  Therefore the "new" servers will end up with the same name as the "old" servers.  This doesn't work for me either.  New servers should have a new name.  This is not just a preference thing, since the LBaaS provider I'm using complained about servers with the same name, so it really just doesn't work for me.
C) Then, I tried to incorporate the server's resource id into the name like this:
  server:    type: OS::Nova::Server    properties:      name:        str_replace:          template: $prefix-$suffix          params:            $prefix: {get_param: name_prefix}            $suffix: {get_resource: server}
I didn't expect this to work, but I tried it anyway.  I was right, Heat complains about a circular reference.

I haven't found any other way to get the naming pattern that I would like.
So here are my questions:
1) Has anybody figured out how to get server names to use a simple pattern  (<prefix>-<uniqueId>) ?
2) Is it possible to get a RandomString to update when the server updates within an AutoScalingGroup?  This would allow #B to work.
3) Is it possible to get/use the id of the resource from within itself?  This would allow #C to work.  The shortId (https://github.com/openstack/heat/blob/master/heat/common/short_id.py#L41-L58) would be even better.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack/attachments/20170410/d5f78db0/attachment.html>


More information about the Openstack mailing list