summaryrefslogtreecommitdiffstats
path: root/share/newton_base/openoapi/vport.py
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2018-08-15 06:11:24 +0000
committerBin Yang <bin.yang@windriver.com>2018-08-15 06:11:24 +0000
commit400e1b7c35a1db4cdcf20f4453631bc0888a330f (patch)
tree49d1c5355fb2072f8be9975fa83ae93ae5d7dc60 /share/newton_base/openoapi/vport.py
parent8eacf7b7496a7864313595dcf3780d83b423c338 (diff)
API upgrading for OPENOAPI
Change-Id: I8d0fdc7671d9333ee24e77dda9e07c32a0767950 Issue-ID: MULTICLOUD-297 Signed-off-by: Bin Yang <bin.yang@windriver.com>
Diffstat (limited to 'share/newton_base/openoapi/vport.py')
-rw-r--r--share/newton_base/openoapi/vport.py36
1 files changed, 31 insertions, 5 deletions
diff --git a/share/newton_base/openoapi/vport.py b/share/newton_base/openoapi/vport.py
index 7f916d3d..648ec02b 100644
--- a/share/newton_base/openoapi/vport.py
+++ b/share/newton_base/openoapi/vport.py
@@ -22,6 +22,7 @@ from rest_framework.views import APIView
from common.exceptions import VimDriverNewtonException
from newton_base.util import VimDriverUtils
+from common.msapi import extsys
logger = logging.getLogger(__name__)
@@ -47,7 +48,7 @@ class Vports(APIView):
try:
# prepare request resource to vim instance
query = VimDriverUtils.get_query_part(request)
- content, status_code = self.get_ports(query, vimid, tenantid, portid)
+ content, status_code = self._get_ports(query, vimid, tenantid, portid)
logger.info("response with status = %s" % status_code)
return Response(data=content, status=status_code)
except VimDriverNewtonException as e:
@@ -61,7 +62,7 @@ class Vports(APIView):
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- def get_ports(self, query="", vimid="", tenantid="", portid=""):
+ def _get_ports(self, query="", vimid="", tenantid="", portid=""):
vim = VimDriverUtils.get_vim_info(vimid)
sess = VimDriverUtils.get_session(vim, tenantid)
@@ -87,6 +88,8 @@ class Vports(APIView):
vim_dict = {
"vimName": vim["name"],
"vimId": vim["vimId"],
+ "cloud-owner": vim["cloud_owner"],
+ "cloud-region-id": vim["cloud_region_id"],
"tenantId": tenantid,
}
content.update(vim_dict)
@@ -120,7 +123,7 @@ class Vports(APIView):
try:
#check if already created: name
query = "name=%s" % request.data["name"]
- content, status_code = self.get_ports(query, vimid, tenantid, portid)
+ content, status_code = self._get_ports(query, vimid, tenantid, portid)
existed = False
if status_code == 200:
for port in content["ports"]:
@@ -135,7 +138,7 @@ class Vports(APIView):
return Response(data=port, status=status_code)
#otherwise create a new one
- return self.create_port(request, vimid, tenantid)
+ return self._create_port(request, vimid, tenantid)
except VimDriverNewtonException as e:
logger.error("response with status = %s" % e.status_code)
return Response(data={'error': e.content}, status=e.status_code)
@@ -147,7 +150,7 @@ class Vports(APIView):
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- def create_port(self, request, vimid, tenantid):
+ def _create_port(self, request, vimid, tenantid):
vim = VimDriverUtils.get_vim_info(vimid)
sess = VimDriverUtils.get_session(vim, tenantid)
if sess:
@@ -185,6 +188,8 @@ class Vports(APIView):
vim_dict = {
"vimName": vim["name"],
"vimId": vim["vimId"],
+ "cloud-owner": vim["cloud_owner"],
+ "cloud-region-id": vim["cloud_region_id"],
"tenantId": tenantid,
"returnCode": 1,
}
@@ -222,3 +227,24 @@ class Vports(APIView):
logger.error(traceback.format_exc())
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+class APIv1Vports(Vports):
+
+ def get(self, request, cloud_owner="", cloud_region_id="", tenantid="", portid=""):
+ self._logger.info("%s, %s" % (cloud_owner, cloud_region_id))
+
+ vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
+ return super(APIv1Vports, self).get(request, vimid, tenantid, portid)
+
+ def post(self, request, cloud_owner="", cloud_region_id="", tenantid="", portid=""):
+ self._logger.info("%s, %s" % (cloud_owner, cloud_region_id))
+
+ vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
+ return super(APIv1Vports, self).post(request, vimid, tenantid, portid)
+
+ def delete(self, request, cloud_owner="", cloud_region_id="", tenantid="", portid=""):
+ self._logger.info("%s, %s" % (cloud_owner, cloud_region_id))
+
+ vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
+ return super(APIv1Vports, self).delete(request, vimid, tenantid, portid)