summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vio/vio/pub/vim/drivers/vimsdk/compute.py13
-rw-r--r--vio/vio/pub/vim/vimapi/nova/OperateServers.py30
-rw-r--r--vio/vio/swagger/urls.py11
-rw-r--r--vio/vio/swagger/views/server/views.py46
4 files changed, 100 insertions, 0 deletions
diff --git a/vio/vio/pub/vim/drivers/vimsdk/compute.py b/vio/vio/pub/vim/drivers/vimsdk/compute.py
index 2326fff..e415573 100644
--- a/vio/vio/pub/vim/drivers/vimsdk/compute.py
+++ b/vio/vio/pub/vim/drivers/vimsdk/compute.py
@@ -77,6 +77,19 @@ class ComputeClient(base.DriverBase):
return list(ifaces)
@sdk.translate_exception
+ def start_server(self, server_id):
+ self.conn.compute.start_server(server=server_id)
+
+ @sdk.translate_exception
+ def stop_server(self, server_id):
+ self.conn.compute.stop_server(server=server_id)
+
+ @sdk.translate_exception
+ def reboot_server(self, server_id, reboot_type):
+ self.conn.compute.reboot_server(server=server_id,
+ reboot_type=reboot_type)
+
+ @sdk.translate_exception
def list_flavors(self, **query):
flavors = self.conn.compute.flavors(**query)
return flavors
diff --git a/vio/vio/pub/vim/vimapi/nova/OperateServers.py b/vio/vio/pub/vim/vimapi/nova/OperateServers.py
index 3075276..b14c7f4 100644
--- a/vio/vio/pub/vim/vimapi/nova/OperateServers.py
+++ b/vio/vio/pub/vim/vimapi/nova/OperateServers.py
@@ -162,3 +162,33 @@ class OperateServers(OperateNova):
'project_id': project_id}
project = self.compute(param).delete_server(server_id)
return project
+
+ def start_server(self, data, project_id, server_id):
+ param = {'username': data['username'],
+ 'user_domain_name': 'default',
+ 'project_domain_name': 'default',
+ 'password': data['password'],
+ 'auth_url': data['url'],
+ 'project_id': project_id}
+ project = self.compute(param).start_server(server_id)
+ return project
+
+ def stop_server(self, data, project_id, server_id):
+ param = {'username': data['username'],
+ 'user_domain_name': 'default',
+ 'project_domain_name': 'default',
+ 'password': data['password'],
+ 'auth_url': data['url'],
+ 'project_id': project_id}
+ project = self.compute(param).stop_server(server_id)
+ return project
+
+ def reboot_server(self, data, project_id, server_id, reboot_type):
+ param = {'username': data['username'],
+ 'user_domain_name': 'default',
+ 'project_domain_name': 'default',
+ 'password': data['password'],
+ 'auth_url': data['url'],
+ 'project_id': project_id}
+ project = self.compute(param).reboot_server(server_id, reboot_type)
+ return project
diff --git a/vio/vio/swagger/urls.py b/vio/vio/swagger/urls.py
index 3b5dac7..8456d71 100644
--- a/vio/vio/swagger/urls.py
+++ b/vio/vio/swagger/urls.py
@@ -25,6 +25,8 @@ from vio.swagger.views.image.views import GetImageFileView
from vio.swagger.views.volume.views import CreateListVolumeView
from vio.swagger.views.volume.views import GetDeleteVolumeView
from vio.swagger.views.server.views import ListServersView, GetServerView
+from vio.swagger.views.server.views import ServerActionView
+from vio.swagger.views.server.views import ServerActionViewV1
from vio.swagger.views.flavor.views import FlavorsView, FlavorView
from vio.swagger.views.network.views import CreateNetworkView
from vio.swagger.views.network.views import DeleteNetworkView
@@ -149,6 +151,10 @@ urlpatterns = [
r'(?P<tenantid>[0-9a-zA-Z]+)/servers/(?P<serverid>[0-9a-zA-Z_-]+)$',
GetServerView.as_view()),
url(r'^api/multicloud-vio/v0/(?P<vimid>[0-9a-zA-Z_-]+)/'
+ r'(?P<tenantid>[0-9a-zA-Z]+)/servers/'
+ r'(?P<serverid>[0-9a-zA-Z_-]+)/action$',
+ ServerActionView.as_view()),
+ url(r'^api/multicloud-vio/v0/(?P<vimid>[0-9a-zA-Z_-]+)/'
r'(?P<tenantid>[0-9a-zA-Z]+)/flavors$',
FlavorsView.as_view()),
url(r'^api/multicloud-vio/v0/(?P<vimid>[0-9a-zA-Z_-]+)/'
@@ -185,6 +191,7 @@ urlpatterns = [
r'(?P<portid>[0-9a-zA-Z\-\_]+)$',
DeletePortView.as_view()),
+
# V1 urls
url(r'^api/multicloud-vio/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/'
r'(?P<cloud_region>[0-9a-zA-Z_-]+)/tenants$',
@@ -223,6 +230,10 @@ urlpatterns = [
GetServerViewV1.as_view()),
url(r'^api/multicloud-vio/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/'
r'(?P<cloud_region>[0-9a-zA-Z_-]+)/(?P<tenantid>[0-9a-zA-Z]+)/'
+ r'servers/(?P<serverid>[0-9a-zA-Z_-]+)/action$',
+ ServerActionViewV1.as_view()),
+ url(r'^api/multicloud-vio/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/'
+ r'(?P<cloud_region>[0-9a-zA-Z_-]+)/(?P<tenantid>[0-9a-zA-Z]+)/'
r'flavors$',
FlavorsViewV1.as_view()),
url(r'^api/multicloud-vio/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/'
diff --git a/vio/vio/swagger/views/server/views.py b/vio/vio/swagger/views/server/views.py
index fca9cb9..be720c8 100644
--- a/vio/vio/swagger/views/server/views.py
+++ b/vio/vio/swagger/views/server/views.py
@@ -183,3 +183,49 @@ class GetServerViewV1(GetServerView):
def delete(self, request, cloud_owner, cloud_region, tenantid, serverid):
return super(GetServerViewV1, self).delete(
request, cloud_owner + "_" + cloud_region, tenantid, serverid)
+
+
+class ServerActionView(APIView):
+
+ def post(self, request, vimid, tenantid, serverid):
+ try:
+ action_req = json.loads(request.body)
+ except Exception as e:
+ return Response(data={'error': 'Fail to decode request body.'},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+ try:
+ vim_info = extsys.get_vim_by_id(vimid)
+ except VimDriverVioException as e:
+ return Response(data={'error': str(e)}, status=e.status_code)
+ data = {'vimid': vim_info['vimId'],
+ 'vimName': vim_info['name'],
+ 'username': vim_info['userName'],
+ 'password': vim_info['password'],
+ 'url': vim_info['url']}
+
+ server_op = OperateServers.OperateServers()
+ try:
+ if 'os-start' in action_req:
+ server_op.start_server(data, tenantid, serverid)
+ elif 'os-stop' in action_req:
+ server_op.stop_server(data, tenantid, serverid)
+ elif 'reboot' in action_req:
+ reboot_type = action_req.get('reboot').get('type')
+ server_op.reboot_server(data, tenantid, serverid, reboot_type)
+ else:
+ return Response(data={'error': 'invalid request body.'},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ except Exception as e:
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ return Response(status=status.HTTP_202_ACCEPTED)
+
+
+class ServerActionViewV1(ServerActionView):
+ def post(self, request, cloud_owner, cloud_region, tenantid, serverid):
+ return super(ServerActionViewV1, self).post(
+ request, cloud_owner + "_" + cloud_region, tenantid, serverid)