Merge "Return addresses with server API object"

This commit is contained in:
Jenkins 2017-08-28 04:34:48 +00:00 committed by Gerrit Code Review
commit 2a569c8533
13 changed files with 77 additions and 88 deletions

View File

@ -142,6 +142,12 @@ address:
in: body in: body
required: true required: true
type: string type: string
addresses:
description: |
The addresses for the server.
in: body
required: true
type: object
affinity_zone: affinity_zone:
description: | description: |
The affinity zone which the server belongs to. The affinity zone which the server belongs to.
@ -531,7 +537,7 @@ nics:
network uuid network uuid
in: body in: body
required: true required: true
type: dict type: object
node_uuid: node_uuid:
description: | description: |
The UUID of the node which our server associated with. Only visible for admin users. The UUID of the node which our server associated with. Only visible for admin users.
@ -543,7 +549,7 @@ nodes:
The compute node name list. The compute node name list.
in: body in: body
required: true required: true
type: dict type: object
personality: personality:
description: | description: |
The file path and contents, text only, to inject into the server at launch. The The file path and contents, text only, to inject into the server at launch. The

View File

@ -23,7 +23,7 @@
"affinity_zone": null, "affinity_zone": null,
"project_id": "2f15c3524826465a9afbd150478b3b76", "project_id": "2f15c3524826465a9afbd150478b3b76",
"user_id": "a6205fcab03d4a289251f420456b1289", "user_id": "a6205fcab03d4a289251f420456b1289",
"nics": [], "addresses": {},
"metadata": { "metadata": {
"My Server Name" : "Apache1" "My Server Name" : "Apache1"
} }

View File

@ -15,24 +15,14 @@
} }
], ],
"name": "test_server", "name": "test_server",
"nics": [ "addresses": {
{ "bcaebdc4-da29-46c2-8f85-ac22ecacec3c": [
"network_id": "f31af5a2-f14d-4007-b2e5-abeb82429b87", {
"port_id": "43cb1111-63c5-45d2-8bcf-3443d94b34f3", "type": "fixed",
"floating_ip": null, "addr": "192.168.0.3"
"mac_address": "52:54:00:d0:f9:2c", }
"fixed_ips": [ ]
{ },
"subnet_id": "5a324b29-9aca-43d8-a6c3-31986dda95b5",
"ip_address": "11.0.0.10"
},
{
"subnet_id": "9baceab1-40ec-4c53-ad83-530a625bddb1",
"ip_address": "fdaa:67c7:e09e:0:5054:ff:fed0:f92c"
}
]
}
],
"power_state": "power on", "power_state": "power on",
"project_id": "c18e8a1a870d4c08a0b51ced6e0b6459", "project_id": "c18e8a1a870d4c08a0b51ced6e0b6459",
"status": "building", "status": "building",

View File

@ -17,24 +17,14 @@
} }
], ],
"name": "test_server", "name": "test_server",
"nics": [ "addresses": {
{ "bcaebdc4-da29-46c2-8f85-ac22ecacec3c": [
"network_id": "f31af5a2-f14d-4007-b2e5-abeb82429b87", {
"port_id": "43cb1111-63c5-45d2-8bcf-3443d94b34f3", "type": "fixed",
"floating_ip": null, "addr": "192.168.0.3"
"mac_address": "52:54:00:d0:f9:2c", }
"fixed_ips": [ ]
{ },
"subnet_id": "5a324b29-9aca-43d8-a6c3-31986dda95b5",
"ip_address": "11.0.0.10"
},
{
"subnet_id": "9baceab1-40ec-4c53-ad83-530a625bddb1",
"ip_address": "fdaa:67c7:e09e:0:5054:ff:fed0:f92c"
}
]
}
],
"power_state": "power on", "power_state": "power on",
"project_id": "c18e8a1a870d4c08a0b51ced6e0b6459", "project_id": "c18e8a1a870d4c08a0b51ced6e0b6459",
"status": "building", "status": "building",

View File

