summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Snapshots
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Server/Snapshots')
-rw-r--r--src/lib/Server/Snapshots/__init__.py5
-rw-r--r--src/lib/Server/Snapshots/model.py22
2 files changed, 24 insertions, 3 deletions
diff --git a/src/lib/Server/Snapshots/__init__.py b/src/lib/Server/Snapshots/__init__.py
index eb849e715..c13dee42e 100644
--- a/src/lib/Server/Snapshots/__init__.py
+++ b/src/lib/Server/Snapshots/__init__.py
@@ -1,6 +1,9 @@
__all__ = ['models', 'db_from_config', 'setup_session']
-import sqlalchemy, sqlalchemy.orm, ConfigParser
+import sqlalchemy
+import sqlalchemy.orm
+import ConfigParser
+
def db_from_config(fname='/etc/bcfg2.conf'):
cp = ConfigParser.ConfigParser()
diff --git a/src/lib/Server/Snapshots/model.py b/src/lib/Server/Snapshots/model.py
index cd2e617f5..cbb14be79 100644
--- a/src/lib/Server/Snapshots/model.py
+++ b/src/lib/Server/Snapshots/model.py
@@ -1,11 +1,14 @@
-from sqlalchemy import Table, Column, Integer, Unicode, ForeignKey, Boolean, DateTime, UnicodeText, desc
+from sqlalchemy import Table, Column, Integer, Unicode, ForeignKey, Boolean, \
+ DateTime, UnicodeText, desc
import datetime
import sqlalchemy.exceptions
from sqlalchemy.orm import relation, backref
from sqlalchemy.ext.declarative import declarative_base
+
class Uniquer(object):
force_rt = True
+
@classmethod
def by_value(cls, session, **kwargs):
if cls.force_rt:
@@ -22,6 +25,7 @@ class Uniquer(object):
Base = declarative_base()
+
class Administrator(Uniquer, Base):
__tablename__ = 'administrator'
id = Column(Integer, primary_key=True)
@@ -36,6 +40,7 @@ admin_group = Table('admin_group', Base.metadata,
Column('admin_id', Integer, ForeignKey('administrator.id')),
Column('group_id', Integer, ForeignKey('group.id')))
+
class Client(Uniquer, Base):
__tablename__ = 'client'
id = Column(Integer, primary_key=True)
@@ -46,6 +51,7 @@ class Client(Uniquer, Base):
online = Column(Boolean, default=True)
online_ts = Column(DateTime)
+
class Group(Uniquer, Base):
__tablename__ = 'group'
id = Column(Integer, primary_key=True)
@@ -53,6 +59,7 @@ class Group(Uniquer, Base):
admins = relation("Administrator", secondary=admin_group,
backref='groups')
+
class ConnectorKeyVal(Uniquer, Base):
__tablename__ = 'connkeyval'
id = Column(Integer, primary_key=True)
@@ -68,6 +75,7 @@ meta_conn = Table('meta_conn', Base.metadata,
Column('metadata_id', Integer, ForeignKey('metadata.id')),
Column('connkeyval_id', Integer, ForeignKey('connkeyval.id')))
+
class Metadata(Base):
__tablename__ = 'metadata'
id = Column(Integer, primary_key=True)
@@ -96,6 +104,7 @@ class Metadata(Base):
value=unicode(value)))
return m
+
class Package(Base, Uniquer):
__tablename__ = 'package'
id = Column(Integer, primary_key=True)
@@ -104,13 +113,15 @@ class Package(Base, Uniquer):
version = Column(Unicode(16))
verification_status = Column(Boolean)
+
class CorrespondenceType(object):
mtype = Package
+
@classmethod
def from_record(cls, mysession, record):
(mod, corr, name, s_dict, e_dict) = record
if not s_dict:
- start=None
+ start = None
else:
start = cls.mtype.by_value(mysession, name=name, **s_dict)
if s_dict != e_dict:
@@ -119,6 +130,7 @@ class CorrespondenceType(object):
end = start
return cls(start=start, end=end, modified=mod, correct=corr)
+
class PackageCorrespondence(Base, CorrespondenceType):
mtype = Package
__tablename__ = 'package_pair'
@@ -134,6 +146,7 @@ package_snap = Table('package_snap', Base.metadata,
Column('ppair_id', Integer, ForeignKey('package_pair.id')),
Column('snapshot_id', Integer, ForeignKey('snapshot.id')))
+
class Service(Base, Uniquer):
__tablename__ = 'service'
id = Column(Integer, primary_key=True)
@@ -141,6 +154,7 @@ class Service(Base, Uniquer):
type = Column(Unicode(12))
status = Column(Boolean)
+
class ServiceCorrespondence(Base, CorrespondenceType):
mtype = Service
__tablename__ = 'service_pair'
@@ -156,6 +170,7 @@ service_snap = Table('service_snap', Base.metadata,
Column('spair_id', Integer, ForeignKey('service_pair.id')),
Column('snapshot_id', Integer, ForeignKey('snapshot.id')))
+
class File(Base, Uniquer):
__tablename__ = 'file'
id = Column(Integer, primary_key=True)
@@ -166,6 +181,7 @@ class File(Base, Uniquer):
perms = Column(Integer(5))
contents = Column(UnicodeText)
+
class FileCorrespondence(Base, CorrespondenceType):
mtype = File
__tablename__ = 'file_pair'
@@ -193,6 +209,7 @@ extra_service_snap = Table('extra_service_snap', Base.metadata,
Column('service_id', Integer, ForeignKey('service.id')),
Column('snapshot_id', Integer, ForeignKey('snapshot.id')))
+
class Action(Base):
__tablename__ = 'action'
id = Column(Integer, primary_key=True)
@@ -204,6 +221,7 @@ action_snap = Table('action_snap', Base.metadata,
Column('action_id', Integer, ForeignKey('action.id')),
Column('snapshot_id', Integer, ForeignKey('snapshot.id')))
+
class Snapshot(Base):
__tablename__ = 'snapshot'
id = Column(Integer, primary_key=True)