cloudvision.api package

Subpackages

Submodules

cloudvision.api.client module

class cloudvision.api.client.AsyncCVClient(token, ssl_context, host, port=443, username=None)[source]

Bases: object

This class enables access to CloudVision GRPC API using grpclib stubs.

Use one of classmethods from_token() from_user_credentials() to intantialize the client, and use it with stubs from cloudvision.api.arista

It is implemented as contextmanager, that provides instance of grpclib.client.Channel. See example below

import asyncio
from cloudvision.api.client import AsyncCVClient
from cloudvision.api.arista.inventory.v1 import DeviceServiceStub, DeviceStreamRequest

async def get_devices():
    client = AsyncCVClient.from_token('<your service account token>', 'your-cvp.io')

    # get channel
    with client as channel:

        # pass it to the stub
        service = DeviceServiceStub(channel)

        # execute one of stub's methods
        async for item in service.get_all(DeviceStreamRequest()):
            print(item)

asyncio.run(get_devices())

Note

If for some reason multiple context managers with the same client are used, each will produce a new channel that would be closed accordingly (see below)

client = AsyncCVCClient(...)

with client as channel1:
    # channel1 is open
    with client as channel2:
        ... # both channel1 and channel2 are open
    # channel2 is closed while channel 1 is still open
# channel1 is closed
classmethod from_token(token, host, port=443, username=None)[source]

If you would like to use service accounts, you can create them in CloudVision UI https://my-cloudvision-instance.io/cv/setting/aaa-service-accounts

Generate a token for service account and pass it to this method to get an instance of the client.

Return type:

AsyncCVClient

classmethod from_user_credentials(username, password, host, port=443)[source]

Use usename and password to authenticate in CloudVision

Return type:

AsyncCVClient

Module contents