|
@@ -1,5 +1,6 @@ |
|
|
#!/usr/bin/env python |
|
|
#!/usr/bin/env python |
|
|
|
|
|
|
|
|
|
|
|
import collections |
|
|
import stat |
|
|
import stat |
|
|
import sys |
|
|
import sys |
|
|
import logging |
|
|
import logging |
|
@@ -573,7 +574,7 @@ class ObjectStore(object): |
|
|
|
|
|
|
|
|
return objs |
|
|
return objs |
|
|
|
|
|
|
|
|
def _get_hostmappings(self): |
|
|
|
|
|
|
|
|
def get_hostmappings(self): |
|
|
'''Returns the tuple (lclpath, hostid, rempath) for all |
|
|
'''Returns the tuple (lclpath, hostid, rempath) for all |
|
|
the mappings for this hostid.''' |
|
|
the mappings for this hostid.''' |
|
|
|
|
|
|
|
@@ -620,7 +621,7 @@ class ObjectStore(object): |
|
|
except KeyError: |
|
|
except KeyError: |
|
|
# check mappings |
|
|
# check mappings |
|
|
fname = pathlib.Path(fname).resolve() |
|
|
fname = pathlib.Path(fname).resolve() |
|
|
for lclpath, hostid, rempath in self._get_hostmappings(): |
|
|
|
|
|
|
|
|
for lclpath, hostid, rempath in self.get_hostmappings(): |
|
|
if fname.parts[:len(lclpath.parts)] == lclpath.parts: |
|
|
if fname.parts[:len(lclpath.parts)] == lclpath.parts: |
|
|
try: |
|
|
try: |
|
|
rempath = pathlib.Path( |
|
|
rempath = pathlib.Path( |
|
@@ -693,6 +694,40 @@ class FileObject(MDBase): |
|
|
def fullname(self): |
|
|
def fullname(self): |
|
|
return os.path.join(self.dir, self.filename) |
|
|
return os.path.join(self.dir, self.filename) |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
def prep_mapping(mapping): |
|
|
|
|
|
r = collections.defaultdict(lambda: []) |
|
|
|
|
|
for lclp, hid, remp in mapping: |
|
|
|
|
|
r[hid].append((pathlib.PosixPath(lclp), |
|
|
|
|
|
pathlib.PosixPath(remp))) |
|
|
|
|
|
|
|
|
|
|
|
return r |
|
|
|
|
|
|
|
|
|
|
|
def get_lcl_name(self, mapping): |
|
|
|
|
|
'''Using mapping (obtained from the object store's |
|
|
|
|
|
get_hostmappings method and passed through local prep_mapping |
|
|
|
|
|
method), try to map the file to a local path. |
|
|
|
|
|
|
|
|
|
|
|
if not possible, returned will be hostid:remotepath. |
|
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
lclhostid = hostuuid() |
|
|
|
|
|
|
|
|
|
|
|
#_debprint('gln:', repr(self), repr(mapping), repr(lclhostid)) |
|
|
|
|
|
|
|
|
|
|
|
if self.hostid == lclhostid: |
|
|
|
|
|
return self.fullname |
|
|
|
|
|
|
|
|
|
|
|
for lclp, remp in mapping[self.hostid]: |
|
|
|
|
|
fname = pathlib.PosixPath(self.fullname) |
|
|
|
|
|
if fname.parts[:len(remp.parts)] == remp.parts: |
|
|
|
|
|
return pathlib.Path( |
|
|
|
|
|
*lclp.parts + |
|
|
|
|
|
fname.parts[len( |
|
|
|
|
|
remp.parts):]) |
|
|
|
|
|
else: |
|
|
|
|
|
return str(self.hostid) + ':' + self.fullname |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def make_id(fname, hostid=None): |
|
|
def make_id(fname, hostid=None): |
|
|
'''Take a local file name, and make the id for it. Note that |
|
|
'''Take a local file name, and make the id for it. Note that |
|
@@ -957,9 +992,9 @@ def cmd_mapping(options, persona, objstr, cache): |
|
|
parts = [ x.split(':', 1) for x in options.mapping ] |
|
|
parts = [ x.split(':', 1) for x in options.mapping ] |
|
|
|
|
|
|
|
|
if len(parts[0]) == 1: |
|
|
if len(parts[0]) == 1: |
|
|
parts[0] = [ hostuuid(), parts[0][0] ] |
|
|
|
|
|
|
|
|
parts[0] = [ str(hostuuid()), parts[0][0] ] |
|
|
|
|
|
|
|
|
if parts[0][0] == hostuuid(): |
|
|
|
|
|
|
|
|
if parts[0][0] == str(hostuuid()): |
|
|
parts[0][1] = str(pathlib.Path(parts[0][1]).resolve()) |
|
|
parts[0][1] = str(pathlib.Path(parts[0][1]).resolve()) |
|
|
|
|
|
|
|
|
if parts[1][1][0] != '/': |
|
|
if parts[1][1][0] != '/': |
|
@@ -1478,7 +1513,8 @@ def cmd_search(options, persona, objstr, cache): |
|
|
r = ( x for x in objstr if x.type == 'file' and testfun(x) ) |
|
|
r = ( x for x in objstr if x.type == 'file' and testfun(x) ) |
|
|
|
|
|
|
|
|
if _type == 'file': |
|
|
if _type == 'file': |
|
|
r = ( x.fullname for x in r ) |
|
|
|
|
|
|
|
|
mapping = FileObject.prep_mapping(objstr.get_hostmappings()) |
|
|
|
|
|
r = ( x.get_lcl_name(mapping) for x in r ) |
|
|
else: |
|
|
else: |
|
|
raise ValueError('unhandled type: %s' % repr(_type)) |
|
|
raise ValueError('unhandled type: %s' % repr(_type)) |
|
|
|
|
|
|
|
@@ -2230,7 +2266,7 @@ class _TestCases(unittest.TestCase): |
|
|
self.assertEqual(objcnt, cmd['count']) |
|
|
self.assertEqual(objcnt, cmd['count']) |
|
|
elif special == 'set hostid': |
|
|
elif special == 'set hostid': |
|
|
hostidpatch = mock.patch(__name__ + '.hostuuid') |
|
|
hostidpatch = mock.patch(__name__ + '.hostuuid') |
|
|
hid = cmd['hostid'] if 'hostid' in cmd else uuid.uuid4() |
|
|
|
|
|
|
|
|
hid = uuid.UUID(cmd['hostid']) if 'hostid' in cmd else uuid.uuid4() |
|
|
hostidpatch.start().return_value = hid |
|
|
hostidpatch.start().return_value = hid |
|
|
patches.append(hostidpatch) |
|
|
patches.append(hostidpatch) |
|
|
elif special == 'iter is unique': |
|
|
elif special == 'iter is unique': |
|
|