Torrent transport can use corret solar_torrent.py
Torrent transport can use solar_torrent.py from connected torrent resource. Change-Id: I289f6c78c400f08c09aa230c709ad58fa54c58cb Closes-bug: #1531234
This commit is contained in:
parent
f08a369eb5
commit
6af7da9add
@ -123,6 +123,11 @@ class Resource(object):
|
|||||||
db_obj = self.db_obj
|
db_obj = self.db_obj
|
||||||
return db_obj.inputs._get_field_val('location_id', other='ip')
|
return db_obj.inputs._get_field_val('location_id', other='ip')
|
||||||
|
|
||||||
|
def get_file_path(self, rel_path):
|
||||||
|
base_path = self.db_obj.base_path
|
||||||
|
path = os.path.join(base_path, rel_path)
|
||||||
|
return path
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def actions(self):
|
def actions(self):
|
||||||
if self.db_obj.actions:
|
if self.db_obj.actions:
|
||||||
@ -372,6 +377,10 @@ def load_by_tags(query):
|
|||||||
return nodes
|
return nodes
|
||||||
|
|
||||||
|
|
||||||
|
def load_by_names(names):
|
||||||
|
return [Resource(r) for r in DBResource.multi_get(names)]
|
||||||
|
|
||||||
|
|
||||||
def validate_resources():
|
def validate_resources():
|
||||||
resources = load_all()
|
resources = load_all()
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from solar.core.log import log
|
from solar.core.log import log
|
||||||
|
from solar.core.resource.resource import load
|
||||||
|
from solar.core.resource.resource import load_by_names
|
||||||
from solar import errors
|
from solar import errors
|
||||||
|
|
||||||
|
|
||||||
@ -103,6 +105,18 @@ def find_named_transport(resource, req_name):
|
|||||||
return transport
|
return transport
|
||||||
|
|
||||||
|
|
||||||
|
def locate_named_transport_resoruce(resource, name):
|
||||||
|
transports = resource.db_obj.inputs._get_field_val('transports_id',
|
||||||
|
other='_key')
|
||||||
|
transports_resource = load(transports)
|
||||||
|
connections = transports_resource.connections
|
||||||
|
just_names = filter(lambda x: x[1] == 'name', connections)
|
||||||
|
transports = load_by_names([x[0] for x in just_names])
|
||||||
|
transport = next(x for x in transports
|
||||||
|
if x.db_obj.inputs._get_raw_field_val('name') == name)
|
||||||
|
return transport
|
||||||
|
|
||||||
|
|
||||||
class SolarTransport(object):
|
class SolarTransport(object):
|
||||||
|
|
||||||
_mode = None
|
_mode = None
|
||||||
|
@ -22,6 +22,7 @@ import libtorrent as lt
|
|||||||
from solar.core.handlers.base import SOLAR_TEMP_LOCAL_LOCATION
|
from solar.core.handlers.base import SOLAR_TEMP_LOCAL_LOCATION
|
||||||
from solar.core.log import log
|
from solar.core.log import log
|
||||||
from solar.core.transports.base import Executor
|
from solar.core.transports.base import Executor
|
||||||
|
from solar.core.transports.base import locate_named_transport_resoruce
|
||||||
from solar.core.transports.base import SyncTransport
|
from solar.core.transports.base import SyncTransport
|
||||||
from solar.core.transports.ssh import SSHSyncTransport
|
from solar.core.transports.ssh import SSHSyncTransport
|
||||||
|
|
||||||
@ -89,20 +90,20 @@ class TorrentSyncTransport(SyncTransport):
|
|||||||
self._sudo_torrents.append((name, magnet_uri, root))
|
self._sudo_torrents.append((name, magnet_uri, root))
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def _start_seeding(self):
|
def _start_seeding(self, resource):
|
||||||
# XXX: naive naive naive
|
# XXX: naive naive naive
|
||||||
# we don't need use sudo there for now
|
# we don't need use sudo there for now
|
||||||
from fabric import api as fabric_api
|
from fabric import api as fabric_api
|
||||||
|
torrent_t = locate_named_transport_resoruce(resource, 'torrent')
|
||||||
|
|
||||||
|
solar_torrent = torrent_t.get_file_path('scripts/solar_torrent.py')
|
||||||
torrents = self._torrents + self._sudo_torrents
|
torrents = self._torrents + self._sudo_torrents
|
||||||
to_seed = ["%s|%s" % (os.path.abspath(
|
to_seed = ["%s|%s" % (os.path.abspath(
|
||||||
os.path.join(x[2], '..')), x[0]) for x in torrents]
|
os.path.join(x[2], '..')), x[0]) for x in torrents]
|
||||||
seed_args = ';'.join(to_seed)
|
seed_args = ';'.join(to_seed)
|
||||||
# TODO: 'g' is just for debug, it should be 's', remove when sure
|
# TODO: 'g' is just for debug, it should be 's', remove when sure
|
||||||
# TODO: find a way to use solar_torrent.py from transport resource
|
|
||||||
helpers_path = os.path.normpath(
|
|
||||||
os.path.join(os.path.realpath(__file__), '..', 'helpers'))
|
|
||||||
cmd = ['/usr/bin/python',
|
cmd = ['/usr/bin/python',
|
||||||
'%s/solar_torrent.py' % helpers_path,
|
solar_torrent,
|
||||||
'g',
|
'g',
|
||||||
'"%s"' % seed_args]
|
'"%s"' % seed_args]
|
||||||
log.debug("Will start seeding: %r" % ' '.join(cmd))
|
log.debug("Will start seeding: %r" % ' '.join(cmd))
|
||||||
@ -135,8 +136,8 @@ class TorrentSyncTransport(SyncTransport):
|
|||||||
self._create_single_torrent(executor.resource, _from, _to, use_sudo)
|
self._create_single_torrent(executor.resource, _from, _to, use_sudo)
|
||||||
|
|
||||||
def run_all(self):
|
def run_all(self):
|
||||||
self._start_seeding()
|
|
||||||
resource = self.executors[0].resource
|
resource = self.executors[0].resource
|
||||||
|
self._start_seeding(resource)
|
||||||
# TODO: we should paralelize it
|
# TODO: we should paralelize it
|
||||||
if self._torrents:
|
if self._torrents:
|
||||||
self._start_remote_fetch(resource, use_sudo=False)
|
self._start_remote_fetch(resource, use_sudo=False)
|
||||||
|
@ -439,6 +439,10 @@ class InputsFieldWrp(IndexFieldWrp):
|
|||||||
_res = self._get_raw_field_val(name)
|
_res = self._get_raw_field_val(name)
|
||||||
self._cache[name] = _res
|
self._cache[name] = _res
|
||||||
if other:
|
if other:
|
||||||
|
if other == '_key':
|
||||||
|
k = self._instance.key
|
||||||
|
self._cache[full_name] = k
|
||||||
|
return k
|
||||||
other_res = self._get_field_val(other)
|
other_res = self._get_field_val(other)
|
||||||
self._cache[full_name] = other_res
|
self._cache[full_name] = other_res
|
||||||
return other_res
|
return other_res
|
||||||
|
Loading…
x
Reference in New Issue
Block a user