Skip to content

Commit 3195e84

Browse files
author
Carlos Konstanski
committed
Create servicedependency objects based on tags
When a resource has a tag with the form 'parent:', create a servicedependency object. Issue: CIRRUS-4265
1 parent 54beac6 commit 3195e84

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

puppetdb_stencil.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525

2626

2727
def is_resource_visible(resource, localsite):
28-
return resource.exported and
29-
(('only-cross-site' not in resource.tags and 'no-cross-site' not in resource.tags) or
28+
return resource.exported and (
29+
('only-cross-site' not in resource.tags and 'no-cross-site' not in resource.tags) or
3030
('only-cross-site' in resource.tags and 'no-cross-site' not in resource.tags and localsite == 'false') or
31-
('only-cross-site' not in resource.tags and 'no-cross-site' in resource.tags and localsite == 'true'))
31+
('only-cross-site' not in resource.tags and 'no-cross-site' in resource.tags and localsite == 'true')
32+
)
3233

3334

3435
def render_resources(database, resource_type, localsite, template_names):
@@ -70,7 +71,7 @@ def render_resources(database, resource_type, localsite, template_names):
7071
nameparts = name.split('_')
7172
if nameparts[0].lower() == object_name and name not in envs_to_ignore:
7273
dto['parameters'].append({'_'.join(nameparts[1:]).lower(): os.environ[name].lower()})
73-
icinga_config += template.render(dto=dto) + '\n'
74+
icinga_config += template.render(dto=dto)
7475
# collect child service dependencies under parent service_description
7576
for tag in resource.tags:
7677
if 'parent:' in tag:
@@ -86,7 +87,7 @@ def render_resources(database, resource_type, localsite, template_names):
8687
parent_service_description = item.replace('_', ' ')
8788
# lookup parent resource by its service_description
8889
for parent in resources:
89-
if is_resource_visible(resource, localsite):
90+
if is_resource_visible(parent, localsite):
9091
for key, value in parent.parameters.items():
9192
if key == 'service_description' and parent_service_description in value.lower():
9293
for child in service_dependencies[item]:
@@ -98,7 +99,7 @@ def render_resources(database, resource_type, localsite, template_names):
9899
'dependent_host_name': child.parameters['host_name'],
99100
'dependent_service_description': child.parameters['service_description']
100101
}]
101-
icinga_config += template.render(dto=dto) + '\n'
102+
icinga_config += template.render(dto=dto)
102103
return icinga_config
103104

104105

0 commit comments

Comments
 (0)