update link to upper-constraints.txt
[vfc/nfvo/lcm.git] / lcm / pub / msapi / activiti.py
1 # Copyright 2017 ZTE Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 import json
15
16 from lcm.pub.exceptions import NSLCMException
17 from lcm.pub.utils import restcall
18
19 """
20 Input:
21 file:formdata
22 filename:formdata
23 =================================
24 Output:
25 {
26     "status": "int",
27     "message": "string",
28     "deployedId": "string",
29     "processId": "string"
30 }
31 """
32
33
34 def deploy_workflow(file_path):
35     file_name = file_path.split("/")[-1]
36     file_data = {
37         'file': open(file_path, 'rb'),
38         'filename': file_name}
39     ret = restcall.upload_by_msb("api/workflow/v1/package", "POST", file_data)
40     if ret[0] != 0:
41         raise NSLCMException("Status code is %s, detail is %s.", ret[2], ret[1])
42     return json.JSONDecoder().decode(ret[1])
43
44
45 """
46 Input:
47 None
48 =================================
49 Output:
50 {
51     "status": "int",
52     "message": "string",
53 }
54 """
55
56
57 def undeploy_workflow(deploy_id):
58     uri = "api/workflow/v1/package/{deployId}".format(deployId=deploy_id)
59     ret = restcall.req_by_msb(uri, "DELETE")
60     if ret[0] != 0:
61         raise NSLCMException("Status code is %s, detail is %s.", ret[2], ret[1])
62     return json.JSONDecoder().decode(ret[1])
63
64
65 """
66 Input:
67 {
68     "processId": "string",
69     "params": "Map<String, String>"
70 }
71 =================================
72 Output:
73 {
74     "status": "int",
75     "message": "string",
76 }
77 """
78
79
80 def exec_workflow(content):
81     content_str = json.JSONEncoder().encode(content)
82     ret = restcall.req_by_msb("api/workflow/v1/process/instance", "POST", content_str)
83     if ret[0] != 0:
84         raise NSLCMException("Status code is %s, detail is %s.", ret[2], ret[1])
85     return json.JSONDecoder().decode(ret[1])