예제 #1
0
 def _configure(self):
     configuration = JsonDict({
         "path": {
             "data": ensureDir(self.stateDir, 'data'),
             "logs": ensureDir(self.stateDir, 'logs'),
             "work": ensureDir(self.stateDir, 'work'), # temporary files
             "conf": self.configDir,
             "plugins": ensureDir(self.stateDir, 'plugins'),
         },
         "cluster":{
             "name": self.name,
         },
         "http":{
             "port": self.port,
         },
         "transport": {
             "tcp": {
                 "port": self.transportPort
             }
         }
     })
     self._configureIndex(configuration)
     if self.identifier:
         configuration.setdefault("node", dict())['name'] = self.identifier
     with open(self.configFile, 'w') as f:
         configuration.dump(f, indent=4, sort_keys=True)
 def testServiceRegistryOldFormat(self):
     uuid1 = str(uuid4())
     uuid2 = str(uuid4())
     with open(join(self.tempdir, 'serviceregistry.json'), 'w') as f:
         d = JsonDict({
                 uuid1: {
                     "ipAddress": "5.153.228.85",
                     "readable": True,
                     "number": 1,
                     "data": {
                         "uptime": 366867,
                         "VERSION": "1.5.12.3"
                     },
                     "writable": True,
                     "lastseen": 1423494771.904539,
                     "type": "holding",
                     "infoport": 35609,
                 },
                 uuid2: {
                     "ipAddress": "5.153.228.85",
                     "readable": True,
                     "number": 1,
                     "data": {
                         "uptime": 366867,
                         "VERSION": "1.5.12.3"
                     },
                     "writable": True,
                     "lastseen": 1423494771.904539,
                     "type": "plein",
                     "infoport": 41609,
                 }
             })
         d.dump(f)
     registry = ServiceRegistry(
         stateDir=self.tempdir,
         domainname='zp.example.org',
         reactor=CallTrace(),
     )
     self.assertEquals(set([uuid1, uuid2]), set(registry.listServices(activeOnly=False).keys()))
예제 #3
0
    def testDump(self):
        jd = JsonDict({'hello': 'world'})
        tempfile = self.tmp_path / 'json.json'
        with open(tempfile, 'w') as f:
            jd.dump(f)
        self.assertEqual('{"hello": "world"}', tempfile.read_text())

        jd['hello'] = 'World'
        jd.dump(str(tempfile))
        self.assertEqual('{"hello": "World"}', tempfile.read_text())

        jd['hello'] = 'World!'
        jd.dump(tempfile)
        self.assertEqual('{"hello": "World!"}', tempfile.read_text())
예제 #4
0
 def testDumpWithFilename(self):
     jd = JsonDict({'hello': 'world'})
     tempfile = join(self.tempdir, 'json.json')
     jd.dump(tempfile)
     self.assertEquals('{"hello": "world"}', open(tempfile).read())
예제 #5
0
 def testDump(self):
     jd = JsonDict({'hello': 'world'})
     tempfile = join(self.tempdir, 'json.json')
     with open(tempfile, 'w') as f:
         jd.dump(f)
     self.assertEquals('{"hello": "world"}', open(tempfile).read())
예제 #6
0
 def testDumpWithFilename(self):
     jd = JsonDict({'hello': 'world'})
     tempfile = join(self.tempdir, 'json.json')
     jd.dump(tempfile)
     self.assertEquals('{"hello": "world"}', open(tempfile).read())
예제 #7
0
 def testDump(self):
     jd = JsonDict({'hello': 'world'})
     tempfile = join(self.tempdir, 'json.json')
     with open(tempfile, 'w') as f:
         jd.dump(f)
     self.assertEquals('{"hello": "world"}', open(tempfile).read())
예제 #8
0
class Group(object):
    def __init__(self, stateDir, identifier):
        self._filepath = join(stateDir, identifier + '.group')
        self.exists = isfile(self._filepath)
        self._data = JsonDict(identifier=identifier)
        if self.exists:
            self._data = JsonDict.load(self._filepath)

    @property
    def identifier(self):
        return self._data['identifier']

    def save(self):
        self._data.dump(self._filepath)
        return self

    @property
    def usernames(self):
        return self._data.get('usernames', [])

    def addUsername(self, name):
        self._data.setdefault('usernames', []).append(name)
        return self.save()

    def removeUsername(self, name):
        self._data['usernames'] = [u for u in self.usernames if u != name]
        return self.save()

    @property
    def domainIds(self):
        return self._data.get('domainIds', [])

    def addDomainId(self, domainId):
        self._data.setdefault('domainIds', []).append(domainId)
        return self.save()

    def removeDomainId(self, domainId):
        self._data['domainIds'] = [d for d in self.domainIds if d != domainId]
        return self.save()

    @property
    def groupInfo(self):
        return self._data.get('info', {})

    def updateGroupInfo(self, data):
        cur = self.groupInfo
        cur.update(data)
        return self.setGroupInfo(cur)

    def setGroupInfo(self, data):
        self._data['info'] = data
        return self.save()

    def _groupInfo(name, default=None):
        return lambda s: s.groupInfo.get(name, default)

    def _setGroupInfo(name, fn=lambda x: x):
        return lambda s, v: s.updateGroupInfo({name: fn(v)})

    adminGroup = property(_groupInfo('adminGroup', False),
                          _setGroupInfo('adminGroup', bool))
    name = property(_groupInfo('name', ''), _setGroupInfo('name'))
    logoUrl = property(_groupInfo('logoUrl'), _setGroupInfo('logoUrl'))

    def setName(self, name):
        self.name = name
        return self