예제 #1
0
async def vdi_list(cluster_id: str):
    """Get VDI by UUID"""
    try:
        session = create_session(_id=cluster_id,
                                 get_xen_clusters=Settings.get_xen_clusters())

        vdis = VDI.get_all(session=session)
        __vdi_list = await asyncio.gather(*[serialize(vdi) for vdi in vdis])

        if vdis is not None:
            ret = dict(success=True, data=__vdi_list)
        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)
예제 #2
0
async def vdi_list(cluster_id: str):
    """ Get VDI 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")

        vdis = VDI.get_all(session=session)

        __vdi_list = []
        _vdi_list = __vdi_list.append
        for vdi in vdis:
            _vdi_list(serialize(vdi))

        if vdis is not None:
            ret = dict(success=True, data=__vdi_list)
        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)