summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-04-04 08:32:13 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-04-04 08:32:13 +0800
commit0491327f8dcd808402669c3d8f32a5a0f879db45 (patch)
tree4772dc63dbc2964132d8b98c15daeeb9642db48b
parent8a67ca0851e4af20791c74d7f6595f631f7130b4 (diff)
Add os-interface api for server
Change-Id: Ia9f98d3ba841dd70d0969334d86dbbd3a0f6ac0e Issue-ID: MULTICLOUD-565 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--share/newton_base/openoapi/server.py83
-rw-r--r--windriver/titanium_cloud/requests/urls.py4
-rw-r--r--windriver/titanium_cloud/requests/urlsV1.py4
3 files changed, 90 insertions, 1 deletions
diff --git a/share/newton_base/openoapi/server.py b/share/newton_base/openoapi/server.py
index 0c2382ae..7dc229f0 100644
--- a/share/newton_base/openoapi/server.py
+++ b/share/newton_base/openoapi/server.py
@@ -555,7 +555,7 @@ class ServerAction(APIView):
endpoint_filter=self.service,
headers={"Content-Type": "application/json",
"Accept": "application/json"})
- resp_body = {}
+ resp_body = resp.json()
return Response(data=resp_body, status=resp.status_code)
except VimDriverKiloException as e:
@@ -568,9 +568,90 @@ class ServerAction(APIView):
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
class APIv1ServerAction(ServerAction):
def post(self, request, cloud_owner="", cloud_region_id="", tenantid="", serverid=""):
self._logger.info("%s, %s" % (cloud_owner, cloud_region_id))
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
return super(APIv1ServerAction, self).post(request, vimid, tenantid, serverid)
+
+
+class ServerOsInterface(APIView):
+ service = {'service_type': 'compute',
+ 'interface': 'public'}
+ def post(self, request, vimid="", tenantid="", serverid=""):
+ logger.debug("ServerOsInterface--post::> %s" % request.data)
+ logger.debug("vimid=%s, tenantid=%s, serverid=%s", vimid, tenantid, serverid)
+ try:
+ # prepare request resource to vim instance
+ vim = VimDriverUtils.get_vim_info(vimid)
+ sess = VimDriverUtils.get_session(vim, tenantid)
+
+ # operate server now
+ req_resouce = "servers/{server_id}/os-interface".format(server_id=serverid)
+ req_body = json.JSONEncoder().encode(request.data)
+ resp = sess.post(req_resouce, data=req_body,
+ endpoint_filter=self.service,
+ headers={"Content-Type": "application/json",
+ "Accept": "application/json"})
+ resp_body = resp.json()
+
+ return Response(data=resp_body, status=resp.status_code)
+ except VimDriverKiloException as e:
+ return Response(data={'error': e.content}, status=e.status_code)
+ except HttpError as e:
+ logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
+ return Response(data=e.response.json(), status=e.http_status)
+ except Exception as e:
+ logger.error(traceback.format_exc())
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+class APIv1ServerOsInterface(ServerOsInterface):
+ def post(self, request, cloud_owner="", cloud_region_id="", tenantid="", serverid=""):
+ self._logger.info("%s, %s" % (cloud_owner, cloud_region_id))
+
+ vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
+ return super(APIv1ServerOsInterface, self).post(request, vimid, tenantid, serverid)
+
+
+class ServerOsInterfacePort(APIView):
+ service = {'service_type': 'compute',
+ 'interface': 'public'}
+ def delete(self, request, vimid="", tenantid="", serverid="", portid=""):
+ logger.debug("ServerOsInterfacePort--delete::portid=%s", portid)
+ logger.debug("vimid=%s, tenantid=%s, serverid=%s", vimid, tenantid, serverid)
+ try:
+ # prepare request resource to vim instance
+ vim = VimDriverUtils.get_vim_info(vimid)
+ sess = VimDriverUtils.get_session(vim, tenantid)
+
+ # operate server now
+ req_resfmt = "servers/{server_id}/os-interface/{port_id}"
+ req_resouce = req_resfmt.format(server_id=serverid, port_id=portid)
+ resp = sess.delete(req_resouce,
+ endpoint_filter=self.service,
+ headers={"Content-Type": "application/json",
+ "Accept": "application/json"})
+ resp_body = {}
+
+ return Response(data=resp_body, status=resp.status_code)
+ except VimDriverKiloException as e:
+ return Response(data={'error': e.content}, status=e.status_code)
+ except HttpError as e:
+ logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
+ return Response(data=e.response.json(), status=e.http_status)
+ except Exception as e:
+ logger.error(traceback.format_exc())
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+class APIv1ServerOsInterfacePort(ServerOsInterfacePort):
+ def delete(self, request, cloud_owner="", cloud_region_id="", tenantid="", serverid="", portid=""):
+ self._logger.info("%s, %s" % (cloud_owner, cloud_region_id))
+
+ vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
+ return super(APIv1ServerOsInterfacePort, self).post(request, vimid, tenantid, serverid, portid)
diff --git a/windriver/titanium_cloud/requests/urls.py b/windriver/titanium_cloud/requests/urls.py
index 73cc1543..bfba9c73 100644
--- a/windriver/titanium_cloud/requests/urls.py
+++ b/windriver/titanium_cloud/requests/urls.py
@@ -36,6 +36,10 @@ urlpatterns = [
volume.Volumes.as_view()),
url(r'^servers(/(?P<serverid>[0-9a-zA-Z_-]+))/action/?$',
server.ServerAction.as_view()),
+ url(r'^servers(/(?P<serverid>[0-9a-zA-Z_-]+))/os-interface/?$',
+ server.ServerOsInterface.as_view()),
+ url(r'^servers(/(?P<serverid>[0-9a-zA-Z_-]+))/os-interface(/(?P<portid>[0-9a-zA-Z_-]+))?',
+ server.ServerOsInterfacePort.as_view()),
url(r'^servers(/(?P<serverid>[0-9a-zA-Z_-]+))?',
server.Servers.as_view()),
url(r'^ports(/(?P<portid>[0-9a-zA-Z_-]+))?',
diff --git a/windriver/titanium_cloud/requests/urlsV1.py b/windriver/titanium_cloud/requests/urlsV1.py
index 6e884ab1..eaca68c6 100644
--- a/windriver/titanium_cloud/requests/urlsV1.py
+++ b/windriver/titanium_cloud/requests/urlsV1.py
@@ -36,6 +36,10 @@ urlpatterns = [
volume.APIv1Volumes.as_view()),
url(r'^servers(/(?P<serverid>[0-9a-zA-Z_-]+))/action/?$',
server.APIv1ServerAction.as_view()),
+ url(r'^servers(/(?P<serverid>[0-9a-zA-Z_-]+))/os-interface/?$',
+ server.APIv1ServerOsInterface.as_view()),
+ url(r'^servers(/(?P<serverid>[0-9a-zA-Z_-]+))/os-interface(/(?P<portid>[0-9a-zA-Z_-]+))?',
+ server.APIv1ServerOsInterfacePort.as_view()),
url(r'^servers(/(?P<serverid>[0-9a-zA-Z_-]+))?',
server.APIv1Servers.as_view()),
url(r'^ports(/(?P<portid>[0-9a-zA-Z_-]+))?',