summaryrefslogtreecommitdiffstats
path: root/newton
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2017-03-29 13:35:13 +0800
committerBin Yang <bin.yang@windriver.com>2017-03-29 13:35:13 +0800
commitf492faa2f0c377f9fe159e9eb15b9fafb1576320 (patch)
tree062d362cd4b5c7583e3a2bffb152043c49116b3e /newton
parent31dd818f6dff95e32b5bcfdc13fd1b584ba45131 (diff)
Fix bug in server API
add nicArray to server information model Change-Id: I58940d2d18a233b5c01bf930acc6c98d68b803ca Issue-Id: MULTIVIM-59 Signed-off-by: Bin Yang <bin.yang@windriver.com>
Diffstat (limited to 'newton')
-rw-r--r--newton/newton/requests/views/server.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/newton/newton/requests/views/server.py b/newton/newton/requests/views/server.py
index 022f206c..5a9a90c3 100644
--- a/newton/newton/requests/views/server.py
+++ b/newton/newton/requests/views/server.py
@@ -198,9 +198,9 @@ class Servers(APIView):
imageObj = server.pop("image", None)
imageId = imageObj.pop("id", None) if imageObj else None
if imageId:
- server["boot"] = {"type":1, "imageId": imageId}
+ server["boot"] = {"type":2, "imageId": imageId}
else:
- server["boot"] = {"type":2, "volumeId":tmpVolumeArray.pop(0)["volumeId"] if len(tmpVolumeArray) > 0 else None}
+ server["boot"] = {"type":1, "volumeId":tmpVolumeArray.pop(0)["volumeId"] if len(tmpVolumeArray) > 0 else None}
#convert OS-EXT-AZ:availability_zone
server["availabilityZone"] = server.pop("OS-EXT-AZ:availability_zone", None)
@@ -222,6 +222,17 @@ class Servers(APIView):
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ def get_ports(self, vimid="", tenantid="", serverid=None):
+ # query attached ports
+ vim = VimDriverUtils.get_vim_info(vimid)
+ sess = VimDriverUtils.get_session(vim, tenantid)
+ req_resouce = "servers/%s/os-interface" % serverid
+ resp = sess.get(req_resouce, endpoint_filter=self.service)
+ ports = resp.json()
+ if ports and ports["interfaceAttachments"] and len(ports["interfaceAttachments"]) > 0:
+ return [{"portId":port["port_id"]} for port in ports["interfaceAttachments"]]
+ else:
+ return None
def get_servers(self, query="", vimid="", tenantid="", serverid=None):
logger.debug("Servers--get_servers::> %s,%s" % (tenantid, serverid))
@@ -257,6 +268,8 @@ class Servers(APIView):
VimDriverUtils.replace_key_by_mapping(server,
self.keys_mapping)
self.convert_resp(server)
+ server["nicArray"] = self.get_ports(vimid, tenantid, server["id"])
+
else:
# convert the key naming in the server specified by id
server = content.pop("server", None)
@@ -268,6 +281,7 @@ class Servers(APIView):
VimDriverUtils.replace_key_by_mapping(server,
self.keys_mapping)
self.convert_resp(server)
+ server["nicArray"] = self.get_ports(vimid, tenantid, serverid)
content.update(server)
return content, resp.status_code