add async task in workflow
[vfc/nfvo/lcm.git] / lcm / workflows / graphflow / task / async_rest_task.py
1 # Copyright 2018 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
15 import logging
16 from lcm.workflows.graphflow.task.async_task import AsyncTask
17
18 logger = logging.getLogger(__name__)
19
20
21 class ASyncRestTask(AsyncTask):
22     STATUS_OK = (HTTP_200_OK, HTTP_201_CREATED, HTTP_204_NO_CONTENT, HTTP_202_ACCEPTED) = ('200', '201', '204', '202')
23     HTTP_METHOD = (POST, GET, PUT, DELETE) = ("POST", "GET", "PUT", "DELETE")
24
25     def __init__(self, *args):
26         super(ASyncRestTask, self).__init__(*args)
27         self.url = self.input.get(self.URL, "")
28         self.method = self.input.get(self.METHOD, "")
29         self.content = self.input.get(self.CONTENT, "")
30
31     def run(self):
32         status, resp_content = self.call_rest(self.url, self.method, self.content)
33         if status not in self.STATUS_OK:
34             status = self.ERROR
35         else:
36             status = self.PROCESSING
37         return status, resp_content
38
39     def call_rest(self, url, method, content=None):
40         pass