Add migration code for updating lease status

Lease status was None before the status module was introduced.
This patch is for updating the None status.

Partially Implements: blueprint state-machine
Change-Id: I64cc07737d5c1c83a4f91d485a21c9a459305b9a
This commit is contained in:
Hiroaki Kobayashi 2018-01-23 11:43:12 +09:00
parent 552d1adaf1
commit 5d3918c885
1 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,43 @@
# Copyright 2018 OpenStack Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""update lease status
Revision ID: 75a74e4539cb
Revises: e66f199a5414
Create Date: 2018-01-23 11:05:56.753579
"""
# revision identifiers, used by Alembic.
revision = '75a74e4539cb'
down_revision = 'e66f199a5414'
from blazar.db import api as db_api
from blazar.status import LeaseStatus as ls
def upgrade():
leases = db_api.lease_get_all()
for lease in leases:
db_api.lease_update(lease['id'],
{'status': ls.derive_stable_status(lease['id'])})
def downgrade():
leases = db_api.lease_get_all()
for lease in leases:
db_api.lease_update(lease['id'],
{'status': None})