From 4d5d2c8040009b3b55273e58527c62be06254a98 Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Mon, 5 Oct 2015 10:57:08 +0300 Subject: [PATCH] Fix hosts_file/riak and solard examples --- examples/hosts_file/hosts.py | 8 ++--- examples/riak/riaks.py | 33 ++++++++++--------- examples/solard/example.py | 32 +++++++++--------- solar/solar/core/resource/resource.py | 2 +- solar/solar/core/resource/virtual_resource.py | 6 ++-- solar/solar/core/signals.py | 4 +-- 6 files changed, 43 insertions(+), 42 deletions(-) diff --git a/examples/hosts_file/hosts.py b/examples/hosts_file/hosts.py index 6d9fec80..f6aba5d3 100644 --- a/examples/hosts_file/hosts.py +++ b/examples/hosts_file/hosts.py @@ -20,22 +20,22 @@ def run(): hosts1 = vr.create('hosts_file1', 'resources/hosts_file', {})[0] hosts2 = vr.create('hosts_file2', 'resources/hosts_file', {})[0] - node1.connect_with_defaults(hosts1, { + node1.connect(hosts1, { 'name': 'hosts:name', 'ip': 'hosts:ip', }) - node2.connect_with_defaults(hosts1, { + node2.connect(hosts1, { 'name': 'hosts:name', 'ip': 'hosts:ip', }) - node1.connect_with_defaults(hosts2, { + node1.connect(hosts2, { 'name': 'hosts:name', 'ip': 'hosts:ip', }) - node2.connect_with_defaults(hosts2, { + node2.connect(hosts2, { 'name': 'hosts:name', 'ip': 'hosts:ip', }) diff --git a/examples/riak/riaks.py b/examples/riak/riaks.py index 0cf93744..3fdf704c 100755 --- a/examples/riak/riaks.py +++ b/examples/riak/riaks.py @@ -32,7 +32,7 @@ db = get_db() def setup_riak(): db.clear() - resources = vr.create('nodes', 'templates/riak_nodes.yaml', {'count': 3}) + resources = vr.create('nodes', 'templates/nodes.yaml', {'count': 3}) nodes = [x for x in resources if x.name.startswith('node')] node1, node2, node3 = nodes @@ -48,10 +48,10 @@ def setup_riak(): riak_services.append(r) for i, riak in enumerate(riak_services): - signals.connect(nodes[i], riak) + nodes[i].connect(riak) for i, riak in enumerate(riak_services[1:]): - signals.connect(riak_services[0], riak, {'riak_name': 'join_to'}) + riak_services[0].connect(riak, {'riak_name': 'join_to'}) hosts_services = [] for i, riak in enumerate(riak_services): @@ -59,14 +59,13 @@ def setup_riak(): hosts_file = vr.create('hosts_file%d' % num, 'resources/hosts_file', {})[0] hosts_services.append(hosts_file) - signals.connect(nodes[i], hosts_file) + nodes[i].connect(hosts_file) for riak in riak_services: for hosts_file in hosts_services: - signals.connect(riak, hosts_file, - {'riak_hostname': 'hosts:name', - 'ip': 'hosts:ip'}, - events=False) + riak.connect_with_events(hosts_file, + {'riak_hostname': 'hosts:name', + 'ip': 'hosts:ip'}) errors = resource.validate_resources() for r, error in errors: @@ -142,24 +141,26 @@ def setup_haproxies(): for single_hpsc in hpsc_http: for riak in riaks: - signals.connect(riak, single_hpsc, {'riak_hostname': 'backends:server', - 'riak_port_http': 'backends:port'}) + riak.connect(single_hpsc, { + 'riak_hostname': 'backends:server', + 'riak_port_http': 'backends:port'}) for single_hpsc in hpsc_pb: for riak in riaks: - signals.connect(riak, single_hpsc, {'riak_hostname': 'backends:server', - 'riak_port_pb': 'backends:port'}) + riak.connect(single_hpsc, + {'riak_hostname': 'backends:server', + 'riak_port_pb': 'backends:port'}) # haproxy config to haproxy service for single_hpc, single_hpsc in zip(hpc, hpsc_http): - signals.connect(single_hpsc, single_hpc, {"backends": "config:backends", + single_hpsc.connect(single_hpc, {"backends": "config:backends", "listen_port": "config:listen_port", "protocol": "config:protocol", "name": "config:name"}) for single_hpc, single_hpsc in zip(hpc, hpsc_pb): - signals.connect(single_hpsc, single_hpc, {"backends": "config:backends", + single_hpsc.connect(single_hpc, {"backends": "config:backends", "listen_port": "config:listen_port", "protocol": "config:protocol", "name": "config:name"}) @@ -173,10 +174,10 @@ def setup_haproxies(): nodes = [node1, node2, node3] for single_node, single_hps in zip(nodes, hps): - signals.connect(single_node, single_hps) + single_node.connect(single_hps) for single_node, single_hpc in zip(nodes, hpc): - signals.connect(single_node, single_hpc) + single_node.connect(single_hpc) has_errors = False for r in locals().values(): diff --git a/examples/solard/example.py b/examples/solard/example.py index 01737e75..74726442 100644 --- a/examples/solard/example.py +++ b/examples/solard/example.py @@ -32,29 +32,27 @@ def run(): {'solard_user': 'vagrant', 'solard_password': 'password'})[0] - signals.connect(transports_for_solard, solard_transport, {}) - - signals.connect(ssh_transport, transports_for_solard, {'ssh_key': 'transports:key', - 'ssh_user': 'transports:user', - 'ssh_port': 'transports:port', - 'name': 'transports:name'}) + transports_for_solard.connect(solard_transport, {}) + ssh_transport.connect(transports_for_solard,{'ssh_key': 'transports:key', + 'ssh_user': 'transports:user', + 'ssh_port': 'transports:port', + 'name': 'transports:name'}) # set transports_id - signals.connect(transports, node, {}) + transports.connect(node, {}) # it uses reverse mappings - signals.connect(ssh_transport, transports, {'ssh_key': 'transports:key', - 'ssh_user': 'transports:user', - 'ssh_port': 'transports:port', - 'name': 'transports:name'}) - - signals.connect(solard_transport, transports, {'solard_user': 'transports:user', - 'solard_port': 'transports:port', - 'solard_password': 'transports:password', - 'name': 'transports:name'}) + ssh_transport.connect(transports, {'ssh_key': 'transports:key', + 'ssh_user': 'transports:user', + 'ssh_port': 'transports:port', + 'name': 'transports:name'}) + solard_transport.connect(transports, {'solard_user': 'transports:user', + 'solard_port': 'transports:port', + 'solard_password': 'transports:password', + 'name': 'transports:name'}) hosts = vr.create('hosts_file', 'resources/hosts_file', {})[0] - signals.connect(node, hosts, { + node.connect(hosts, { 'ip': 'hosts:ip', 'name': 'hosts:name' }) diff --git a/solar/solar/core/resource/resource.py b/solar/solar/core/resource/resource.py index 40803c73..f7427714 100644 --- a/solar/solar/core/resource/resource.py +++ b/solar/solar/core/resource/resource.py @@ -258,7 +258,7 @@ class Resource(object): if events: api.add_events(self.name, events) - def connect_with_defaults(self, receiver, mapping=None, events=None): + def connect(self, receiver, mapping=None, events=None): return self.connect_with_events( receiver, mapping=mapping, events=events, use_defaults=True) diff --git a/solar/solar/core/resource/virtual_resource.py b/solar/solar/core/resource/virtual_resource.py index 16425495..357510d2 100644 --- a/solar/solar/core/resource/virtual_resource.py +++ b/solar/solar/core/resource/virtual_resource.py @@ -129,7 +129,7 @@ def create_resources(resources, tags=None): if node: node = load_resource(node) r = new_resources[0] - signals.connect(node, r, {}) + node.connect(r, mapping={}) r.add_tags('location={}'.format(node.name)) update_inputs(resource_name, args) return created_resources @@ -167,8 +167,10 @@ def update_inputs(child, args): mapping = {} parent = load_resource(c['parent']) events = c['events'] + use_defaults = not c['events'] is False mapping[c['parent_input']] = c['child_input'] - parent.connect_with_events(child, mapping, events) + parent.connect_with_events( + child, mapping, events, use_defaults=use_defaults) child.update(assignments) diff --git a/solar/solar/core/signals.py b/solar/solar/core/signals.py index c9041169..0ddce5d6 100644 --- a/solar/solar/core/signals.py +++ b/solar/solar/core/signals.py @@ -127,9 +127,9 @@ def location_and_transports(emitter, receiver, orig_mapping): return - def connect(emitter, receiver, mapping=None): - mapping = mapping or guess_mapping(emitter, receiver) + if mapping is None: + mapping = guess_mapping(emitter, receiver) # XXX: we didn't agree on that "reverse" there location_and_transports(emitter, receiver, mapping)