|
| 1 | +from typing import TYPE_CHECKING, Any |
| 2 | + |
| 3 | +from cloudfoundry_client.v3.entities import EntityManager, Entity, ToOneRelationship |
| 4 | + |
| 5 | +if TYPE_CHECKING: |
| 6 | + from cloudfoundry_client.client import CloudFoundryClient |
| 7 | + |
| 8 | + |
| 9 | +class DropletManager(EntityManager[Entity]): |
| 10 | + def __init__(self, target_endpoint: str, client: "CloudFoundryClient"): |
| 11 | + super(DropletManager, self).__init__(target_endpoint, client, "/v3/droplets") |
| 12 | + |
| 13 | + def create(self, |
| 14 | + app_guid: str, |
| 15 | + process_types: dict[str, str] | None = None, |
| 16 | + meta_labels: dict | None = None, |
| 17 | + meta_annotations: dict | None = None, |
| 18 | + ) -> Entity: |
| 19 | + data: dict[str, Any] = { |
| 20 | + "relationships": { |
| 21 | + "app": ToOneRelationship(app_guid) |
| 22 | + }, |
| 23 | + } |
| 24 | + if process_types is not None: |
| 25 | + data["process_types"] = process_types |
| 26 | + self._metadata(data, meta_labels, meta_annotations) |
| 27 | + return super(DropletManager, self)._create(data) |
| 28 | + |
| 29 | + def copy(self, |
| 30 | + droplet_guid: str, |
| 31 | + app_guid: str, |
| 32 | + meta_labels: dict | None = None, |
| 33 | + meta_annotations: dict | None = None, |
| 34 | + ) -> Entity: |
| 35 | + data: dict[str, Any] = { |
| 36 | + "relationships": { |
| 37 | + "app": ToOneRelationship(app_guid) |
| 38 | + }, |
| 39 | + } |
| 40 | + self._metadata(data, meta_labels, meta_annotations) |
| 41 | + url = EntityManager._get_url_with_encoded_params( |
| 42 | + "%s%s" % (self.target_endpoint, self.entity_uri), |
| 43 | + source_guid=droplet_guid |
| 44 | + ) |
| 45 | + return self._post(url, data=data) |
| 46 | + |
| 47 | + def update(self, |
| 48 | + droplet_gid: str, |
| 49 | + meta_labels: dict | None = None, |
| 50 | + meta_annotations: dict | None = None, |
| 51 | + ) -> Entity: |
| 52 | + data: dict[str, Any] = {} |
| 53 | + self._metadata(data, meta_labels, meta_annotations) |
| 54 | + return super(DropletManager, self)._update(droplet_gid, data) |
| 55 | + |
| 56 | + def remove(self, route_gid: str): |
| 57 | + return super(DropletManager, self)._remove(route_gid) |
0 commit comments