Update configparser to align with Python3

Will stick with Python3 as that is what is used
in DryDock
This commit is contained in:
eanylin 2017-06-11 21:53:08 -05:00
parent 0eef85185c
commit 92a190ce4b
5 changed files with 48 additions and 32 deletions

View File

@ -1,4 +1,3 @@
# shipyard
Directed acyclic graph controller for Kubernetes and OpenStack control plane life cycle management
## Testing 1 2 3

View File

@ -5,7 +5,7 @@ A python REST workflow orchestrator
To run:
```
$ virtualenv -p python2.7 /var/tmp/shipyard
$ virtualenv -p python3 /var/tmp/shipyard
$ . /var/tmp/shipyard/bin/activate
$ python setup.py install
$ uwsgi --http :9000 -w shipyard_airflow.shipyard --callable shipyard -L

View File

@ -11,10 +11,11 @@
# 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 falcon.request as request
import falcon, falcon.request as request
import uuid
import json
import ConfigParser
import configparser
import os
class BaseResource(object):
@ -57,17 +58,23 @@ class BaseResource(object):
resp.status = status_code
# Get Config Data
def retrieve_config(self, resp, section="", variable=""):
config = ConfigParser.ConfigParser()
def retrieve_config(self, section="", data=""):
# The current assumption is that shipyard.conf will be placed in a fixed path
# within the shipyard container - Path TBD
config.read('/home/ubuntu/att-comdev/shipyard/shipyard_airflow/control/shipyard.conf')
path = '/home/ubuntu/att-comdev/shipyard/shipyard_airflow/control/shipyard.conf'
# Retrieve data from shipyard.conf
query_data = config.get(section, variable)
# Check that shipyard.conf exists
if os.path.isfile(path):
config = configparser.ConfigParser()
config.read(path)
return query_data
# Retrieve data from shipyard.conf
query_data = config.get(section, data)
return query_data
else:
return 'Error - Missing Configuration File'
class ShipyardRequestContext(object):

View File

@ -23,20 +23,25 @@ class DagRunResource(BaseResource):
def on_post(self, req, resp, dag_id, run_id=None, conf=None, execution_date=None):
# Retrieve URL
web_server_url = self.retrieve_config(resp, 'BASE', 'WEB_SERVER')
web_server_url = self.retrieve_config('BASE', 'WEB_SERVER')
req_url = '{}/api/experimental/dags/{}/dag_runs'.format(web_server_url, dag_id)
response = requests.post(req_url,
json={
"run_id": run_id,
"conf": conf,
"execution_date": execution_date,
})
if response.ok:
resp.status = falcon.HTTP_200
else:
self.return_error(resp, falcon.HTTP_400, 'Fail to Execute Dag')
if 'Error' in web_server_url:
resp.status = falcon.HTTP_400
resp.body = json.dumps({'Error': 'Missing Configuration File'})
return
else:
req_url = '{}/api/experimental/dags/{}/dag_runs'.format(web_server_url, dag_id)
response = requests.post(req_url,
json={
"run_id": run_id,
"conf": conf,
"execution_date": execution_date,
})
if response.ok:
resp.status = falcon.HTTP_200
else:
self.return_error(resp, falcon.HTTP_400, 'Fail to Execute Dag')
return

View File

@ -23,16 +23,21 @@ class TaskResource(BaseResource):
def on_get(self, req, resp, dag_id, task_id):
# Retrieve URL
web_server_url = self.retrieve_config(resp, 'BASE', 'WEB_SERVER')
web_server_url = self.retrieve_config('BASE', 'WEB_SERVER')
req_url = '{}/api/experimental/dags/{}/tasks/{}'.format(web_server_url, dag_id, task_id)
task_details = requests.get(req_url).json()
if 'error' in task_details:
if 'Error' in web_server_url:
resp.status = falcon.HTTP_400
resp.body = json.dumps(task_details)
resp.body = json.dumps({'Error': 'Missing Configuration File'})
return
else:
resp.status = falcon.HTTP_200
resp.body = json.dumps(task_details)
req_url = '{}/api/experimental/dags/{}/tasks/{}'.format(web_server_url, dag_id, task_id)
task_details = requests.get(req_url).json()
if 'error' in task_details:
resp.status = falcon.HTTP_400
resp.body = json.dumps(task_details)
return
else:
resp.status = falcon.HTTP_200
resp.body = json.dumps(task_details)