diff options
author | 2017-08-19 14:27:16 +0800 | |
---|---|---|
committer | 2017-08-19 14:27:16 +0800 | |
commit | 99371e7da417fc7050c20dacfa8897c41565f65c (patch) | |
tree | dce8702a768960786edf584ba230fe6b35e103af | |
parent | b4ae92c191552276611cd3c161d0af18cb5a088d (diff) |
Add workflow api init codes
Change-Id: Ia93c3bd198f2ad541671393dd06d651f4fe4a4f1
Issue-Id: VFC-115
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/urls.py | 1 | ||||
-rw-r--r-- | lcm/workflows/__init__.py | 13 | ||||
-rw-r--r-- | lcm/workflows/tests.py | 31 | ||||
-rw-r--r-- | lcm/workflows/urls.py | 23 | ||||
-rw-r--r-- | lcm/workflows/views.py | 47 |
5 files changed, 115 insertions, 0 deletions
diff --git a/lcm/urls.py b/lcm/urls.py index c9a808b3..9471def9 100644 --- a/lcm/urls.py +++ b/lcm/urls.py @@ -23,6 +23,7 @@ urlpatterns = [ url(r'^', include('lcm.ns.sfcs.urls')), url(r'^', include('lcm.ns.urls')), url(r'^', include('lcm.jobs.urls')), + url(r'^', include('lcm.workflows.urls')), ] # regist to MSB when startup diff --git a/lcm/workflows/__init__.py b/lcm/workflows/__init__.py new file mode 100644 index 00000000..c7b6818e --- /dev/null +++ b/lcm/workflows/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2017 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/lcm/workflows/tests.py b/lcm/workflows/tests.py new file mode 100644 index 00000000..31651624 --- /dev/null +++ b/lcm/workflows/tests.py @@ -0,0 +1,31 @@ +# Copyright 2017 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import json +from django.test import Client +from rest_framework import status + + +class WorkflowViewTest(unittest.TestCase): + def setUp(self): + self.client = Client() + + def tearDown(self): + pass + + def test_deploy_workflow(self): + response = self.client.post("/api/nslcm/v1/workflow", + {"filePath": "/home/init.zip"}, format='json') + self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content) diff --git a/lcm/workflows/urls.py b/lcm/workflows/urls.py new file mode 100644 index 00000000..2545ffba --- /dev/null +++ b/lcm/workflows/urls.py @@ -0,0 +1,23 @@ +# Copyright 2017 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django.conf.urls import url +from rest_framework.urlpatterns import format_suffix_patterns +from lcm.workflows import views + +urlpatterns = [ + url(r'^api/nslcm/v1/workflow$', views.deploy_workflow, name='deploy_workflow'), +] + +urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/lcm/workflows/views.py b/lcm/workflows/views.py new file mode 100644 index 00000000..92f029fb --- /dev/null +++ b/lcm/workflows/views.py @@ -0,0 +1,47 @@ +# Copyright 2017 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import logging +import traceback + +from rest_framework import status +from rest_framework.decorators import api_view +from rest_framework.response import Response + +from lcm.pub.database import models +from lcm.pub.utils.syscomm import fun_name +from lcm.pub.utils.values import ignore_case_get + + +logger = logging.getLogger(__name__) + + +@api_view(http_method_names=['POST']) +def deploy_workflow(request, *args, **kwargs): + logger.debug("Enter %s", fun_name()) + file_path = ignore_case_get(request.data, "filePath") + logger.debug("file_path is %s", file_path) + ret = None + try: + ret = [0, "TODO"] + except: + logger.error(traceback.format_exc()) + return Response(data={'error': str(sys.exc_info())}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + logger.debug("Leave %s, Return value is %s", fun_name(), ret) + return Response(data=ret[1], status=status.HTTP_202_ACCEPTED) + + + + + |