diff --git a/nimble/api/controllers/v1/instances.py b/nimble/api/controllers/v1/instances.py index 1d4ad4ad..38e48e1c 100644 --- a/nimble/api/controllers/v1/instances.py +++ b/nimble/api/controllers/v1/instances.py @@ -63,8 +63,8 @@ class Instance(base.APIBase): image_uuid = types.uuid """The image UUID of the instance""" - network_uuid = types.uuid - """The network UUID of the instance""" + network_info = {wtypes.text: types.jsontype} + """The network information of the instance""" links = wsme.wsattr([link.Link], readonly=True) """A list containing a self link""" diff --git a/nimble/api/controllers/v1/types.py b/nimble/api/controllers/v1/types.py index 4e269d19..32616e30 100644 --- a/nimble/api/controllers/v1/types.py +++ b/nimble/api/controllers/v1/types.py @@ -15,11 +15,15 @@ # License for the specific language governing permissions and limitations # under the License. +import json + from oslo_utils import strutils from oslo_utils import uuidutils +import six from wsme import types as wtypes from nimble.common import exception +from nimble.common.i18n import _ class UuidType(wtypes.UserType): @@ -62,5 +66,32 @@ class BooleanType(wtypes.UserType): return BooleanType.validate(value) +class JsonType(wtypes.UserType): + """A simple JSON type.""" + + basetype = wtypes.text + name = 'json' + + def __str__(self): + # These are the json serializable native types + return ' | '.join(map(str, (wtypes.text, six.integer_types, float, + BooleanType, list, dict, None))) + + @staticmethod + def validate(value): + try: + json.dumps(value) + except TypeError: + raise exception.Invalid(_('%s is not JSON serializable') % value) + else: + return value + + @staticmethod + def frombasetype(value): + return JsonType.validate(value) + + boolean = BooleanType() uuid = UuidType() +# Can't call it 'json' because that's the name of the stdlib module +jsontype = JsonType() diff --git a/nimble/db/sqlalchemy/alembic/versions/91941bf1ebc9_initial_migration.py b/nimble/db/sqlalchemy/alembic/versions/91941bf1ebc9_initial_migration.py index aabe336c..07d8631c 100644 --- a/nimble/db/sqlalchemy/alembic/versions/91941bf1ebc9_initial_migration.py +++ b/nimble/db/sqlalchemy/alembic/versions/91941bf1ebc9_initial_migration.py @@ -69,7 +69,7 @@ def upgrade(): sa.Column('task_state', sa.String(length=255), nullable=True), sa.Column('instance_type_id', sa.Integer(), nullable=True), sa.Column('image_uuid', sa.String(length=36), nullable=True), - sa.Column('network_uuid', sa.String(length=36), nullable=True), + sa.Column('network_info', sa.Text(), nullable=True), sa.Column('launched_at', sa.DateTime(), nullable=True), sa.Column('terminated_at', sa.DateTime(), nullable=True), sa.Column('availability_zone', sa.String(length=255), nullable=True), diff --git a/nimble/db/sqlalchemy/models.py b/nimble/db/sqlalchemy/models.py index 0290c9df..d738c2a0 100644 --- a/nimble/db/sqlalchemy/models.py +++ b/nimble/db/sqlalchemy/models.py @@ -19,6 +19,7 @@ SQLAlchemy models for baremetal compute service. from oslo_db import options as db_options from oslo_db.sqlalchemy import models +from oslo_db.sqlalchemy import types as db_types import six.moves.urllib.parse as urlparse from sqlalchemy import Boolean, Column from sqlalchemy import schema, String, Integer, Text @@ -105,6 +106,6 @@ class Instance(Base): instance_type_id = Column(Integer, nullable=True) availability_zone = Column(String(255), nullable=True) image_uuid = Column(String(36), nullable=True) - network_uuid = Column(String(36), nullable=True) + network_info = Column(db_types.JsonEncodedDict) node_uuid = Column(String(36), nullable=True) extra = Column(Text, nullable=True) diff --git a/nimble/engine/manager.py b/nimble/engine/manager.py index 130c108e..6bd7927a 100644 --- a/nimble/engine/manager.py +++ b/nimble/engine/manager.py @@ -58,7 +58,7 @@ class EngineManager(base_manager.BaseEngineManager): def _build_networks(self, context, instance): macs = ironic.get_macs_from_node(instance.node_uuid) - port = neutron.create_ports(context, instance.network_uuid, macs[0]) + port = neutron.create_ports(context, instance.network_info, macs[0]) ironic.plug_vifs(instance.node_uuid, port['port']['id']) def _wait_for_active(self, instance): diff --git a/nimble/objects/instance.py b/nimble/objects/instance.py index 6b61f01e..2ca1ac48 100644 --- a/nimble/objects/instance.py +++ b/nimble/objects/instance.py @@ -39,7 +39,7 @@ class Instance(base.NimbleObject, object_base.VersionedObjectDictCompat): 'instance_type_id': object_fields.IntegerField(nullable=True), 'availability_zone': object_fields.StringField(nullable=True), 'image_uuid': object_fields.UUIDField(nullable=True), - 'network_uuid': object_fields.UUIDField(nullable=True), + 'network_info': object_fields.FlexibleDictField(nullable=True), 'node_uuid': object_fields.UUIDField(nullable=True), 'extra': object_fields.FlexibleDictField(nullable=True), }