summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--newton/newton/requests/urls.py2
-rw-r--r--share/newton_base/openoapi/server.py32
2 files changed, 34 insertions, 0 deletions
diff --git a/newton/newton/requests/urls.py b/newton/newton/requests/urls.py
index 435ff239..ff1a7fb2 100644
--- a/newton/newton/requests/urls.py
+++ b/newton/newton/requests/urls.py
@@ -36,6 +36,8 @@ urlpatterns = [
volume.Volumes.as_view()),
url(r'^servers(/(?P<serverid>[0-9a-zA-Z_-]+))?',
server.Servers.as_view()),
+ url(r'^servers(/(?P<serverid>[0-9a-zA-Z_-]+))/action/?$',
+ server.ServerAction.as_view()),
url(r'^ports(/(?P<portid>[0-9a-zA-Z_-]+))?',
vport.Vports.as_view()),
url(r'^flavors(/(?P<flavorid>[0-9a-zA-Z_-]+))?',
diff --git a/share/newton_base/openoapi/server.py b/share/newton_base/openoapi/server.py
index 3e90bf84..0dd813c4 100644
--- a/share/newton_base/openoapi/server.py
+++ b/share/newton_base/openoapi/server.py
@@ -526,3 +526,35 @@ class APIv1Servers(Servers):
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
return super(APIv1Servers, self).delete(request, vimid, tenantid, serverid)
+
+
+class ServerAction(APIView):
+ service = {'service_type': 'compute',
+ 'interface': 'public'}
+ def post(self, request, vimid="", tenantid="", serverid=""):
+ logger.debug("ServerAction--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}/action".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)