class InstanceData(DB.Model): """Model for Altai-API specific extra instance data""" __tablename__ = 'instance_data' instance_id = DB.Column(DB.String(64), primary_key=True) expires_at = DB.Column(DB.DateTime) remind_at = DB.Column(DB.DateTime)
def make_app(config_env=CONFIG_ENV): app = ApiApp(__name__) app.config.from_object('altai_api.default_settings') if config_env is not None and config_env in os.environ: app.config.from_envvar(config_env) DB.init_app(app) blueprints = ( ('audit_log', '/v1/audit-log'), ('config', '/v1/config'), ('fw_rule_sets', '/v1/fw-rule-sets'), ('fw_rules', '/v1/fw-rule-sets/<fw_rule_set_id>/rules'), ('nodes', '/v1/nodes'), ('images', '/v1/images'), ('instance_fw_rule_sets', '/v1/instances/<instance_id>/fw-rule-sets'), ('instances', '/v1/instances'), ('instance_types', '/v1/instance-types'), ('invites', '/v1/invites'), ('me', '/v1/me'), ('my_ssh_keys', '/v1/me/ssh-keys'), ('networks', '/v1/networks'), ('projects', '/v1/projects'), ('project_users', '/v1/projects/<project_id>/users'), ('stats', '/v1/stats'), ('users_ssh_keys', '/v1/users/<user_id>/ssh-keys'), ('users', '/v1/users') ) # Import blueprints and register them for name, path in blueprints: module = __import__('altai_api.blueprints.%s' % name, level=0, fromlist=['BP']) app.register_blueprint(module.BP, url_prefix=path) # NOTE(imelnikov): should be done at the very last register_entry_points(app) return app
def make_app(config_env=CONFIG_ENV): app = ApiApp(__name__) app.config.from_object('altai_api.default_settings') if config_env is not None and config_env in os.environ: app.config.from_envvar(config_env) DB.init_app(app) blueprints = (('audit_log', '/v1/audit-log'), ('config', '/v1/config'), ('fw_rule_sets', '/v1/fw-rule-sets'), ('fw_rules', '/v1/fw-rule-sets/<fw_rule_set_id>/rules'), ('nodes', '/v1/nodes'), ('images', '/v1/images'), ('instance_fw_rule_sets', '/v1/instances/<instance_id>/fw-rule-sets'), ('instances', '/v1/instances'), ('instance_types', '/v1/instance-types'), ('invites', '/v1/invites'), ('me', '/v1/me'), ('my_ssh_keys', '/v1/me/ssh-keys'), ('networks', '/v1/networks'), ('projects', '/v1/projects'), ('project_users', '/v1/projects/<project_id>/users'), ('stats', '/v1/stats'), ('users_ssh_keys', '/v1/users/<user_id>/ssh-keys'), ('users', '/v1/users')) # Import blueprints and register them for name, path in blueprints: module = __import__('altai_api.blueprints.%s' % name, level=0, fromlist=['BP']) app.register_blueprint(module.BP, url_prefix=path) # NOTE(imelnikov): should be done at the very last register_entry_points(app) return app
def init_db(argv): if len(argv) != 2: show_help(argv) DB.create_all() for group, name, value in _DEFAULT_CONFIG: _set_value(group, name, value)
class Token(DB.Model): __tablename__ = 'tokens' code = DB.Column(DB.String(32), primary_key=True) token_type = DB.Column(DB.String(32), nullable=False) email = DB.Column(DB.String(120), nullable=False) user_id = DB.Column(DB.String(64), nullable=False) complete = DB.Column(DB.Boolean, nullable=False, default=False) created_at = DB.Column(DB.DateTime, nullable=False, default=datetime.utcnow) complete_at = DB.Column(DB.DateTime, nullable=True, default=None)
class AuditRecord(DB.Model): __tablename__ = 'audit_records' record_id = DB.Column(DB.Integer, primary_key=True, autoincrement=True) resource = DB.Column(DB.String(1024), nullable=False) method = DB.Column(DB.String(16), nullable=False) response_status = DB.Column(DB.Integer, nullable=False) message = DB.Column(DB.String(16)) resource_id = DB.Column(DB.String(1024)) user_id = DB.Column(DB.String(64)) project_id = DB.Column(DB.String(64)) remote_address = DB.Column(DB.String(255)) timestamp = DB.Column(DB.DateTime, nullable=False, default=datetime.utcnow) extra = DB.Column(Json(), nullable=False, default={})
class ConfigVar(DB.Model): __tablename__ = 'configuration' group = DB.Column(DB.String(1024), primary_key=True) name = DB.Column(DB.String(1024), primary_key=True) value = DB.Column(Json, nullable=False, default=None)
def tearDown(self): with self.app.test_request_context(): DB.drop_all() DB.session.remove() super(DBTestCase, self).tearDown()
def setUp(self): super(DBTestCase, self).setUp() # use memory backend by default self.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://' with self.app.test_request_context(): DB.create_all()