@ -23,24 +23,14 @@
"affinity_zone": null, "affinity_zone": null,
"project_id": "2f15c3524826465a9afbd150478b3b76", "project_id": "2f15c3524826465a9afbd150478b3b76",
"user_id": "a6205fcab03d4a289251f420456b1289", "user_id": "a6205fcab03d4a289251f420456b1289",
"nics": [ "addresses": {
{ "bcaebdc4-da29-46c2-8f85-ac22ecacec3c": [
"network_id": "f31af5a2-f14d-4007-b2e5-abeb82429b87", {
"port_id": "99845c22-6268-46c1-b068-1dbcb8adaf68", "type": "fixed",
"floating_ip": null, "addr": "192.168.0.3"
"mac_address": "52:54:00:cc:ed:87", }
"fixed_ips": [ ]
{ },
"subnet_id": "5a324b29-9aca-43d8-a6c3-31986dda95b5",
"ip_address": "11.0.0.6"
},
{
"subnet_id": "9baceab1-40ec-4c53-ad83-530a625bddb1",
"ip_address": "fdaa:67c7:e09e:0:5054:ff:fecc:ed87"
}
]
}
],
"metadata": { "metadata": {
"k1": "v1", "k1": "v1",
"k2": "v2" "k2": "v2"

View File

@ -58,7 +58,7 @@ Response
- flavor_uuid: flavorRef - flavor_uuid: flavorRef
- image_uuid: imageRef - image_uuid: imageRef
- availability_zone: availability_zone - availability_zone: availability_zone
- nics: nics - addresses: addresses
- links: links - links: links
- uuid: server_uuid - uuid: server_uuid
- status: server_status - status: server_status
@ -208,7 +208,7 @@ Response
- flavor_uuid: flavorRef - flavor_uuid: flavorRef
- image_uuid: imageRef - image_uuid: imageRef
- availability_zone: availability_zone - availability_zone: availability_zone
- nics: nics - addresses: addresses
- links: links - links: links
- uuid: server_uuid - uuid: server_uuid
- status: server_status - status: server_status
@ -259,7 +259,7 @@ Response
- flavor_uuid: flavorRef - flavor_uuid: flavorRef
- image_uuid: imageRef - image_uuid: imageRef
- availability_zone: availability_zone - availability_zone: availability_zone
- nics: nics - addresses: addresses
- node_uuid: node_uuid - node_uuid: node_uuid
- links: links - links: links
- uuid: server_uuid - uuid: server_uuid
@ -322,7 +322,7 @@ Response
- flavor_uuid: flavorRef - flavor_uuid: flavorRef
- image_uuid: imageRef - image_uuid: imageRef
- availability_zone: availability_zone - availability_zone: availability_zone
- nics: nics - addresses: addresses
- links: links - links: links
- uuid: server_uuid - uuid: server_uuid
- status: server_status - status: server_status

View File

@ -435,8 +435,8 @@ class Server(base.APIBase):
image_uuid = types.uuid image_uuid = types.uuid
"""The image UUID of the server""" """The image UUID of the server"""
nics = types.jsontype addresses = types.jsontype
"""The nics information of the server""" """The addresses of the server"""
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"""
@ -461,9 +461,8 @@ class Server(base.APIBase):
self.fields = [] self.fields = []
for field in objects.Server.fields: for field in objects.Server.fields:
if field == 'nics': if field == 'nics':
self.fields.append(field) addresses = api_utils.show_addresses(kwargs.get('nics') or [])
nics = api_utils.show_nics(kwargs.get('nics') or []) setattr(self, 'addresses', addresses)
setattr(self, field, nics)
continue continue
if field == 'fault': if field == 'fault':
if kwargs.get('status') != 'error': if kwargs.get('status') != 'error':

View File

@ -56,6 +56,22 @@ def apply_jsonpatch(doc, patch):
return jsonpatch.apply_patch(doc, jsonpatch.JsonPatch(patch)) return jsonpatch.apply_patch(doc, jsonpatch.JsonPatch(patch))
def show_addresses(nics):
addresses = {}
for nic in nics:
address = []
for fixed_ip in nic.get('fixed_ips', []):
address.append({'addr': fixed_ip['ip_address'],
'type': 'fixed'})
if nic.get('floating_ip'):
address.append({'addr': nic['floating_ip'],
'type': 'floating'})
key = nic.get('network_id')
if key:
addresses[key] = address
return addresses
def show_nics(nics): def show_nics(nics):
show_keys = ['port_id', 'network_id', 'mac_address', show_keys = ['port_id', 'network_id', 'mac_address',
'fixed_ips', 'floating_ip', 'extra'] 'fixed_ips', 'floating_ip', 'extra']

View File

@ -152,25 +152,24 @@ class BuildNetworkTask(flow_utils.MoganTask):
if vif.get('net_id'): if vif.get('net_id'):
port = self.manager.network_api.create_port( port = self.manager.network_api.create_port(
context, vif['net_id'], server.uuid) context, vif['net_id'], server.uuid)
port_dict = port['port']
elif vif.get('port_id'): elif vif.get('port_id'):
port_dict = self.manager.network_api.show_port( port = self.manager.network_api.show_port(
context, vif.get('port_id')) context, vif.get('port_id'))
nic_dict = {'port_id': port_dict['id'], nic_dict = {'port_id': port['id'],
'network_id': port_dict['network_id'], 'network_id': port['network_id'],
'mac_address': port_dict['mac_address'], 'mac_address': port['mac_address'],
'fixed_ips': port_dict['fixed_ips'], 'fixed_ips': port['fixed_ips'],
'server_uuid': server.uuid} 'server_uuid': server.uuid}
server_nic = objects.ServerNic(context, **nic_dict) server_nic = objects.ServerNic(context, **nic_dict)
nics_obj.objects.append(server_nic) nics_obj.objects.append(server_nic)
self.manager.driver.plug_vif(server.node_uuid, self.manager.driver.plug_vif(server.node_uuid,
port_dict['id']) port['id'])
# Get updated VIF info # Get updated VIF info
port_dict = self.manager.network_api.show_port( port_dict = self.manager.network_api.show_port(
context, port_dict.get('id')) context, port.get('id'))
# Update the real physical mac address from ironic. # Update the real physical mac address from ironic.
server_nic.mac_address = port_dict['mac_address'] server_nic.mac_address = port_dict['mac_address']

View File

@ -534,14 +534,13 @@ class EngineManager(base_manager.BaseEngineManager):
LOG.debug("Attaching interface %(net_id) to server %(server)s", LOG.debug("Attaching interface %(net_id) to server %(server)s",
{'net_id': net_id, 'server': server}) {'net_id': net_id, 'server': server})
try: try:
vif = self.network_api.create_port(context, net_id, server.uuid) port = self.network_api.create_port(context, net_id, server.uuid)
vif_port = vif['port'] self.driver.plug_vif(server.node_uuid, port['id'])
self.driver.plug_vif(server.node_uuid, vif_port['id'])
nics_obj = objects.ServerNics(context) nics_obj = objects.ServerNics(context)
nic_dict = {'port_id': vif_port['id'], nic_dict = {'port_id': port['id'],
'network_id': vif_port['network_id'], 'network_id': port['network_id'],
'mac_address': vif_port['mac_address'], 'mac_address': port['mac_address'],
'fixed_ips': vif_port['fixed_ips'], 'fixed_ips': port['fixed_ips'],
'server_uuid': server.uuid} 'server_uuid': server.uuid}
nics_obj.objects.append(objects.ServerNic( nics_obj.objects.append(objects.ServerNic(
context, **nic_dict)) context, **nic_dict))

View File

@ -81,7 +81,8 @@ class API(object):
{'net': network_uuid, 'server': server_uuid, 'exc': e}) {'net': network_uuid, 'server': server_uuid, 'exc': e})
LOG.exception(msg) LOG.exception(msg)
raise exception.NetworkError(msg) raise exception.NetworkError(msg)
return port
return port['port']
def show_port(self, context, port_uuid): def show_port(self, context, port_uuid):
client = get_client(context.auth_token) client = get_client(context.auth_token)

View File

@ -126,12 +126,11 @@ class TestServers(v1_test.APITestV1):
self.assertEqual('b8f82429-3a13-4ffe-9398-4d1abdc256a8', self.assertEqual('b8f82429-3a13-4ffe-9398-4d1abdc256a8',
resp['image_uuid']) resp['image_uuid'])
self.assertIsNone(resp['availability_zone']) self.assertIsNone(resp['availability_zone'])
self.assertEqual([], resp['nics']) self.assertEqual({}, resp['addresses'])
self.assertEqual({'fake_key': 'fake_value'}, resp['metadata']) self.assertEqual({'fake_key': 'fake_value'}, resp['metadata'])
self.assertIn('links', resp) self.assertIn('links', resp)
self.assertIn('created_at', resp) self.assertIn('created_at', resp)
self.assertIn('updated_at', resp) self.assertIn('updated_at', resp)
self.assertIn('nics', resp)
self.assertIn('project_id', resp) self.assertIn('project_id', resp)
self.assertIn('launched_at', resp) self.assertIn('launched_at', resp)
@ -154,12 +153,12 @@ class TestServers(v1_test.APITestV1):
self.assertEqual('b8f82429-3a13-4ffe-9398-4d1abdc256a8', self.assertEqual('b8f82429-3a13-4ffe-9398-4d1abdc256a8',
resp['image_uuid']) resp['image_uuid'])
self.assertIsNone(resp['availability_zone']) self.assertIsNone(resp['availability_zone'])
self.assertEqual([], resp['nics']) self.assertEqual({}, resp['addresses'])
self.assertEqual({'fake_key': 'fake_value'}, resp['metadata']) self.assertEqual({'fake_key': 'fake_value'}, resp['metadata'])
self.assertIn('links', resp) self.assertIn('links', resp)
self.assertIn('created_at', resp) self.assertIn('created_at', resp)
self.assertIn('updated_at', resp) self.assertIn('updated_at', resp)
self.assertIn('nics', resp) self.assertIn('addresses', resp)
self.assertIn('project_id', resp) self.assertIn('project_id', resp)
self.assertIn('launched_at', resp) self.assertIn('launched_at', resp)

View File

@ -46,7 +46,7 @@ class BaremetalComputeAPIServersTest(base.BaseBaremetalComputeTest):
self.assertIn('project_id', resp) self.assertIn('project_id', resp)
self.assertIn('user_id', resp) self.assertIn('user_id', resp)
self.assertIn('availability_zone', resp) self.assertIn('availability_zone', resp)
self.assertIn('nics', resp) self.assertIn('addresses', resp)
self.assertIn('name', resp) self.assertIn('name', resp)
def test_server_show(self): def test_server_show(self):
@ -64,7 +64,7 @@ class BaremetalComputeAPIServersTest(base.BaseBaremetalComputeTest):
self.assertIn('project_id', resp) self.assertIn('project_id', resp)
self.assertIn('user_id', resp) self.assertIn('user_id', resp)
self.assertIn('availability_zone', resp) self.assertIn('availability_zone', resp)
self.assertIn('nics', resp) self.assertIn('addresses', resp)
self.assertIn('name', resp) self.assertIn('name', resp)
def test_server_list(self): def test_server_list(self):