~zhangbailin/openstack-venus/master

« back to all changes in this revision

Viewing changes to venus/task/backends/models.py

  • Committer: jiasirui
  • Date: 2021-05-11 06:40:14 UTC
  • Revision ID: git-v1:4f7515ed2e0664102fbd4197473a917b591144ce
delete mysql storage and use config file store data

Change-Id: I0785cf2c7c0d828d653bd6f20f3e804275014f99

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2020 Inspur
2
 
#
3
 
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
 
# not use this file except in compliance with the License. You may obtain
5
 
# a copy of the License at
6
 
#
7
 
#      http://www.apache.org/licenses/LICENSE-2.0
8
 
#
9
 
# Unless required by applicable law or agreed to in writing, software
10
 
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
 
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
 
# License for the specific language governing permissions and limitations
13
 
# under the License.
14
 
 
15
 
"""
16
 
SQLAlchemy models for venus data.
17
 
"""
18
 
 
19
 
from oslo_db.sqlalchemy import models
20
 
from oslo_utils import timeutils
21
 
from sqlalchemy import Column
22
 
from sqlalchemy.ext.declarative import declarative_base
23
 
from sqlalchemy import DateTime, String
24
 
from venus.conf import CONF
25
 
BASE = declarative_base()
26
 
 
27
 
 
28
 
class VenusBase(models.TimestampMixin,
29
 
                models.ModelBase):
30
 
    """Base class for Venus Models."""
31
 
 
32
 
    __table_args__ = {'mysql_engine': 'InnoDB'}
33
 
 
34
 
    # TODO(rpodolyaka): reuse models.SoftDeleteMixin in the next stage
35
 
    #                   of implementing of BP db-cleanup
36
 
    created_at = Column(DateTime)
37
 
    updated_at = Column(DateTime)
38
 
    deleted_at = Column(DateTime)
39
 
    deleted = Column(String(1), default=0)
40
 
    metadata = None
41
 
 
42
 
    def delete(self, session):
43
 
        """Delete this object."""
44
 
        self.deleted = True
45
 
        self.deleted_at = timeutils.utcnow()
46
 
        self.save(session=session)
47
 
 
48
 
 
49
 
def register_models():
50
 
    """Rvenuster Models and create metadata.
51
 
 
52
 
    Called from venus.db.sqlalchemy.__init__ as part of loading the driver,
53
 
    it will never need to be called explicitly elsewhere unless the
54
 
    connection is lost and needs to be reestablished.
55
 
    """
56
 
    from sqlalchemy import create_engine
57
 
 
58
 
    models = ()
59
 
    engine = create_engine(CONF.database.connection, echo=False)
60
 
    for model in models:
61
 
        model.metadata.create_all(engine)
62
 
 
63
 
 
64
 
class RegitsterTask(BASE, VenusBase):
65
 
    __tablename__ = 't_mo_regitster_task'
66
 
    Id = Column(String(11), primary_key=True)
67
 
    task_name = Column(String(255))
68
 
    host_name = Column(String(255))
69
 
    update_time = Column(DateTime())