Added tags for profile and filtering of the nodes
This commit is contained in:
parent
9ba6eb822c
commit
ab9c4c2aa5
@ -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()
|
||||
|
@ -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)()
|
||||
|
7
solar/solar/core/profile.py
Normal file
7
solar/solar/core/profile.py
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
class Profile(object):
|
||||
|
||||
def __init__(self, profile):
|
||||
self._profile = profile
|
||||
self.tags = set(profile['tags'])
|
||||
self.extensions = profile.get('extensions', [])
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user