Esempio n. 1
0
async def find_VDI_by_name(cluster_id: str, args: NameArgs):
    """Find VDI by Name"""
    try:
        session = create_session(_id=cluster_id,
                                 get_xen_clusters=Settings.get_xen_clusters())

        name = args.name
        vdis = VDI.get_by_name(session=session, name=name)

        if vdis is not None:
            __vdis_list = []
            for vdi in vdis:
                __vdis_list.append(await serialize(vdi))

            ret = dict(success=True, data=__vdis_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)
Esempio n. 2
0
async def insert_cd_inurl_name(cluster_id: str, iso_name: str):
    """ Find VDI by Name """
    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_by_name(session=session, name=iso_name)
        print(vdis)

        if vdis is not None:
            __vdis_list = []
            vdis_list = __vdis_list.append
            for vdi in vdis:
                vdis_list(serialize(vdi))

            ret = dict(success=True, data=__vdis_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)