/usr/lib/python3/dist-packages/digitalocean/Manager.py is in python3-digitalocean 1.13.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | # -*- coding: utf-8 -*-
try:
from urlparse import urlparse, parse_qs
except ImportError:
from urllib.parse import urlparse, parse_qs # noqa
from .baseapi import BaseAPI
from .Account import Account
from .Action import Action
from .Certificate import Certificate
from .Domain import Domain
from .Droplet import Droplet
from .FloatingIP import FloatingIP
from .Firewall import Firewall, InboundRule, OutboundRule
from .Image import Image
from .LoadBalancer import LoadBalancer
from .LoadBalancer import StickySesions, HealthCheck, ForwardingRule
from .Region import Region
from .SSHKey import SSHKey
from .Size import Size
from .Snapshot import Snapshot
from .Tag import Tag
from .Volume import Volume
class Manager(BaseAPI):
def __init__(self, *args, **kwargs):
super(Manager, self).__init__(*args, **kwargs)
def get_account(self):
"""
Returns an Account object.
"""
return Account.get_object(api_token=self.token)
def get_all_regions(self):
"""
This function returns a list of Region object.
"""
data = self.get_data("regions/")
regions = list()
for jsoned in data['regions']:
region = Region(**jsoned)
region.token = self.token
regions.append(region)
return regions
def get_all_droplets(self, tag_name=None):
"""
This function returns a list of Droplet object.
"""
params = dict()
if tag_name:
params["tag_name"] = tag_name
data = self.get_data("droplets/", params=params)
droplets = list()
for jsoned in data['droplets']:
droplet = Droplet(**jsoned)
droplet.token = self.token
for net in droplet.networks['v4']:
if net['type'] == 'private':
droplet.private_ip_address = net['ip_address']
if net['type'] == 'public':
droplet.ip_address = net['ip_address']
if droplet.networks['v6']:
droplet.ip_v6_address = droplet.networks['v6'][0]['ip_address']
if "backups" in droplet.features:
droplet.backups = True
else:
droplet.backups = False
if "ipv6" in droplet.features:
droplet.ipv6 = True
else:
droplet.ipv6 = False
if "private_networking" in droplet.features:
droplet.private_networking = True
else:
droplet.private_networking = False
droplets.append(droplet)
return droplets
def get_droplet(self, droplet_id):
"""
Return a Droplet by its ID.
"""
return Droplet.get_object(api_token=self.token, droplet_id=droplet_id)
def get_all_sizes(self):
"""
This function returns a list of Size object.
"""
data = self.get_data("sizes/")
sizes = list()
for jsoned in data['sizes']:
size = Size(**jsoned)
size.token = self.token
sizes.append(size)
return sizes
def get_images(self, private=False, type=None):
"""
This function returns a list of Image object.
"""
params = {}
if private:
params['private'] = 'true'
if type:
params['type'] = type
data = self.get_data("images/", params=params)
images = list()
for jsoned in data['images']:
image = Image(**jsoned)
image.token = self.token
images.append(image)
return images
def get_all_images(self):
"""
This function returns a list of Image objects containing all
available DigitalOcean images, both public and private.
"""
images = self.get_images()
return images
def get_image(self, image_id_or_slug):
"""
Return a Image by its ID/Slug.
"""
return Image.get_object(
api_token=self.token,
image_id_or_slug=image_id_or_slug,
)
def get_my_images(self):
"""
This function returns a list of Image objects representing
private DigitalOcean images (e.g. snapshots and backups).
"""
images = self.get_images(private=True)
return images
def get_global_images(self):
"""
This function returns a list of Image objects representing
public DigitalOcean images (e.g. base distribution images
and 'One-Click' applications).
"""
data = self.get_images()
images = list()
for i in data:
if i.public:
i.token = self.token
images.append(i)
return images
def get_distro_images(self):
"""
This function returns a list of Image objects representing
public base distribution images.
"""
images = self.get_images(type='distribution')
return images
def get_app_images(self):
"""
This function returns a list of Image objectobjects representing
public DigitalOcean 'One-Click' application images.
"""
images = self.get_images(type='application')
return images
def get_all_domains(self):
"""
This function returns a list of Domain object.
"""
data = self.get_data("domains/")
domains = list()
for jsoned in data['domains']:
domain = Domain(**jsoned)
domain.token = self.token
domains.append(domain)
return domains
def get_domain(self, domain_name):
"""
Return a Domain by its domain_name
"""
return Domain.get_object(api_token=self.token, domain_name=domain_name)
def get_all_sshkeys(self):
"""
This function returns a list of SSHKey object.
"""
data = self.get_data("account/keys/")
ssh_keys = list()
for jsoned in data['ssh_keys']:
ssh_key = SSHKey(**jsoned)
ssh_key.token = self.token
ssh_keys.append(ssh_key)
return ssh_keys
def get_ssh_key(self, ssh_key_id):
"""
Return a SSHKey object by its ID.
"""
return SSHKey.get_object(api_token=self.token, ssh_key_id=ssh_key_id)
def get_all_tags(self):
"""
This method returns a list of all tags.
"""
data = self.get_data("tags")
return [
Tag(token=self.token, **tag) for tag in data['tags']
]
def get_action(self, action_id):
"""
Return an Action object by a specific ID.
"""
return Action.get_object(api_token=self.token, action_id=action_id)
def get_all_floating_ips(self):
"""
This function returns a list of FloatingIP objects.
"""
data = self.get_data("floating_ips")
floating_ips = list()
for jsoned in data['floating_ips']:
floating_ip = FloatingIP(**jsoned)
floating_ip.token = self.token
floating_ips.append(floating_ip)
return floating_ips
def get_floating_ip(self, ip):
"""
Returns a of FloatingIP object by its IP address.
"""
return FloatingIP.get_object(api_token=self.token, ip=ip)
def get_all_load_balancers(self):
"""
Returns a list of Load Balancer objects.
"""
data = self.get_data("load_balancers")
load_balancers = list()
for jsoned in data['load_balancers']:
load_balancer = LoadBalancer(**jsoned)
load_balancer.token = self.token
load_balancer.health_check = HealthCheck(**jsoned['health_check'])
load_balancer.sticky_sessions = StickySesions(**jsoned['sticky_sessions'])
forwarding_rules = list()
for rule in jsoned['forwarding_rules']:
forwarding_rules.append(ForwardingRule(**rule))
load_balancer.forwarding_rules = forwarding_rules
load_balancers.append(load_balancer)
return load_balancers
def get_load_balancer(self, id):
"""
Returns a Load Balancer object by its ID.
Args:
id (str): Load Balancer ID
"""
return LoadBalancer.get_object(api_token=self.token, id=id)
def get_certificate(self, id):
"""
Returns a Certificate object by its ID.
Args:
id (str): Certificate ID
"""
return Certificate.get_object(api_token=self.token, cert_id=id)
def get_all_certificates(self):
"""
This function returns a list of Certificate objects.
"""
data = self.get_data("certificates")
certificates = list()
for jsoned in data['certificates']:
cert = Certificate(**jsoned)
cert.token = self.token
certificates.append(cert)
return certificates
def get_snapshot(self, snapshot_id):
"""
Return a Snapshot by its ID.
"""
return Snapshot.get_object(
api_token=self.token, snapshot_id=snapshot_id
)
def get_all_snapshots(self):
"""
This method returns a list of all Snapshots.
"""
data = self.get_data("snapshots/")
return [
Snapshot(token=self.token, **snapshot)
for snapshot in data['snapshots']
]
def get_droplet_snapshots(self):
"""
This method returns a list of all Snapshots based on Droplets.
"""
data = self.get_data("snapshots?resource_type=droplet")
return [
Snapshot(token=self.token, **snapshot)
for snapshot in data['snapshots']
]
def get_volume_snapshots(self):
"""
This method returns a list of all Snapshots based on volumes.
"""
data = self.get_data("snapshots?resource_type=volume")
return [
Snapshot(token=self.token, **snapshot)
for snapshot in data['snapshots']
]
def get_all_volumes(self):
"""
This function returns a list of Volume objects.
"""
data = self.get_data("volumes")
volumes = list()
for jsoned in data['volumes']:
volume = Volume(**jsoned)
volume.token = self.token
volumes.append(volume)
return volumes
def get_volume(self, volume_id):
"""
Returns a Volume object by its ID.
"""
return Volume.get_object(api_token=self.token, volume_id=volume_id)
def get_all_firewalls(self):
"""
This function returns a list of Firewall objects.
"""
data = self.get_data("firewalls")
firewalls = list()
for jsoned in data['firewalls']:
firewall = Firewall(**jsoned)
firewall.token = self.token
in_rules = list()
for rule in jsoned['inbound_rules']:
in_rules.append(InboundRule(**rule))
firewall.inbound_rules = in_rules
out_rules = list()
for rule in jsoned['outbound_rules']:
out_rules.append(OutboundRule(**rule))
firewall.outbound_rules = out_rules
firewalls.append(firewall)
return firewalls
def get_firewall(self, firewall_id):
"""
Return a Firewall by its ID.
"""
return Firewall.get_object(
api_token=self.token,
firewall_id=firewall_id,
)
def __str__(self):
return "<Manager>"
|