def test_export_import(self): """Test ExportInfrastructure and ImportInfrastructure operations""" radl = RADL() radl.add( system("s0", [ Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"), Feature("disk.0.os.credentials.username", "=", "user"), Feature("disk.0.os.credentials.password", "=", "pass") ])) radl.add(deploy("s0", 1)) auth0 = self.getAuth([0], [], [("Dummy", 0)]) infId = IM.CreateInfrastructure(str(radl), auth0) res = IM.ExportInfrastructure(infId, True, auth0) new_inf_id = IM.ImportInfrastructure(res, auth0) IM.DestroyInfrastructure(new_inf_id, auth0)
def RESTGetInfrastructureProperty(infid=None, prop=None): try: auth = get_auth_header() except: return return_error(401, "No authentication data provided") try: if prop == "contmsg": headeronly = False if "headeronly" in bottle.request.params.keys(): str_headeronly = bottle.request.params.get( "headeronly").lower() if str_headeronly in ['yes', 'true', '1']: headeronly = True elif str_headeronly in ['no', 'false', '0']: headeronly = False else: return return_error( 400, "Incorrect value in context parameter") res = InfrastructureManager.GetInfrastructureContMsg( infid, auth, headeronly) elif prop == "radl": res = InfrastructureManager.GetInfrastructureRADL(infid, auth) elif prop == "tosca": accept = get_media_type('Accept') if accept and "application/json" not in accept and "*/*" not in accept and "application/*" not in accept: return return_error( 415, "Unsupported Accept Media Types: %s" % accept) bottle.response.content_type = "application/json" auth = InfrastructureManager.check_auth_data(auth) sel_inf = InfrastructureManager.get_infrastructure(infid, auth) if "TOSCA" in sel_inf.extra_info: res = sel_inf.extra_info["TOSCA"].serialize() else: bottle.abort( 403, "'tosca' infrastructure property is not valid in this infrastructure" ) elif prop == "state": accept = get_media_type('Accept') if accept and "application/json" not in accept and "*/*" not in accept and "application/*" not in accept: return return_error( 415, "Unsupported Accept Media Types: %s" % accept) bottle.response.content_type = "application/json" res = InfrastructureManager.GetInfrastructureState(infid, auth) return format_output(res, default_type="application/json", field_name="state") elif prop == "outputs": accept = get_media_type('Accept') if accept and "application/json" not in accept and "*/*" not in accept and "application/*" not in accept: return return_error( 415, "Unsupported Accept Media Types: %s" % accept) bottle.response.content_type = "application/json" auth = InfrastructureManager.check_auth_data(auth) sel_inf = InfrastructureManager.get_infrastructure(infid, auth) if "TOSCA" in sel_inf.extra_info: res = sel_inf.extra_info["TOSCA"].get_outputs(sel_inf) else: bottle.abort( 403, "'outputs' infrastructure property is not valid in this infrastructure" ) return format_output(res, default_type="application/json", field_name="outputs") elif prop == "data": accept = get_media_type('Accept') if accept and "application/json" not in accept and "*/*" not in accept and "application/*" not in accept: return return_error( 415, "Unsupported Accept Media Types: %s" % accept) delete = False if "delete" in bottle.request.params.keys(): str_delete = bottle.request.params.get("delete").lower() if str_delete in ['yes', 'true', '1']: delete = True elif str_delete in ['no', 'false', '0']: delete = False else: return return_error(400, "Incorrect value in delete parameter") data = InfrastructureManager.ExportInfrastructure( infid, delete, auth) return format_output(data, default_type="application/json", field_name="data") else: return return_error(404, "Incorrect infrastructure property") return format_output(res, field_name=prop) except DeletedInfrastructureException as ex: return return_error(404, "Error Getting Inf. prop: %s" % ex.args[0]) except IncorrectInfrastructureException as ex: return return_error(404, "Error Getting Inf. prop: %s" % ex.args[0]) except UnauthorizedUserException as ex: return return_error(403, "Error Getting Inf. prop: %s" % ex.args[0]) except Exception as ex: logger.exception("Error Getting Inf. prop") return return_error(400, "Error Getting Inf. prop: %s" % ex.args[0])