Merge pull request #250 from pigmej/torrent_transport
torrent transport
This commit is contained in:
commit
0608deb2b0
25
examples/torrent/README.md
Normal file
25
examples/torrent/README.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
Example of using torrent transport with solar. Torrent is used to distribute task data. After fetching is finished torrent client forks and continues seeding.
|
||||||
|
|
||||||
|
|
||||||
|
The example contains single node with single host mapping + transports.
|
||||||
|
|
||||||
|
Execute:
|
||||||
|
```
|
||||||
|
python examples/torrent/example.py
|
||||||
|
solar changes stage
|
||||||
|
solar changes process
|
||||||
|
solar orch run-once last
|
||||||
|
```
|
||||||
|
|
||||||
|
Wait for finish:
|
||||||
|
|
||||||
|
```
|
||||||
|
solar orch report last -w 100
|
||||||
|
```
|
||||||
|
|
||||||
|
After this you should see new entry in `/etc/hosts` file.
|
||||||
|
|
||||||
|
|
||||||
|
* All created torrents are in `/vagrant/torrents`, it doesn't need to be shared
|
||||||
|
* Initial seeding is done using torrent file
|
||||||
|
* Downloading and then seeding is always done with magnetlinks
|
74
examples/torrent/example.py
Normal file
74
examples/torrent/example.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
from solar.core.resource import virtual_resource as vr
|
||||||
|
from solar import errors
|
||||||
|
|
||||||
|
from solar.interfaces.db import get_db
|
||||||
|
|
||||||
|
|
||||||
|
db = get_db()
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
db.clear()
|
||||||
|
|
||||||
|
node = vr.create('node', 'resources/ro_node', {'name': 'first' + str(time.time()),
|
||||||
|
'ip': '10.0.0.3',
|
||||||
|
'node_id': 'node1',
|
||||||
|
})[0]
|
||||||
|
|
||||||
|
transports = vr.create('transports_node1', 'resources/transports')[0]
|
||||||
|
|
||||||
|
ssh_transport = vr.create('ssh_transport', 'resources/transport_ssh',
|
||||||
|
{'ssh_key': '/vagrant/.vagrant/machines/solar-dev1/virtualbox/private_key',
|
||||||
|
'ssh_user': 'vagrant'})[0]
|
||||||
|
|
||||||
|
transports.connect(node, {})
|
||||||
|
|
||||||
|
# it uses reverse mappings
|
||||||
|
ssh_transport.connect(transports, {'ssh_key': 'transports:key',
|
||||||
|
'ssh_user': 'transports:user',
|
||||||
|
'ssh_port': 'transports:port',
|
||||||
|
'name': 'transports:name'})
|
||||||
|
|
||||||
|
hosts = vr.create('hosts_file', 'resources/hosts_file', {})[0]
|
||||||
|
|
||||||
|
# let's add torrent transport for hosts file deployment (useless in real life)
|
||||||
|
|
||||||
|
torrent_transport = vr.create('torrent_transport',
|
||||||
|
'resources/transport_torrent',
|
||||||
|
{'trackers': ['udp://open.demonii.com:1337',
|
||||||
|
'udp://tracker.openbittorrent.com:80']})[0]
|
||||||
|
# you could use any trackers as you want
|
||||||
|
|
||||||
|
transports_for_torrent = vr.create(
|
||||||
|
'transports_for_torrent', 'resources/transports')[0]
|
||||||
|
|
||||||
|
transports_for_torrent.connect(torrent_transport, {})
|
||||||
|
|
||||||
|
ssh_transport.connect_with_events(transports_for_torrent, {'ssh_key': 'transports:key',
|
||||||
|
'ssh_user': 'transports:user',
|
||||||
|
'ssh_port': 'transports:port',
|
||||||
|
'name': 'transports:name'},
|
||||||
|
events={})
|
||||||
|
|
||||||
|
transports_for_hosts = vr.create(
|
||||||
|
'transports_for_hosts', 'resources/transports')[0]
|
||||||
|
|
||||||
|
torrent_transport.connect(transports_for_hosts, {'trackers': 'transports:trackers',
|
||||||
|
'name': 'transports:name'})
|
||||||
|
|
||||||
|
ssh_transport.connect(transports_for_hosts, {'ssh_key': 'transports:key',
|
||||||
|
'ssh_user': 'transports:user',
|
||||||
|
'ssh_port': 'transports:port',
|
||||||
|
'name': 'transports:name'})
|
||||||
|
|
||||||
|
transports_for_hosts.connect(hosts)
|
||||||
|
transports_for_hosts.connect_with_events(node, events={})
|
||||||
|
|
||||||
|
node.connect(hosts, {
|
||||||
|
'ip': 'hosts:ip',
|
||||||
|
'name': 'hosts:name'
|
||||||
|
})
|
||||||
|
|
||||||
|
run()
|
9
resources/transport_torrent/actions/run.yaml
Normal file
9
resources/transport_torrent/actions/run.yaml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
- hosts: [{{ host }}]
|
||||||
|
sudo: yes
|
||||||
|
tasks:
|
||||||
|
- apt:
|
||||||
|
name: python-libtorrent
|
||||||
|
state: present
|
||||||
|
- copy:
|
||||||
|
src: {{scripts_dir}}/solar_torrent.py
|
||||||
|
dest: /var/tmp/solar_torrent.py
|
18
resources/transport_torrent/meta.yaml
Normal file
18
resources/transport_torrent/meta.yaml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
id: transport_torrent
|
||||||
|
handler: ansible
|
||||||
|
input:
|
||||||
|
trackers:
|
||||||
|
schema: [str!]
|
||||||
|
value: []
|
||||||
|
name:
|
||||||
|
schema: str!
|
||||||
|
value: torrent
|
||||||
|
location_id:
|
||||||
|
schema: str
|
||||||
|
value:
|
||||||
|
reverse: True
|
||||||
|
is_own: False
|
||||||
|
transports_id:
|
||||||
|
schema: str
|
||||||
|
value:
|
||||||
|
is_emit: False
|
1
resources/transport_torrent/scripts/solar_torrent.py
Symbolic link
1
resources/transport_torrent/scripts/solar_torrent.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../../solar/solar/core/transports/helpers/solar_torrent.py
|
@ -1,7 +1,7 @@
|
|||||||
id: transports
|
id: transports
|
||||||
input:
|
input:
|
||||||
transports:
|
transports:
|
||||||
schema: [{user: str, password: str, port: int!, key: str, name: str!}]
|
schema: [{user: str, password: str, port: int!, key: str, name: str!, trackers: [str]}]
|
||||||
value: []
|
value: []
|
||||||
transports_id:
|
transports_id:
|
||||||
schema: str!
|
schema: str!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user