Actions are in separate directory

This makes meta.yaml simpler
This commit is contained in:
Przemyslaw Kaminski
2015-04-16 09:14:56 +02:00
parent bf0e8a344f
commit 7f59729b4b
17 changed files with 15 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
# -*- coding: UTF-8 -*-
import handlers
def resource_action(resource, action):
handler = resource.metadata['handler']
handler = handlers.get(handler)

View File

@@ -2,10 +2,12 @@
RESOURCE_DB = {}
def resource_add(key, value):
if key in RESOURCE_DB:
raise Exception('Key `{0}` already exists'.format(key))
RESOURCE_DB[key] = value
def get_resource(key):
return RESOURCE_DB.get(key, None)

View File

@@ -56,7 +56,7 @@ class Empty(object):
pass
HANDLERS = {'ansible' : Ansible,
HANDLERS = {'ansible': Ansible,
'shell': Shell,
'none': Empty}

View File

@@ -42,7 +42,7 @@ class Resource(object):
def _validate_args(self, args):
for req in self.requires:
if not req in args:
if req not in args:
raise Exception('Requirement `{0}` is missing in args'.format(req))
@@ -57,10 +57,16 @@ def create(name, base_path, dest_path, args, connections={}):
dest_path = os.path.join(dest_path, name)
base_meta_file = os.path.join(base_path, 'meta.yaml')
meta_file = os.path.join(dest_path, 'meta.yaml')
actions_path = os.path.join(base_path, 'actions')
meta = yaml.load(open(base_meta_file).read())
meta['id'] = name
meta['version'] = '1.0.0'
meta['actions'] = {}
if os.path.exists(actions_path):
for f in os.listdir(actions_path):
meta['actions'][os.path.splitext(f)[0]] = f
resource = Resource(name, meta, args, dest_path)
signals.assign_connections(resource, connections)

View File

@@ -1,9 +1,6 @@
id: data_container
handler: ansible
version: 1.0.0
actions:
run: run.yml
remove: remove.yml
input:
host:
image:

View File

@@ -1,9 +1,6 @@
id: container
handler: ansible
version: 1.0.0
actions:
run: run.yml
remove: remove.yml
input:
image:
volume_binds:

View File

@@ -1,8 +1,5 @@
id: file
handler: shell
version: 1.0.0
actions:
run: run.sh
remove: remove.sh
input:
path: /tmp/test_file

View File

@@ -1,9 +1,6 @@
id: mariadb
handler: ansible
version: 1.0.0
actions:
run: run.yml
remove: remove.yml
input:
image: tutum/mariadq
tags: [n/1]

View File

@@ -3,12 +3,15 @@ from collections import defaultdict
import db
CLIENTS = defaultdict(lambda: defaultdict(list))
def connect(emitter, reciver, mappings):
for src, dst in mappings:
CLIENTS[emitter.name][src].append((reciver.name, dst))
def notify(source, key, value):
if key in CLIENTS[source.name]:
for client, r_key in CLIENTS[source.name][key]:
@@ -19,6 +22,7 @@ def notify(source, key, value):
#XXX resource deleted?
pass
def assign_connections(reciver, connections):
mappings = defaultdict(list)
for key, dest in connections.iteritems():