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:
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.
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
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.
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?