Ejemplo 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"}
Ejemplo 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)"
    }
Ejemplo 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}
Ejemplo 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)"
    }
Ejemplo n.º 5
0
async def list_server():
    servers = []
    for server in mongo.get_db().servers.find():
        servers.append(Server(**server))
    return {'servers': servers}
Ejemplo 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}
Ejemplo n.º 7
0
async def retrieve_single_provider(id: str):
    provider = mongo.get_db().providers.find_one({"_id": PyObjectId(id)})
    return {'provider': Provider(**provider)}
Ejemplo n.º 8
0
async def retrieve_all_providers():
    providers = []
    for provider in mongo.get_db().providers.find():
        providers.append(Provider(**provider))
    return {'providers': providers}