Implemented resources to nodes assignment
This commit is contained in:
parent
85c9fcafa7
commit
da3724cd3f
@ -9,4 +9,5 @@ file-system-db:
|
||||
storage-path: /vagrant/tmp/storage
|
||||
|
||||
template-dir: /vagrant/templates
|
||||
resources-files-mask: /vagrant/examples/resources/*.yml
|
||||
resources-files-mask: /vagrant/x/resources/*/*.yaml
|
||||
resource-instances-path: /vagrant/tmp/resource-instances
|
||||
|
@ -28,6 +28,7 @@ import yaml
|
||||
from solar import extensions
|
||||
from solar import utils
|
||||
from solar.core import data
|
||||
from solar.core.resource import assign_resources_to_nodes
|
||||
from solar.core.tags_set_parser import Expression
|
||||
from solar.interfaces.db import get_db
|
||||
|
||||
@ -109,15 +110,29 @@ class Cmd(object):
|
||||
|
||||
def assign(self, args):
|
||||
nodes = filter(
|
||||
lambda n: Expression(args.nodes, n['tags']).evaluate(),
|
||||
lambda n: Expression(args.nodes, n.get('tags', [])).evaluate(),
|
||||
self.db.get_list('nodes'))
|
||||
|
||||
resources = filter(
|
||||
lambda r: Expression(args.resources, r['tags']).evaluate(),
|
||||
lambda r: Expression(args.resources, r.get('tags', [])).evaluate(),
|
||||
self._get_resources_list())
|
||||
|
||||
resource_instances_path = utils.read_config()['resource-instances-path']
|
||||
utils.create_dir(resource_instances_path)
|
||||
assign_resources_to_nodes(
|
||||
resources,
|
||||
nodes,
|
||||
resource_instances_path)
|
||||
|
||||
def _get_resources_list(self):
|
||||
return utils.load_by_mask(utils.read_config()['resources-files-mask'])
|
||||
result = []
|
||||
for path in utils.find_by_mask(utils.read_config()['resources-files-mask']):
|
||||
resource = utils.yaml_load(path)
|
||||
resource['path'] = path
|
||||
resource['dir_path'] = os.path.dirname(path)
|
||||
result.append(resource)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -4,6 +4,8 @@ import json
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
import yaml
|
||||
|
||||
from solar.core import actions
|
||||
@ -174,3 +176,19 @@ def load_all(dest_path):
|
||||
signals.Connections.reconnect_all()
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def assign_resources_to_nodes(resources, nodes, dst_dir):
|
||||
for node in nodes:
|
||||
for resource in resources:
|
||||
merged = deepcopy(resource)
|
||||
# Node specific setting should override resource's
|
||||
merged.update(deepcopy(node))
|
||||
# Tags for specific resource is set of tags from node and from resource
|
||||
merged['tags'] = list(set(node.get('tags', [])) + set(resource.get('tags', [])))
|
||||
|
||||
create(
|
||||
format('{0}-{1}'.format(node['id'], resource['id'])),
|
||||
resource['dir_path'],
|
||||
dst_dir,
|
||||
merged)
|
||||
|
Loading…
Reference in New Issue
Block a user