Merge "Add affinity_zone field for server object"

This commit is contained in:
Jenkins 2017-08-25 11:39:29 +00:00 committed by Gerrit Code Review
commit 77d19eceb7
13 changed files with 27 additions and 3 deletions

View File

@ -142,6 +142,12 @@ address:
in: body
required: true
type: string
affinity_zone:
description: |
The affinity zone which the server belongs to.
in: body
required: false
type: string
aggregate_metadata:
description: |
Metadata key and value pairs associate with the aggregate.

View File

@ -20,6 +20,7 @@
"created_at": "2016-09-27T02:37:21.966342+00:00",
"launched_at": "2016-09-27T02:39:21.966342+00:00",
"updated_at": null,
"affinity_zone": null,
"project_id": "2f15c3524826465a9afbd150478b3b76",
"user_id": "a6205fcab03d4a289251f420456b1289",
"nics": [],

View File

@ -30,6 +30,7 @@
"detail": "fault detail"
},
"launched_at" : null,
"affinity_zone": null,
"updated_at": "2016-10-17T04:12:44+00:00",
"user_id": "cdbf77d47f1d4d04ad9b7ff62b672467",
"uuid": "f978ef48-d4af-4dad-beec-e6174309bc71",

View File

@ -37,6 +37,7 @@
"project_id": "c18e8a1a870d4c08a0b51ced6e0b6459",
"status": "building",
"launched_at" : null,
"affinity_zone": null,
"updated_at": "2016-10-17T04:12:44+00:00",
"user_id": "cdbf77d47f1d4d04ad9b7ff62b672467",
"uuid": "f978ef48-d4af-4dad-beec-e6174309bc71",

View File

@ -40,6 +40,7 @@
"status": "building",
"updated_at": "2016-10-17T04:12:44+00:00",
"launched_at": null,
"affinity_zone": null,
"user_id": "cdbf77d47f1d4d04ad9b7ff62b672467",
"uuid": "f978ef48-d4af-4dad-beec-e6174309bc71",
"metadata": {

View File

@ -20,6 +20,7 @@
"created_at": "2016-09-27T02:37:21.966342+00:00",
"launched_at": "2016-09-27T02:39:21.966342+00:00",
"updated_at": null,
"affinity_zone": null,
"project_id": "2f15c3524826465a9afbd150478b3b76",
"user_id": "a6205fcab03d4a289251f420456b1289",
"nics": [

View File

@ -68,6 +68,7 @@ Response
- updated_at: updated_at
- created_at: created_at
- metadata: metadata
- affinity_zone: affinity_zone
**Example Create Server: JSON response**
@ -218,6 +219,7 @@ Response
- created_at: created_at
- launched_at: launched_at
- metadata: metadata
- affinity_zone: affinity_zone
**Example Detailed list of Servers: JSON response**
@ -270,6 +272,7 @@ Response
- created_at: created_at
- launched_at: launched_at
- metadata: metadata
- affinity_zone: affinity_zone
**Example Server Details: JSON response**
@ -329,6 +332,7 @@ Response
- updated_at: updated_at
- created_at: created_at
- metadata: metadata
- affinity_zone: affinity_zone
**Example Update Server: JSON response**

View File

@ -46,6 +46,8 @@ import re
_DEFAULT_SERVER_RETURN_FIELDS = ('uuid', 'name', 'description',
'status', 'power_state')
_ONLY_ADMIN_VISIBLE_SEVER_FIELDS = ('node_uuid', 'affinity_zone',)
LOG = log.getLogger(__name__)
@ -451,6 +453,9 @@ class Server(base.APIBase):
node_uuid = types.uuid
"""The node UUID of the server"""
affinity_zone = wtypes.text
"""The affinity zone of the server"""
def __init__(self, **kwargs):
super(Server, self).__init__(**kwargs)
self.fields = []
@ -464,7 +469,7 @@ class Server(base.APIBase):
if kwargs.get('status') != 'error':
setattr(self, field, wtypes.Unset)
continue
if field == 'node_uuid':
if field in _ONLY_ADMIN_VISIBLE_SEVER_FIELDS:
if not pecan.request.context.is_admin:
setattr(self, field, wtypes.Unset)
continue
@ -503,7 +508,7 @@ class ServerPatchType(types.JsonPatchType):
return defaults + ['/project_id', '/user_id', '/status',
'/power_state', '/availability_zone',
'/flavor_uuid', '/image_uuid',
'/nics', '/launched_at']
'/nics', '/launched_at', '/affinity_zone']
class ServerCollection(base.APIBase):

View File

@ -77,6 +77,7 @@ def upgrade():
sa.Column('node_uuid', sa.String(length=36), nullable=True),
sa.Column('extra', sa.Text(), nullable=True),
sa.Column('locked', sa.Boolean(), nullable=True),
sa.Column('affinity_zone', sa.String(length=255), nullable=True),
sa.Column('locked_by', sa.Enum('admin', 'owner'), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('uuid', name='uniq_servers0uuid'),

View File

@ -90,6 +90,7 @@ class Server(Base):
extra = Column(db_types.JsonEncodedDict)
locked = Column(Boolean)
locked_by = Column(Enum('owner', 'admin'))
affinity_zone = Column(String(255), nullable=True)
class ServerNic(Base):

View File

@ -54,6 +54,7 @@ class Server(base.MoganObject, object_base.VersionedObjectDictCompat):
'metadata': object_fields.FlexibleDictField(nullable=True),
'locked': object_fields.BooleanField(default=False),
'locked_by': object_fields.StringField(nullable=True),
'affinity_zone': object_fields.StringField(nullable=True),
}
def __init__(self, context=None, **kwargs):

View File

@ -62,6 +62,7 @@ def get_test_server(**kw):
'created_at': kw.get('created_at'),
'locked': kw.get('locked', False),
'locked_by': kw.get('locked_by', None),
'affinity_zone': kw.get('affinity_zone', 'ZON1')
}

View File

@ -382,7 +382,7 @@ class _TestObject(object):
# version bump. It is md5 hash of object fields and remotable methods.
# The fingerprint values should only be changed if there is a version bump.
expected_object_fingerprints = {
'Server': '1.0-dc54162c0cc91fac43fed5304cd2c968',
'Server': '1.0-6d6a620781fe8da4feaec11272e3e5d3',
'ServerFault': '1.0-74349ff701259e4834b4e9dc2dac1b12',
'ServerFaultList': '1.0-43e8aad0258652921f929934e9e048fd',
'Flavor': '1.0-9f7166aa387d89ec40cd699019d0c9a9',