CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-apache-libcloud

A standard Python library that abstracts away differences among multiple cloud provider APIs

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

core-driver-system.mddocs/

Core Driver System

The core driver system provides the foundation for Libcloud's unified interface across all cloud providers. It implements a factory pattern that allows you to obtain provider-specific drivers through a consistent API.

Driver Types

class DriverType:
    """Enumeration of supported service types"""
    BACKUP = BackupProvider
    COMPUTE = ComputeProvider
    CONTAINER = ContainerProvider
    DNS = DnsProvider
    LOADBALANCER = LoadBalancerProvider
    STORAGE = StorageProvider

Driver Factory Functions

Universal Driver Factory

def get_driver(type: DriverType, provider: str) -> BaseDriver

Get a driver instance for the specified type and provider.

Parameters:

  • type: The service type from DriverType enum
  • provider: The provider identifier string

Returns:

  • Driver instance for the specified provider

Raises:

  • DriverTypeNotFoundError: If the driver type is not supported

Example:

from libcloud.base import get_driver, DriverType
from libcloud.compute.types import Provider

# Using universal factory
driver = get_driver(DriverType.COMPUTE, Provider.EC2)

Service-Specific Factories

Each service provides its own factory function for convenience:

# Compute
def get_compute_driver(provider: str) -> NodeDriver

# Storage  
def get_storage_driver(provider: str) -> StorageDriver

# DNS
def get_dns_driver(provider: str) -> DNSDriver

# Load Balancer
def get_loadbalancer_driver(provider: str) -> Driver

# Container
def get_container_driver(provider: str) -> ContainerDriver

# Backup
def get_backup_driver(provider: str) -> BackupDriver

Example:

from libcloud.compute.providers import get_driver
from libcloud.compute.types import Provider

# Using service-specific factory
driver = get_driver(Provider.EC2)

Base Driver Classes

BaseDriver

class BaseDriver:
    """Base class for all Libcloud drivers"""
    name: str
    website: str
    type: Type
    api_name: str
    
    def __init__(self, key: str, secret: str = None, secure: bool = True, host: str = None, port: int = None, **kwargs)

All driver classes inherit from BaseDriver and provide service-specific methods.

Debugging Support

Enable Debug Logging

def enable_debug(fo: TextIOWrapper) -> None

Enable library-wide debugging to a file-like object. This logs all HTTP requests and responses to help with troubleshooting.

Parameters:

  • fo: File-like object to write debug information to

Example:

import libcloud
import sys

# Enable debug logging to stderr
libcloud.enable_debug(sys.stderr)

# Enable debug logging to a file
with open('libcloud.log', 'w') as f:
    libcloud.enable_debug(f)

You can also enable debugging via environment variable:

export LIBCLOUD_DEBUG=/dev/stderr
# or
export LIBCLOUD_DEBUG=libcloud.log

Driver Type Factory Map

DriverTypeFactoryMap: Dict[Type, Callable]

Internal mapping of driver types to their factory functions. Used by the universal get_driver() function.

Exceptions

class DriverTypeNotFoundError(KeyError):
    """Raised when an unsupported driver type is requested"""
    def __init__(self, type: Type)

Version Information

__version__: str

The current version of the Libcloud library.

Example:

import libcloud
print(f"Libcloud version: {libcloud.__version__}")

Usage Patterns

Basic Driver Initialization

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

# Get driver class
cls = get_driver(Provider.EC2)

# Initialize driver with credentials
driver = cls('access_key', 'secret_key', region='us-east-1')

# Use driver methods
nodes = driver.list_nodes()

Error Handling

from libcloud.base import get_driver, DriverType, DriverTypeNotFoundError
from libcloud.common.types import InvalidCredsError

try:
    driver = get_driver(DriverType.COMPUTE, 'invalid_provider')
except DriverTypeNotFoundError as e:
    print(f"Driver not found: {e}")

try:
    cls = get_driver(DriverType.COMPUTE, Provider.EC2)
    driver = cls('invalid_key', 'invalid_secret')
    nodes = driver.list_nodes()
except InvalidCredsError as e:
    print(f"Invalid credentials: {e}")

Install with Tessl CLI

npx tessl i tessl/pypi-apache-libcloud

docs

backup-services.md

compute-services.md

container-services.md

core-driver-system.md

dns-management.md

index.md

load-balancer-services.md

storage-services.md

tile.json