From ab9c4c2aa55d3598debfa5aa98f7885a183f3290 Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Mon, 6 Apr 2015 15:43:14 -0700 Subject: [PATCH] Added tags for profile and filtering of the nodes --- solar/solar/cli.py | 3 --- solar/solar/core/extensions_manager.py | 8 +++----- solar/solar/core/profile.py | 7 +++++++ solar/solar/extensions/__init__.py | 14 ++++++++------ solar/solar/extensions/ansible.py | 13 ++++++++++++- solar/solar/extensions/base.py | 5 +++-- 6 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 solar/solar/core/profile.py diff --git a/solar/solar/cli.py b/solar/solar/cli.py index 687401fb..9faa250f 100644 --- a/solar/solar/cli.py +++ b/solar/solar/cli.py @@ -98,9 +98,6 @@ class Cmd(object): parser.add_argument( '-p', '--profile') - parser.add_argument( - '-t', '--tags', nargs='+', required=True, - help='A list of tags for deployment') def configure(self, args): extensions.find_by_provider_from_profile(args.profile, 'configure').configure() diff --git a/solar/solar/core/extensions_manager.py b/solar/solar/core/extensions_manager.py index ca924c01..7d1f710a 100644 --- a/solar/solar/core/extensions_manager.py +++ b/solar/solar/core/extensions_manager.py @@ -4,10 +4,8 @@ from solar import errors class ExtensionsManager(object): - def __init__(self): - # TODO: probably we should pass as a parameter profile, global - # config with specific versions of extensions - pass + def __init__(self, profile): + self.profile = profile def get_data(self, key): """Finds data by extensions provider""" @@ -16,4 +14,4 @@ class ExtensionsManager(object): if not providers: raise errors.CannotFindExtension('Cannot find extension which provides "{0}"'.format(key)) - return getattr(providers[0](), key)() + return getattr(providers[0](self.profile), key)() diff --git a/solar/solar/core/profile.py b/solar/solar/core/profile.py new file mode 100644 index 00000000..0e3b80b3 --- /dev/null +++ b/solar/solar/core/profile.py @@ -0,0 +1,7 @@ + +class Profile(object): + + def __init__(self, profile): + self._profile = profile + self.tags = set(profile['tags']) + self.extensions = profile.get('extensions', []) diff --git a/solar/solar/extensions/__init__.py b/solar/solar/extensions/__init__.py index f3a6c2c2..870a3cff 100644 --- a/solar/solar/extensions/__init__.py +++ b/solar/solar/extensions/__init__.py @@ -29,17 +29,19 @@ def find_extension(id_, version): def find_by_provider_from_profile(profile_path, provider): - profile = utils.yaml_load(profile_path) - extensions = profile.get('extensions', []) + # Circular dependencies problem + from solar.core import extensions_manager + from solar.core import profile + + profile = profile.Profile(utils.yaml_load(profile_path)) + extensions = profile.extensions result = None for ext in extensions: result = find_extension(ext['id'], ext['version']) if result: break - # Circular dependencies problem - from solar.core.extensions_manager import ExtensionsManager # Create data manager - core_manager = ExtensionsManager() + core_manager = extensions_manager.ExtensionsManager(profile) - return result(core_manager) + return result(profile) diff --git a/solar/solar/extensions/ansible.py b/solar/solar/extensions/ansible.py index cdbf54e1..7e1e3774 100644 --- a/solar/solar/extensions/ansible.py +++ b/solar/solar/extensions/ansible.py @@ -28,7 +28,18 @@ class AnsibleOrchestration(base.BaseExtension): super(AnsibleOrchestration, self).__init__(*args, **kwargs) self.resources = self.core.get_data('resources') - self.nodes = self.core.get_data('nodes_resources') + self.nodes = self._get_nodes() + + def _get_nodes(self): + nodes = [] + for node in self.core.get_data('nodes_resources'): + if self.profile.tags <= set(node.get('tags', [])): + nodes.append(node) + + return nodes + + def _get_resources_for_nodes(self): + pass @property def inventory(self): diff --git a/solar/solar/extensions/base.py b/solar/solar/extensions/base.py index 2f0e3486..2437dc95 100644 --- a/solar/solar/extensions/base.py +++ b/solar/solar/extensions/base.py @@ -7,13 +7,14 @@ class BaseExtension(object): NAME = None PROVIDES = [] - def __init__(self, core_manager=None, config=None): + def __init__(self, profile, core_manager=None, config=None): self.config = config or {} self.uid = self.ID self.db = get_db() + self.profile = profile from solar.core.extensions_manager import ExtensionsManager - self.core = core_manager or ExtensionsManager() + self.core = core_manager or ExtensionsManager(self.profile) def prepare(self): """Make some changes in database state."""