Skip to content

Commit

Permalink
[FIX] Minor himl fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
costimuraru committed Aug 20, 2019
1 parent d007d5b commit 50bd5ea
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 35 deletions.
13 changes: 7 additions & 6 deletions src/ops/cli/helmfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
# governing permissions and limitations under the License.


import os
import logging
import os

from ops.cli.parser import SubParserConfig
from ops.hierarchical.composition_config_generator import CompositionConfigGenerator

Expand Down Expand Up @@ -92,11 +93,11 @@ def get_tmp_file():
def generate_helmfile_config(self, path, args):
output_file = args.helmfile_path + "/hiera-generated.yaml"
logger.info('Generating helmfiles config %s', output_file)
return self.generator.process(path=path,
filters=["helm", "account", "region", "cluster"],
output_format="yaml",
output_file=output_file,
print_data=True)
return self.config_generator.generate_config(config_path=path,
filters=["helm", "account", "region", "cluster"],
output_format="yaml",
output_file=output_file,
print_data=True)

def get_helmfile_command(self, args):
cmd = ' '.join(args.extra_args + [args.subcommand])
Expand Down
2 changes: 1 addition & 1 deletion src/ops/cli/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def run_v2_integration(self, args):
reverse_order = "destroy" == args.subcommand
compositions = tf_config_generator.get_sorted_compositions(config_path, reverse=reverse_order)
if len(compositions) == 0:
raise Exception("No terraform compositions were detected for it in %s.", self, config_path)
raise Exception("No terraform compositions were detected in {}.".format(config_path))

return self.run_v2_compositions(args, config_path, tf_config_generator, terraform_path, compositions)

Expand Down
61 changes: 33 additions & 28 deletions src/ops/hierarchical/composition_config_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CompositionConfigGenerator:

def __init__(self, composition_order):
self.composition_sorter = CompositionSorter(composition_order)
self.generator = ConfigProcessor()
self.config_generator = HierarchicalConfigGenerator()

def get_sorted_compositions(self, path, reverse=False):
all_compositions = self.discover_all_compositions(path)
Expand Down Expand Up @@ -86,11 +86,11 @@ def generate_files(self, config_path, composition_path, composition):
def generate_provider_config(self, config_path, composition_path):
output_file = "{}provider.tf.json".format(composition_path)
logger.info('Generating terraform config %s', output_file)
self.generate_config(config_path=config_path,
filters=["provider", "terraform"],
output_format="json",
output_file=output_file,
print_data=True)
self.config_generator.generate_config(config_path=config_path,
filters=["provider", "terraform"],
output_format="json",
output_file=output_file,
print_data=True)

def generate_variables_config(self, config_path, composition_path):
output_file = "{}variables.tfvars.json".format(composition_path)
Expand All @@ -100,25 +100,39 @@ def generate_variables_config(self, config_path, composition_path):
if "composition=account" in config_path:
excluded_keys.append("remote_states")

self.generate_config(config_path=config_path,
exclude_keys=excluded_keys,
enclosing_key="config",
output_format="json",
output_file=output_file,
print_data=True)
self.config_generator.generate_config(config_path=config_path,
exclude_keys=excluded_keys,
enclosing_key="config",
output_format="json",
output_file=output_file,
print_data=True)


class CompositionSorter(object):
def __init__(self, composition_order):
self.composition_order = composition_order

def get_sorted_compositions(self, compositions, reverse=False):
result = filter(lambda x: x in compositions, self.composition_order)
return tuple(reversed(result)) if reverse else result


class HierarchicalConfigGenerator(object):
def __init__(self):
self.config_processor = ConfigProcessor()

def generate_config(self, config_path, filters=(), exclude_keys=(), enclosing_key=None, output_format="yaml",
print_data=False, output_file=None):
cmd = self.get_sh_command(config_path, filters, exclude_keys, enclosing_key, output_format, print_data,
output_file)
display(cmd, color="yellow")
self.generator.process(path=config_path,
filters=filters,
exclude_keys=exclude_keys,
enclosing_key=enclosing_key,
output_format=output_format,
output_file=output_file,
print_data=print_data)
return self.config_processor.process(path=config_path,
filters=filters,
exclude_keys=exclude_keys,
enclosing_key=enclosing_key,
output_format=output_format,
output_file=output_file,
print_data=print_data)

@staticmethod
def get_sh_command(config_path, filters=(), exclude_keys=(), enclosing_key=None, output_format="yaml",
Expand All @@ -136,12 +150,3 @@ def get_sh_command(config_path, filters=(), exclude_keys=(), enclosing_key=None,
command += " --print-data"

return command


class CompositionSorter(object):
def __init__(self, composition_order):
self.composition_order = composition_order

def get_sorted_compositions(self, compositions, reverse=False):
result = filter(lambda x: x in compositions, self.composition_order)
return tuple(reversed(result)) if reverse else result

0 comments on commit 50bd5ea

Please sign in to comment.