Openstack Heat - separate templates - openstack

I am looking for the best way of creating a stack, in a number of separate steps.
I would like in the first template, to only get up the compute nodes and the network configuration.
In the second template, I would like to create the storage nodes and attach them to the already existing compute nodes.
What do you think is the best way to do this?

Following is one possible approach.
1) Define first template for your compute nodes and network configuration. But define outputs in your first template to expose your compute node IDs. For example, if you create a OS::Nova::Server with name mynode1, you can expose its ID as the output for that template as follows:
outputs:
mynode1_id:
description: ID of mynode1
value: {getattr: [mynode1, id]}
Once you instantiate a heat stack, say mystack1, with this first template, then you can access the ID of mynode1 as follows:
heat output-show mystack1 mynode1_id
2) Create your second template for storage with IDs of your compute nodes from step1 as input parameters. For example:
parameters:
mynode1_id:
type: string
description: ID for mynode1
Then you can use that in your "resources:" section as follows:
resources:
...
...
my_volume_attach:
type: OS::Cinder::VolumeAttachment
properties:
instance_uuid: {get_param: mynode1_id}
...
3) Invoke your second heat stack creation as follows:
heat stack-create -f second-template.yaml -P mynode1_id=`heat output-show mystack1 mynode1_id` mystack2

You might also want to define dependencies between your resources, using the depends_on attribute.
From your description it doesn't seem like using several templates is the correct solution.
for example - if you want objects 3,4 created after objects 1,2, you can define a template as follows:
heat_template_version: '2015-10-15'
parameters:
param1:
type: string
description: just an example of parameter
resources:
object1:
type: OS::Neutron::XXX
properties:
property: XXX
description: object1
object2:
type: OS::Neutron::XXX
properties:
property: XXX
description: object2
object3:
type: OS::Nova::XXX
properties:
property: XXX
description: object3
depends_on: object1
object4:
type: OS::Nova::XXX
properties:
property: XXX
description: object4
depends_on: object1

Related

Avoid Symfony to override parameters between bundles

I'm using YML parameters inside each bundle to use them as data fixtures as follows:
AppBundle\Resources\config\datafixtures.yml
parameters:
datafixtures:
defaultusers:
0:
name: john
email: john#company1.lol
1:
name: steve
email: steve#company1.lol
GeolocationBundle\Resources\config\datafixtures.yml
parameters:
datafixtures:
cities:
0:
external_service_area: Cantabria
company_area: Santander
1:
external_service_area: Gipuzkoa
company_area: San Sebastian
The problem comes when I import the files in the app config.yml file.
imports:
- { resource: '#AppBundle/Resources/config/datafixtures.yml' }
- { resource: '#GeolocationBundle/Resources/config/datafixtures.yml' }
Instead of merging the trees, it overrides them. Is there a way to make them merge?
Bassically the tree form makes them override each other, so the best way to avoid it is to define each node with a single complete name:
AppBundle\Resources\config\datafixtures.yml
parameters:
datafixtures.defaultusers:
GeolocationBundle\Resources\config\datafixtures.yml
parameters:
datafixtures.cities:

How to dynamically change autoscaling instance names

I have created a heat stack which autoscales depending on CPU use. Each time a new instance is created, it is given a random name.
Is there a way to set a specific name with a counter added to the end of it so that each time a new instance is created it increases by 1?
E.g. Myinstance1, Myinstance2, Myinstance3 ... MyinstanceX
Thanks in advance!
In Openstack HEAT, stack resource names are manipulated with stack_name and suffixed with a short_id. That's why on every autoscaled up instance you could see the instance name as such. This is how the implementation done in overall HEAT project and it is not possible to define instance name suffixed with incremental number.
if i understood you correctly, and if you are Object Oriented Programing:
you are looking for a design pattern called Factory, or more simply, create a static member that will increase in the constructor, and will be added to the name member of the instance created.
You can set the custom names by going to your Auto Scaling Groups and Tags tab, and then adding a tag with the key of "Name" and the value of "MyInstance". Numbering does not make that much sense since your instances are going to be launched and terminated constantly.
Update at 21/09/2020 :
Seems that creating an incremental number is impossible so far, but I found a workaround to achieve my goal, so post here hoping that could give you some ideas.
Mindset:
I tried to find something (which is number) that is created dynamically with the instance for scaling up, to me that is OS::Neutron::Port, so I append one part of IP address after a string to get a distinctive name for each instance.
Solution:
1.Create a port OS::Neutron::Port.
2.Get IP address using get_attr.
3.Split it with dot as delimiter using str_split.
4.Append one part of the address to the string using str_replace.
Sample Code:
lb_server.yaml
resources:
corey_port:
type: OS::Neutron::Port
properties:
network: { get_param: network }
fixed_ips:
- subnet: { get_param: subnet }
number:
type: OS::Heat::Value
properties:
value:
# 192.168.xxx.yyy => [192,168,xxx,yyy]
str_split: ['.', { get_attr: [corey_port, fixed_ips, 0, ip_address] }]
server:
type: OS::Nova::Server
properties:
name:
str_replace:
template: Corey-%last%
params:
# 0 1 2 3
#[192,168,xxx,yyy]
"last%": { get_attr: [number, value, 3] }
flavor: { get_param: flavor }
......
The outcome shoud be Corey-168, Corey-50, Corey-254, etc.

