1 # Copyright 2018 ZTE Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 from lcm.workflows.graphflow.task.async_task import AsyncTask
18 logger = logging.getLogger(__name__)
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")
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, "")
32 status, resp_content = self.call_rest(self.url, self.method, self.content)
33 if status not in self.STATUS_OK:
36 status = self.PROCESSING
37 return status, resp_content
39 def call_rest(self, url, method, content=None):