Exemplo n.º 1
0
async def vif_get_qos_speed_by_uuid(cluster_id: str, vif_uuid: str):
    """ Set VIF QoS Type by UUID """
    try:
        try:
            session = create_session(
                _id=cluster_id, get_xen_clusters=Settings.get_xen_clusters()
            )
        except KeyError as key_error:
            raise HTTPException(
                status_code=400, detail=f"{key_error} is not a valid path"
            )
        vif: VIF = VIF.get_by_uuid(session=session, uuid=vif_uuid)

        if vif is not None:
            ret = dict(success=True, data=vif.get_qos_info()["kbps"])
        else:
            ret = dict(success=False)

        session.xenapi.session.logout()
        return ret
    except Fault as xml_rpc_error:
        raise HTTPException(
            status_code=int(xml_rpc_error.faultCode),
            detail=xml_rpc_error.faultString,
        )
    except RemoteDisconnected as rd_error:
        raise HTTPException(status_code=500, detail=rd_error.strerror)
Exemplo n.º 2
0
async def vif_get_ipv4_by_uuid(cluster_id: str, vif_uuid: str):
    """Get VIF IPv4 by UUID"""
    try:
        session = create_session(_id=cluster_id,
                                 get_xen_clusters=Settings.get_xen_clusters())

        vif: VIF = VIF.get_by_uuid(session=session, uuid=vif_uuid)
        ret = dict(
            success=True,
            data=dict(
                address=vif.get_address_v4(),
                gateway=vif.get_gateway_v4(),
            ),
        )

        session.xenapi.session.logout()
        return ret
    except Failure as xenapi_error:
        raise HTTPException(status_code=500,
                            detail=xenapi_failure_jsonify(xenapi_error))
    except Fault as xml_rpc_error:
        raise HTTPException(
            status_code=int(xml_rpc_error.faultCode),
            detail=xml_rpc_error.faultString,
        )
    except RemoteDisconnected as rd_error:
        raise HTTPException(status_code=500, detail=rd_error.strerror)
Exemplo n.º 3
0
async def vif_get_by_uuid(cluster_id: str, vif_uuid: str):
    """Get VIF by UUID"""
    try:
        session = create_session(_id=cluster_id,
                                 get_xen_clusters=Settings.get_xen_clusters())

        vif: VIF = VIF.get_by_uuid(session=session, uuid=vif_uuid)

        if vif is not None:
            ret = dict(success=True, data=await serialize(vif))
        else:
            ret = dict(success=False)

        session.xenapi.session.logout()
        return ret
    except Failure as xenapi_error:
        raise HTTPException(status_code=500,
                            detail=xenapi_failure_jsonify(xenapi_error))
    except Fault as xml_rpc_error:
        raise HTTPException(
            status_code=int(xml_rpc_error.faultCode),
            detail=xml_rpc_error.faultString,
        )
    except RemoteDisconnected as rd_error:
        raise HTTPException(status_code=500, detail=rd_error.strerror)
Exemplo n.º 4
0
async def vif_get_qos_type_by_uuid(cluster_id: str, vif_uuid: str,
                                   data: QoSTypeArgs):
    """Set VIF QoS Data by UUID"""
    try:
        session = create_session(_id=cluster_id,
                                 get_xen_clusters=Settings.get_xen_clusters())

        vif: VIF = VIF.get_by_uuid(session=session, uuid=vif_uuid)

        result = True
        if data.type is not None:
            vif.set_qos_type(data.type)

        if data.info is not None:
            vif.set_qos_info(data.info)

        ret = dict(success=True, data=result)

        session.xenapi.session.logout()
        return ret
    except Failure as xenapi_error:
        raise HTTPException(status_code=500,
                            detail=xenapi_failure_jsonify(xenapi_error))
    except Fault as xml_rpc_error:
        raise HTTPException(
            status_code=int(xml_rpc_error.faultCode),
            detail=xml_rpc_error.faultString,
        )
    except RemoteDisconnected as rd_error:
        raise HTTPException(status_code=500, detail=rd_error.strerror)
Exemplo n.º 5
0
async def vif_set_ipv6_by_uuid(
    cluster_id: str, vif_uuid: str, addresses: IPAddressesModel
):
    """Set VIF IPv6 by UUID"""
    try:
        session = create_session(
            _id=cluster_id, get_xen_clusters=Settings.get_xen_clusters()
        )

        vif: VIF = VIF.get_by_uuid(session=session, uuid=vif_uuid)
        vif.set_allowed_address_v6(addresses.addresses)

        ret = dict(
            success=True,
        )

        session.xenapi.session.logout()
        return ret
    except Failure as xenapi_error:
        raise HTTPException(
            status_code=500, detail=xenapi_failure_jsonify(xenapi_error)
        )
    except Fault as xml_rpc_error:
        raise HTTPException(
            status_code=int(xml_rpc_error.faultCode),
            detail=xml_rpc_error.faultString,
        )
    except RemoteDisconnected as rd_error:
        raise HTTPException(status_code=500, detail=rd_error.strerror)
