Add workflow api init codes 85/8085/1
authorfujinhua <fu.jinhua@zte.com.cn>
Sat, 19 Aug 2017 06:27:16 +0000 (14:27 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Sat, 19 Aug 2017 06:27:16 +0000 (14:27 +0800)
Change-Id: Ia93c3bd198f2ad541671393dd06d651f4fe4a4f1
Issue-Id: VFC-115
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
lcm/urls.py
lcm/workflows/__init__.py [new file with mode: 0644]
lcm/workflows/tests.py [new file with mode: 0644]
lcm/workflows/urls.py [new file with mode: 0644]
lcm/workflows/views.py [new file with mode: 0644]

index c9a808b..9471def 100644 (file)
@@ -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 (file)
index 0000000..c7b6818
--- /dev/null
@@ -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 (file)
index 0000000..3165162
--- /dev/null
@@ -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 (file)
index 0000000..2545ffb
--- /dev/null
@@ -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 (file)
index 0000000..92f029f
--- /dev/null
@@ -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)
+
+
+
+
+