Esempio n. 1
0
async def delete_single_provider(id: str):
    provider = mongo.get_db().providers.find_one({"_id": PyObjectId(id)})
    if provider:
        result = mongo.get_db().providers.delete_one({"_id": PyObjectId(id)})
        return {"status": "success", "message": result}
    else:
        return {"status": "fail", "message": "no provider matched"}
Esempio n. 2
0
async def sync_single_provider(id: str):
    provider = mongo.get_db().providers.find_one({"_id": PyObjectId(id)})
    resources = build_provider_resources(provider)
    browndfields = discover_brownfields(resources)
    bf_list = list(map(dict, [bf for bf in browndfields]))
    result = mongo.get_db().servers.insert_many(bf_list)
    inserted_count = len(result.inserted_ids)
    return {
        "status": "success",
        "message": f"inserted {inserted_count} server(s)"
    }
Esempio n. 3
0
async def sync_resource():
    servers = []
    for provider in mongo.get_db().providers.find():
        servers += build_provider_resources(provider)
    mongo.get_db().servers.delete_many(
        {"tenant_id": "113ac03bf6e341be9ae4df61a59354dc"})
    response = discover_brownfields(servers)
    res = list(map(dict, [r for r in response]))
    mongo.get_db().servers.insert_many(res)
    # ret.inserted_ids
    # for r in response:
    #     mongo.get_db().servers.insert_one(r.dict(by_alias=True))
    return {'servers': response}
Esempio n. 4
0
async def delete_all_providers():
    result = mongo.get_db().providers.delete_many({"region": None})
    deleted_count = result.deleted_count
    return {
        "status": "success",
        "message": f"deleted {deleted_count} provider(s)"
    }
Esempio n. 5
0
async def list_server():
    servers = []
    for server in mongo.get_db().servers.find():
        servers.append(Server(**server))
    return {'servers': servers}
Esempio n. 6
0
async def create_single_provider(provider: Provider):
    if hasattr(provider, 'id'):
        delattr(provider, 'id')
    result = mongo.get_db().providers.insert_one(provider.dict(by_alias=True))
    provider.id = result.inserted_id
    return {'provider': provider}
Esempio n. 7
0
async def retrieve_single_provider(id: str):
    provider = mongo.get_db().providers.find_one({"_id": PyObjectId(id)})
    return {'provider': Provider(**provider)}
Esempio n. 8
0
async def retrieve_all_providers():
    providers = []
    for provider in mongo.get_db().providers.find():
        providers.append(Provider(**provider))
    return {'providers': providers}