Custom names for resources in cluster created using HEAT templates in Openstack

I am trying to create a cluster using Heat Templates of Openstack. I have following template defining my resource group.
cluster:
type: OS::Heat::ResourceGroup
properties:
count: { get_param: instance_count }
resource_def:
type: ../templates/vm.yaml
properties:
image: { get_param: image }
flavor: { get_param: flavor }
private_network : { get_attr : [network, name] }
This works, but the name of all these servers is very cryptic. I was wondering if it would be possible to provide a prefix to name to each of the instances.
Or another way could be is I can str_replace a template value with the current index of the cluster count.
Is there a way to achieve this?
Nevermind, got it from the ResourceGroup documentation. Use %index%.
Here is the example from the documentation.
resources:
my_indexed_group:
type: OS::Heat::ResourceGroup
properties:
count: 3
resource_def:
type: OS::Nova::Server
properties:
# create a unique name for each server
# using its index in the group
name: my_server_%index%
image: CentOS 6.5
flavor: 4GB Performance

How can I populate a heat template in OpenStack with `user_data` without including the script inline?

I.e. I want my template to look something like:
...
resources:
server1:
type: OS::Nova::Server
properties:
name: Server1
image: { get_param: image }
flavor: { get_param: flavor }
user_data: ?????
...
and I want the contents of user_data to be stored in a separate file.
How can I accomplish this?
I believe that's what get_file is for. From the doc:
The example below demonstrates get_file usage with both relative and
absolute URLs.
resources:
my_instance:
type: OS::Nova::Server
properties:
# general properties ...
user_data:
get_file: my_instance_user_data.sh
my_other_instance:
type: OS::Nova::Server
properties:
# general properties ...
user_data:
get_file: http://example.com/my_other_instance_user_data.sh
If this template was launched from a local file this would result in a
files dictionary containing entries with keys
file:///path/to/my_instance_user_data.sh and
http://example.com/my_other_instance_user_data.sh.

Symfony 2 with Doctrine 2 Single Table Inheritance

In my project based on Symfony 2 + Doctrine 2 I implement model with following approach (based on FOSUserBundle source code):
All classes which belong to model are in "Model" folder of my bundle
In "Entity" folder I have classes which extend classes from Model
In "Resources/config/doctrine/" I have files with mappings in YAML format
Important: Classes for persistance (Entities) for which I want STI extend respective classes from Model, not from Entity.
The problem:
#Resources/config/doctrine/ContentElement.orm.yml
My\CoreBundle\Entity\ContentElement:
type: entity
table: content_element
inheritanceType: SINGLE_TABLE
discriminatorColumn:
name: discr
type: string
length: 255
discriminatorMap:
contentElement: ContentElementList
htmlContentElement: HtmlContentElement
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
anchor_id:
type: string
anchor_text:
type: string
#Resources/config/doctrine/HtmlContentElement.orm.yml
My\CoreBundle\Entity\HtmlContentElement:
type: entity
fields:
html:
type: text
When I try to update database I've got errors from YAML driver until I specify additionally 'id' (which should be inherited as I thought)
After adding mapping for id I have sql queries in which I see 2 separate tables for each entity.
I suspect that this happens because HtmlContentElement extends Model\HtmlContentElement but not Entity\ContentElement.
Am I right and is there known solution to my problem?

Resources