def transform(line): def _jsonify_literals(parts): for part, is_ref in parts: if is_ref: yield part else: yield json.dumps(part) return ', '.join(_jsonify_literals(split_by_token('{ ', ' }', line))) + ', "\\n",\n'
def render_late_content(content, late_values): def _dereference_placeholders(parts): for part, is_placeholder in parts: if is_placeholder: if part not in late_values: log.debug('Found placeholder for unknown value "{}" in late config: {}'.format(part, repr(content))) raise Exception('Bad late config file: Found placeholder for unknown value "{}"'.format(part)) yield late_values[part] else: yield part return ''.join(_dereference_placeholders(split_by_token( gen.internals.LATE_BIND_PLACEHOLDER_START, gen.internals.LATE_BIND_PLACEHOLDER_END, content, strip_token_decoration=True, )))
def transform(cloud_config_yaml_str): ''' Transforms the given yaml into a list of strings which are concatenated together by the ARM template system. We must make it a list of strings so that ARM template parameters appear at the top level of the template and get substituted. ''' cc_json = json.dumps(yaml.safe_load(cloud_config_yaml_str), sort_keys=True) def _quote_literals(parts): for part, is_param in parts: if is_param: yield part else: validate_cloud_config(part) yield "'{}'".format(part) # We're embedding this as a json string. return json.dumps("[base64(concat('#cloud-config\n\n', " + ", ".join( _quote_literals( split_by_token('[[[', ']]]', cc_json, strip_token_decoration=True))) + "))]")
def transform(cloud_config_yaml_str): ''' Transforms the given yaml into a list of strings which are concatenated together by the ARM template system. We must make it a list of strings so that ARM template parameters appear at the top level of the template and get substituted. ''' cc_json = json.dumps(yaml.safe_load(cloud_config_yaml_str), sort_keys=True) def _quote_literals(parts): for part, is_param in parts: if is_param: yield part else: validate_cloud_config(part) yield "'{}'".format(part) # We're embedding this as a json string. return json.dumps( "[base64(concat('#cloud-config\n\n', " + ", ".join(_quote_literals(split_by_token('[[[', ']]]', cc_json, strip_token_decoration=True))) + "))]" )