Update configparser to align with Python3
Will stick with Python3 as that is what is used in DryDock
This commit is contained in:
parent
0eef85185c
commit
92a190ce4b
|
@ -1,4 +1,3 @@
|
||||||
# shipyard
|
# shipyard
|
||||||
Directed acyclic graph controller for Kubernetes and OpenStack control plane life cycle management
|
Directed acyclic graph controller for Kubernetes and OpenStack control plane life cycle management
|
||||||
|
|
||||||
## Testing 1 2 3
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ A python REST workflow orchestrator
|
||||||
To run:
|
To run:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ virtualenv -p python2.7 /var/tmp/shipyard
|
$ virtualenv -p python3 /var/tmp/shipyard
|
||||||
$ . /var/tmp/shipyard/bin/activate
|
$ . /var/tmp/shipyard/bin/activate
|
||||||
$ python setup.py install
|
$ python setup.py install
|
||||||
$ uwsgi --http :9000 -w shipyard_airflow.shipyard --callable shipyard -L
|
$ uwsgi --http :9000 -w shipyard_airflow.shipyard --callable shipyard -L
|
||||||
|
|
|
@ -11,10 +11,11 @@
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import falcon.request as request
|
import falcon, falcon.request as request
|
||||||
import uuid
|
import uuid
|
||||||
import json
|
import json
|
||||||
import ConfigParser
|
import configparser
|
||||||
|
import os
|
||||||
|
|
||||||
class BaseResource(object):
|
class BaseResource(object):
|
||||||
|
|
||||||
|
@ -57,17 +58,23 @@ class BaseResource(object):
|
||||||
resp.status = status_code
|
resp.status = status_code
|
||||||
|
|
||||||
# Get Config Data
|
# Get Config Data
|
||||||
def retrieve_config(self, resp, section="", variable=""):
|
def retrieve_config(self, section="", data=""):
|
||||||
config = ConfigParser.ConfigParser()
|
|
||||||
|
|
||||||
# The current assumption is that shipyard.conf will be placed in a fixed path
|
# The current assumption is that shipyard.conf will be placed in a fixed path
|
||||||
# within the shipyard container - Path TBD
|
# 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'
|
||||||
|
|
||||||
|
# Check that shipyard.conf exists
|
||||||
|
if os.path.isfile(path):
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read(path)
|
||||||
|
|
||||||
# Retrieve data from shipyard.conf
|
# Retrieve data from shipyard.conf
|
||||||
query_data = config.get(section, variable)
|
query_data = config.get(section, data)
|
||||||
|
|
||||||
return query_data
|
return query_data
|
||||||
|
else:
|
||||||
|
return 'Error - Missing Configuration File'
|
||||||
|
|
||||||
|
|
||||||
class ShipyardRequestContext(object):
|
class ShipyardRequestContext(object):
|
||||||
|
|
|
@ -23,20 +23,25 @@ class DagRunResource(BaseResource):
|
||||||
|
|
||||||
def on_post(self, req, resp, dag_id, run_id=None, conf=None, execution_date=None):
|
def on_post(self, req, resp, dag_id, run_id=None, conf=None, execution_date=None):
|
||||||
# Retrieve URL
|
# 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)
|
if 'Error' in web_server_url:
|
||||||
|
resp.status = falcon.HTTP_400
|
||||||
response = requests.post(req_url,
|
resp.body = json.dumps({'Error': 'Missing Configuration File'})
|
||||||
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
|
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
|
||||||
|
|
||||||
|
|
|
@ -23,16 +23,21 @@ class TaskResource(BaseResource):
|
||||||
|
|
||||||
def on_get(self, req, resp, dag_id, task_id):
|
def on_get(self, req, resp, dag_id, task_id):
|
||||||
# Retrieve URL
|
# 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)
|
if 'Error' in web_server_url:
|
||||||
task_details = requests.get(req_url).json()
|
|
||||||
|
|
||||||
if 'error' in task_details:
|
|
||||||
resp.status = falcon.HTTP_400
|
resp.status = falcon.HTTP_400
|
||||||
resp.body = json.dumps(task_details)
|
resp.body = json.dumps({'Error': 'Missing Configuration File'})
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
resp.status = falcon.HTTP_200
|
req_url = '{}/api/experimental/dags/{}/tasks/{}'.format(web_server_url, dag_id, task_id)
|
||||||
resp.body = json.dumps(task_details)
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue