Added hosts_file_example
This commit is contained in:
parent
62ac4b7027
commit
297de1f3d0
23
examples/hosts_file/README.md
Normal file
23
examples/hosts_file/README.md
Normal 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
|
||||||
|
```
|
||||||
|
|
57
examples/hosts_file/hosts.py
Normal file
57
examples/hosts_file/hosts.py
Normal 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()
|
@ -6,6 +6,9 @@ input:
|
|||||||
ip:
|
ip:
|
||||||
schema: str!
|
schema: str!
|
||||||
value:
|
value:
|
||||||
|
name:
|
||||||
|
schema: str
|
||||||
|
value:
|
||||||
ssh_key:
|
ssh_key:
|
||||||
schema: str!
|
schema: str!
|
||||||
value:
|
value:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user