diff --git a/tile_generator/config.py b/tile_generator/config.py index 776a3396..daaf85ab 100644 --- a/tile_generator/config.py +++ b/tile_generator/config.py @@ -376,7 +376,8 @@ def build_job_manifest(self, job): 'pks_password': '(( ..pivotal-container-service.properties.pks_basic_auth.password ))', }) merge_dict(manifest, job['properties']) - for property in self.get('all_properties', []): + all_properties = self.get('all_properties', []) + for property in [p for p in all_properties if 'job' not in p]: merge_dict(manifest, template.render_property(property)) for service_plan_form in self.get('service_plan_forms', []): manifest[service_plan_form['name']] = '(( .properties.{}.value ))'.format(service_plan_form['name']) diff --git a/tile_generator/template.py b/tile_generator/template.py index 5cb52da4..0c18ce9f 100644 --- a/tile_generator/template.py +++ b/tile_generator/template.py @@ -69,6 +69,7 @@ def render_yaml(input): def multiline_representer(dumper, data): return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|" if "\n" in data else None) yaml.SafeDumper.add_representer(str, multiline_representer) + yaml.SafeDumper.ignore_aliases = lambda *args : True return yaml.safe_dump(input, default_flow_style=False, width=float("inf")) def render_yaml_literal(input): diff --git a/tile_generator/tile_metadata.py b/tile_generator/tile_metadata.py index 5fc09587..e6054485 100644 --- a/tile_generator/tile_metadata.py +++ b/tile_generator/tile_metadata.py @@ -1,4 +1,5 @@ import yaml +import copy from . import template as template_helper @@ -172,8 +173,9 @@ def _build_property_blueprints(self): # Custom properties from the tile.yml file # for prop in self.config['all_properties']: - prop = template_helper.expand_selector(prop) - self.tile_metadata['property_blueprints'] += [prop] + if 'job' not in prop: + prop = template_helper.expand_selector(prop) + self.tile_metadata['property_blueprints'] += [prop] def _build_form_types(self): form_types = list() @@ -191,7 +193,7 @@ def _build_form_types(self): custom_form["property_inputs"] = list() for prop in form.get('properties', []): prop_input = { - "reference": ".properties." + prop['name'], + "reference": "." + prop.get('job', "properties") + "." + prop['name'], "label": prop['label'], "description": prop.get('description') or prop.get('label') } @@ -384,6 +386,26 @@ def _build_job_types(self): job_types.append(compilation_job) + prop_blueprints = [{'default': {'identity': 'vcap'}, + 'name': 'vm_credentials', + 'type': 'salted_credentials'}] + + # Grab all job specific property blueprints + job_specific_prop_blueprints = [prop for prop in self.config['all_properties'] if 'job' in prop] + for prop in job_specific_prop_blueprints: + keys = list(prop.keys()) + for k in keys: + # Remove any keys not specified here https://docs.pivotal.io/tiledev/2-2/property-reference.html#common-attributes + # but keep `job` key because it is needed for matching + if k not in ['job', 'name', 'type', 'optional', 'configurable', 'freeze_on_deploy']: prop.pop(k) + + def match_job_specific_prop_blueprints(job_name, prop_blueprints): + for prop in job_specific_prop_blueprints: + if prop['job'] == job_name: + tmp_prop = dict(prop) + tmp_prop.pop('job') + prop_blueprints.append(tmp_prop) + # # {{ job.template }} job for {{ job.package.name }} @@ -432,17 +454,10 @@ def _build_job_types(self): 'name': 'route_registrar', 'release': 'routing'} ], - 'property_blueprints': [ - { - 'default': {'identity': 'vcap'}, - 'name': 'vm_credentials', - 'type': 'salted_credentials'}, - { - 'name': 'app_credentials', - 'type': 'salted_credentials' - } - ] + 'property_blueprints': prop_blueprints + [{'name': 'app_credentials', + 'type': 'salted_credentials'}] } + match_job_specific_prop_blueprints(release_job['name'], release_job['property_blueprints']) release_job['manifest'] = dict() release_job['manifest'].update(job.get('manifest', {})) @@ -461,8 +476,9 @@ def _build_job_types(self): release_job_manifest['route_registrar'] = routes for prop in self.config.get('all_properties'): - prop = template_helper.render_property(prop) - release_job_manifest.update(prop) + if 'job' not in prop: + prop = template_helper.render_property(prop) + release_job_manifest.update(prop) for service_plan_form in self.config.get('service_plan_forms', []): form_name = service_plan_form.get('name') @@ -497,10 +513,10 @@ def _build_job_types(self): release_job['manifest'] = literal_unicode(template_helper.render_yaml(release_job_manifest)) instance_def = { - 'configurable': True, - 'default': job.get('instances', 1), - 'name': 'instances', - 'type': 'integer' + 'configurable': True, + 'default': job.get('instances', 1), + 'name': 'instances', + 'type': 'integer' } if self.config['metadata_version'] < 1.7: release_job['instance_definitions'] = [instance_def] @@ -518,13 +534,11 @@ def _build_job_types(self): 'max_in_flight': job.get('max_in_flight', 1), 'single_az_only': job.get('single_az_only', True if job.get('lifecycle') == 'errand' else False), 'static_ip': job.get('static_ip', 0), - 'property_blueprints': [{ - 'default': {'identity': 'vcap'}, - 'name': 'vm_credentials', - 'type': 'salted_credentials' - }], + 'property_blueprints': copy.copy(prop_blueprints), 'manifest': literal_unicode(template_helper.render_yaml(job.get('manifest'))), } + match_job_specific_prop_blueprints(bosh_release_job['name'], bosh_release_job['property_blueprints']) + if job.get('lifecycle') == 'errand': bosh_release_job['errand'] = True if job.get('run_post_deploy_errand_default'): @@ -637,18 +651,12 @@ def _build_job_types(self): "dynamic_ip": 1, "max_in_flight": 1, "single_az_only": True, - "property_blueprints": [{ - "default": {"identity": "vcap"}, - "type": "salted_credentials", - "name": "vm_credentials" - }, - { - "type": "salted_credentials", - "name": "app_credentials" - } - ], + "property_blueprints": prop_blueprints + [{"type": "salted_credentials", + "name": "app_credentials"}], "manifest": literal_unicode(template_helper.render_yaml(job.get('manifest'))) } + match_job_specific_prop_blueprints(job_type['name'], job_type['property_blueprints']) + if job['name'] == 'deploy-all' or job['name'] == 'delete-all': job_type['templates'].append({ "release": 'cf-cli',