Merge "Remove update_service call and change create_service."
This commit is contained in:
commit
02b3e7cb5a
@ -211,7 +211,7 @@ def save_archive(request):
|
|||||||
return path_to_archive
|
return path_to_archive
|
||||||
|
|
||||||
|
|
||||||
def create_service(data):
|
def create_service(service_id, data):
|
||||||
required = ['full_service_name', 'service_display_name']
|
required = ['full_service_name', 'service_display_name']
|
||||||
optional = {'enabled': True,
|
optional = {'enabled': True,
|
||||||
'version': 0.1,
|
'version': 0.1,
|
||||||
@ -227,15 +227,23 @@ def create_service(data):
|
|||||||
if not data.get(parameter):
|
if not data.get(parameter):
|
||||||
data[parameter] = optional[parameter]
|
data[parameter] = optional[parameter]
|
||||||
|
|
||||||
service_id = data.get('full_service_name')
|
|
||||||
path_to_manifest = os.path.join(CONF.manifests,
|
path_to_manifest = os.path.join(CONF.manifests,
|
||||||
service_id + '-manifest.yaml')
|
service_id + '-manifest.yaml')
|
||||||
|
|
||||||
|
backup_done = False
|
||||||
|
with tempfile.NamedTemporaryFile() as backup:
|
||||||
|
# make a backup
|
||||||
|
if os.path.exists(path_to_manifest):
|
||||||
|
backup_done = True
|
||||||
|
shutil.copy(path_to_manifest, backup.name)
|
||||||
try:
|
try:
|
||||||
with open(path_to_manifest, 'w') as service_manifest:
|
with open(path_to_manifest, 'w') as service_manifest:
|
||||||
service_manifest.write(serialize(data))
|
service_manifest.write(serialize(data))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
if os.path.exists(path_to_manifest):
|
if backup_done:
|
||||||
|
shutil.move(backup.name, path_to_manifest)
|
||||||
|
elif os.path.exists(path_to_manifest):
|
||||||
os.remove(path_to_manifest)
|
os.remove(path_to_manifest)
|
||||||
return make_response('Error during service manifest creation', 500)
|
return make_response('Error during service manifest creation', 500)
|
||||||
return jsonify(result='success')
|
return jsonify(result='success')
|
||||||
|
@ -217,28 +217,12 @@ def reset_caches():
|
|||||||
return jsonify(result='success')
|
return jsonify(result='success')
|
||||||
|
|
||||||
|
|
||||||
@v1_api.route('/admin/services/create', methods=['PUT'])
|
@v1_api.route('/admin/services/<service_name>', methods=['PUT'])
|
||||||
def create_service():
|
def create_service(service_name):
|
||||||
try:
|
try:
|
||||||
service_data = json.loads(request.data)
|
service_data = json.loads(request.data)
|
||||||
except:
|
except:
|
||||||
return make_response('Unable to load json data', 500)
|
return make_response('Unable to load json data', 500)
|
||||||
resp = api.create_service(service_data)
|
resp = api.create_service(service_name, service_data)
|
||||||
api.reset_cache()
|
api.reset_cache()
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
@v1_api.route('/admin/services/<service_name>', methods=['POST'])
|
|
||||||
def update_service(service_name):
|
|
||||||
api.check_service_name(service_name)
|
|
||||||
parser = ManifestParser()
|
|
||||||
try:
|
|
||||||
service_data = json.loads(request.data)
|
|
||||||
except:
|
|
||||||
return make_response('Unable to load json data', 500)
|
|
||||||
result = parser.update_service(service_name, service_data)
|
|
||||||
if result:
|
|
||||||
api.reset_cache()
|
|
||||||
return jsonify(result='success')
|
|
||||||
else:
|
|
||||||
return make_response('Unable to update service', 500)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user