Exemplo n.º 6
0
async def vif_set_qos_speed_by_uuid(cluster_id: str, vif_uuid: str, speed: str):
    """ Set VIF QoS Speed by UUID """
    try:
        try:
            session = create_session(
                _id=cluster_id, get_xen_clusters=Settings.get_xen_clusters()
            )
        except KeyError as key_error:
            raise HTTPException(
                status_code=400, detail=f"{key_error} is not a valid path"
            )

        vif: VIF = VIF.get_by_uuid(session=session, uuid=vif_uuid)

        speedNum = speed

        try:
            speedNum = int(speed)
        except ValueError:
            return dict(success=False)

        if speedNum <= 0:
            a = vif.set_qos_type("")
            b = vif.set_qos_info({})

            ret = dict(success=a and b)

        else:
            if vif is not None:
                if vif.get_qos_type() != "ratelimit":
                    vif.set_qos_type("ratelimit")

                ret = dict(success=vif.set_qos_info(dict(kbps=speed)))
            else:
                ret = dict(success=False)

        session.xenapi.session.logout()
        return ret
    except Fault as xml_rpc_error:
        raise HTTPException(
            status_code=int(xml_rpc_error.faultCode),
            detail=xml_rpc_error.faultString,
        )
    except RemoteDisconnected as rd_error:
        raise HTTPException(status_code=500, detail=rd_error.strerror)
Exemplo n.º 7
0
async def vif_get_network(cluster_id: str, vif_uuid: str, url_after: str = ""):
    """Redirect To VIF's Network"""
    try:
        session = create_session(
            _id=cluster_id, get_xen_clusters=Settings.get_xen_clusters()
        )

        vif: VIF = VIF.get_by_uuid(session=session, uuid=vif_uuid)

        if vif is None:
            session.xenapi.session.logout()
            raise HTTPException(
                status_code=404, detail=f"VIF {vif_uuid} does not exist"
            )

        network = vif.get_network()

        if network is None:
            session.xenapi.session.logout()
            raise HTTPException(
                status_code=404, detail=f"VIF {vif_uuid} does not exist on ANY Network"
            )

        network_uuid = network.get_uuid()

        session.xenapi.session.logout()
        return RedirectResponse(f"/v1/{cluster_id}/network/{network_uuid}{url_after}")
    except Failure as xenapi_error:
        raise HTTPException(
            status_code=500, detail=xenapi_failure_jsonify(xenapi_error)
        )
    except Fault as xml_rpc_error:
        raise HTTPException(
            status_code=int(xml_rpc_error.faultCode),
            detail=xml_rpc_error.faultString,
        )
    except RemoteDisconnected as rd_error:
        raise HTTPException(status_code=500, detail=rd_error.strerror)
Exemplo n.º 8
0
async def vif_set_ipv4_by_uuid(cluster_id: str, vif_uuid: str, data: IPModel):
    """Set VIF IPv4 Data by UUID"""
    try:
        session = create_session(_id=cluster_id,
                                 get_xen_clusters=Settings.get_xen_clusters())

        vif: VIF = VIF.get_by_uuid(session=session, uuid=vif_uuid)
        result = vif.config_ipv4("Static", data.address,
                                 "" if data.gateway is None else data.gateway)

        ret = dict(success=True, data=result)

        session.xenapi.session.logout()
        return ret
    except Failure as xenapi_error:
        raise HTTPException(status_code=500,
                            detail=xenapi_failure_jsonify(xenapi_error))
    except Fault as xml_rpc_error:
        raise HTTPException(
            status_code=int(xml_rpc_error.faultCode),
            detail=xml_rpc_error.faultString,
        )
    except RemoteDisconnected as rd_error:
        raise HTTPException(status_code=500, detail=rd_error.strerror)
Exemplo n.º 9
0
async def verify_vif_uuid(cluster_id: str, vif_uuid: Optional[str] = None):
    if vif_uuid is None:
        return

    session = create_session(cluster_id,
                             get_xen_clusters=Settings.get_xen_clusters())

    try:
        vif = VIF.get_by_uuid(session, vif_uuid)

    except Failure as xenapi_error:
        if xenapi_error.details[0] == "UUID_INVALID":
            raise HTTPException(status_code=404,
                                detail=f"VIF {vif_uuid} does not exist")

        raise HTTPException(status_code=500,
                            detail=xenapi_failure_jsonify(xenapi_error))
    except Fault as xml_rpc_error:
        raise HTTPException(
            status_code=int(xml_rpc_error.faultCode),
            detail=xml_rpc_error.faultString,
        )

    session.xenapi.session.logout()
Exemplo n.º 10
0
async def vif_clear_lock_by_uuid(cluster_id: str, vif_uuid: str,
                                 data: ModeModel):
    """Clear VIF Lock Data to Default by UUID"""
    try:
        session = create_session(_id=cluster_id,
                                 get_xen_clusters=Settings.get_xen_clusters())

        vif: VIF = VIF.get_by_uuid(session=session, uuid=vif_uuid)
        vif.set_locking_mode("network_default")

        ret = dict(success=True)

        session.xenapi.session.logout()
        return ret
    except Failure as xenapi_error:
        raise HTTPException(status_code=500,
                            detail=xenapi_failure_jsonify(xenapi_error))
    except Fault as xml_rpc_error:
        raise HTTPException(
            status_code=int(xml_rpc_error.faultCode),
            detail=xml_rpc_error.faultString,
        )
    except RemoteDisconnected as rd_error:
        raise HTTPException(status_code=500, detail=rd_error.strerror)