Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cloudfoundry_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
from cloudfoundry_client.v3.apps import AppManager
from cloudfoundry_client.v3.buildpacks import BuildpackManager
from cloudfoundry_client.v3.domains import DomainManager
from cloudfoundry_client.v3.droplets import DropletManager
from cloudfoundry_client.v3.feature_flags import FeatureFlagManager
from cloudfoundry_client.v3.isolation_segments import IsolationSegmentManager
from cloudfoundry_client.v3.organization_quotas import OrganizationQuotaManager
from cloudfoundry_client.v3.packages import PackageManager
from cloudfoundry_client.v3.processes import ProcessManager
from cloudfoundry_client.v3.organizations import OrganizationManager
from cloudfoundry_client.v3.roles import RoleManager
Expand Down Expand Up @@ -118,11 +120,13 @@ def __init__(self, cloud_controller_v3_url: str, credential_manager: "CloudFound
self.apps = AppManager(target_endpoint, credential_manager)
self.buildpacks = BuildpackManager(target_endpoint, credential_manager)
self.domains = DomainManager(target_endpoint, credential_manager)
self.droplets = DropletManager(target_endpoint, credential_manager)
self.feature_flags = FeatureFlagManager(target_endpoint, credential_manager)
self.isolation_segments = IsolationSegmentManager(target_endpoint, credential_manager)
self.jobs = JobManager(target_endpoint, credential_manager)
self.organizations = OrganizationManager(target_endpoint, credential_manager)
self.organization_quotas = OrganizationQuotaManager(target_endpoint, credential_manager)
self.packages = PackageManager(target_endpoint, credential_manager)
self.processes = ProcessManager(target_endpoint, credential_manager)
self.roles = RoleManager(target_endpoint, credential_manager)
self.routes = RouteManager(target_endpoint, credential_manager)
Expand Down
9 changes: 7 additions & 2 deletions cloudfoundry_client/v3/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ def remove(self, application_guid: str, asynchronous: bool = True) -> str | None
def get_env(self, application_guid: str) -> JsonObject:
return super(AppManager, self)._get("%s%s/%s/env" % (self.target_endpoint, self.entity_uri, application_guid))

def get_routes(self, application_guid: str) -> JsonObject:
return super(AppManager, self)._get("%s%s/%s/routes" % (self.target_endpoint, self.entity_uri, application_guid))
def list_routes(self, application_guid: str, **kwargs) -> Pagination[Entity]:
uri: str = "%s/%s/routes" % (self.entity_uri, application_guid)
return super(AppManager, self)._list(requested_path=uri, **kwargs)

def list_droplets(self, application_guid: str, **kwargs) -> Pagination[Entity]:
uri: str = "%s/%s/droplets" % (self.entity_uri, application_guid)
return super(AppManager, self)._list(requested_path=uri, **kwargs)

def get_manifest(self, application_guid: str) -> str:
return self.client.get(url="%s%s/%s/manifest" % (self.target_endpoint, self.entity_uri, application_guid)).text
Expand Down
57 changes: 57 additions & 0 deletions cloudfoundry_client/v3/droplets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from typing import TYPE_CHECKING, Any

from cloudfoundry_client.v3.entities import EntityManager, Entity, ToOneRelationship

if TYPE_CHECKING:
from cloudfoundry_client.client import CloudFoundryClient


class DropletManager(EntityManager[Entity]):
def __init__(self, target_endpoint: str, client: "CloudFoundryClient"):
super(DropletManager, self).__init__(target_endpoint, client, "/v3/droplets")

def create(self,
app_guid: str,
process_types: dict[str, str] | None = None,
meta_labels: dict | None = None,
meta_annotations: dict | None = None,
) -> Entity:
data: dict[str, Any] = {
"relationships": {
"app": ToOneRelationship(app_guid)
},
}
if process_types is not None:
data["process_types"] = process_types
self._metadata(data, meta_labels, meta_annotations)
return super(DropletManager, self)._create(data)

def copy(self,
droplet_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=droplet_guid
)
return self._post(url, data=data)

def update(self,
droplet_gid: str,
meta_labels: dict | None = None,
meta_annotations: dict | None = None,
) -> Entity:
data: dict[str, Any] = {}
self._metadata(data, meta_labels, meta_annotations)
return super(DropletManager, self)._update(droplet_gid, data)

def remove(self, route_gid: str):
return super(DropletManager, self)._remove(route_gid)
9 changes: 7 additions & 2 deletions cloudfoundry_client/v3/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,16 @@ def _get(self, url: str, entity_type: type[ENTITY_TYPE] | None = None, **kwargs)
def _post(
self,
url: str,
data: dict | None = None,
entity_type: type[ENTITY_TYPE] | None = None,
data: dict | None = None,
params: dict | None = None,
files: Any = None
) -> ENTITY_TYPE:
response = self.client.post(url, json=data, files=files)
response = self.client.post(
url if params is None else EntityManager._get_url_with_encoded_params(url, **params),
json=data,
files=files
)
return self._read_response(response, entity_type)

def _put(self, url: str, data: dict, entity_type: type[ENTITY_TYPE] | None = None) -> ENTITY_TYPE:
Expand Down
16 changes: 16 additions & 0 deletions cloudfoundry_client/v3/packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import TYPE_CHECKING

from cloudfoundry_client.common_objects import Pagination
from cloudfoundry_client.v3.entities import EntityManager, Entity

if TYPE_CHECKING:
from cloudfoundry_client.client import CloudFoundryClient


class PackageManager(EntityManager[Entity]):
def __init__(self, target_endpoint: str, client: "CloudFoundryClient"):
super(PackageManager, self).__init__(target_endpoint, client, "/v3/packages")

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)
119 changes: 119 additions & 0 deletions tests/fixtures/v3/apps/GET_{id}_droplets_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"pagination": {
"total_results": 2,
"total_pages": 1,
"first": {
"href": "https://api.example.org/v3/app/7b34f1cf-7e73-428a-bb5a-8a17a8058396/droplets?page=1&per_page=50"
},
"last": {
"href": "https://api.example.org/v3/app/7b34f1cf-7e73-428a-bb5a-8a17a8058396/droplets?page=1&per_page=50"
},
"next": null,
"previous": null
},
"resources": [
{
"guid": "585bc3c1-3743-497d-88b0-403ad6b56d16",
"state": "STAGED",
"error": null,
"lifecycle": {
"type": "buildpack",
"data": {}
},
"image": null,
"execution_metadata": "PRIVATE DATA HIDDEN",
"process_types": {
"redacted_message": "[PRIVATE DATA HIDDEN IN LISTS]"
},
"checksum": {
"type": "sha256",
"value": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
},
"buildpacks": [
{
"name": "ruby_buildpack",
"detect_output": "ruby 1.6.14",
"version": "1.1.1.",
"buildpack_name": "ruby"
}
],
"stack": "cflinuxfs4",
"created_at": "2016-03-28T23:39:34Z",
"updated_at": "2016-03-28T23:39:47Z",
"relationships": {
"app": {
"data": {
"guid": "7b34f1cf-7e73-428a-bb5a-8a17a8058396"
}
}
},
"links": {
"self": {
"href": "https://api.example.org/v3/droplets/585bc3c1-3743-497d-88b0-403ad6b56d16"
},
"package": {
"href": "https://api.example.org/v3/packages/8222f76a-9e09-4360-b3aa-1ed329945e92"
},
"app": {
"href": "https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058396"
},
"assign_current_droplet": {
"href": "https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058396/relationships/current_droplet",
"method": "PATCH"
},
"download": {
"href": "https://api.example.org/v3/droplets/585bc3c1-3743-497d-88b0-403ad6b56d16/download"
}
},
"metadata": {
"labels": {},
"annotations": {}
}
},
{
"guid": "fdf3851c-def8-4de1-87f1-6d4543189e22",
"state": "STAGED",
"error": null,
"lifecycle": {
"type": "docker",
"data": {}
},
"execution_metadata": "[PRIVATE DATA HIDDEN IN LISTS]",
"process_types": {
"redacted_message": "[PRIVATE DATA HIDDEN IN LISTS]"
},
"image": "cloudfoundry/diego-docker-app-custom:latest",
"checksum": null,
"buildpacks": null,
"stack": null,
"created_at": "2016-03-17T00:00:01Z",
"updated_at": "2016-03-17T21:41:32Z",
"relationships": {
"app": {
"data": {
"guid": "7b34f1cf-7e73-428a-bb5a-8a17a8058396"
}
}
},
"links": {
"self": {
"href": "https://api.example.org/v3/droplets/fdf3851c-def8-4de1-87f1-6d4543189e22"
},
"package": {
"href": "https://api.example.org/v3/packages/c5725684-a02f-4e59-bc67-8f36ae944688"
},
"app": {
"href": "https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058396"
},
"assign_current_droplet": {
"href": "https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058396/relationships/current_droplet",
"method": "PATCH"
}
},
"metadata": {
"labels": {},
"annotations": {}
}
}
]
}
Loading
Loading