From 672bd325d3a5327273773efdc8c7ae8b2a311064 Mon Sep 17 00:00:00 2001 From: Timur Sufiev Date: Wed, 4 Dec 2013 18:18:43 +0400 Subject: [PATCH] Support getting and updating network_info of environment. Change-Id: I6f0f5fe75cecba1ba78aeebc6e974b314ce5485e Closes-bug: #1257629 --- muranoapi/common/service.py | 1 + .../versions/002_add_networking_field.py | 33 +++++++++++++++++++ muranoapi/db/models.py | 1 + 3 files changed, 35 insertions(+) create mode 100644 muranoapi/db/migrate_repo/versions/002_add_networking_field.py diff --git a/muranoapi/common/service.py b/muranoapi/common/service.py index 29490b85..f6fe6e58 100644 --- a/muranoapi/common/service.py +++ b/muranoapi/common/service.py @@ -102,6 +102,7 @@ def handle_result(message): return environment.description = environment_result + environment.networking = environment_result.get('networking', {}) environment.version += 1 environment.save(session) diff --git a/muranoapi/db/migrate_repo/versions/002_add_networking_field.py b/muranoapi/db/migrate_repo/versions/002_add_networking_field.py new file mode 100644 index 00000000..39437160 --- /dev/null +++ b/muranoapi/db/migrate_repo/versions/002_add_networking_field.py @@ -0,0 +1,33 @@ +# Copyright (c) 2013 Mirantis, Inc. +# +# 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. +from migrate.changeset.constraint import ForeignKeyConstraint + +from sqlalchemy.schema import MetaData, Table, Column +from sqlalchemy.types import String, Text, DateTime, BigInteger + + +meta = MetaData() + + +def upgrade(migrate_engine): + meta.bind = migrate_engine + environment = Table('environment', meta, autoload=True) + networking = Column('networking', Text(), nullable=True, default='{}') + networking.create(environment) + + +def downgrade(migrate_engine): + meta.bind = migrate_engine + environment = Table('environment', meta, autoload=True) + environment.c.networking.drop() diff --git a/muranoapi/db/models.py b/muranoapi/db/models.py index 017d206b..c091a0d3 100644 --- a/muranoapi/db/models.py +++ b/muranoapi/db/models.py @@ -104,6 +104,7 @@ class Environment(BASE, ModelBase): tenant_id = Column(String(32), nullable=False) version = Column(BigInteger, nullable=False, default=0) description = Column(JsonBlob(), nullable=False, default={}) + networking = Column(JsonBlob(), nullable=True, default={}) sessions = relationship("Session", backref='environment', cascade='save-update, merge, delete')