codecraftai-restclient-digitalocean 1.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ccai/restclient/digitalocean/__init__.py +12 -0
- ccai/restclient/digitalocean/apigroups/__init__.py +12 -0
- ccai/restclient/digitalocean/apigroups/collectiongroup.py +101 -0
- ccai/restclient/digitalocean/apigroups/domaingroup.py +109 -0
- ccai/restclient/digitalocean/apigroups/dropletgroup.py +41 -0
- ccai/restclient/digitalocean/apigroups/firewallgroup.py +59 -0
- ccai/restclient/digitalocean/apigroups/sshkeygroup.py +45 -0
- ccai/restclient/digitalocean/apigroups/volumegroup.py +74 -0
- ccai/restclient/digitalocean/apigroups/vpcgroup.py +38 -0
- ccai/restclient/digitalocean/digitaloceanapierror.py +75 -0
- ccai/restclient/digitalocean/digitaloceanrestclient.py +223 -0
- ccai/restclient/digitalocean/spacesclient.py +306 -0
- codecraftai_restclient_digitalocean-1.2.0.dist-info/METADATA +103 -0
- codecraftai_restclient_digitalocean-1.2.0.dist-info/RECORD +16 -0
- codecraftai_restclient_digitalocean-1.2.0.dist-info/WHEEL +4 -0
- codecraftai_restclient_digitalocean-1.2.0.dist-info/licenses/LICENSE.md +204 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. package:: ccai.restclient.digitalocean
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: A pure-Python REST client for the DigitalOcean API v2 and for
|
|
5
|
+
Spaces, its S3-compatible object store.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2026, Code Craft AI LLC"
|
|
12
|
+
__credits__ = []
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. package:: ccai.restclient.digitalocean.apigroups
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: The DigitalOcean api groups, named to match the surface the
|
|
5
|
+
pydo SDK presented.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2026, Code Craft AI LLC"
|
|
12
|
+
__credits__ = []
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: collectiongroup
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: :class:`CollectionGroup` — the shared behaviour of the regular
|
|
5
|
+
DigitalOcean collections.
|
|
6
|
+
|
|
7
|
+
Most DigitalOcean collections follow the same shape: a collection path
|
|
8
|
+
(``/vpcs``), entries nested under the plural name (``vpcs``) on a list,
|
|
9
|
+
the resource nested under the singular name (``vpc``) on a create, and
|
|
10
|
+
deletion by id. That uniformity lives here.
|
|
11
|
+
|
|
12
|
+
The method names and keyword names deliberately match the ones the ``pydo``
|
|
13
|
+
SDK used — ``list(per_page=, page=)``, ``create(body=)``,
|
|
14
|
+
``delete(vpc_id=)`` — so call sites written against the SDK keep their
|
|
15
|
+
shape. Where a caller's keyword differed from pydo's own, the CALLER's
|
|
16
|
+
spelling wins, because this client is what defines the contract now.
|
|
17
|
+
|
|
18
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
__author__ = "Myron Walker"
|
|
22
|
+
__copyright__ = "Copyright 2026, Code Craft AI LLC"
|
|
23
|
+
__credits__ = []
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
from typing import Any, Dict, Optional
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CollectionGroup:
|
|
30
|
+
"""
|
|
31
|
+
Shared behaviour for a regular DigitalOcean collection.
|
|
32
|
+
|
|
33
|
+
:cvar COLLECTION_PATH: The collection path, e.g. ``/vpcs``.
|
|
34
|
+
:cvar IDENTIFIER_KEYWORD: The keyword callers name the resource by,
|
|
35
|
+
e.g. ``vpc_id``.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
COLLECTION_PATH: str = ""
|
|
39
|
+
IDENTIFIER_KEYWORD: str = ""
|
|
40
|
+
|
|
41
|
+
def __init__(self, *, client: Any) -> None:
|
|
42
|
+
"""
|
|
43
|
+
Construct a collection group bound to a client.
|
|
44
|
+
|
|
45
|
+
:param client: The owning :class:`DigitalOceanRestClient`.
|
|
46
|
+
"""
|
|
47
|
+
self._client = client
|
|
48
|
+
return
|
|
49
|
+
|
|
50
|
+
def list(self, *, per_page: Optional[int] = None,
|
|
51
|
+
page: Optional[int] = None,
|
|
52
|
+
**filters: Any) -> Dict[str, Any]:
|
|
53
|
+
"""
|
|
54
|
+
List one page of the collection.
|
|
55
|
+
|
|
56
|
+
This returns ONE page, exactly as the SDK did. Callers that need
|
|
57
|
+
the whole collection follow ``links.pages.next`` themselves — the
|
|
58
|
+
venue has a helper for it — so paging stays where the caller can
|
|
59
|
+
see it.
|
|
60
|
+
|
|
61
|
+
:param per_page: Optional page size.
|
|
62
|
+
:param page: Optional page number.
|
|
63
|
+
:param filters: Any further query parameters, e.g. ``tag_name``.
|
|
64
|
+
|
|
65
|
+
:returns: The decoded response, carrying the entries under the
|
|
66
|
+
collection's plural key plus ``links`` and ``meta``.
|
|
67
|
+
"""
|
|
68
|
+
params: Dict[str, Any] = {"per_page": per_page, "page": page}
|
|
69
|
+
for key, value in filters.items():
|
|
70
|
+
params[key] = value
|
|
71
|
+
|
|
72
|
+
rtnval = self._client.request(method="GET",
|
|
73
|
+
path=self.COLLECTION_PATH,
|
|
74
|
+
params=params)
|
|
75
|
+
return rtnval
|
|
76
|
+
|
|
77
|
+
def create(self, *, body: Dict[str, Any]) -> Dict[str, Any]:
|
|
78
|
+
"""
|
|
79
|
+
Create a resource.
|
|
80
|
+
|
|
81
|
+
:param body: The creation body, passed through as given.
|
|
82
|
+
|
|
83
|
+
:returns: The decoded response, carrying the resource under the
|
|
84
|
+
collection's singular key.
|
|
85
|
+
"""
|
|
86
|
+
rtnval = self._client.request(method="POST",
|
|
87
|
+
path=self.COLLECTION_PATH, body=body)
|
|
88
|
+
return rtnval
|
|
89
|
+
|
|
90
|
+
def _delete_by_id(self, *, identifier: Any) -> Dict[str, Any]:
|
|
91
|
+
"""
|
|
92
|
+
Delete a resource by id.
|
|
93
|
+
|
|
94
|
+
:param identifier: The resource id.
|
|
95
|
+
|
|
96
|
+
:returns: The decoded response, empty on a ``204``.
|
|
97
|
+
"""
|
|
98
|
+
rtnval = self._client.request(
|
|
99
|
+
method="DELETE",
|
|
100
|
+
path="{}/{}".format(self.COLLECTION_PATH, identifier))
|
|
101
|
+
return rtnval
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: domaingroup
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: :class:`DomainGroup` — the ``/domains`` api group and its
|
|
5
|
+
records sub-collection.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2026, Code Craft AI LLC"
|
|
12
|
+
__credits__ = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from typing import Any, Dict, Optional
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class DomainGroup:
|
|
19
|
+
"""
|
|
20
|
+
The DigitalOcean domains collection and its DNS records.
|
|
21
|
+
|
|
22
|
+
Records are addressed under their zone (``/domains/{name}/records``),
|
|
23
|
+
so the zone name is a parameter on every record call rather than
|
|
24
|
+
state held by the group.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
COLLECTION_PATH = "/domains"
|
|
28
|
+
|
|
29
|
+
def __init__(self, *, client: Any) -> None:
|
|
30
|
+
"""
|
|
31
|
+
Construct a domain group bound to a client.
|
|
32
|
+
|
|
33
|
+
:param client: The owning :class:`DigitalOceanRestClient`.
|
|
34
|
+
"""
|
|
35
|
+
self._client = client
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
def list(self, *, per_page: Optional[int] = None,
|
|
39
|
+
page: Optional[int] = None) -> Dict[str, Any]:
|
|
40
|
+
"""
|
|
41
|
+
List one page of the account's domains.
|
|
42
|
+
|
|
43
|
+
:param per_page: Optional page size.
|
|
44
|
+
:param page: Optional page number.
|
|
45
|
+
|
|
46
|
+
:returns: The decoded response, carrying ``domains``.
|
|
47
|
+
"""
|
|
48
|
+
rtnval = self._client.request(
|
|
49
|
+
method="GET", path=self.COLLECTION_PATH,
|
|
50
|
+
params={"per_page": per_page, "page": page})
|
|
51
|
+
return rtnval
|
|
52
|
+
|
|
53
|
+
def list_records(self, *, domain_name: str,
|
|
54
|
+
per_page: Optional[int] = None,
|
|
55
|
+
page: Optional[int] = None,
|
|
56
|
+
**filters: Any) -> Dict[str, Any]:
|
|
57
|
+
"""
|
|
58
|
+
List one page of a zone's DNS records.
|
|
59
|
+
|
|
60
|
+
:param domain_name: The zone name.
|
|
61
|
+
:param per_page: Optional page size.
|
|
62
|
+
:param page: Optional page number.
|
|
63
|
+
:param filters: Any further query parameters, e.g. ``name`` or
|
|
64
|
+
``type``.
|
|
65
|
+
|
|
66
|
+
:returns: The decoded response, carrying ``domain_records``.
|
|
67
|
+
"""
|
|
68
|
+
params: Dict[str, Any] = {"per_page": per_page, "page": page}
|
|
69
|
+
for key, value in filters.items():
|
|
70
|
+
params[key] = value
|
|
71
|
+
|
|
72
|
+
rtnval = self._client.request(
|
|
73
|
+
method="GET",
|
|
74
|
+
path="{}/{}/records".format(self.COLLECTION_PATH, domain_name),
|
|
75
|
+
params=params)
|
|
76
|
+
return rtnval
|
|
77
|
+
|
|
78
|
+
def create_record(self, *, domain_name: str,
|
|
79
|
+
body: Dict[str, Any]) -> Dict[str, Any]:
|
|
80
|
+
"""
|
|
81
|
+
Create a DNS record in a zone.
|
|
82
|
+
|
|
83
|
+
:param domain_name: The zone name.
|
|
84
|
+
:param body: The record body, carrying ``type``, ``name``,
|
|
85
|
+
``data`` and optionally ``ttl``.
|
|
86
|
+
|
|
87
|
+
:returns: The decoded response, carrying ``domain_record``.
|
|
88
|
+
"""
|
|
89
|
+
rtnval = self._client.request(
|
|
90
|
+
method="POST",
|
|
91
|
+
path="{}/{}/records".format(self.COLLECTION_PATH, domain_name),
|
|
92
|
+
body=body)
|
|
93
|
+
return rtnval
|
|
94
|
+
|
|
95
|
+
def delete_record(self, *, domain_name: str,
|
|
96
|
+
domain_record_id: Any) -> Dict[str, Any]:
|
|
97
|
+
"""
|
|
98
|
+
Delete a DNS record from a zone.
|
|
99
|
+
|
|
100
|
+
:param domain_name: The zone name.
|
|
101
|
+
:param domain_record_id: The record id.
|
|
102
|
+
|
|
103
|
+
:returns: The decoded response.
|
|
104
|
+
"""
|
|
105
|
+
rtnval = self._client.request(
|
|
106
|
+
method="DELETE",
|
|
107
|
+
path="{}/{}/records/{}".format(self.COLLECTION_PATH, domain_name,
|
|
108
|
+
domain_record_id))
|
|
109
|
+
return rtnval
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: dropletgroup
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: :class:`DropletGroup` — the ``/droplets`` api group.
|
|
5
|
+
|
|
6
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__author__ = "Myron Walker"
|
|
10
|
+
__copyright__ = "Copyright 2026, Code Craft AI LLC"
|
|
11
|
+
__credits__ = []
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from typing import Any, Dict
|
|
15
|
+
|
|
16
|
+
from ccai.restclient.digitalocean.apigroups.collectiongroup import (
|
|
17
|
+
CollectionGroup
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class DropletGroup(CollectionGroup):
|
|
22
|
+
"""
|
|
23
|
+
The DigitalOcean droplets collection.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
COLLECTION_PATH = "/droplets"
|
|
27
|
+
IDENTIFIER_KEYWORD = "droplet_id"
|
|
28
|
+
|
|
29
|
+
def destroy(self, *, droplet_id: Any) -> Dict[str, Any]:
|
|
30
|
+
"""
|
|
31
|
+
Destroy a droplet.
|
|
32
|
+
|
|
33
|
+
Named ``destroy`` rather than ``delete`` to match the surface
|
|
34
|
+
callers already use for this collection.
|
|
35
|
+
|
|
36
|
+
:param droplet_id: The droplet id.
|
|
37
|
+
|
|
38
|
+
:returns: The decoded response.
|
|
39
|
+
"""
|
|
40
|
+
rtnval = self._delete_by_id(identifier=droplet_id)
|
|
41
|
+
return rtnval
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: firewallgroup
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: :class:`FirewallGroup` — the ``/firewalls`` api group.
|
|
5
|
+
|
|
6
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__author__ = "Myron Walker"
|
|
10
|
+
__copyright__ = "Copyright 2026, Code Craft AI LLC"
|
|
11
|
+
__credits__ = []
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from typing import Any, Dict
|
|
15
|
+
|
|
16
|
+
from ccai.restclient.digitalocean.apigroups.collectiongroup import (
|
|
17
|
+
CollectionGroup
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class FirewallGroup(CollectionGroup):
|
|
22
|
+
"""
|
|
23
|
+
The DigitalOcean firewalls collection.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
COLLECTION_PATH = "/firewalls"
|
|
27
|
+
IDENTIFIER_KEYWORD = "firewall_id"
|
|
28
|
+
|
|
29
|
+
def update(self, *, firewall_id: Any,
|
|
30
|
+
body: Dict[str, Any]) -> Dict[str, Any]:
|
|
31
|
+
"""
|
|
32
|
+
Replace a firewall's configuration.
|
|
33
|
+
|
|
34
|
+
The API models this as a PUT, which is a full replacement rather
|
|
35
|
+
than a merge: the body must describe the firewall's complete
|
|
36
|
+
desired state, since omitted rules are removed.
|
|
37
|
+
|
|
38
|
+
:param firewall_id: The firewall id.
|
|
39
|
+
:param body: The complete replacement configuration.
|
|
40
|
+
|
|
41
|
+
:returns: The decoded response, carrying the firewall under
|
|
42
|
+
``firewall``.
|
|
43
|
+
"""
|
|
44
|
+
rtnval = self._client.request(
|
|
45
|
+
method="PUT",
|
|
46
|
+
path="{}/{}".format(self.COLLECTION_PATH, firewall_id),
|
|
47
|
+
body=body)
|
|
48
|
+
return rtnval
|
|
49
|
+
|
|
50
|
+
def delete(self, *, firewall_id: Any) -> Dict[str, Any]:
|
|
51
|
+
"""
|
|
52
|
+
Delete a firewall.
|
|
53
|
+
|
|
54
|
+
:param firewall_id: The firewall id.
|
|
55
|
+
|
|
56
|
+
:returns: The decoded response.
|
|
57
|
+
"""
|
|
58
|
+
rtnval = self._delete_by_id(identifier=firewall_id)
|
|
59
|
+
return rtnval
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: sshkeygroup
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: :class:`SshKeyGroup` — the account ssh-keys api group.
|
|
5
|
+
|
|
6
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__author__ = "Myron Walker"
|
|
10
|
+
__copyright__ = "Copyright 2026, Code Craft AI LLC"
|
|
11
|
+
__credits__ = []
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from typing import Any, Dict
|
|
15
|
+
|
|
16
|
+
from ccai.restclient.digitalocean.apigroups.collectiongroup import (
|
|
17
|
+
CollectionGroup
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SshKeyGroup(CollectionGroup):
|
|
22
|
+
"""
|
|
23
|
+
The DigitalOcean ssh-keys collection.
|
|
24
|
+
|
|
25
|
+
The path is ``/account/keys`` — ssh keys belong to the account rather
|
|
26
|
+
than to any one resource — while the response key is ``ssh_keys``.
|
|
27
|
+
That mismatch is the API's, not a mistake here.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
COLLECTION_PATH = "/account/keys"
|
|
31
|
+
IDENTIFIER_KEYWORD = "ssh_key_id"
|
|
32
|
+
|
|
33
|
+
def delete(self, *, ssh_key_id: Any) -> Dict[str, Any]:
|
|
34
|
+
"""
|
|
35
|
+
Delete an ssh key.
|
|
36
|
+
|
|
37
|
+
The API accepts either the numeric id or the key fingerprint in
|
|
38
|
+
this position, so both work.
|
|
39
|
+
|
|
40
|
+
:param ssh_key_id: The ssh key id or fingerprint.
|
|
41
|
+
|
|
42
|
+
:returns: The decoded response.
|
|
43
|
+
"""
|
|
44
|
+
rtnval = self._delete_by_id(identifier=ssh_key_id)
|
|
45
|
+
return rtnval
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: volumegroup
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: :class:`VolumeGroup` and :class:`VolumeActionGroup` — the
|
|
5
|
+
``/volumes`` api group and its actions sub-collection.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2026, Code Craft AI LLC"
|
|
12
|
+
__credits__ = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from typing import Any, Dict
|
|
16
|
+
|
|
17
|
+
from ccai.restclient.digitalocean.apigroups.collectiongroup import (
|
|
18
|
+
CollectionGroup
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class VolumeGroup(CollectionGroup):
|
|
23
|
+
"""
|
|
24
|
+
The DigitalOcean block-storage volumes collection.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
COLLECTION_PATH = "/volumes"
|
|
28
|
+
IDENTIFIER_KEYWORD = "volume_id"
|
|
29
|
+
|
|
30
|
+
def delete(self, *, volume_id: Any) -> Dict[str, Any]:
|
|
31
|
+
"""
|
|
32
|
+
Delete a volume.
|
|
33
|
+
|
|
34
|
+
:param volume_id: The volume id.
|
|
35
|
+
|
|
36
|
+
:returns: The decoded response.
|
|
37
|
+
"""
|
|
38
|
+
rtnval = self._delete_by_id(identifier=volume_id)
|
|
39
|
+
return rtnval
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class VolumeActionGroup:
|
|
43
|
+
"""
|
|
44
|
+
The volume actions sub-collection.
|
|
45
|
+
|
|
46
|
+
Attach and detach are modelled by the API as actions posted against a
|
|
47
|
+
volume, with the verb named inside the body rather than by the path.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(self, *, client: Any) -> None:
|
|
51
|
+
"""
|
|
52
|
+
Construct a volume-action group bound to a client.
|
|
53
|
+
|
|
54
|
+
:param client: The owning :class:`DigitalOceanRestClient`.
|
|
55
|
+
"""
|
|
56
|
+
self._client = client
|
|
57
|
+
return
|
|
58
|
+
|
|
59
|
+
def post_by_id(self, *, volume_id: Any,
|
|
60
|
+
body: Dict[str, Any]) -> Dict[str, Any]:
|
|
61
|
+
"""
|
|
62
|
+
Post an action against one volume.
|
|
63
|
+
|
|
64
|
+
:param volume_id: The volume id.
|
|
65
|
+
:param body: The action body, carrying ``type`` and whatever that
|
|
66
|
+
action needs (e.g. ``droplet_id``, ``region``).
|
|
67
|
+
|
|
68
|
+
:returns: The decoded response, carrying the action record under
|
|
69
|
+
``action``.
|
|
70
|
+
"""
|
|
71
|
+
rtnval = self._client.request(
|
|
72
|
+
method="POST",
|
|
73
|
+
path="/volumes/{}/actions".format(volume_id), body=body)
|
|
74
|
+
return rtnval
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: vpcgroup
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: :class:`VpcGroup` — the ``/vpcs`` api group.
|
|
5
|
+
|
|
6
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__author__ = "Myron Walker"
|
|
10
|
+
__copyright__ = "Copyright 2026, Code Craft AI LLC"
|
|
11
|
+
__credits__ = []
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from typing import Any, Dict
|
|
15
|
+
|
|
16
|
+
from ccai.restclient.digitalocean.apigroups.collectiongroup import (
|
|
17
|
+
CollectionGroup
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class VpcGroup(CollectionGroup):
|
|
22
|
+
"""
|
|
23
|
+
The DigitalOcean VPCs collection.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
COLLECTION_PATH = "/vpcs"
|
|
27
|
+
IDENTIFIER_KEYWORD = "vpc_id"
|
|
28
|
+
|
|
29
|
+
def delete(self, *, vpc_id: Any) -> Dict[str, Any]:
|
|
30
|
+
"""
|
|
31
|
+
Delete a VPC.
|
|
32
|
+
|
|
33
|
+
:param vpc_id: The VPC id.
|
|
34
|
+
|
|
35
|
+
:returns: The decoded response.
|
|
36
|
+
"""
|
|
37
|
+
rtnval = self._delete_by_id(identifier=vpc_id)
|
|
38
|
+
return rtnval
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: digitaloceanapierror
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Errors raised for non-success DigitalOcean responses.
|
|
5
|
+
|
|
6
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__author__ = "Myron Walker"
|
|
10
|
+
__copyright__ = "Copyright 2026, Code Craft AI LLC"
|
|
11
|
+
__credits__ = []
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from typing import Optional
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class DigitalOceanApiRequestError(Exception):
|
|
18
|
+
"""
|
|
19
|
+
Raised when the DigitalOcean API returns a non-success status.
|
|
20
|
+
|
|
21
|
+
:ivar status: The HTTP status code.
|
|
22
|
+
:ivar reason: The message from the API's error body, or the HTTP
|
|
23
|
+
reason phrase.
|
|
24
|
+
:ivar body: The raw response body text.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, message: str, *, status: int = 0,
|
|
28
|
+
reason: str = "", body: Optional[str] = None) -> None:
|
|
29
|
+
"""
|
|
30
|
+
Construct a DigitalOceanApiRequestError.
|
|
31
|
+
|
|
32
|
+
:param message: The human-readable error message.
|
|
33
|
+
:param status: The HTTP status code.
|
|
34
|
+
:param reason: The extracted reason.
|
|
35
|
+
:param body: The raw response body.
|
|
36
|
+
"""
|
|
37
|
+
super().__init__(message)
|
|
38
|
+
self.status: int = status
|
|
39
|
+
self.reason: str = reason
|
|
40
|
+
self.body: Optional[str] = body
|
|
41
|
+
return
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class SpacesRequestError(Exception):
|
|
45
|
+
"""
|
|
46
|
+
Raised when a Spaces (S3-compatible) request returns a non-success
|
|
47
|
+
status.
|
|
48
|
+
|
|
49
|
+
The ``code`` carries the S3 error code parsed out of the XML body
|
|
50
|
+
(``NoSuchBucket``, ``BucketAlreadyOwnedByYou`` ...). Callers
|
|
51
|
+
distinguish "absent" from "broken" on that code, so it is a first-class
|
|
52
|
+
attribute rather than something to dig out of a message: a missing
|
|
53
|
+
bucket is a normal answer, while an auth or throttle failure must never
|
|
54
|
+
be mistaken for one.
|
|
55
|
+
|
|
56
|
+
:ivar status: The HTTP status code.
|
|
57
|
+
:ivar code: The S3 error code, empty when the body carried none.
|
|
58
|
+
:ivar body: The raw response body text.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def __init__(self, message: str, *, status: int = 0, code: str = "",
|
|
62
|
+
body: Optional[str] = None) -> None:
|
|
63
|
+
"""
|
|
64
|
+
Construct a SpacesRequestError.
|
|
65
|
+
|
|
66
|
+
:param message: The human-readable error message.
|
|
67
|
+
:param status: The HTTP status code.
|
|
68
|
+
:param code: The S3 error code.
|
|
69
|
+
:param body: The raw response body.
|
|
70
|
+
"""
|
|
71
|
+
super().__init__(message)
|
|
72
|
+
self.status: int = status
|
|
73
|
+
self.code: str = code
|
|
74
|
+
self.body: Optional[str] = body
|
|
75
|
+
return
|