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

Added in version 1.26.1.

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, insecure=False, cacert=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.

Note

With default parameters, it would assume that the host has a self-signed certificate and it will fetch it and verify hostname and expiry. It is recommended that you use CA signed certificate in your CloudVision deployment, so you’d either add this CA to the list of trusted CAs, or provide it’s certificate via cacert parameter

Danger

Avoid setting insecure=True as this would disable certificate check

Changed in version 1.27.2: Added insecure and cacert parameters

Parameters:
  • host – CloudVision hostname

  • insecure – skip certificate verification

  • cacert (pathlib.Path or str) – path to CA certificate to use for verifying the host’s certificate

Return type:

AsyncCVClient

classmethod from_user_credentials(username, password, host, port=443, insecure=False, cacert=None)[source]

Use usename and password to authenticate in CloudVision

Note

With default parameters, it would assume that the host has a self-signed certificate and it will fetch it and verify hostname and expiry. It is recommended that you use CA signed certificate in your CloudVision deployment, so you’d either add this CA to the list of trusted CAs, or provide it’s certificate via cacert parameter

Danger

Avoid setting insecure=True as this would disable certificate check

Changed in version 1.27.2: Added insecure and cacert parameters

Parameters:
  • host – CloudVision hostname

  • insecure – skip certificate verification

  • cacert (pathlib.Path or str) – path to CA certificate to use for verifying the host’s certificate

Return type:

AsyncCVClient

Raises:

UnableToAuthenticateException

exception cloudvision.api.client.UnableToAuthenticateException[source]

Bases: Exception

Is thrown when unable to authenticate using username and password

Module contents