|
@@ -30,6 +30,7 @@ import pathlib |
|
|
import pasn1 |
|
|
import pasn1 |
|
|
import re |
|
|
import re |
|
|
import shutil |
|
|
import shutil |
|
|
|
|
|
import socket |
|
|
import string |
|
|
import string |
|
|
import sys |
|
|
import sys |
|
|
import tempfile |
|
|
import tempfile |
|
@@ -327,6 +328,11 @@ class Persona(object): |
|
|
|
|
|
|
|
|
self._created_by_ref = self._identity.uuid |
|
|
self._created_by_ref = self._identity.uuid |
|
|
|
|
|
|
|
|
|
|
|
def Host(self, *args, **kwargs): |
|
|
|
|
|
kwargs['created_by_ref'] = self.uuid |
|
|
|
|
|
|
|
|
|
|
|
return self.sign(Host(*args, **kwargs)) |
|
|
|
|
|
|
|
|
def Container(self, *args, **kwargs): |
|
|
def Container(self, *args, **kwargs): |
|
|
kwargs['created_by_ref'] = self.uuid |
|
|
kwargs['created_by_ref'] = self.uuid |
|
|
|
|
|
|
|
@@ -471,6 +477,13 @@ class ObjectStore(object): |
|
|
self._created_by_ref = created_by_ref |
|
|
self._created_by_ref = created_by_ref |
|
|
self._uuids = {} |
|
|
self._uuids = {} |
|
|
self._hashes = {} |
|
|
self._hashes = {} |
|
|
|
|
|
self._hostuuids = {} |
|
|
|
|
|
|
|
|
|
|
|
def get_host(self, hostuuid): |
|
|
|
|
|
return self._hostuuids[hostuuid] |
|
|
|
|
|
|
|
|
|
|
|
def get_hosts(self): |
|
|
|
|
|
return self._hostuuids.values() |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def makehash(hashstr, strict=True): |
|
|
def makehash(hashstr, strict=True): |
|
@@ -553,10 +566,18 @@ class ObjectStore(object): |
|
|
self._uuids[_makeuuid(obj.id)] = obj |
|
|
self._uuids[_makeuuid(obj.id)] = obj |
|
|
elif obj.type == 'container': |
|
|
elif obj.type == 'container': |
|
|
self._uuids[obj.make_id(obj.uri)] = obj |
|
|
self._uuids[obj.make_id(obj.uri)] = obj |
|
|
|
|
|
elif obj.type == 'host': |
|
|
|
|
|
self._uuids[obj.hostuuid] = obj |
|
|
|
|
|
self._hostuuids[obj.hostuuid] = obj |
|
|
|
|
|
|
|
|
for j in obj.hashes: |
|
|
|
|
|
h = self.makehash(j) |
|
|
|
|
|
self._hashes.setdefault(h, []).append(obj) |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
hashes = obj.hashes |
|
|
|
|
|
except AttributeError: |
|
|
|
|
|
pass |
|
|
|
|
|
else: |
|
|
|
|
|
for j in hashes: |
|
|
|
|
|
h = self.makehash(j) |
|
|
|
|
|
self._hashes.setdefault(h, []).append(obj) |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|
def load(cls, fname): |
|
|
def load(cls, fname): |
|
@@ -679,6 +700,9 @@ def _hashfile(fname): |
|
|
|
|
|
|
|
|
return '%s:%s' % (_defaulthash, hash.hexdigest()) |
|
|
return '%s:%s' % (_defaulthash, hash.hexdigest()) |
|
|
|
|
|
|
|
|
|
|
|
class Host(MDBase): |
|
|
|
|
|
_type = 'host' |
|
|
|
|
|
|
|
|
class FileObject(MDBase): |
|
|
class FileObject(MDBase): |
|
|
_type = 'file' |
|
|
_type = 'file' |
|
|
|
|
|
|
|
@@ -892,6 +916,32 @@ def cmd_modify(options): |
|
|
|
|
|
|
|
|
write_objstore(options, objstr) |
|
|
write_objstore(options, objstr) |
|
|
|
|
|
|
|
|
|
|
|
def printhost(host): |
|
|
|
|
|
print('%s\t%s' % (host.name, host.hostuuid)) |
|
|
|
|
|
|
|
|
|
|
|
def cmd_hosts(options): |
|
|
|
|
|
persona, objstr = get_objstore(options) |
|
|
|
|
|
|
|
|
|
|
|
selfuuid = hostuuid() |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
host = objstr.get_host(selfuuid) |
|
|
|
|
|
except KeyError: |
|
|
|
|
|
host = persona.Host(name=socket.gethostname(), hostuuid=selfuuid) |
|
|
|
|
|
objstr.loadobj(host) |
|
|
|
|
|
|
|
|
|
|
|
printhost(host) |
|
|
|
|
|
|
|
|
|
|
|
hosts = objstr.get_hosts() |
|
|
|
|
|
|
|
|
|
|
|
for i in hosts: |
|
|
|
|
|
if i is host: |
|
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
printhost(i) |
|
|
|
|
|
|
|
|
|
|
|
write_objstore(options, objstr) |
|
|
|
|
|
|
|
|
def cmd_dump(options): |
|
|
def cmd_dump(options): |
|
|
persona, objstr = get_objstore(options) |
|
|
persona, objstr = get_objstore(options) |
|
|
|
|
|
|
|
@@ -1096,6 +1146,9 @@ def main(): |
|
|
help='files to modify') |
|
|
help='files to modify') |
|
|
parser_container.set_defaults(func=cmd_container) |
|
|
parser_container.set_defaults(func=cmd_container) |
|
|
|
|
|
|
|
|
|
|
|
parser_hosts = subparsers.add_parser('hosts', help='dump all the hosts, self is always first') |
|
|
|
|
|
parser_hosts.set_defaults(func=cmd_hosts) |
|
|
|
|
|
|
|
|
parser_dump = subparsers.add_parser('dump', help='dump all the objects') |
|
|
parser_dump = subparsers.add_parser('dump', help='dump all the objects') |
|
|
parser_dump.set_defaults(func=cmd_dump) |
|
|
parser_dump.set_defaults(func=cmd_dump) |
|
|
|
|
|
|
|
@@ -1597,7 +1650,8 @@ 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') |
|
|
hostidpatch.start().return_value = uuid.uuid4() |
|
|
|
|
|
|
|
|
hid = cmd['hostid'] if 'hostid' in cmd else uuid.uuid4() |
|
|
|
|
|
hostidpatch.start().return_value = hid |
|
|
patches.append(hostidpatch) |
|
|
patches.append(hostidpatch) |
|
|
elif special == 'iter is unique': |
|
|
elif special == 'iter is unique': |
|
|
objst = ObjectStore.load(storefname) |
|
|
objst = ObjectStore.load(storefname) |
|
|