示例#1
0
文件: REST.py 项目: changeyourname/im
def RESTGetInfrastructureProperty(id=None, prop=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        if prop == "contmsg":
            res = InfrastructureManager.GetInfrastructureContMsg(id, auth)
        elif prop == "radl":
            res = InfrastructureManager.GetInfrastructureRADL(id, auth)
        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(id, auth)
            return format_output(res,
                                 default_type="application/json",
                                 field_name="state")
        else:
            return return_error(404, "Incorrect infrastructure property")

        return format_output(res, field_name=prop)
    except DeletedInfrastructureException, ex:
        return return_error(404, "Error Getting Inf. prop: " + str(ex))
示例#2
0
文件: REST.py 项目: changeyourname/im
def RESTReconfigureInfrastructure(id=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        vm_list = None
        if "vm_list" in bottle.request.params.keys():
            str_vm_list = bottle.request.params.get("vm_list")
            try:
                vm_list = [int(vm_id) for vm_id in str_vm_list.split(",")]
            except:
                return return_error(400, "Incorrect vm_list format.")

        content_type = get_media_type('Content-Type')
        radl_data = bottle.request.body.read()

        if radl_data:
            if content_type:
                if "application/json" in content_type:
                    radl_data = parse_radl_json(radl_data)
                elif "text/plain" in content_type or "*/*" in content_type or "text/*" in content_type:
                    content_type = "text/plain"
                else:
                    return return_error(
                        415, "Unsupported Media Type %s" % content_type)
        else:
            radl_data = ""
        bottle.response.content_type = "text/plain"
        return InfrastructureManager.Reconfigure(id, radl_data, auth, vm_list)
    except DeletedInfrastructureException, ex:
        return return_error(404,
                            "Error reconfiguring infrastructure: " + str(ex))
示例#3
0
文件: REST.py 项目: changeyourname/im
def RESTCreateInfrastructure():
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        content_type = get_media_type('Content-Type')
        radl_data = bottle.request.body.read()

        if content_type:
            if "application/json" in content_type:
                radl_data = parse_radl_json(radl_data)
            elif "text/plain" in content_type or "*/*" in content_type or "text/*" in content_type:
                content_type = "text/plain"
            else:
                return return_error(415,
                                    "Unsupported Media Type %s" % content_type)

        inf_id = InfrastructureManager.CreateInfrastructure(radl_data, auth)

        bottle.response.content_type = "text/uri-list"
        protocol = "http://"
        if Config.REST_SSL:
            protocol = "https://"

        res = protocol + \
            bottle.request.environ['HTTP_HOST'] + \
            "/infrastructures/" + str(inf_id)

        return format_output(res, "text/uri-list", "uri")
    except InvaliddUserException, ex:
        return return_error(401, "Error Getting Inf. info: " + str(ex))
示例#4
0
文件: REST.py 项目: changeyourname/im
def RESTGetVMProperty(infid=None, vmid=None, prop=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        if prop == 'contmsg':
            info = InfrastructureManager.GetVMContMsg(infid, vmid, auth)
        else:
            info = InfrastructureManager.GetVMProperty(infid, vmid, prop, auth)

        if info is None:
            return return_error(
                404, "Incorrect property %s for VM ID %s" % (prop, vmid))
        else:
            return format_output(info, field_name=prop)
    except DeletedInfrastructureException, ex:
        return return_error(404, "Error Getting VM. property: " + str(ex))
示例#5
0
文件: REST.py 项目: changeyourname/im
def RESTStopVM(infid=None, vmid=None, prop=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        bottle.response.content_type = "text/plain"
        return InfrastructureManager.StopVM(infid, vmid, auth)
    except DeletedInfrastructureException, ex:
        return return_error(404, "Error stopping VM: " + str(ex))
示例#6
0
文件: REST.py 项目: changeyourname/im
def RESTGetVMInfo(infid=None, vmid=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        radl = InfrastructureManager.GetVMInfo(infid, vmid, auth)
        return format_output(radl, field_name="radl")
    except DeletedInfrastructureException, ex:
        return return_error(404, "Error Getting VM. info: " + str(ex))
示例#7
0
文件: REST.py 项目: changeyourname/im
def RESTDestroyInfrastructure(id=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        InfrastructureManager.DestroyInfrastructure(id, auth)
        bottle.response.content_type = "text/plain"
        return ""
    except DeletedInfrastructureException, ex:
        return return_error(404, "Error Destroying Inf: " + str(ex))
示例#8
0
文件: REST.py 项目: indigo-dc/im
def RESTGetInfrastructureProperty(id=None, prop=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        if prop == "contmsg":
            res = InfrastructureManager.GetInfrastructureContMsg(id, auth)
        elif prop == "radl":
            res = InfrastructureManager.GetInfrastructureRADL(id, auth)
        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(id, 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(id, 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")
        else:
            return return_error(404, "Incorrect infrastructure property")

        return format_output(res, field_name=prop)
    except DeletedInfrastructureException, ex:
        return return_error(404, "Error Getting Inf. prop: " + str(ex))
示例#9
0
文件: REST.py 项目: changeyourname/im
def RESTAddResource(id=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        context = True
        if "context" in bottle.request.params.keys():
            str_ctxt = bottle.request.params.get("context").lower()
            if str_ctxt in ['yes', 'true', '1']:
                context = True
            elif str_ctxt in ['no', 'false', '0']:
                context = False
            else:
                return return_error(400,
                                    "Incorrect value in context parameter")

        content_type = get_media_type('Content-Type')
        radl_data = bottle.request.body.read()

        if content_type:
            if "application/json" in content_type:
                radl_data = parse_radl_json(radl_data)
            elif "text/plain" in content_type or "*/*" in content_type or "text/*" in content_type:
                content_type = "text/plain"
            else:
                return return_error(415,
                                    "Unsupported Media Type %s" % content_type)

        vm_ids = InfrastructureManager.AddResource(id, radl_data, auth,
                                                   context)

        protocol = "http://"
        if Config.REST_SSL:
            protocol = "https://"
        res = []
        for vm_id in vm_ids:
            res.append(protocol + bottle.request.environ['HTTP_HOST'] +
                       "/infrastructures/" + str(id) + "/vms/" + str(vm_id))

        return format_output(res, "text/uri-list", "uri-list", "uri")
    except DeletedInfrastructureException, ex:
        return return_error(404, "Error Adding resources: " + str(ex))
示例#10
0
文件: REST.py 项目: changeyourname/im
def RESTGetInfrastructureList():
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        inf_ids = InfrastructureManager.GetInfrastructureList(auth)
        res = []

        protocol = "http://"
        if Config.REST_SSL:
            protocol = "https://"
        for inf_id in inf_ids:
            res.append(protocol + bottle.request.environ['HTTP_HOST'] +
                       "/infrastructures/" + str(inf_id))

        return format_output(res, "text/uri-list", "uri-list", "uri")
    except InvaliddUserException, ex:
        return return_error(401, "Error Getting Inf. List: " + str(ex))
示例#11
0
文件: REST.py 项目: changeyourname/im
def RESTGetInfrastructureInfo(id=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        vm_ids = InfrastructureManager.GetInfrastructureInfo(id, auth)
        res = []

        protocol = "http://"
        if Config.REST_SSL:
            protocol = "https://"
        for vm_id in vm_ids:
            res.append(protocol + bottle.request.environ['HTTP_HOST'] +
                       '/infrastructures/' + str(id) + '/vms/' + str(vm_id))

        return format_output(res, "text/uri-list", "uri-list", "uri")
    except DeletedInfrastructureException, ex:
        return return_error(404, "Error Getting Inf. info: " + str(ex))
示例#12
0
文件: REST.py 项目: indigo-dc/im
def RESTCreateInfrastructure():
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        content_type = get_media_type('Content-Type')
        radl_data = bottle.request.body.read()
        tosca_data = None

        if content_type:
            if "application/json" in content_type:
                radl_data = parse_radl_json(radl_data)
            elif "text/yaml" in content_type:
                tosca_data = Tosca(radl_data)
                _, radl_data = tosca_data.to_radl()
            elif "text/plain" in content_type or "*/*" in content_type or "text/*" in content_type:
                content_type = "text/plain"
            else:
                return return_error(415, "Unsupported Media Type %s" % content_type)

        inf_id = InfrastructureManager.CreateInfrastructure(radl_data, auth)

        # Store the TOSCA document
        if tosca_data:
            sel_inf = InfrastructureManager.get_infrastructure(inf_id, auth)
            sel_inf.extra_info['TOSCA'] = tosca_data

        bottle.response.content_type = "text/uri-list"
        protocol = "http://"
        if Config.REST_SSL:
            protocol = "https://"

        res = protocol + \
            bottle.request.environ['HTTP_HOST'] + \
            "/infrastructures/" + str(inf_id)

        return format_output(res, "text/uri-list", "uri")
    except InvaliddUserException, ex:
        return return_error(401, "Error Getting Inf. info: " + str(ex))
示例#13
0
文件: REST.py 项目: changeyourname/im
def RESTRemoveResource(infid=None, vmid=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        context = True
        if "context" in bottle.request.params.keys():
            str_ctxt = bottle.request.params.get("context").lower()
            if str_ctxt in ['yes', 'true', '1']:
                context = True
            elif str_ctxt in ['no', 'false', '0']:
                context = False
            else:
                return return_error(400,
                                    "Incorrect value in context parameter")

        InfrastructureManager.RemoveResource(infid, vmid, auth, context)
        bottle.response.content_type = "text/plain"
        return ""
    except DeletedInfrastructureException, ex:
        return return_error(404, "Error Removing resources: " + str(ex))
示例#14
0
文件: REST.py 项目: changeyourname/im
def RESTAlterVM(infid=None, vmid=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        content_type = get_media_type('Content-Type')
        radl_data = bottle.request.body.read()

        if content_type:
            if "application/json" in content_type:
                radl_data = parse_radl_json(radl_data)
            elif "text/plain" in content_type or "*/*" in content_type or "text/*" in content_type:
                content_type = "text/plain"
            else:
                return return_error(415,
                                    "Unsupported Media Type %s" % content_type)

        vm_info = InfrastructureManager.AlterVM(infid, vmid, radl_data, auth)

        return format_output(vm_info, field_name="radl")
    except DeletedInfrastructureException, ex:
        return return_error(404, "Error modifying resources: " + str(ex))
示例#15
0
文件: REST.py 项目: indigo-dc/im
def RESTAddResource(id=None):
    try:
        auth = get_auth_header()
    except:
        return return_error(401, "No authentication data provided")

    try:
        context = True
        if "context" in bottle.request.params.keys():
            str_ctxt = bottle.request.params.get("context").lower()
            if str_ctxt in ['yes', 'true', '1']:
                context = True
            elif str_ctxt in ['no', 'false', '0']:
                context = False
            else:
                return return_error(400, "Incorrect value in context parameter")

        content_type = get_media_type('Content-Type')
        radl_data = bottle.request.body.read()
        tosca_data = None
        remove_list = []

        if content_type:
            if "application/json" in content_type:
                radl_data = parse_radl_json(radl_data)
            elif "text/yaml" in content_type:
                tosca_data = Tosca(radl_data)
                auth = InfrastructureManager.check_auth_data(auth)
                sel_inf = InfrastructureManager.get_infrastructure(id, auth)
                # merge the current TOSCA with the new one
                if isinstance(sel_inf.extra_info['TOSCA'], Tosca):
                    tosca_data = sel_inf.extra_info['TOSCA'].merge(tosca_data)
                remove_list, radl_data = tosca_data.to_radl(sel_inf)
            elif "text/plain" in content_type or "*/*" in content_type or "text/*" in content_type:
                content_type = "text/plain"
            else:
                return return_error(415, "Unsupported Media Type %s" % content_type)

        if remove_list:
            InfrastructureManager.RemoveResource(
                id, remove_list, auth, context)

        vm_ids = InfrastructureManager.AddResource(
            id, radl_data, auth, context)

        # Replace the TOSCA document
        if tosca_data:
            sel_inf = InfrastructureManager.get_infrastructure(id, auth)
            sel_inf.extra_info['TOSCA'] = tosca_data

        protocol = "http://"
        if Config.REST_SSL:
            protocol = "https://"
        res = []
        for vm_id in vm_ids:
            res.append(protocol + bottle.request.environ[
                       'HTTP_HOST'] + "/infrastructures/" + str(id) + "/vms/" + str(vm_id))

        return format_output(res, "text/uri-list", "uri-list", "uri")
    except DeletedInfrastructureException, ex:
        return return_error(404, "Error Adding resources: " + str(ex))