-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathpackages.py
More file actions
55 lines (46 loc) · 1.88 KB
/
packages.py
File metadata and controls
55 lines (46 loc) · 1.88 KB
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
from enum import Enum
from typing import TYPE_CHECKING, Any
from cloudfoundry_client.common_objects import Pagination
from cloudfoundry_client.v3.entities import EntityManager, Entity, ToOneRelationship
if TYPE_CHECKING:
from cloudfoundry_client.client import CloudFoundryClient
class PackageType(Enum):
BITS = 'bits'
DOCKER = 'docker'
class PackageManager(EntityManager[Entity]):
def __init__(self, target_endpoint: str, client: "CloudFoundryClient"):
super(PackageManager, self).__init__(target_endpoint, client, "/v3/packages")
def create(self,
app_guid: str,
package_type: PackageType,
meta_labels: dict | None = None,
meta_annotations: dict | None = None,
) -> Entity:
data: dict[str, Any] = {
"type": package_type.value,
"relationships": {
"app": ToOneRelationship(app_guid)
},
}
self._metadata(data, meta_labels, meta_annotations)
return super(PackageManager, self)._create(data)
def copy(self,
package_guid: str,
app_guid: str,
meta_labels: dict | None = None,
meta_annotations: dict | None = None,
) -> Entity:
data: dict[str, Any] = {
"relationships": {
"app": ToOneRelationship(app_guid)
},
}
self._metadata(data, meta_labels, meta_annotations)
url = EntityManager._get_url_with_encoded_params(
"%s%s" % (self.target_endpoint, self.entity_uri),
source_guid=package_guid
)
return self._post(url, data=data)
def list_droplets(self, package_guid: str, **kwargs) -> Pagination[Entity]:
uri: str = "%s/%s/droplets" % (self.entity_uri, package_guid)
return super(PackageManager, self)._list(requested_path=uri, **kwargs)