diff --git a/examples/hosts_file/README.md b/examples/hosts_file/README.md new file mode 100644 index 0000000..b3f66ee --- /dev/null +++ b/examples/hosts_file/README.md @@ -0,0 +1,23 @@ +Very simple solar example two nodes + hosts file mapping + +Run: + +`python examples/hosts_file/hosts.py` + +Then you can continue with standard solar things: + +``` +solar changes stage -d +solar changes process +solar changes run-once last +watch -n 1 solar changes report last +``` + +Wait until all actions have state `SUCCESS`, +after that check `/etc/hosts` files on both nodes, it will contain entries like: + +``` +10.0.0.3 first1441705177.99 +10.0.0.4 second1441705178.0 +``` + diff --git a/examples/hosts_file/hosts.py b/examples/hosts_file/hosts.py new file mode 100644 index 0000000..35b3940 --- /dev/null +++ b/examples/hosts_file/hosts.py @@ -0,0 +1,57 @@ +import click +import sys +import time + +from solar.core import signals +from solar.core.resource import virtual_resource as vr + +from solar.interfaces.db import get_db + + +db = get_db() + + +def run(): + db.clear() + signals.Connections.clear() + + node1 = vr.create('node1', 'resources/ro_node', {'name': 'first' + str(time.time()), + 'ip': '10.0.0.3', + 'ssh_key': '/vagrant/.vagrant/machines/solar-dev1/virtualbox/private_key', + 'ssh_user': 'vagrant'})[0] + + node2 = vr.create('node2', 'resources/ro_node', {'name': 'second' + str(time.time()), + 'ip': '10.0.0.4', + 'ssh_key': '/vagrant/.vagrant/machines/solar-dev2/virtualbox/private_key', + 'ssh_user': 'vagrant'})[0] + + + + hosts1 = vr.create('hosts_file1', 'resources/hosts_file', {})[0] + hosts2 = vr.create('hosts_file2', 'resources/hosts_file', {})[0] + signals.connect(node1, hosts1, { + 'name': 'hosts_names', + 'ip': ['hosts_ips', 'ip'], + 'ssh_user': 'ssh_user', + 'ssh_key': 'ssh_key' + }) + + signals.connect(node2, hosts2, { + 'name': 'hosts_names', + 'ip': ['hosts_ips', 'ip'], + 'ssh_user': 'ssh_user', + 'ssh_key': 'ssh_key' + }) + + signals.connect(node1, hosts2, { + 'ip': 'hosts_ips', + 'name': 'hosts_names' + }) + + signals.connect(node2, hosts1, { + 'ip': 'hosts_ips', + 'name': 'hosts_names' + }) + + +run() diff --git a/resources/ro_node/meta.yaml b/resources/ro_node/meta.yaml index c37fcb7..206c5ed 100644 --- a/resources/ro_node/meta.yaml +++ b/resources/ro_node/meta.yaml @@ -6,6 +6,9 @@ input: ip: schema: str! value: + name: + schema: str + value: ssh_key: schema: str! value: