Replace network_uuid with network_info

Change-Id: I9714741e7f6446668c94c3b4f1de5a40c3a8248e
This commit is contained in:
Zhenguo Niu
2016-09-23 23:26:41 +08:00
parent b6595cdeff
commit d23c59ec91
6 changed files with 38 additions and 6 deletions

View File

@@ -63,8 +63,8 @@ class Instance(base.APIBase):
image_uuid = types.uuid image_uuid = types.uuid
"""The image UUID of the instance""" """The image UUID of the instance"""
network_uuid = types.uuid network_info = {wtypes.text: types.jsontype}
"""The network UUID of the instance""" """The network information of the instance"""
links = wsme.wsattr([link.Link], readonly=True) links = wsme.wsattr([link.Link], readonly=True)
"""A list containing a self link""" """A list containing a self link"""

View File

@@ -15,11 +15,15 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import json
from oslo_utils import strutils from oslo_utils import strutils
from oslo_utils import uuidutils from oslo_utils import uuidutils
import six
from wsme import types as wtypes from wsme import types as wtypes
from nimble.common import exception from nimble.common import exception
from nimble.common.i18n import _
class UuidType(wtypes.UserType): class UuidType(wtypes.UserType):
@@ -62,5 +66,32 @@ class BooleanType(wtypes.UserType):
return BooleanType.validate(value) 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() boolean = BooleanType()
uuid = UuidType() uuid = UuidType()
# Can't call it 'json' because that's the name of the stdlib module
jsontype = JsonType()

View File

@@ -69,7 +69,7 @@ def upgrade():
sa.Column('task_state', sa.String(length=255), nullable=True), sa.Column('task_state', sa.String(length=255), nullable=True),
sa.Column('instance_type_id', sa.Integer(), nullable=True), sa.Column('instance_type_id', sa.Integer(), nullable=True),
sa.Column('image_uuid', sa.String(length=36), 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('launched_at', sa.DateTime(), nullable=True),
sa.Column('terminated_at', sa.DateTime(), nullable=True), sa.Column('terminated_at', sa.DateTime(), nullable=True),
sa.Column('availability_zone', sa.String(length=255), nullable=True), sa.Column('availability_zone', sa.String(length=255), nullable=True),

View File

@@ -19,6 +19,7 @@ SQLAlchemy models for baremetal compute service.
from oslo_db import options as db_options from oslo_db import options as db_options
from oslo_db.sqlalchemy import models from oslo_db.sqlalchemy import models
from oslo_db.sqlalchemy import types as db_types
import six.moves.urllib.parse as urlparse import six.moves.urllib.parse as urlparse
from sqlalchemy import Boolean, Column from sqlalchemy import Boolean, Column
from sqlalchemy import schema, String, Integer, Text from sqlalchemy import schema, String, Integer, Text
@@ -105,6 +106,6 @@ class Instance(Base):
instance_type_id = Column(Integer, nullable=True) instance_type_id = Column(Integer, nullable=True)
availability_zone = Column(String(255), nullable=True) availability_zone = Column(String(255), nullable=True)
image_uuid = Column(String(36), 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) node_uuid = Column(String(36), nullable=True)
extra = Column(Text, nullable=True) extra = Column(Text, nullable=True)

View File

@@ -58,7 +58,7 @@ class EngineManager(base_manager.BaseEngineManager):
def _build_networks(self, context, instance): def _build_networks(self, context, instance):
macs = ironic.get_macs_from_node(instance.node_uuid) 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']) ironic.plug_vifs(instance.node_uuid, port['port']['id'])
def _wait_for_active(self, instance): def _wait_for_active(self, instance):

View File

@@ -39,7 +39,7 @@ class Instance(base.NimbleObject, object_base.VersionedObjectDictCompat):
'instance_type_id': object_fields.IntegerField(nullable=True), 'instance_type_id': object_fields.IntegerField(nullable=True),
'availability_zone': object_fields.StringField(nullable=True), 'availability_zone': object_fields.StringField(nullable=True),
'image_uuid': object_fields.UUIDField(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), 'node_uuid': object_fields.UUIDField(nullable=True),
'extra': object_fields.FlexibleDictField(nullable=True), 'extra': object_fields.FlexibleDictField(nullable=True),
} }