class RoutingTable(Base): """ Routing table object. """ __tablename__ = 'rt_def' __table_args__ = (Comment('Routing tables'), Index('rt_def_u_name', 'name', unique=True), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_NETS', 'cap_read': 'NETS_LIST', 'cap_create': 'NETS_EDIT', 'cap_edit': 'NETS_EDIT', 'cap_delete': 'NETS_EDIT', 'menu_name': _('Routing Tables'), 'show_in_menu': 'admin', 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('rtid', 'name'), 'grid_hidden': ('rtid', ), 'form_view': ('name', ), 'easy_search': ('name', ), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new routing table')) } }) id = Column('rtid', UInt32(), Sequence('rt_def_rtid_seq'), Comment('Routing table ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) name = Column(Unicode(255), Comment('Routing table name'), nullable=False, info={ 'header_string': _('Name'), 'column_flex': 1 }) entries = relationship('RoutingTableEntry', backref=backref('table', innerjoin=True), cascade='all, delete-orphan', passive_deletes=True) def __str__(self): return str(self.name)
class HouseGroupMapping(Base): """ Mapping between houses and house groups. """ __tablename__ = 'addr_hgroups_houses' __table_args__ = ( Comment('House group memberships'), Index('addr_hgroups_houses_u_member', 'ahgid', 'houseid', unique=True), Index('addr_hgroups_houses_i_houseid', 'houseid'), { 'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8', 'info' : { 'menu_name' : _('House Groups'), 'cap_menu' : 'BASE_GEO', 'cap_read' : 'GEO_LIST', 'cap_create' : 'GEO_CREATE', 'cap_edit' : 'GEO_EDIT', 'cap_delete' : 'GEO_DELETE', 'default_sort' : (), 'grid_view' : ('group', 'house'), 'detail_pane' : ('netprofile_core.views', 'dpane_simple') } } ) id = Column( 'ahghid', UInt32(), Sequence('addr_hgroups_houses_ahghid_seq'), Comment('House group membership ID'), primary_key=True, nullable=False, info={ 'header_string' : _('ID') } ) group_id = Column( 'ahgid', UInt32(), ForeignKey('addr_hgroups_def.ahgid', name='addr_hgroups_houses_fk_ahgid', ondelete='CASCADE', onupdate='CASCADE'), Comment('House group ID'), nullable=False, info={ 'header_string' : _('Group') } ) house_id = Column( 'houseid', UInt32(), ForeignKey('addr_houses.houseid', name='addr_hgroups_houses_fk_houseid', ondelete='CASCADE', onupdate='CASCADE'), Comment('House ID'), nullable=False, info={ 'header_string' : _('House') } )
class PDNSCryptokey(Base): """ PowerDNS Cryptokey """ __tablename__ = 'pdns_cryptokeys' __table_args__ = ( Comment('PowerDNS Cryptokeys'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_DOMAINS', # 'cap_read' : 'DOMAINS_LIST', # 'cap_create' : 'DOMAINS_CREATE', # 'cap_edit' : 'DOMAINS_EDIT', # 'cap_delete' : 'DOMAINS_DELETE', 'menu_name': _('PowerDNS Cryptokeys'), 'show_in_menu': 'modules', 'menu_order': 30, 'default_sort': ({ 'property': 'ip', 'direction': 'ASC' }, ), 'grid_view': ('domain_id', 'flags', 'active', 'content'), 'easy_search': ('domain_id', 'flags', 'active', 'content'), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new cryptokey')) } }) id = Column('id', UInt16(), Comment('Cryptokey ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) domain_id = Column('domain_id', UInt16(), Comment('Domain ID'), ForeignKey('pdns_domains.id', name='pdns_cryptokeys_fk_domain_id'), nullable=False, info={'header_string': _('Domain ID')}) flags = Column('flags', UInt16(), Comment('Flags'), nullable=False, info={'header_string': _('Flags')}) active = Column('active', UInt8(), nullable=True, default=None, info={'header_string': _('Active')}) content = Column('content', UnicodeText(), nullable=False, info={'header_string': _('Content')}) def __str__(self): return '%s:%s' % (self.domain_id, self.content)
class UserDomain(Base): """ A Domain-User Relation object. """ __tablename__ = 'userdomains' __table_args__ = ( Comment('User Domains'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_DOMAINS', # 'cap_read' : 'DOMAINS_LIST', # 'cap_create' : 'DOMAINS_CREATE', # 'cap_edit' : 'DOMAINS_EDIT', # 'cap_delete' : 'DOMAINS_DELETE', 'show_in_menu': 'modules', 'menu_name': _('User Domains'), 'menu_order': 50, 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('accessuser', 'domainname'), 'form_view': ('accessuser', 'domainname'), 'easy_search': ('domain', 'accessuser'), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new user-domain relation')) } }) id = Column('id', UInt32(), Sequence('domains_def_domainid_seq'), Comment('Domain Name ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) accessuser = Column('accessuserid', UInt32(), ForeignKey('entities_access.entityid', name='userdomains_fk_accessuserid', onupdate='CASCADE'), Comment('Access Entity ID'), nullable=False, info={'header_string': _('User')}) domainname = Column('domainname', Unicode(255), Comment('Domain name'), nullable=False, info={'header_string': _('Domain Name')}) def __str__(self): return '%s:%s' % str(self.domainname, self.accessuser)
class PDNSSupermaster(Base): """ PowerDNS Supermaster Record """ __tablename__ = 'pdns_supermasters' __table_args__ = ( Comment('PowerDNS Supermaster record'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_DOMAINS', # 'cap_read' : 'DOMAINS_LIST', # 'cap_create' : 'DOMAINS_CREATE', # 'cap_edit' : 'DOMAINS_EDIT', # 'cap_delete' : 'DOMAINS_DELETE', 'menu_name': _('PowerDNS Supermaster Record'), 'show_in_menu': 'modules', 'menu_order': 30, 'default_sort': ({ 'property': 'ip', 'direction': 'ASC' }, ), 'grid_view': ('ip', 'nameserver'), 'easy_search': ('ip', 'nameserver'), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new DNS supermaster record')) } }) id = Column('id', UInt16(), Comment('Supermaster ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) ip = Column('ip', Unicode(64), Comment('IP Address'), nullable=False, info={'header_string': _('IP Address')}) nameserver = Column('nameserver', Unicode(255), Comment('Nameserver'), nullable=False, info={'header_string': _('Nameserver')}) account = Column('account', Unicode(40), Comment('Account'), nullable=True, default=None, info={'header_string': _('Account')}) def __str__(self): return "%s:%s" % (self.ip, self.nameserver)
class PDNSTsigkey(Base): """ PowerDNS TSIG shared secrets """ __tablename__ = 'pdns_tsigkeys' __table_args__ = ( Comment('PowerDNS TSIG shared secrets'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_DOMAINS', # 'cap_read' : 'DOMAINS_LIST', # 'cap_create' : 'DOMAINS_CREATE', # 'cap_edit' : 'DOMAINS_EDIT', # 'cap_delete' : 'DOMAINS_DELETE', # 'menu_name' : _('TSIG Shared Secrets'), 'show_in_menu': 'modules', 'menu_order': 30, 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('name', 'algorithm', 'secret'), 'easy_search': ('name', 'algorithm', 'secret'), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new TSIG shared secret')) } }) id = Column('id', UInt16(), Comment('Secret ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) name = Column('name', Unicode(255), Comment('Shared secret name'), nullable=True, default=None, info={'header_string': _('Name')}) algorithm = Column('algorithm', Unicode(50), nullable=True, default=None, info={'header_string': _('Algorithm')}) secret = Column('secret', Unicode(255), nullable=True, default=None, info={'header_string': _('Secret')}) def __str__(self): return self.name
class PDNSTemplateType(Base): """ PowerDNS Service Template Typeclass """ __tablename__ = 'pdns_templatetypes' __table_args__ = ( Comment('PowerDNS Template Types'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_DOMAINS', # 'cap_read' : 'DOMAINS_LIST', # 'cap_create' : 'DOMAINS_CREATE', # 'cap_edit' : 'DOMAINS_EDIT', # 'cap_delete' : 'DOMAINS_DELETE', 'show_in_menu': 'admin', 'menu_name': _('PDNS Template Types'), 'menu_order': 50, 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('name', 'descr'), 'form_view': ('name', 'descr'), 'easy_search': ('name', ), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new template type')) } }) id = Column('id', UInt32(), Sequence('pdns_templatetypes_templateid_seq'), Comment('Template Type ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) name = Column('name', Unicode(255), Comment('Template Type'), nullable=False, info={'header_string': _('Template Type')}) descr = Column('descr', UnicodeText(), Comment('Description'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Description')}) fields = association_proxy('template_fields', 'field') def __str__(self): return self.name
class PDNSTemplate(Base): """ PDNS Association table for both template and field types """ __tablename__ = 'pdns_templates' __table_args__ = ( Comment('PowerDNS Template-Field Association Table'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_DOMAINS', # 'cap_read' : 'DOMAINS_LIST', # 'cap_create' : 'DOMAINS_CREATE', # 'cap_edit' : 'DOMAINS_EDIT', # 'cap_delete' : 'DOMAINS_DELETE', 'show_in_menu': 'admin', 'menu_name': _('PDNS Templates'), 'menu_order': 50, 'grid_view': ('template', 'field', 'defaultvalues'), 'form_view': ('template', 'field', 'defaultvalues'), 'easy_search': ('template', ), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': Wizard(Step( 'template', 'field', id='generic', title=_('Add new template'), on_submit=_wizcb_pdnstemplate_submit('PDNSTemplate')), title=_('New domain template'), validator='CreateDomainTemplate') } }) id = Column('relationid', UInt32(), Sequence('pdns_templates_relationid_seq'), Comment('ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) templateid = Column('templ_id', UInt32(), ForeignKey('pdns_templatetypes.id'), info={'header_string': _('Template')}) fieldid = Column('field_id', UInt32(), ForeignKey('pdns_recordtypes.id'), info={ 'header_string': _('Record'), 'editor_xtype': 'gridfield' }) defaultvalues = Column('defvalues', Unicode(255), Comment('Default Values'), nullable=True, default=None, info={'header_string': _('Default Values')}) template = relationship("PDNSTemplateType", backref=backref('template_fields', cascade="all, delete-orphan")) field = relationship("PDNSFieldType") def __str__(self): return '%s %s Record' % (self.template.name, self.field.name)
class Currency(Base): """ Stash currency object. """ __tablename__ = 'currencies_def' __table_args__ = ( Comment('Currencies'), Index('currencies_def_u_name', 'name', unique=True), Index('currencies_def_u_code', 'code', unique=True), { 'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8', 'info' : { 'cap_menu' : 'BASE_STASHES', 'cap_read' : 'STASHES_LIST', 'cap_create' : 'STASHES_CURRENCIES_CREATE', 'cap_edit' : 'STASHES_CURRENCIES_EDIT', 'cap_delete' : 'STASHES_CURRENCIES_DELETE', 'menu_name' : _('Currencies'), 'show_in_menu' : 'admin', 'default_sort' : ({ 'property': 'name', 'direction': 'ASC' },), 'grid_view' : ('currid', 'name', 'code'), 'grid_hidden' : ('currid',), 'form_view' : ( 'name', 'code', 'prefix', 'suffix', 'xchange_rate', 'xchange_from', 'xchange_to', 'convert_from', 'convert_to', 'allow_credit', 'allow_accounts', 'allow_services', 'allow_futures', 'oper_visible', 'user_visible', 'descr' ), 'easy_search' : ('name', 'code', 'prefix', 'suffix'), 'detail_pane' : ('netprofile_core.views', 'dpane_simple'), 'create_wizard' : SimpleWizard(title=_('Add new currency')) } } ) id = Column( 'currid', UInt32(), Sequence('currencies_def_currid_seq'), Comment('Currency ID'), primary_key=True, nullable=False, info={ 'header_string' : _('ID') } ) name = Column( Unicode(255), Comment('Currency name'), nullable=False, info={ 'header_string' : _('Name'), 'column_flex' : 3 } ) code = Column( CHAR(3), Comment('ISO 4217 currency code'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Code') } ) prefix = Column( Unicode(16), Comment('Currency symbol prefix'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Prefix') } ) suffix = Column( Unicode(16), Comment('Currency symbol suffix'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Suffix') } ) exchange_rate = Column( 'xchange_rate', Money(), Comment('Fallback exchange rate with default currency'), nullable=False, default=1, server_default=text('1'), info={ 'header_string' : _('Exchange Rate') } ) can_exchange_from = Column( 'xchange_from', NPBoolean(), Comment('Can exchange from this currency'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Exchange From') } ) can_exchange_to = Column( 'xchange_to', NPBoolean(), Comment('Can exchange to this currency'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Exchange To') } ) can_convert_from = Column( 'convert_from', NPBoolean(), Comment('Allow converting stashes from this currency'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Convert From') } ) can_convert_to = Column( 'convert_to', NPBoolean(), Comment('Allow converting stashes to this currency'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Convert To') } ) allow_credit = Column( NPBoolean(), Comment('Allow crediting with this currency'), nullable=False, default=True, server_default=npbool(True), info={ 'header_string' : _('Crediting') } ) allow_accounts = Column( NPBoolean(), Comment('Allow linking accounts to stashes with this currency'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Allow Accounts') } ) allow_services = Column( NPBoolean(), Comment('Allow linking paid services to stashes with this currency'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Allow Paid Services') } ) allow_futures = Column( NPBoolean(), Comment('Allow promised payments to stashes with this currency'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Allow Promised Payments') } ) visible_to_operator = Column( 'oper_visible', NPBoolean(), Comment('Visibility in operator interface'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Visible to Operator') } ) visible_to_user = Column( 'user_visible', NPBoolean(), Comment('Visibility in user interface'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Visible to User') } ) description = Column( 'descr', UnicodeText(), Comment('Currency description'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Description') } ) def __str__(self): return str(self.name) def format(self, req, amount): return money_format(req, amount, code=self.code, prefix=self.prefix, suffix=self.suffix) def format_long(self, req, amount): return money_format_long(req, amount, code=self.code)
class StashIOType(Base): """ Stash I/O operation type object. """ __tablename__ = 'stashes_io_types' __table_args__ = ( Comment('Stashes input/output operation types'), Index('stashes_io_types_i_type', 'type'), Index('stashes_io_types_u_ftype', 'ftype', unique=True), Index('stashes_io_types_i_oper_visible', 'oper_visible'), Index('stashes_io_types_i_user_visible', 'user_visible'), Index('stashes_io_types_i_oper_cap', 'oper_cap'), { 'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8', 'info' : { 'cap_menu' : 'BASE_STASHES', 'cap_read' : 'STASHES_IO', 'cap_create' : 'STASHES_IOTYPES_CREATE', 'cap_edit' : 'STASHES_IOTYPES_EDIT', 'cap_delete' : 'STASHES_IOTYPES_DELETE', 'menu_name' : _('Operation Types'), 'show_in_menu' : 'admin', 'default_sort' : ({ 'property': 'name', 'direction': 'ASC' },), 'grid_view' : ('name', 'class', 'type'), 'form_view' : ('name', 'class', 'type', 'ftype', 'user_visible', 'oper_visible', 'oper_capability', 'pays_futures', 'descr'), 'easy_search' : ('name',), 'detail_pane' : ('netprofile_core.views', 'dpane_simple'), 'create_wizard' : SimpleWizard(title=_('Add new operation type')) } } ) id = Column( 'siotypeid', UInt32(), Sequence('stashes_io_types_siotypeid_seq', start=101, increment=1), Comment('Stash I/O ID'), primary_key=True, nullable=False, info={ 'header_string' : _('ID') } ) name = Column( Unicode(255), Comment('Stash I/O name'), nullable=False, info={ 'header_string' : _('Name'), 'column_flex' : 1 } ) io_class = Column( 'class', OperationClass.db_type(), Comment('Stash I/O class'), nullable=False, default=OperationClass.system, server_default=OperationClass.system, info={ 'header_string' : _('Class') } ) type = Column( IOOperationType.db_type(), Comment('Stash I/O type'), nullable=False, default=IOOperationType.bidirectional, server_default=IOOperationType.bidirectional, info={ 'header_string' : _('Type') } ) function_type = Column( 'ftype', IOFunctionType.db_type(), Comment('Special built-in function for this I/O type'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Function') } ) visible_to_operator = Column( 'oper_visible', NPBoolean(), Comment('Visibility in operator interface'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Visible to Operator') } ) visible_to_user = Column( 'user_visible', NPBoolean(), Comment('Visibility in user interface'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Visible to User') } ) fulfills_futures = Column( 'pays_futures', NPBoolean(), Comment('Serves as a fulfillment for promised payments'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Counts for promised payments') } ) oper_capability_code = Column( 'oper_cap', ASCIIString(48), Comment('Stash I/O required operator capability'), ForeignKey('privileges.code', name='stashes_io_types_fk_oper_cap', onupdate='CASCADE', ondelete='SET NULL'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Required Operator Capability') } ) description = Column( 'descr', UnicodeText(), Comment('Stash I/O description'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Description') } ) oper_capability = relationship( 'Privilege', backref=backref( 'stash_io_types', passive_deletes=True ), lazy='joined' ) def __str__(self): if self.io_class == OperationClass.system: req = getattr(self, '__req__', None) if req: return req.localizer.translate(_(self.name)) return str(self.name)
class PDNSRecord(Base): """ PowerDNS DNS Record """ __tablename__ = 'pdns_records' __table_args__ = ( Comment('PowerDNS DNS Record'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_DOMAINS', # 'cap_read' : 'DOMAINS_LIST', # 'cap_create' : 'DOMAINS_CREATE', # 'cap_edit' : 'DOMAINS_EDIT', # 'cap_delete' : 'DOMAINS_DELETE', 'menu_name': _('PowerDNS DNS Records'), 'show_in_menu': 'modules', 'menu_order': 30, 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('name', 'domain', 'rtype', 'content', 'ttl', 'prio', 'change_date', 'ordername'), 'easy_search': ('name', ), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new DNS record')) } }) id = Column('id', UInt16(), Comment('Domain ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) domain_id = Column('domain_id', UInt16(), Comment('Domain ID'), ForeignKey('pdns_domains.id', name='pdns_records_fk_domain_id', ondelete='CASCADE', onupdate='CASCADE'), nullable=False, info={'header_string': _('Domain ID')}) name = Column('name', Unicode(255), Comment('Name'), nullable=True, default=None, info={'header_string': _('Name')}) rtype = Column('type', Unicode(10), Comment('Record Type'), nullable=True, default=None, info={'header_string': _('Record Type')}) content = Column('content', UnicodeText(), Comment('Content'), nullable=True, default=None, info={'header_string': _('Content')}) ttl = Column('ttl', UInt32(), Comment('TTL'), nullable=True, default=None, info={'header_string': _('TTL')}) prio = Column('prio', UInt32(), Comment('Priority'), nullable=True, default=None, info={'header_string': _('Priority')}) change_date = Column('change_date', TIMESTAMP(), Comment('Change Date Timestamp'), nullable=True, default=None, info={'header_string': _('Change Date')}) disabled = Column('disabled', TINYINT(1), Comment('Disabled Flag'), nullable=False, default=0, info={'header_string': _('Disabled')}) ordername = Column('ordername', Unicode(255), Comment('Order Name'), nullable=True, default=None, info={'header_string': _('Order Name')}) auth = Column('auth', TINYINT(1), Comment('Authoritative Zone Flag'), nullable=False, default=1, info={'header_string': _('Authoritative Zone Flag')}) domain = relationship('PDNSDomain', innerjoin=True, backref=backref('records', cascade='all, delete-orphan', passive_deletes=True)) def __str__(self): return ("{0} {1} {2} {3}".format(self.name, self.rtype, self.content, self.ttl))
class ServerType(Base): """ Server type definition. """ __tablename__ = 'srv_types' __table_args__ = ( Comment('Server types'), Index('srv_types_u_name', 'name', unique=True), { 'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8', 'info' : { 'cap_menu' : 'BASE_ADMIN', 'cap_read' : 'SRV_LIST', 'cap_create' : 'SRVTYPES_CREATE', 'cap_edit' : 'SRVTYPES_EDIT', 'cap_delete' : 'SRVTYPES_DELETE', 'show_in_menu' : 'admin', 'menu_name' : _('Server Types'), 'default_sort' : ({ 'property': 'name' ,'direction': 'ASC' },), 'grid_view' : ('srvtypeid', 'name'), 'grid_hidden' : ('srvtypeid',), 'form_view' : ('name', 'descr'), 'easy_search' : ('name',), 'detail_pane' : ('netprofile_core.views', 'dpane_simple'), 'create_wizard' : SimpleWizard(title=_('Add new server type')) } } ) id = Column( 'srvtypeid', UInt32(), Sequence('srv_types_srvtypeid_seq', start=101, increment=1), Comment('Server type ID'), primary_key=True, nullable=False, info={ 'header_string' : _('ID') } ) name = Column( Unicode(255), Comment('Server type name'), nullable=False, info={ 'header_string' : _('Name'), 'column_flex' : 1 } ) generator_name = Column( 'gen', ASCIIString(64), Comment('Registered generator class name'), nullable=False, info={ 'header_string' : _('Class') } ) parameter_defaults = Column( 'paramdef', PickleType(), Comment('Dictionary of parameter defaults'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Defaults') } ) description = Column( 'descr', UnicodeText(), Comment('Server type description'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Description') } ) servers = relationship( 'Server', backref=backref('type', innerjoin=True) ) hosts = association_proxy( 'servers', 'host', creator=lambda v: Server(host=v) ) def __str__(self): return '%s' % str(self.name)
class ServerParameter(Base): """ Parameter of a server instance object. """ __tablename__ = 'srv_params' __table_args__ = ( Comment('Server parameters'), Index('srv_params_u_param', 'srvid', 'name', unique=True), Index('srv_params_i_name', 'name'), { 'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8', 'info' : { 'cap_menu' : 'BASE_ADMIN', 'cap_read' : 'SRV_LIST', 'cap_create' : 'SRV_EDIT', 'cap_edit' : 'SRV_EDIT', 'cap_delete' : 'SRV_EDIT', 'menu_name' : _('Server Parameters'), 'grid_view' : ('srvparamid', 'server', 'name', 'value'), 'grid_hidden' : ('srvparamid',), 'create_wizard' : SimpleWizard(title=_('Add new parameter')) } } ) id = Column( 'srvparamid', UInt32(), Sequence('srv_params_srvparamid_seq'), Comment('Server parameter ID'), primary_key=True, nullable=False, info={ 'header_string' : _('ID') } ) server_id = Column( 'srvid', UInt32(), ForeignKey('srv_def.srvid', name='srv_params_fk_srvid', onupdate='CASCADE', ondelete='CASCADE'), Comment('Server ID'), nullable=False, info={ 'header_string' : _('Server'), 'column_flex' : 1, 'filter_type' : 'none' } ) name = Column( ASCIIString(64), Comment('Server parameter name'), nullable=False, info={ 'header_string' : _('Name'), 'column_flex' : 1 } ) value = Column( Unicode(255), Comment('Server parameter value'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Value'), 'column_flex' : 1 } ) def __str__(self): return '%s: %s' % ( str(self.server), str(self.name) )
class Server(Base): """ Server instance object. """ __tablename__ = 'srv_def' __table_args__ = ( Comment('Servers'), Index('srv_def_u_srv', 'hostid', 'srvtypeid', unique=True), Index('srv_def_i_srvtypeid', 'srvtypeid'), { 'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8', 'info' : { 'cap_menu' : 'BASE_ADMIN', 'cap_read' : 'SRV_LIST', 'cap_create' : 'SRV_CREATE', 'cap_edit' : 'SRV_EDIT', 'cap_delete' : 'SRV_DELETE', 'show_in_menu' : 'admin', 'menu_name' : _('Servers'), 'grid_view' : ('srvid', 'host', 'type'), 'grid_hidden' : ('srvid',), 'detail_pane' : ('netprofile_core.views', 'dpane_simple'), 'create_wizard' : SimpleWizard(title=_('Add new server')), 'extra_actions' : [{ 'iconCls' : 'ico-redo', 'tooltip' : _('Generate server configuration'), 'itemId' : 'srvgen' }] } } ) id = Column( 'srvid', UInt32(), Sequence('srv_def_srvid_seq'), Comment('Server ID'), primary_key=True, nullable=False, info={ 'header_string' : _('ID') } ) host_id = Column( 'hostid', UInt32(), ForeignKey('hosts_def.hostid', name='srv_def_fk_hostid', onupdate='CASCADE'), Comment('Host ID'), nullable=False, info={ 'header_string' : _('Host'), 'column_flex' : 1, 'filter_type' : 'none' } ) type_id = Column( 'srvtypeid', UInt32(), ForeignKey('srv_types.srvtypeid', name='srv_def_fk_srvtypeid', onupdate='CASCADE'), Comment('Server type ID'), nullable=False, info={ 'header_string' : _('Type'), 'column_flex' : 1, 'filter_type' : 'nplist' } ) host = relationship( 'Host', innerjoin=True, backref='servers' ) parameters = relationship( 'ServerParameter', collection_class=attribute_mapped_collection('name'), backref=backref('server', innerjoin=True), cascade='all, delete-orphan', passive_deletes=True ) def __str__(self): return '%s: %s' % ( str(self.type), str(self.host) ) def get_param(self, name, default=None): # TODO: Maybe fix to be more DB-friendly? if name in self.parameters: return self.parameters[name].value srvt = self.type try: if name in srvt.parameter_defaults: return srvt.parameter_defaults[name] except (TypeError, IndexError): pass return default def get_bool_param(self, name, default=False): ret = self.get_param(name, default) if isinstance(ret, bool): return ret if not isinstance(ret, str): raise ValueError('Invalid parameter type') ret = ret.lower() if ret in ('t', 'true', 'y', 'yes', 'on', '1', 'enabled'): return True if ret in ('f', 'false', 'n', 'no', 'off', '0', 'disabled'): return False return default def has_param(self, name): ret = self.get_param(name) return ret not in (None, False, '')
class PaidServiceType(Base): """ Paid service type object. """ __tablename__ = 'paid_types' __table_args__ = (Comment('Paid service types'), Index('paid_types_i_qp_type', 'qp_type'), Index('paid_types_u_name', 'name', unique=True), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_PAIDSERVICES', 'cap_read': 'PAIDSERVICES_LIST', 'cap_create': 'PAIDSERVICETYPES_CREATE', 'cap_edit': 'PAIDSERVICETYPES_EDIT', 'cap_delete': 'PAIDSERVICETYPES_DELETE', 'menu_main': True, 'menu_name': _('Paid Services'), 'show_in_menu': 'modules', 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('paidid', 'name', 'isum', 'qsum', 'qp_amount', 'qp_unit', 'qp_type', 'sp_amount'), 'grid_hidden': ('paidid', 'sp_amount'), 'form_view': ('name', 'isum', 'qsum', 'qp_amount', 'qp_unit', 'qp_type', 'qp_order', 'sp_amount', 'cb_before', 'cb_success', 'cb_failure', 'cb_ratemod', 'descr'), 'easy_search': ('name', 'descr'), 'extra_data': ('formatted_initial_sum', 'formatted_quota_sum'), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new type')) } }) id = Column('paidid', UInt32(), Sequence('paid_types_paidid_seq'), Comment('Paid service ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) name = Column(Unicode(255), Comment('Paid service name'), nullable=False, info={ 'header_string': _('Name'), 'column_flex': 3 }) initial_sum = Column('isum', Money(), Comment('Initial payment sum'), nullable=False, default=0, server_default=text('0'), info={ 'header_string': _('Initial Payment'), 'column_flex': 1, 'column_xtype': 'templatecolumn', 'template': '{formatted_initial_sum}' }) quota_sum = Column('qsum', Money(), Comment('Quota sum'), nullable=False, default=0, server_default=text('0'), info={ 'header_string': _('Quota Payment'), 'column_flex': 1, 'column_xtype': 'templatecolumn', 'template': '{formatted_quota_sum}' }) quota_period_type = Column('qp_type', PaidServiceQPType.db_type(), Comment('Quota period type'), nullable=False, default=PaidServiceQPType.independent, server_default=PaidServiceQPType.independent, info={'header_string': _('Type')}) pay_order = Column('qp_order', UInt8(), Comment('Pay order for linked services'), nullable=False, default=0, server_default=text('0'), info={'header_string': _('Pay Order')}) skipped_periods = Column('sp_amount', UInt16(), Comment('Number of skipped periods'), nullable=False, default=0, server_default=text('0'), info={'header_string': _('Skipped Periods')}) quota_period_amount = Column( 'qp_amount', UInt16(), Comment('Quota period amount'), nullable=False, default=1, server_default=text('1'), info={'header_string': _('Quota Period Amount')}) quota_period_unit = Column('qp_unit', QuotaPeriodUnit.db_type(), Comment('Quota period unit'), nullable=False, default=QuotaPeriodUnit.calendar_month, server_default=QuotaPeriodUnit.calendar_month, info={'header_string': _('Quota Period Unit')}) cb_before = Column(ASCIIString(255), Comment('Callback before charging'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Callback Before Charging')}) cb_success = Column(ASCIIString(255), Comment('Callback on success'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Callback on Success')}) cb_failure = Column(ASCIIString(255), Comment('Callback on failure'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Callback on Failure')}) cb_ratemod = Column(ASCIIString(255), Comment('Callback on linked rate'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Callback on Linked Rate')}) description = Column('descr', UnicodeText(), Comment('Paid service description'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Description')}) def __str__(self): return '%s' % (str(self.name), ) def formatted_initial_sum(self, req): return money_format(req, self.initial_sum) def formatted_quota_sum(self, req): return money_format(req, self.quota_sum)
class PaidService(Base): """ Paid service mapping object. """ __tablename__ = 'paid_def' __table_args__ = (Comment('Paid service mappings'), Index('paid_def_i_entityid', 'entityid'), Index('paid_def_i_aeid', 'aeid'), Index('paid_def_i_hostid', 'hostid'), Index('paid_def_i_stashid', 'stashid'), Index('paid_def_i_paidid', 'paidid'), Index('paid_def_i_active', 'active'), Index('paid_def_i_qpend', 'qpend'), Trigger('before', 'insert', 't_paid_def_bi'), Trigger('before', 'update', 't_paid_def_bu'), Trigger('after', 'insert', 't_paid_def_ai'), Trigger('after', 'update', 't_paid_def_au'), Trigger('after', 'delete', 't_paid_def_ad'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_PAIDSERVICES', 'cap_read': 'PAIDSERVICES_LIST', 'cap_create': 'PAIDSERVICES_CREATE', 'cap_edit': 'PAIDSERVICES_EDIT', 'cap_delete': 'PAIDSERVICES_DELETE', 'default_sort': ({ 'property': 'qpend', 'direction': 'DESC' }, ), 'grid_view': ('epid', 'entity', 'stash', 'type', 'active', 'qpend'), 'grid_hidden': ('epid', ), 'form_view': (), 'detail_pane': ('netprofile_core.views', 'dpane_simple') } }) id = Column('epid', UInt32(), Sequence('paid_def_epid_seq'), Comment('Paid service mapping ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) entity_id = Column('entityid', UInt32(), Comment('Entity ID'), ForeignKey('entities_def.entityid', name='paid_def_fk_entityid', onupdate='CASCADE', ondelete='CASCADE'), nullable=False, info={ 'header_string': _('Entity'), 'filter_type': 'none', 'column_flex': 2 }) access_entity_id = Column('aeid', UInt32(), Comment('Access entity ID'), ForeignKey('entities_access.entityid', name='paid_def_fk_aeid', onupdate='CASCADE', ondelete='CASCADE'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string': _('Access Entity'), 'filter_type': 'none', 'column_flex': 2 }) host_id = Column('hostid', UInt32(), Comment('Host ID'), ForeignKey('hosts_def.hostid', name='paid_def_fk_hostid', onupdate='CASCADE', ondelete='CASCADE'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string': _('Host'), 'filter_type': 'none', 'column_flex': 2 }) stash_id = Column('stashid', UInt32(), ForeignKey('stashes_def.stashid', name='paid_def_fk_stashid', onupdate='CASCADE', ondelete='CASCADE'), Comment('Used stash ID'), nullable=False, info={ 'header_string': _('Stash'), 'column_flex': 3 }) paid_id = Column('paidid', UInt32(), ForeignKey('paid_types.paidid', name='paid_def_fk_paidid', onupdate='CASCADE'), Comment('Type ID'), nullable=False, info={ 'header_string': _('Stash'), 'column_flex': 3 }) active = Column(NPBoolean(), Comment('Is service active'), nullable=False, default=True, server_default=npbool(True), info={'header_string': _('Active')}) quota_period_end = Column('qpend', TIMESTAMP(), Comment('End of quota period'), nullable=True, default=None, server_default=FetchedValue(), info={'header_string': _('Ends')}) description = Column('descr', UnicodeText(), Comment('Description'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Description')}) type = relationship('PaidServiceType', innerjoin=True, lazy='joined', backref='paid_services') entity = relationship('Entity', foreign_keys=entity_id, innerjoin=True, backref=backref('paid_services', cascade='all, delete-orphan', passive_deletes=True)) access_entity = relationship('AccessEntity', foreign_keys=access_entity_id, backref=backref('paid_services_access', cascade='all, delete-orphan', passive_deletes=True)) host = relationship('Host', backref=backref('paid_services', cascade='all, delete-orphan', passive_deletes=True)) stash = relationship('Stash', innerjoin=True, backref=backref('paid_services', cascade='all, delete-orphan', passive_deletes=True)) def __str__(self): return '%s: %s' % (str(self.stash), str(self.type))
class StashOperation(Base): """ Low-level stash operation object. """ __tablename__ = 'stashes_ops' __table_args__ = ( Comment('Operations on stashes'), Index('stashes_ops_i_stashid', 'stashid'), Index('stashes_ops_i_type', 'type'), Index('stashes_ops_i_ts', 'ts'), Index('stashes_ops_i_operator', 'operator'), Index('stashes_ops_i_entityid', 'entityid'), { 'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8', 'info' : { 'cap_menu' : 'BASE_STASHES', 'cap_read' : 'STASHES_IO', 'cap_create' : '__NOPRIV__', 'cap_edit' : '__NOPRIV__', 'cap_delete' : '__NOPRIV__', 'menu_name' : _('Operations'), 'default_sort' : ({ 'property': 'ts', 'direction': 'DESC' },), 'grid_view' : ('type', 'stash', 'entity', 'operator_user', 'ts', 'diff', 'acct_ingress', 'acct_egress'), 'form_view' : ('type', 'stash', 'entity', 'operator_user', 'ts', 'diff', 'acct_ingress', 'acct_egress') } } ) id = Column( 'stashopid', UInt64(), Sequence('stashes_ops_stashopid_seq'), Comment('Stash operation ID'), primary_key=True, nullable=False, info={ 'header_string': _('ID') } ) stash_id = Column( 'stashid', UInt32(), ForeignKey('stashes_def.stashid', name='stashes_ops_fk_stashid', ondelete='CASCADE', onupdate='CASCADE'), Comment('Stash ID'), nullable=False, info={ 'header_string': _('Stash'), 'filter_type' : 'none' } ) type = Column( StashOperationType.db_type(), Comment('Type of operation'), nullable=False, default=StashOperationType.oper, server_default=StashOperationType.oper, info={ 'header_string': _('Type') } ) timestamp = Column( 'ts', TIMESTAMP(), Comment('Time stamp of operation'), CurrentTimestampDefault(), nullable=False, info={ 'header_string' : _('Date') } ) operator_id = Column( 'operator', UInt32(), ForeignKey('users.uid', name='stashes_ops_fk_operator', ondelete='SET NULL', onupdate='CASCADE'), Comment('Optional operator ID'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Operator'), 'filter_type' : 'nplist' } ) entity_id = Column( 'entityid', UInt32(), ForeignKey('entities_def.entityid', name='stashes_ops_fk_entityid', ondelete='SET NULL', onupdate='CASCADE'), Comment('Optional entity ID'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Entity'), 'filter_type' : 'none' } ) difference = Column( 'diff', Money(), Comment('Changes made to stash'), nullable=False, default=0, server_default=text('0'), info={ 'header_string' : _('Change') } ) accounted_ingress = Column( 'acct_ingress', Traffic(), Comment('Accounted ingress traffic'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Ingress Traffic') } ) accounted_egress = Column( 'acct_egress', Traffic(), Comment('Accounted egress traffic'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Egress Traffic') } ) comments = Column( UnicodeText(), Comment('Optional Comments'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Comments') } ) stash = relationship( 'Stash', innerjoin=True, backref=backref( 'operations', cascade='all, delete-orphan', passive_deletes=True ) ) operator_user = relationship( 'User', backref=backref( 'stash_operations', passive_deletes=True ) ) entity = relationship( 'Entity', backref=backref( 'stash_operations', passive_deletes=True ) ) def __str__(self): return '%s: %s' % ( str(self.stash), str(self.timestamp) )
class StashIO(Base): """ Stash I/O operation object. """ __tablename__ = 'stashes_io_def' __table_args__ = ( Comment('Stashes input/output operations'), Index('stashes_io_def_i_siotypeid', 'siotypeid'), Index('stashes_io_def_i_stashid', 'stashid'), Index('stashes_io_def_i_currid', 'currid'), Index('stashes_io_def_i_uid', 'uid'), Index('stashes_io_def_i_entityid', 'entityid'), Index('stashes_io_def_i_ts', 'ts'), Trigger('before', 'insert', 't_stashes_io_def_bi'), Trigger('after', 'insert', 't_stashes_io_def_ai'), { 'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8', 'info' : { 'cap_menu' : 'BASE_STASHES', 'cap_read' : 'STASHES_IO', 'cap_create' : 'STASHES_IO', 'cap_edit' : '__NOPRIV__', 'cap_delete' : '__NOPRIV__', 'menu_name' : _('Operations'), 'show_in_menu' : 'modules', 'default_sort' : ({ 'property': 'ts', 'direction': 'DESC' },), 'grid_view' : ('sioid', 'type', 'stash', 'entity', 'user', 'ts', 'currency', 'diff'), 'grid_hidden' : ('sioid', 'currency'), 'form_view' : ('type', 'stash', 'currency', 'entity', 'user', 'ts', 'diff', 'descr'), 'extra_data' : ('formatted_difference',), 'detail_pane' : ('netprofile_core.views', 'dpane_simple'), 'create_wizard' : Wizard( Step( 'stash', 'type', 'diff', 'descr', id='generic', on_submit=_wizcb_stashio_submit ), title=_('Add new operation') ) } } ) id = Column( 'sioid', UInt32(), Sequence('stashes_io_def_sioid_seq'), Comment('Stash I/O ID'), primary_key=True, nullable=False, info={ 'header_string' : _('ID') } ) type_id = Column( 'siotypeid', UInt32(), Comment('Stash I/O type ID'), ForeignKey('stashes_io_types.siotypeid', name='stashes_io_def_fk_siotypeid', ondelete='CASCADE', onupdate='CASCADE'), nullable=False, info={ 'header_string' : _('Type'), 'filter_type' : 'nplist', 'editor_xtype' : 'simplemodelselect', 'editor_config' : { 'extraParams' : { '__ffilter' : [{ 'property' : 'oper_visible', 'operator' : 'eq', 'value' : True }]} }, 'column_flex' : 2 } ) stash_id = Column( 'stashid', UInt32(), Comment('Stash ID'), ForeignKey('stashes_def.stashid', name='stashes_io_def_fk_stashid', ondelete='CASCADE', onupdate='CASCADE'), nullable=False, info={ 'header_string' : _('Stash'), 'filter_type' : 'none', 'column_flex' : 2 } ) currency_id = Column( 'currid', UInt32(), Comment('Currency ID'), ForeignKey('currencies_def.currid', name='stashes_io_def_fk_currid', onupdate='CASCADE'), # ondelete=RESTRICT nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Currency'), 'editor_xtype' : 'simplemodelselect', 'editor_config' : { 'extraParams' : { '__ffilter' : [{ 'property' : 'oper_visible', 'operator' : 'eq', 'value' : True }]} }, 'filter_type' : 'nplist' } ) user_id = Column( 'uid', UInt32(), Comment('User ID'), ForeignKey('users.uid', name='stashes_io_def_fk_uid', ondelete='SET NULL', onupdate='CASCADE'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Operator'), 'filter_type' : 'nplist' } ) entity_id = Column( 'entityid', UInt32(), Comment('Related entity ID'), ForeignKey('entities_def.entityid', name='stashes_io_def_fk_entityid', ondelete='SET NULL', onupdate='CASCADE'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Entity'), 'filter_type' : 'none', 'column_flex' : 1 } ) timestamp = Column( 'ts', TIMESTAMP(), Comment('Time stamp of operation'), CurrentTimestampDefault(), nullable=False, info={ 'header_string' : _('Date'), 'column_flex' : 1 } ) difference = Column( 'diff', Money(), Comment('Operation result'), nullable=False, info={ 'header_string' : _('Change'), 'column_xtype' : 'templatecolumn', 'template' : '{formatted_difference}' } ) description = Column( 'descr', UnicodeText(), Comment('Description'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Description') } ) type = relationship( 'StashIOType', innerjoin=True, lazy='joined', backref=backref( 'ios', cascade='all, delete-orphan', passive_deletes=True ) ) stash = relationship( 'Stash', innerjoin=True, backref=backref( 'ios', cascade='all, delete-orphan', passive_deletes=True ) ) currency = relationship( 'Currency', lazy='joined', backref=backref( 'ios', passive_deletes='all' ) ) user = relationship( 'User', backref=backref( 'stash_ios', passive_deletes=True ) ) entity = relationship( 'Entity', backref=backref( 'stash_ios', passive_deletes=True ) ) def __str__(self): return '%s: %s' % ( str(self.stash), str(self.type) ) def formatted_difference(self, req): return money_format(req, self.difference, currency=self.currency)
class PDNSComment(Base): """ A PowerDNS Comment object """ __tablename__ = 'pdns_comments' __table_args__ = ( Comment('PowerDNS Comments'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_DOMAINS', # 'cap_read' : 'DOMAINS_LIST', # 'cap_create' : 'DOMAINS_CREATE', # 'cap_edit' : 'DOMAINS_EDIT', # 'cap_delete' : 'DOMAINS_DELETE', 'show_in_menu': 'modules', 'menu_name': _('PowerDNS Comments'), 'menu_order': 50, 'default_sort': ({ 'property': 'id', 'direction': 'ASC' }, ), 'grid_view': ('domain_id', 'name', 'domaintype', 'comment'), 'form_view': ('domain_id', 'name', 'domaintype', 'modified', 'comment'), 'easy_search': ('domain_id'), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new comment')) } }) commentid = Column('id', UInt16(), Sequence('pdns_comments_id_seq'), Comment('Comment ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) domain_id = Column('domain_id', UInt16(), Comment('Domain ID'), ForeignKey('pdns_domains.id', name='pdns_comments_fk_domain_id'), nullable=False, info={'header_string': _('Domain ID')}) domainname = Column('name', Unicode(255), Comment('Domain Name'), nullable=False, info={'header_string': _('Domain Name')}) domaintype = Column('type', Unicode(10), Comment('Domain Type'), nullable=True, default=None, info={'header_string': _('Domain Type')}) modified = Column('modified_at', TIMESTAMP(), Comment('Modification timestamp'), nullable=False, default=datetime.datetime.utcnow, info={'header_string': _('Modified')}) account = Column('account', Unicode(10), Comment('Account'), nullable=False, info={'header_string': _('Account')}) comment = Column('comment', UnicodeText(), nullable=False, info={'header_string': _('Comment')}) def __str__(self): return '%s:%s:%s' % str(self.domainname, self.account, self.comment)
class NetworkGroup(Base): """ Network group object. """ __tablename__ = 'nets_groups' __table_args__ = (Comment('Network groups'), Index('nets_groups_u_name', 'name', unique=True), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_NETS', 'cap_read': 'NETS_LIST', 'cap_create': 'NETGROUPS_CREATE', 'cap_edit': 'NETGROUPS_EDIT', 'cap_delete': 'NETGROUPS_DELETE', 'menu_name': _('Groups'), 'show_in_menu': 'modules', 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('netgid', 'name', 'descr'), 'grid_hidden': ('netgid', ), 'form_view': ('name', 'descr'), 'easy_search': ('name', ), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new network group')) } }) id = Column('netgid', UInt32(), Sequence('nets_groups_netgid_seq'), Comment('Network group ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) name = Column(Unicode(255), Comment('Network group name'), nullable=False, info={ 'header_string': _('Name'), 'column_flex': 1 }) description = Column('descr', UnicodeText(), Comment('Network group description'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Description')}) def __str__(self): return str(self.name)
class PDNSDomain(Base): """ PowerDNS Domain """ __tablename__ = 'pdns_domains' __table_args__ = ( Comment('PowerDNS Domain Record'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_DOMAINS', # 'cap_read' : 'DOMAINS_LIST', # 'cap_create' : 'DOMAINS_CREATE', # 'cap_edit' : 'DOMAINS_EDIT', # 'cap_delete' : 'DOMAINS_DELETE', 'menu_name': _('PowerDNS Domain Records'), 'show_in_menu': 'modules', 'menu_order': 30, 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('name', 'master', 'last_check', 'dtype', 'notified_serial', 'account'), 'easy_search': ('name', 'master', 'last_check', 'dtype', 'notified_serial', 'account'), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new DNS domain')) } }) id = Column('id', UInt16(), Comment('Domain ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) name = Column('name', Unicode(255), Comment('Name'), nullable=False, info={'header_string': _('Name')}) master = Column('master', Unicode(128), Comment('Master Nameserver'), nullable=True, default=None, info={'header_string': _('Master')}) last_check = Column('last_check', TIMESTAMP(), Comment('Last check timestamp'), nullable=True, default=None, info={'header_string': _('Last Check')}) dtype = Column('type', Unicode(10), Comment('Domain Type'), nullable=True, default=None, info={'header_string': _('Type')}) notified_serial = Column('notified_serial', UInt16(), Comment('Notified Serial'), nullable=True, default=None, info={'header_string': _('Notified Serial')}) account = Column( 'account', UInt32(), # Unicode(40), ForeignKey('entities_access.entityid', name='pdns_domains_fk_accessuserid', onupdate='CASCADE'), Comment('Account'), nullable=False, # default=None, info={'header_string': _('Account')}) domainrecords = relationship("PDNSRecord", cascade='all, delete-orphan') def __str__(self): return self.name
class NetworkServiceType(Base): """ Network service type object. """ __tablename__ = 'nets_hltypes' __table_args__ = (Comment('Networks-hosts linkage types'), Index('nets_hltypes_u_name', 'name', unique=True), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_NETS', 'cap_read': 'NETS_LIST', 'cap_create': 'NETS_SERVICETYPES_CREATE', 'cap_edit': 'NETS_SERVICETYPES_EDIT', 'cap_delete': 'NETS_SERVICETYPES_DELETE', 'menu_name': _('Services'), 'show_in_menu': 'admin', 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('hltypeid', 'name', 'unique'), 'grid_hidden': ('hltypeid', ), 'form_view': ('name', 'unique'), 'easy_search': ('name', ), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard( title=_('Add new network service type')) } }) id = Column('hltypeid', UInt32(), Sequence('nets_hltypes_hltypeid_seq', start=101, increment=1), Comment('Networks-hosts linkage type ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) name = Column(Unicode(255), Comment('Networks-hosts linkage type name'), nullable=False, info={ 'header_string': _('Name'), 'column_flex': 1 }) unique = Column(NPBoolean(), Comment('Is unique per network?'), nullable=False, default=False, server_default=npbool(False), info={'header_string': _('Unique')}) services = relationship('NetworkService', backref=backref('type', innerjoin=True)) def __str__(self): req = getattr(self, '__req__', None) if req: return req.localizer.translate(_(self.name)) return str(self.name)
class ServiceType(Base): """ Service type object. """ __tablename__ = 'services_types' __table_args__ = (Comment('Service types'), Index('services_types_u_service', 'proto', 'abbrev', unique=True), Index('services_types_i_abbrev', 'abbrev'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_SERVICES', 'cap_read': 'SERVICES_LIST', 'cap_create': 'SERVICES_TYPES_CREATE', 'cap_edit': 'SERVICES_TYPES_EDIT', 'cap_delete': 'SERVICES_TYPES_DELETE', 'menu_name': _('Service Types'), 'show_in_menu': 'admin', 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('stid', 'abbrev', 'name', 'proto', 'port_start', 'port_end'), 'grid_hidden': ('stid', ), 'form_view': ('abbrev', 'name', 'proto', 'port_start', 'port_end', 'alias'), 'easy_search': ('abbrev', 'name'), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new service type')) } }) id = Column('stid', UInt32(), Sequence('services_types_stid_seq'), Comment('Service type ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) abbreviation = Column('abbrev', ASCIIString(32), Comment('Service type abbreviation'), nullable=False, info={'header_string': _('Abbrev.')}) name = Column(Unicode(255), Comment('Service type name'), nullable=False, info={ 'header_string': _('Name'), 'column_flex': 1 }) protocol = Column('proto', ServiceProtocol.db_type(), Comment('Used protocol(s)'), nullable=False, default=ServiceProtocol.tcp, server_default=ServiceProtocol.tcp, info={'header_string': _('Protocol')}) start_port = Column('port_start', UInt16(), Comment('Port range start'), nullable=False, info={'header_string': _('Start Port')}) end_port = Column('port_end', UInt16(), Comment('Port range end'), nullable=False, info={'header_string': _('End Port')}) alias = Column(ASCIIText(), Comment('List of alternate names'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Aliases')}) services = relationship('Service', backref=backref('type', innerjoin=True)) def __str__(self): pfx = [] if self.abbreviation: pfx.append(str(self.abbreviation)) if self.protocol != ServiceProtocol.none: pfx.append(str(self.protocol.description)) if len(pfx) > 0: return '[%s] %s' % ('/'.join(pfx), str(self.name)) return str(self.name) @property def record_name(self): rrn = [] if self.abbreviation: rrn.append('_' + self.abbreviation) if self.protocol != ServiceProtocol.none: rrn.append('_' + self.protocol.name) return '.'.join(rrn) @property def port_range(self): if self.start_port and self.end_port and (self.start_port <= self.end_port): return range(self.start_port, self.end_port + 1) return ()
class Host(Base): """ Host object. """ __tablename__ = 'hosts_def' __table_args__ = (Comment('Hosts'), Index('hosts_def_u_hostname', 'domainid', 'name', unique=True), Index('hosts_def_i_hgid', 'hgid'), Index('hosts_def_i_entityid', 'entityid'), Index('hosts_def_i_aliasid', 'aliasid'), Index('hosts_def_i_cby', 'cby'), Index('hosts_def_i_mby', 'mby'), Trigger('before', 'insert', 't_hosts_def_bi'), Trigger('before', 'update', 't_hosts_def_bu'), Trigger('after', 'insert', 't_hosts_def_ai'), Trigger('after', 'update', 't_hosts_def_au'), Trigger('after', 'delete', 't_hosts_def_ad'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_HOSTS', 'cap_read': 'HOSTS_LIST', 'cap_create': 'HOSTS_CREATE', 'cap_edit': 'HOSTS_EDIT', 'cap_delete': 'HOSTS_DELETE', 'menu_name': _('Hosts'), 'show_in_menu': 'modules', 'menu_main': True, 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('hostid', MarkupColumn(name='name', header_string=_('Name'), template='{__str__}', column_flex=3, sortable=True), 'domain', 'group', 'entity'), 'grid_hidden': ('hostid', 'domain'), 'form_view': ('name', 'domain', 'group', 'entity', 'original', 'aliastype', 'descr', 'ctime', 'cby', 'mtime', 'mby'), 'easy_search': ('name', ), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': Wizard(Step('name', 'domain', 'entity', title=_('New host data')), Step('group', 'original', 'aliastype', 'descr', title=_('New host details')), title=_('Add new host')) } }) id = Column('hostid', UInt32(), Sequence('hosts_def_hostid_seq'), Comment('Host ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) group_id = Column('hgid', UInt32(), ForeignKey('hosts_groups.hgid', name='hosts_def_fk_hgid', onupdate='CASCADE'), Comment('Host group ID'), nullable=False, info={ 'header_string': _('Group'), 'filter_type': 'nplist', 'column_flex': 1 }) entity_id = Column('entityid', UInt32(), ForeignKey('entities_def.entityid', name='hosts_def_fk_entityid', onupdate='CASCADE', ondelete='CASCADE'), Comment('Entity ID'), nullable=False, info={ 'header_string': _('Entity'), 'filter_type': 'none', 'column_flex': 1 }) domain_id = Column('domainid', UInt32(), ForeignKey('domains_def.domainid', name='hosts_def_fk_domainid', onupdate='CASCADE'), Comment('Domain ID'), nullable=False, info={ 'header_string': _('Domain'), 'filter_type': 'nplist', 'column_flex': 2 }) name = Column(Unicode(255), Comment('Host Name'), nullable=False, info={'header_string': _('Name')}) original_id = Column('aliasid', UInt32(), ForeignKey('hosts_def.hostid', name='hosts_def_fk_aliasid', ondelete='CASCADE', onupdate='CASCADE'), Comment('Aliased host ID'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string': _('Aliased'), 'filter_type': 'nplist' }) alias_type = Column('aliastype', HostAliasType.db_type(), Comment('Host alias type'), nullable=False, default=HostAliasType.symbolic, server_default=HostAliasType.symbolic, info={'header_string': _('Alias Type')}) creation_time = Column('ctime', TIMESTAMP(), Comment('Time of creation'), nullable=True, default=None, server_default=FetchedValue(), info={ 'header_string': _('Created'), 'read_only': True }) modification_time = Column('mtime', TIMESTAMP(), Comment('Time of last modification'), CurrentTimestampDefault(on_update=True), nullable=False, info={ 'header_string': _('Modified'), 'read_only': True }) created_by_id = Column('cby', UInt32(), ForeignKey('users.uid', name='hosts_def_fk_cby', ondelete='SET NULL', onupdate='CASCADE'), Comment('Created by'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string': _('Created'), 'read_only': True }) modified_by_id = Column('mby', UInt32(), ForeignKey('users.uid', name='hosts_def_fk_mby', ondelete='SET NULL', onupdate='CASCADE'), Comment('Last modified by'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string': _('Modified'), 'read_only': True }) description = Column('descr', UnicodeText(), Comment('Host description'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Description')}) group = relationship('HostGroup', innerjoin=True, backref='hosts') entity = relationship('Entity', innerjoin=True, backref=backref('hosts', cascade='all, delete-orphan', passive_deletes=True)) domain = relationship('Domain', innerjoin=True, backref='hosts') original = relationship('Host', backref=backref('aliases', cascade='all, delete-orphan', passive_deletes=True), remote_side=[id]) created_by = relationship('User', foreign_keys=created_by_id, backref=backref('created_hosts', passive_deletes=True)) modified_by = relationship('User', foreign_keys=modified_by_id, backref=backref('modified_hosts', passive_deletes=True)) services = relationship('Service', backref=backref('host', innerjoin=True), cascade='all, delete-orphan', passive_deletes=True) @property def real(self): if not self.original: return self h = self while h.original: h = h.original return h def __str__(self): if self.domain: return '%s.%s' % (str(self.name), str(self.domain)) return str(self.name) @classmethod def resolve(cls, name, domain_aliases=True): parts = name.strip('.').split('.') num_parts = len(parts) if num_parts == 1: # TODO: support specifying default domain raise ValueError('Hostname must be fully qualified') variants = list(('.'.join(parts[:i]), '.'.join(parts[i:])) for i in range(1, num_parts)) sess = DBSession() for host_part, domain_part in variants: domain = Domain.resolve(domain_part, domain_aliases=domain_aliases) if domain is None: continue try: return sess.query(Host).filter(Host.domain == domain, Host.name == host_part).one() except NoResultFound: pass
class HostGroup(Base): """ Host group object. """ __tablename__ = 'hosts_groups' __table_args__ = (Comment('Host groups'), Index('hosts_groups_u_hgname', 'name', unique=True), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_HOSTS', 'cap_read': 'HOSTS_LIST', 'cap_create': 'HOSTS_GROUPS_CREATE', 'cap_edit': 'HOSTS_GROUPS_EDIT', 'cap_delete': 'HOSTS_GROUPS_DELETE', 'menu_name': _('Host Groups'), 'show_in_menu': 'admin', 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('hgid', 'name', 'public'), 'grid_hidden': ('hgid', ), 'form_view': ('name', 'public', 'startoffset', 'endoffset', 'startoffset6', 'endoffset6', 'use_hwaddr', 'use_dhcp', 'use_banning'), 'easy_search': ('name', ), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new host group')) } }) id = Column('hgid', UInt32(), Sequence('hosts_groups_hgid_seq'), Comment('Host group ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) name = Column(Unicode(255), Comment('Host group name'), nullable=False, info={ 'header_string': _('Name'), 'column_flex': 1 }) public = Column(NPBoolean(), Comment('Is host group globally visible?'), nullable=False, default=True, server_default=npbool(True), info={'header_string': _('Public')}) ipv4_start_offset = Column('startoffset', UInt16(), Comment('IP allocator start offset'), nullable=False, default=0, server_default=text('0'), info={'header_string': _('IPv4 Start Offset')}) ipv4_end_offset = Column('endoffset', UInt16(), Comment('IP allocator end offset'), nullable=False, default=0, server_default=text('0'), info={'header_string': _('IPv4 End Offset')}) ipv6_start_offset = Column('startoffset6', UInt64(), Comment('IPv6 allocator start offset'), nullable=False, default=0, server_default=text('0'), info={'header_string': _('IPv6 Start Offset')}) ipv6_end_offset = Column('endoffset6', UInt64(), Comment('IPv6 allocator end offset'), nullable=False, default=0, server_default=text('0'), info={'header_string': _('IPv6 End Offset')}) use_hwaddr = Column(NPBoolean(), Comment('Use unique hardware address check'), nullable=False, default=True, server_default=npbool(True), info={'header_string': _('Unique Hardware Address')}) use_dhcp = Column(NPBoolean(), Comment('Use DHCP'), nullable=False, default=True, server_default=npbool(True), info={'header_string': _('DHCP')}) use_banning = Column(NPBoolean(), Comment('Use banning system'), nullable=False, default=True, server_default=npbool(True), info={'header_string': _('Banning System')}) def __str__(self): return str(self.name)
class Stash(Base): """ Stash object. """ __tablename__ = 'stashes_def' __table_args__ = ( Comment('Stashes of money'), Index('stashes_def_i_entityid', 'entityid'), Index('stashes_def_i_currid', 'currid'), Trigger('before', 'insert', 't_stashes_def_bi'), Trigger('before', 'update', 't_stashes_def_bu'), { 'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8', 'info' : { 'cap_menu' : 'BASE_STASHES', 'cap_read' : 'STASHES_LIST', 'cap_create' : 'STASHES_CREATE', 'cap_edit' : 'STASHES_EDIT', 'cap_delete' : 'STASHES_DELETE', 'menu_name' : _('Stashes'), 'menu_main' : True, 'show_in_menu' : 'modules', 'default_sort' : ({ 'property': 'name', 'direction': 'ASC' },), 'grid_view' : ('stashid', 'entity', 'name', 'currency', 'amount', 'credit'), 'grid_hidden' : ('stashid', 'currency'), 'form_view' : ('entity', 'name', 'currency', 'amount', 'credit', 'alltime_min', 'alltime_max'), 'easy_search' : ('name',), 'extra_data' : ('formatted_amount', 'formatted_credit'), 'detail_pane' : ('netprofile_core.views', 'dpane_simple'), 'create_wizard' : SimpleWizard(title=_('Add new stash')) } } ) id = Column( 'stashid', UInt32(), Sequence('stashes_def_stashid_seq'), Comment('Stash ID'), primary_key=True, nullable=False, info={ 'header_string' : _('ID') } ) entity_id = Column( 'entityid', UInt32(), Comment('Owner entity ID'), ForeignKey('entities_def.entityid', name='stashes_def_fk_entityid', onupdate='CASCADE', ondelete='CASCADE'), nullable=False, info={ 'header_string' : _('Entity'), 'filter_type' : 'none', 'column_flex' : 2 } ) currency_id = Column( 'currid', UInt32(), Comment('Currency ID'), ForeignKey('currencies_def.currid', name='stashes_def_fk_currid', onupdate='CASCADE'), # ondelete=RESTRICT nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Currency'), 'editor_xtype' : 'simplemodelselect', 'editor_config' : { 'extraParams' : { '__ffilter' : [{ 'property' : 'oper_visible', 'operator' : 'eq', 'value' : True }]} }, 'filter_type' : 'nplist' } ) name = Column( Unicode(255), Comment('Stash name'), nullable=False, info={ 'header_string' : _('Name'), 'column_flex' : 3 } ) amount = Column( Money(), Comment('Stash balance'), nullable=False, default=0, server_default=text('0'), info={ 'header_string' : _('Balance'), 'column_flex' : 1, 'column_xtype' : 'templatecolumn', 'template' : '{formatted_amount}' } ) credit = Column( Money(), Comment('Stash credit'), nullable=False, default=0, server_default=text('0'), info={ 'header_string' : _('Credit'), 'column_flex' : 1, 'column_xtype' : 'templatecolumn', 'template' : '{formatted_credit}' } ) alltime_max = Column( Money(), Comment('All-time maximum balance'), nullable=False, default=0, server_default=text('0'), info={ 'header_string' : _('Max. Balance'), 'read_only' : True } ) alltime_min = Column( Money(), Comment('All-time minimum balance'), nullable=False, default=0, server_default=text('0'), info={ 'header_string' : _('Min. Balance'), 'read_only' : True } ) entity = relationship( 'Entity', innerjoin=True, backref=backref( 'stashes', cascade='all, delete-orphan', passive_deletes=True ) ) currency = relationship( 'Currency', lazy='joined', backref=backref( 'stashes', passive_deletes='all' ) ) def __str__(self): return '%s: %s' % ( self.entity.nick, str(self.name) ) def formatted_amount(self, req): return money_format(req, self.amount, currency=self.currency) def formatted_credit(self, req): return money_format(req, self.credit, currency=self.currency)
class Service(Base): """ Service object. """ __tablename__ = 'services_def' __table_args__ = (Comment('Services'), Index('services_def_u_service', 'hostid', 'stid', 'domainid', unique=True), Index('services_def_i_stid', 'stid'), Index('services_def_i_domainid', 'domainid'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_SERVICES', 'cap_read': 'SERVICES_LIST', 'cap_create': 'SERVICES_CREATE', 'cap_edit': 'SERVICES_EDIT', 'cap_delete': 'SERVICES_DELETE', 'menu_name': _('Service Types'), 'grid_view': ('sid', 'host', 'domain', 'type', 'priority', 'weight', 'vis'), 'grid_hidden': ('sid', ), 'form_view': ('host', 'domain', 'type', 'priority', 'weight', 'vis'), 'create_wizard': SimpleWizard(title=_('Add new service')) } }) id = Column('sid', UInt32(), Sequence('services_def_sid_seq'), Comment('Service ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) host_id = Column('hostid', UInt32(), ForeignKey('hosts_def.hostid', name='services_def_fk_hostid', ondelete='CASCADE', onupdate='CASCADE'), Comment('Host ID'), nullable=False, info={ 'header_string': _('Host'), 'filter_type': 'none' }) type_id = Column('stid', UInt32(), ForeignKey('services_types.stid', name='services_def_fk_stid', onupdate='CASCADE'), Comment('Service type ID'), nullable=False, info={ 'header_string': _('Type'), 'filter_type': 'nplist', 'column_flex': 1 }) domain_id = Column('domainid', UInt32(), ForeignKey('domains_def.domainid', name='services_def_fk_domainid', ondelete='CASCADE', onupdate='CASCADE'), Comment('Alternate domain ID'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string': _('Domain'), 'filter_type': 'none', 'column_flex': 1 }) priority = Column(UInt32(), Comment('Service priority'), nullable=False, default=0, server_default=text('0'), info={'header_string': _('Priority')}) weight = Column(UInt32(), Comment('Service weight'), nullable=False, default=0, server_default=text('0'), info={'header_string': _('Weight')}) visibility = Column('vis', ObjectVisibility.db_type(), Comment('Service visibility'), nullable=False, default=ObjectVisibility.internal, server_default=ObjectVisibility.internal, info={'header_string': _('Visibility')}) domain = relationship('Domain', backref=backref('srv_records', cascade='all, delete-orphan', passive_deletes=True)) @property def service_domain(self): if self.domain: return self.domain return self.host.domain
class Network(Base): """ Network object. """ __tablename__ = 'nets_def' __table_args__ = ( Comment('Networks'), Index('nets_def_u_name', 'name', unique=True), Index('nets_def_u_ipaddr', 'ipaddr', unique=True), Index('nets_def_u_ip6addr', 'ip6addr', unique=True), Index('nets_def_i_domainid', 'domainid'), Index('nets_def_i_netgid', 'netgid'), Index('nets_def_i_rtid', 'rtid'), Index('nets_def_i_mgmtdid', 'mgmtdid'), Trigger('after', 'insert', 't_nets_def_ai'), Trigger('after', 'update', 't_nets_def_au'), Trigger('after', 'delete', 't_nets_def_ad'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_NETS', 'cap_read': 'NETS_LIST', 'cap_create': 'NETS_CREATE', 'cap_edit': 'NETS_EDIT', 'cap_delete': 'NETS_DELETE', 'menu_name': _('Networks'), 'show_in_menu': 'modules', 'menu_main': True, 'default_sort': ({ 'property': 'name', 'direction': 'ASC' }, ), 'grid_view': ('netid', 'name', 'domain', 'group', 'ipaddr', 'ip6addr', MarkupColumn( name='state', header_string=_('State'), template=TemplateObject( 'netprofile_networks:templates/networks_icons.mak'), column_width=40, column_resizable=False)), 'grid_hidden': ('netid', 'domain', 'group'), 'form_view': ('name', 'domain', 'group', 'management_device', 'enabled', 'public', 'ipaddr', 'cidr', 'ip6addr', 'cidr6', 'vlanid', 'routing_table', 'gueststart', 'guestend', 'gueststart6', 'guestend6', 'descr'), 'easy_search': ('name', ), 'detail_pane': ('netprofile_core.views', 'dpane_simple'), 'create_wizard': SimpleWizard(title=_('Add new network')) } }) id = Column('netid', UInt32(), Sequence('nets_def_netid_seq'), Comment('Network ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) name = Column(Unicode(255), Comment('Network name'), nullable=False, info={ 'header_string': _('Name'), 'column_flex': 1 }) domain_id = Column('domainid', UInt32(), ForeignKey('domains_def.domainid', name='nets_def_fk_domainid', onupdate='CASCADE'), Comment('Domain ID'), nullable=False, info={ 'header_string': _('Domain'), 'filter_type': 'nplist', 'column_flex': 1 }) group_id = Column('netgid', UInt32(), ForeignKey('nets_groups.netgid', name='nets_def_fk_netgid', ondelete='SET NULL', onupdate='CASCADE'), Comment('Network group ID'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string': _('Group'), 'filter_type': 'nplist', 'column_flex': 1 }) management_device_id = Column('mgmtdid', UInt32(), ForeignKey('devices_network.did', name='nets_def_fk_mgmtdid', ondelete='SET NULL', onupdate='CASCADE'), Comment('Management device ID'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string': _('Management Device'), 'filter_type': 'none' }) enabled = Column(NPBoolean(), Comment('Is network enabled?'), nullable=False, default=True, server_default=npbool(True), info={'header_string': _('Enabled')}) public = Column(NPBoolean(), Comment('Is network visible to outsiders?'), nullable=False, default=True, server_default=npbool(True), info={'header_string': _('Public')}) ipv4_address = Column('ipaddr', IPv4Address(), Comment('Network IPv4 address'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('IPv4 Address')}) ipv6_address = Column('ip6addr', IPv6Address(), Comment('Network IPv6 address'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('IPv6 Address')}) ipv4_cidr = Column('cidr', UInt8(), Comment('Network CIDR number'), nullable=False, default=24, server_default=text('24'), info={'header_string': _('IPv4 Netmask')}) ipv6_cidr = Column('cidr6', UInt8(), Comment('Network CIDRv6 number'), nullable=False, default=64, server_default=text('64'), info={'header_string': _('IPv6 Netmask')}) vlan_id = Column('vlanid', UInt16(), Comment('Network VLAN ID'), nullable=False, default=0, server_default=text('0'), info={'header_string': _('VLAN')}) routing_table_id = Column('rtid', UInt32(), ForeignKey('rt_def.rtid', name='nets_def_fk_rtid', ondelete='SET NULL', onupdate='CASCADE'), Comment('Routing table ID'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string': _('Routing Table'), 'filter_type': 'nplist' }) ipv4_guest_start = Column( 'gueststart', UInt16(), Comment('Start of IPv4 guest allocation area'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Start of IPv4 Guest Allocation Area')}) ipv4_guest_end = Column( 'guestend', UInt16(), Comment('End of IPv4 guest allocation area'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('End of IPv4 Guest Allocation Area')}) ipv6_guest_start = Column( 'gueststart6', IPv6Offset(), Comment('Start of IPv6 guest allocation area'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Start of IPv6 Guest Allocation Area')}) ipv6_guest_end = Column( 'guestend6', IPv6Offset(), Comment('End of IPv6 guest allocation area'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('End of IPv6 Guest Allocation Area')}) description = Column('descr', UnicodeText(), Comment('Network description'), nullable=True, default=None, server_default=text('NULL'), info={'header_string': _('Description')}) domain = relationship('Domain', innerjoin=True, backref='networks') group = relationship('NetworkGroup', backref=backref('networks', passive_deletes=True)) management_device = relationship('NetworkDevice', backref=backref('networks', passive_deletes=True)) routing_table = relationship('RoutingTable', backref=backref('networks', passive_deletes=True)) services = relationship('NetworkService', backref=backref('network', innerjoin=True), cascade='all, delete-orphan', passive_deletes=True) @property def ipv4_network(self): if self.ipv4_address: return ipaddr.IPv4Network( '%s/%s' % (str(self.ipv4_address), str(self.ipv4_cidr))) @property def ipv6_network(self): if self.ipv6_address: return ipaddr.IPv6Network( '%s/%s' % (str(self.ipv6_address), str(self.ipv6_cidr))) def __str__(self): return str(self.name)
class DomainService(Base): """ Domain service object. """ __tablename__ = 'domains_hosts' __table_args__ = (Comment('Domains-hosts linkage'), Index('domains_hosts_u_dhl', 'domainid', 'hostid', 'hltypeid', unique=True), Index('domains_hosts_i_hostid', 'hostid'), Index('domains_hosts_i_hltypeid', 'hltypeid'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_DOMAINS', 'cap_read': 'DOMAINS_LIST', 'cap_create': 'DOMAINS_EDIT', 'cap_edit': 'DOMAINS_EDIT', 'cap_delete': 'DOMAINS_EDIT', 'menu_name': _('Services'), 'grid_view': ('domain', 'host', 'type'), 'form_view': ('domain', 'host', 'type'), 'create_wizard': SimpleWizard(title=_('Add new domain service')) } }) id = Column('dhid', UInt32(), Sequence('domains_hosts_dhid_seq'), Comment('Domain-host linkage ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) domain_id = Column('domainid', UInt32(), ForeignKey('domains_def.domainid', name='domains_hosts_fk_domainid', ondelete='CASCADE', onupdate='CASCADE'), Comment('Domain ID'), nullable=False, info={ 'header_string': _('Domain'), 'filter_type': 'none', 'column_flex': 1 }) host_id = Column('hostid', UInt32(), ForeignKey('hosts_def.hostid', name='domains_hosts_fk_hostid', onupdate='CASCADE', ondelete='CASCADE'), Comment('Host ID'), nullable=False, info={ 'header_string': _('Host'), 'filter_type': 'none', 'column_flex': 1 }) type_id = Column('hltypeid', UInt32(), ForeignKey('domains_hltypes.hltypeid', name='domains_hosts_fk_hltypeid', onupdate='CASCADE'), Comment('Domain-host linkage type'), nullable=False, info={ 'header_string': _('Type'), 'filter_type': 'nplist', 'column_flex': 1 }) domain = relationship('Domain', innerjoin=True, backref=backref('services', cascade='all, delete-orphan', passive_deletes=True)) host = relationship('Host', innerjoin=True, backref=backref('domain_services', cascade='all, delete-orphan', passive_deletes=True)) type = relationship('DomainServiceType', innerjoin=True, backref='services')
class RoutingTableEntry(Base): """ IPv4 routing table entry object. """ __tablename__ = 'rt_bits' __table_args__ = (Comment('IPv4 routing table entries'), Index('rt_bits_i_rtid', 'rtid'), Index('rt_bits_i_rtr', 'rtr'), { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'info': { 'cap_menu': 'BASE_NETS', 'cap_read': 'NETS_LIST', 'cap_create': 'NETS_EDIT', 'cap_edit': 'NETS_EDIT', 'cap_delete': 'NETS_EDIT', 'menu_name': _('Routing Table Entries'), 'grid_view': ('rtbid', 'table', 'net', 'cidr', 'next_hop'), 'grid_hidden': ('rtbid', ), 'form_view': ('table', 'net', 'cidr', 'next_hop'), 'create_wizard': SimpleWizard( title=_('Add new IPv4 routing table entry')) } }) id = Column('rtbid', UInt32(), Sequence('rt_bits_rtbid_seq'), Comment('Routing table bit ID'), primary_key=True, nullable=False, info={'header_string': _('ID')}) table_id = Column('rtid', UInt32(), ForeignKey('rt_def.rtid', name='rt_bits_fk_rtid', onupdate='CASCADE', ondelete='CASCADE'), Comment('Routing table ID'), nullable=False, info={ 'header_string': _('Table'), 'filter_type': 'nplist', 'column_flex': 1 }) network = Column('net', IPv4Address(), Comment('Network address'), nullable=False, info={ 'header_string': _('Network'), 'column_flex': 1 }) cidr = Column(UInt8(), Comment('Network CIDR'), nullable=False, default=24, server_default=text('24'), info={'header_string': _('Netmask')}) next_hop_id = Column('rtr', UInt32(), ForeignKey('hosts_def.hostid', name='rt_bits_fk_hostid', onupdate='CASCADE', ondelete='CASCADE'), Comment('Next hop host ID'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string': _('Next Hop'), 'filter_type': 'none', 'column_flex': 1 }) next_hop = relationship('Host', backref=backref('next_hops', cascade='all, delete-orphan', passive_deletes=True)) @property def ipv4_network(self): return ipaddr.IPv4Network('%s/%s' % (str(self.network), str(self.cidr))) def dhcp_strings(self, net): if self.next_hop: gws = self.next_hop.ipv4_addresses else: gws = itertools.chain.from_iterable(ns.host.ipv4_addresses for ns in net.services if ns.type_id == 4) ret = [] netstr = ':'.join('{0:02x}'.format(o) for o in self.network.packed[:math.ceil(self.cidr / 8)]) for gw in gws: ret.append('%02x%s%s:%s' % (self.cidr, ':' if self.cidr > 0 else '', netstr, '%02x:%02x:%02x:%02x' % tuple(gw.address.packed))) return ret