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
required: true
type: string
addresses:
description: |
The addresses for the server.
in: body
required: true
type: object
affinity_zone:
description: |
The affinity zone which the server belongs to.
@ -531,7 +537,7 @@ nics:
network uuid
in: body
required: true
type: dict
type: object
node_uuid:
description: |
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.
in: body
required: true
type: dict
type: object
personality:
description: |
The file path and contents, text only, to inject into the server at launch. The

View File

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

View File

@ -15,24 +15,14 @@
}
],
"name": "test_server",
"nics": [
{
"network_id": "f31af5a2-f14d-4007-b2e5-abeb82429b87",
"port_id": "43cb1111-63c5-45d2-8bcf-3443d94b34f3",
"floating_ip": null,
"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"
}
]
}
],
"addresses": {
"bcaebdc4-da29-46c2-8f85-ac22ecacec3c": [
{
"type": "fixed",
"addr": "192.168.0.3"
}
]
},
"power_state": "power on",
"project_id": "c18e8a1a870d4c08a0b51ced6e0b6459",
"status": "building",

View File

@ -17,24 +17,14 @@
}
],
"name": "test_server",
"nics": [
{
"network_id": "f31af5a2-f14d-4007-b2e5-abeb82429b87",
"port_id": "43cb1111-63c5-45d2-8bcf-3443d94b34f3",
"floating_ip": null,
"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"
}
]
}
],
"addresses": {
"bcaebdc4-da29-46c2-8f85-ac22ecacec3c": [
{
"type": "fixed",
"addr": "192.168.0.3"
}
]
},
"power_state": "power on",
"project_id": "c18e8a1a870d4c08a0b51ced6e0b6459",
"status": "building",

View File

@ -23,24 +23,14 @@
"affinity_zone": null,
"project_id": "2f15c3524826465a9afbd150478b3b76",
"user_id": "a6205fcab03d4a289251f420456b1289",
"nics": [
{
"network_id": "f31af5a2-f14d-4007-b2e5-abeb82429b87",
"port_id": "99845c22-6268-46c1-b068-1dbcb8adaf68",
"floating_ip": null,
"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"
}
]
}
],
"addresses": {
"bcaebdc4-da29-46c2-8f85-ac22ecacec3c": [
{
"type": "fixed",
"addr": "192.168.0.3"
}
]
},
"metadata": {
"k1": "v1",
"k2": "v2"

View File

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

View File

@ -435,8 +435,8 @@ class Server(base.APIBase):
image_uuid = types.uuid
"""The image UUID of the server"""
nics = types.jsontype
"""The nics information of the server"""
addresses = types.jsontype
"""The addresses of the server"""
links = wsme.wsattr([link.Link], readonly=True)
"""A list containing a self link"""
@ -461,9 +461,8 @@ class Server(base.APIBase):
self.fields = []
for field in objects.Server.fields:
if field == 'nics':
self.fields.append(field)
nics = api_utils.show_nics(kwargs.get('nics') or [])
setattr(self, field, nics)
addresses = api_utils.show_addresses(kwargs.get('nics') or [])
setattr(self, 'addresses', addresses)
continue
if field == 'fault':
if kwargs.get('status') != 'error':

View File

@ -56,6 +56,22 @@ def apply_jsonpatch(doc, 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):
show_keys = ['port_id', 'network_id', 'mac_address',
'fixed_ips', 'floating_ip', 'extra']

View File

@ -152,25 +152,24 @@ class BuildNetworkTask(flow_utils.MoganTask):
if vif.get('net_id'):
port = self.manager.network_api.create_port(
context, vif['net_id'], server.uuid)
port_dict = port['port']
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'))
nic_dict = {'port_id': port_dict['id'],
'network_id': port_dict['network_id'],
'mac_address': port_dict['mac_address'],
'fixed_ips': port_dict['fixed_ips'],
nic_dict = {'port_id': port['id'],
'network_id': port['network_id'],
'mac_address': port['mac_address'],
'fixed_ips': port['fixed_ips'],
'server_uuid': server.uuid}
server_nic = objects.ServerNic(context, **nic_dict)
nics_obj.objects.append(server_nic)
self.manager.driver.plug_vif(server.node_uuid,
port_dict['id'])
port['id'])
# Get updated VIF info
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.
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",
{'net_id': net_id, 'server': server})
try:
vif = self.network_api.create_port(context, net_id, server.uuid)
vif_port = vif['port']
self.driver.plug_vif(server.node_uuid, vif_port['id'])
port = self.network_api.create_port(context, net_id, server.uuid)
self.driver.plug_vif(server.node_uuid, port['id'])
nics_obj = objects.ServerNics(context)
nic_dict = {'port_id': vif_port['id'],
'network_id': vif_port['network_id'],
'mac_address': vif_port['mac_address'],
'fixed_ips': vif_port['fixed_ips'],
nic_dict = {'port_id': port['id'],
'network_id': port['network_id'],
'mac_address': port['mac_address'],
'fixed_ips': port['fixed_ips'],
'server_uuid': server.uuid}
nics_obj.objects.append(objects.ServerNic(
context, **nic_dict))

View File

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

View File

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

View File

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