0
# Apache Libcloud
1
2
Apache Libcloud is a comprehensive Python library that provides a unified interface for managing cloud computing resources across multiple cloud provider APIs. It abstracts away the differences between various cloud providers (AWS, Azure, Google Cloud, and many others) by offering standardized APIs for compute instances, storage services, DNS management, load balancers, containers, and backup services.
3
4
## Package Information
5
6
- **Package Name**: apache-libcloud
7
- **Language**: Python
8
- **Installation**: `pip install apache-libcloud`
9
- **Supported Python Versions**: 3.7+
10
11
## Core Imports
12
13
```python
14
import libcloud
15
from libcloud.base import get_driver, DriverType
16
```
17
18
Service-specific imports:
19
20
```python
21
# Compute
22
from libcloud.compute.types import Provider as ComputeProvider
23
from libcloud.compute.providers import get_driver as get_compute_driver
24
25
# Storage
26
from libcloud.storage.types import Provider as StorageProvider
27
from libcloud.storage.providers import get_driver as get_storage_driver
28
29
# DNS
30
from libcloud.dns.types import Provider as DNSProvider
31
from libcloud.dns.providers import get_driver as get_dns_driver
32
33
# Load Balancer
34
from libcloud.loadbalancer.types import Provider as LoadBalancerProvider
35
from libcloud.loadbalancer.providers import get_driver as get_loadbalancer_driver
36
37
# Container
38
from libcloud.container.types import Provider as ContainerProvider
39
from libcloud.container.providers import get_driver as get_container_driver
40
41
# Backup
42
from libcloud.backup.types import Provider as BackupProvider
43
from libcloud.backup.providers import get_driver as get_backup_driver
44
```
45
46
## Basic Usage
47
48
```python
49
from libcloud.compute.types import Provider
50
from libcloud.compute.providers import get_driver
51
52
# Get a compute driver for EC2
53
cls = get_driver(Provider.EC2)
54
driver = cls('access_id', 'secret_key', region='us-east-1')
55
56
# List all nodes
57
nodes = driver.list_nodes()
58
for node in nodes:
59
print(f"Node: {node.name}, State: {node.state}")
60
61
# Create a new node
62
sizes = driver.list_sizes()
63
images = driver.list_images()
64
locations = driver.list_locations()
65
66
new_node = driver.create_node(
67
name='my-server',
68
size=sizes[0],
69
image=images[0],
70
location=locations[0]
71
)
72
```
73
74
## Architecture
75
76
Libcloud uses a driver-based architecture where each cloud provider is implemented as a driver that inherits from service-specific base classes. The core components are:
77
78
- **Driver Types**: Six main service categories (compute, storage, DNS, load balancer, container, backup)
79
- **Providers**: Specific cloud service implementations within each driver type
80
- **Base Classes**: Common interfaces that all drivers implement (Node, Container, Object, Zone, etc.)
81
- **Factory Pattern**: `get_driver()` functions to instantiate provider-specific drivers
82
83
## Capabilities
84
85
### Core Driver System
86
87
The foundation of Libcloud's unified interface, providing driver factory functions and type definitions.
88
89
```python { .api }
90
class DriverType:
91
BACKUP = BackupProvider
92
COMPUTE = ComputeProvider
93
CONTAINER = ContainerProvider
94
DNS = DnsProvider
95
LOADBALANCER = LoadBalancerProvider
96
STORAGE = StorageProvider
97
98
def get_driver(type: DriverType, provider: str) -> BaseDriver
99
```
100
101
```python { .api }
102
def enable_debug(fo: TextIOWrapper) -> None
103
```
104
105
[Core Driver System](./core-driver-system.md)
106
107
### Compute Services
108
109
Manage virtual machines, instances, and compute resources across 60+ cloud providers including AWS EC2, Azure, Google Compute Engine, and more.
110
111
```python { .api }
112
class NodeDriver(BaseDriver):
113
def list_nodes(self) -> List[Node]
114
def create_node(self, name: str, size: NodeSize, image: NodeImage, location: NodeLocation = None, **kwargs) -> Node
115
def destroy_node(self, node: Node) -> bool
116
def reboot_node(self, node: Node) -> bool
117
118
class Node:
119
id: str
120
name: str
121
state: NodeState
122
public_ips: List[str]
123
private_ips: List[str]
124
size: NodeSize
125
image: NodeImage
126
```
127
128
[Compute Services](./compute-services.md)
129
130
### Storage Services
131
132
Object storage and blob operations across 20+ storage providers including AWS S3, Azure Blob Storage, Google Cloud Storage, and more.
133
134
```python { .api }
135
class StorageDriver(BaseDriver):
136
def list_containers(self) -> List[Container]
137
def create_container(self, container_name: str) -> Container
138
def upload_object(self, file_path: str, container: Container, object_name: str) -> Object
139
def download_object(self, obj: Object, destination_path: str) -> bool
140
141
class Container:
142
name: str
143
extra: Dict[str, Any]
144
145
class Object:
146
name: str
147
size: int
148
hash: str
149
container: Container
150
```
151
152
[Storage Services](./storage-services.md)
153
154
### DNS Management
155
156
DNS zone and record management across 15+ DNS providers including Route 53, CloudFlare, Google DNS, and more.
157
158
```python { .api }
159
class DNSDriver(BaseDriver):
160
def list_zones(self) -> List[Zone]
161
def create_zone(self, domain: str) -> Zone
162
def create_record(self, name: str, zone: Zone, type: RecordType, data: str) -> Record
163
164
class Zone:
165
id: str
166
domain: str
167
type: str
168
ttl: int
169
170
class Record:
171
id: str
172
name: str
173
type: RecordType
174
data: str
175
zone: Zone
176
```
177
178
[DNS Management](./dns-management.md)
179
180
### Load Balancer Services
181
182
Load balancer management across multiple cloud providers including AWS ELB/ALB, Azure Load Balancer, and more.
183
184
```python { .api }
185
class Driver(BaseDriver):
186
def list_balancers(self) -> List[LoadBalancer]
187
def create_balancer(self, name: str, port: int, protocol: str, algorithm: Algorithm, members: List[Member]) -> LoadBalancer
188
189
class LoadBalancer:
190
id: str
191
name: str
192
state: State
193
ip: str
194
port: int
195
196
class Member:
197
id: str
198
ip: str
199
port: int
200
```
201
202
[Load Balancer Services](./load-balancer-services.md)
203
204
### Container Services
205
206
Container and cluster management for Kubernetes, AWS ECS, and other container platforms.
207
208
```python { .api }
209
class ContainerDriver(BaseDriver):
210
def list_containers(self) -> List[Container]
211
def deploy_container(self, name: str, image: ContainerImage) -> Container
212
def list_clusters(self) -> List[ContainerCluster]
213
214
class Container:
215
id: str
216
name: str
217
image: ContainerImage
218
state: ContainerState
219
220
class ContainerCluster:
221
id: str
222
name: str
223
state: str
224
```
225
226
[Container Services](./container-services.md)
227
228
### Backup Services
229
230
Backup and snapshot management for cloud storage and compute resources.
231
232
```python { .api }
233
class BackupDriver(BaseDriver):
234
def list_targets(self) -> List[BackupTarget]
235
def create_target_from_node(self, node: Node, name: str = None) -> BackupTarget
236
237
class BackupTarget:
238
id: str
239
name: str
240
size: int
241
type: BackupTargetType
242
```
243
244
[Backup Services](./backup-services.md)
245
246
## Common Types
247
248
```python { .api }
249
from libcloud.common.types import LibcloudError, InvalidCredsError, MalformedResponseError, ProviderError
250
251
class LibcloudError(Exception):
252
"""Base exception class for all Libcloud errors"""
253
254
def __init__(self, value: str, driver: BaseDriver = None) -> None
255
256
value: str
257
driver: BaseDriver
258
259
class ProviderError(LibcloudError):
260
"""Exception raised when provider returns HTTP error response (4xx, 5xx)"""
261
262
def __init__(self, value: str, http_code: int, driver: BaseDriver = None) -> None
263
264
http_code: int
265
266
class InvalidCredsError(ProviderError):
267
"""Exception raised when invalid credentials are provided (HTTP 401)"""
268
269
def __init__(self, value: str = "Invalid credentials with the provider", driver: BaseDriver = None) -> None
270
271
class MalformedResponseError(LibcloudError):
272
"""Exception raised when the response cannot be parsed"""
273
274
def __init__(self, value: str, body: str = None, driver: BaseDriver = None) -> None
275
276
body: str
277
278
# Deprecated alias
279
InvalidCredsException = InvalidCredsError
280
```
281
282
## Utility Functions
283
284
```python { .api }
285
# Security settings
286
from libcloud.security import VERIFY_SSL_CERT, CA_CERTS_PATH
287
288
VERIFY_SSL_CERT: bool
289
CA_CERTS_PATH: str
290
291
# Networking utilities
292
from libcloud.utils.networking import is_private_subnet, is_public_subnet, is_valid_ip_address
293
294
def is_private_subnet(ip: str) -> bool
295
def is_public_subnet(ip: str) -> bool
296
def is_valid_ip_address(ip: str) -> bool
297
def join_ipv4_segments(segments: List[int]) -> str
298
def increment_ipv4_segments(segments: List[int]) -> List[int]
299
300
# Pricing information
301
from libcloud.pricing import get_pricing, get_size_price, get_image_price, set_pricing
302
303
def get_pricing(driver_type: str, driver_name: str) -> Dict[str, float]
304
def get_size_price(driver_type: str, driver_name: str, size_id: str) -> float
305
def get_image_price(driver_type: str, driver_name: str, image_id: str) -> float
306
def set_pricing(pricing_data: Dict) -> None
307
def clear_pricing_data() -> None
308
def download_pricing_file(file_url: str = None) -> str
309
310
# Debug functionality
311
from libcloud import enable_debug
312
313
def enable_debug(fo: TextIOWrapper) -> None
314
```