Added hosts_file_example

This commit is contained in:
Jedrzej Nowak 2015-09-08 11:41:53 +02:00
parent 62ac4b7027
commit 297de1f3d0
3 changed files with 83 additions and 0 deletions

View File

@ -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
```

View File

@ -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()

View File

@ -6,6 +6,9 @@ input:
ip:
schema: str!
value:
name:
schema: str
value:
ssh_key:
schema: str!
value: