From 396729cbc615a946a3f728b963f943446a65c71f Mon Sep 17 00:00:00 2001 From: Adam Feuer Date: Mon, 20 Feb 2017 23:11:08 -0800 Subject: [PATCH] pillar example working --- flyingcloud/base.py | 23 +++++++++++++---------- flyingcloud/main.py | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/flyingcloud/base.py b/flyingcloud/base.py index cfcf073..7165bad 100644 --- a/flyingcloud/base.py +++ b/flyingcloud/base.py @@ -94,7 +94,7 @@ def __init__( registry_config=None, source_version_tag="latest", environment=None, - pillar=None + pillar=None, ): self.app_name = app_name self.layer_name = layer_name @@ -103,7 +103,9 @@ def __init__( self.description = description self.exposed_ports = exposed_ports or [] self.environment = environment - self.pillar = None + self.pillar = pillar + self.base_dir = None + self.pillar_dir = None config = self.RegistryConfig.copy() if registry_config: @@ -147,9 +149,13 @@ def check_user_is_root(cls): raise NotSudoError("You must be root (use sudo)") def set_pillar(self, namespace): - pillar = namespace.pillar + pillar = namespace.pillar or self.pillar + self.base_dir = namespace.base_dir if pillar: self.pillar = pillar + pillar_basedir = os.path.join(self.base_dir, 'pillar') + self.pillar_dir = os.path.join(pillar_basedir, self.pillar) + namespace.logger.info("Using pillar '{}' and setting pillar_dir to '{}'.".format(self.pillar, self.pillar_dir)) def check_environment_variables(self, namespace): cfg = self.registry_config @@ -310,13 +316,13 @@ def salt_highstate( volume_map = { salt_dir: "/srv/salt", } - if namespace.pillar_dir: - volume_map[namespace.pillar_dir] = "/srv/pillar" + if self.pillar_dir: + volume_map[self.pillar_dir] = "/srv/pillar" try: target_container_name = self.docker_create_container( namespace, container_name, source_image_name, environment=self.make_environment(namespace.env_vars, self.environment), - volume_map=volume_map, + volume_map=volume_map ) self.docker_start(namespace, target_container_name) @@ -917,10 +923,7 @@ def parse_args(self, defaults, *layer_classes, **kwargs): self.add_additional_configuration(namespace) - if namespace.pillar: - pillar_basedir = os.path.join(defaults['base_dir'], "pillar") - namespace.pillar_dir = os.path.join(pillar_basedir, namespace.pillar) - + namespace.base_dir = defaults['base_dir'] return namespace @classmethod diff --git a/flyingcloud/main.py b/flyingcloud/main.py index f27ac19..81033ab 100755 --- a/flyingcloud/main.py +++ b/flyingcloud/main.py @@ -113,7 +113,8 @@ def main(): description=project_info['description'] ) instance.check_environment_variables(namespace) - instance.set_pillar(namespace) + for layer in layers: + layer.set_pillar(namespace) instance = namespace.layer_inst instance.do_operation(namespace)