예제 #1
0
 def upgrade(self):
     if not os.path.exists(self.dbfile):
         raise errors.StorageError(
             'Unable to perform db upgrade, can\'t find a dbfile')
     self.db = adbapi.ConnectionPool('sqlite3',
                                     self.dbfile,
                                     check_same_thread=False)
     version = yield self.getVersion()
     version = str(version)
     if version == '1':
         yield self._upgrade1to2()
     elif version == '2':
         pass
     else:
         raise errors.StorageError('unknown storage version %s' % (version))
     defer.returnValue(True)
예제 #2
0
 def _parseReadData(self, dtype, data):
     if dtype == 'pickle':
         data = pickle.loads(str(data))
     else:
         raise errors.StorageError(
             'unknown data type "%s" while reading node data' % (dtype))
     return data
예제 #3
0
def load(storage_type, *args, **kwargs):
    if storage_type == 'stsqlite':
        return stsqlite.Storage(*args, **kwargs)
    elif storage_type == 'stmysql':
        return stmysql.Storage(*args, **kwargs)
    else:
        raise errors.StorageError('invalid storage backend')
예제 #4
0
 def addOID(self, parent_oid, oid, class_id, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     q = """insert into idmap (parent_oid, oid, class_id) values (%s, %s, %s)"""
     if txn:
         return self.txndbrun(txn, q, (parent_oid, oid, class_id))
     else:
         return self.runOperation(q, (parent_oid, oid, class_id))
예제 #5
0
 def disassociate(self, self_oid, other_oid, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     q = """delete from associations where self_oid = %s and other_oid = %s"""
     if txn:
         return self.txndbrun(txn, q, (self_oid, other_oid))
     else:
         return self.runOperation(q, (self_oid, other_oid))
예제 #6
0
 def removeOID(self, oid, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     if txn:
         ret = self._txnRemoveOID(txn, oid)
     else:
         ret = yield self._removeOID(oid)
     defer.returnValue(ret)
예제 #7
0
 def relocate(self, self_oid, new_parent_oid, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     q = """update idmap set parent_oid = %s where oid = %s"""
     if txn:
         return self.txndbrun(txn, q, (new_parent_oid, self_oid))
     else:
         return self.runOperation(q, (new_parent_oid, self_oid))
예제 #8
0
 def setVersion(self, version):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     q = """delete from version"""
     yield self.runOperation(q)
     q = """insert into version (version) values (%s)"""
     yield self.runOperation(q, (version, ))
     defer.returnValue(True)
예제 #9
0
 def associate(self, self_oid, other_oid, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     q = """insert into associations (self_oid, other_oid) values (%s, %s)"""
     if txn:
         return self.txndbrun(txn, q, (self_oid, other_oid))
     else:
         return self.runOperation(q, (self_oid, other_oid))
예제 #10
0
 def disassociate(self, self_oid, other_oid, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     if txn:
         op = txn.execute
     else:
         op = self.db.runOperation
     q = """delete from associations where self_oid = ? and other_oid = ?"""
     return op(q, (self_oid, other_oid))
예제 #11
0
 def removeData(self, oid, name):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     if txn:
         op = txn.execute
     else:
         op = self.db.runOperation
     q = """delete from nodedata where oid=? and name=?"""
     return op(q, (oid, name), commit=True, write_lock=True)
예제 #12
0
 def addOID(self, parent_oid, oid, class_id, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     if txn:
         op = txn.execute
     else:
         op = self.db.runOperation
     q = """insert into idmap (parent_oid, oid, class_id) values (?, ?, ?)"""
     return op(q, (parent_oid, oid, class_id))
예제 #13
0
 def associate(self, self_oid, other_oid, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     if txn:
         op = txn.execute
     else:
         op = self.db.runOperation
     q = """insert into associations (self_oid, other_oid) values (?, ?)"""
     return op(q, (self_oid, other_oid))
예제 #14
0
 def relocate(self, self_oid, new_parent_oid, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     if txn:
         op = txn.execute
     else:
         op = self.db.runOperation
     q = """update idmap set parent_oid = ? where oid = ?"""
     return op(q, (new_parent_oid, self_oid))
예제 #15
0
 def writeData(self, oid, name, data, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     dtype = 'pickle'
     data = pickle.dumps(data)
     qargs = (oid, name, dtype, data)
     q = """replace into nodedata (oid, name, datatype, data) values (%s, %s, %s, %s)"""
     if txn:
         return self.txndbrun(txn, q, qargs)
     else:
         return self.runOperation(q, qargs)
예제 #16
0
 def removeData(self, oid, name):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     q = """delete from nodedata where oid=%s and name=%s"""
     if txn:
         return self.txndbrun(txn,
                              q, (oid, name),
                              commit=True,
                              write_lock=True)
     else:
         return self.runOperation(q, (oid, name),
                                  commit=True,
                                  write_lock=True)
예제 #17
0
 def writeData(self, oid, name, data, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     if txn:
         op = txn.execute
     else:
         op = self.db.runOperation
     dtype = 'pickle'
     data = pickle.dumps(data)
     data = sqlite.Binary(data)
     qargs = (oid, name, dtype, data)
     q = """replace into nodedata (oid, name, datatype, data) values (?, ?, ?, ?)"""
     return op(q, qargs)
예제 #18
0
 def initialize(self, version):
     needs_init = False
     if not os.path.exists(self.dbfile):
         needs_init = True
     self.db = adbapi.ConnectionPool('sqlite3',
                                     self.dbfile,
                                     check_same_thread=False)
     if needs_init:
         if self.readonly:
             raise errors.StorageError('storage in readonly mode')
         for table in sqltables:
             yield self.db.runOperation(table)
         yield self.setVersion(version)
예제 #19
0
 def removeDeviceConfigData(self, oid, timestamp=None, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     if txn:
         op = txn.execute
     else:
         op = self.db.runOperation
     if timestamp is not None:
         q = """delete from device_config_data where oid = ? and timestamp = ?"""
         yield op(q, (oid, timestamp))
     else:
         q = """delete from device_config_data where oid = ?"""
         yield op(q, (oid, ))
     defer.returnValue(True)
예제 #20
0
 def removeOID(self, oid, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     if txn:
         op = txn.execute
     else:
         op = self.db.runOperation
     q = """delete from idmap where oid = ?"""
     yield op(q, (oid, ))
     q = """delete from nodedata where oid = ?"""
     yield op(q, (oid, ))
     q = """delete from associations where self_oid = ?"""
     yield op(q, (oid, ))
     defer.returnValue(True)
예제 #21
0
 def initialize(self, version):
     self.db = adbapi.ConnectionPool(
         'MySQLdb',
         host=self.db_config.get('mysql', 'hostname'),
         user=self.db_config.get('mysql', 'username'),
         passwd=self.db_config.get('mysql', 'password'),
         db=self.db_config.get('mysql', 'dbname'),
         cp_reconnect=True,
     )
     db_initialized = yield self._checkDBInitialized()
     if not db_initialized:
         if self.readonly:
             raise errors.StorageError('storage in readonly mode')
         for table in sqltables:
             yield self.runOperation(table)
         yield self.setVersion(version)
예제 #22
0
 def upgrade(self):
     self.db = adbapi.ConnectionPool(
         'MySQLdb',
         host=self.db_config.get('mysql', 'hostname'),
         user=self.db_config.get('mysql', 'username'),
         passwd=self.db_config.get('mysql', 'password'),
         db=self.db_config.get('mysql', 'dbname'))
     version = yield self.getVersion()
     version = str(version)
     if version == '1':
         yield self._upgrade1to2()
     elif version == '2':
         pass
     else:
         raise errors.StorageError('unknown storage version %s' % (version))
     defer.returnValue(True)
예제 #23
0
 def removeDeviceConfigData(self, oid, timestamp=None, txn=None):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     ret = None
     if txn:
         if timestamp is not None:
             q = """delete from device_config_data where oid = %s and timestamp = %s"""
             ret = self.txndbrun(txn, op, q, (oid, timestamp))
         else:
             q = """delete from device_config_data where oid = %s"""
             ret = self.txndbrun(txn, op, q, (oid, ))
     else:
         op = self.db.runOperation
         if timestamp is not None:
             q = """delete from device_config_data where oid = %s and timestamp = %s"""
             ret = self.runOperation(q, (oid, timestamp))
         else:
             q = """delete from device_config_data where oid = %s"""
             ret = self.runOperation(q, (oid, ))
     return ret
예제 #24
0
 def addDeviceConfigData(self, oid, data, timestamp):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     q = """insert into device_config_data (oid, data, timestamp) values (%s, %s, %s)"""
     return self.runOperation(q, (oid, data, timestamp))
예제 #25
0
 def addDeviceConfigData(self, oid, data, timestamp):
     if self.readonly:
         raise errors.StorageError('storage in readonly mode')
     q = """insert into device_config_data (oid, data, timestamp) values (?, ?, ?)"""
     op = self.db.runOperation
     return op(q, (oid, sqlite.Binary(data), timestamp))