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.
15 from lcm.workflows.graphflow.task.sync_task import SyncTask
18 logger = logging.getLogger(__name__)
21 class SyncRestTask(SyncTask):
23 STATUS_OK = (HTTP_200_OK, HTTP_201_CREATED, HTTP_204_NO_CONTENT, HTTP_202_ACCEPTED) = ('200', '201', '204', '202')
24 HTTP_METHOD = (POST, GET, PUT, DELETE) = ("POST", "GET", "PUT", "DELETE")
26 def __init__(self, *args):
27 super(SyncRestTask, self).__init__(*args)
28 self.url = self.input.get(self.URL, "")
29 self.method = self.input.get(self.METHOD, "")
30 self.content = self.input.get(self.CONTENT, "")
33 status, output = self.call_rest(self.url, self.method, self.content)
34 if status in self.STATUS_OK:
35 status = self.FINISHED
38 logger.debug("SyncRestTask status %s, output %s" % (status, output))
41 def call_rest(self, url, method, content):