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
6 changes: 4 additions & 2 deletions cloudfoundry_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from cloudfoundry_client.v2.events import EventManager
from cloudfoundry_client.v2.jobs import JobManager as JobManagerV2
from cloudfoundry_client.v2.resources import ResourceManager
from cloudfoundry_client.v2.routes import RouteManager
from cloudfoundry_client.v2.routes import RouteManager as RouteManagerV2
from cloudfoundry_client.v2.service_bindings import ServiceBindingManager
from cloudfoundry_client.v2.service_brokers import ServiceBrokerManager as ServiceBrokerManagerV2
from cloudfoundry_client.v2.service_instances import ServiceInstanceManager as ServiceInstanceManagerV2
Expand All @@ -36,6 +36,7 @@
from cloudfoundry_client.v3.processes import ProcessManager
from cloudfoundry_client.v3.organizations import OrganizationManager
from cloudfoundry_client.v3.roles import RoleManager
from cloudfoundry_client.v3.routes import RouteManager
from cloudfoundry_client.v3.security_groups import SecurityGroupManager
from cloudfoundry_client.v3.service_brokers import ServiceBrokerManager
from cloudfoundry_client.v3.service_credential_bindings import ServiceCredentialBindingManager
Expand Down Expand Up @@ -97,7 +98,7 @@ def __init__(self, cloud_controller_v2_url: str, credential_manager: "CloudFound
self.event = EventManager(target_endpoint, credential_manager)
self.organizations = EntityManagerV2(target_endpoint, credential_manager, "/v2/organizations")
self.private_domains = EntityManagerV2(target_endpoint, credential_manager, "/v2/private_domains")
self.routes = RouteManager(target_endpoint, credential_manager)
self.routes = RouteManagerV2(target_endpoint, credential_manager)
self.services = EntityManagerV2(target_endpoint, credential_manager, "/v2/services")
self.shared_domains = EntityManagerV2(target_endpoint, credential_manager, "/v2/shared_domains")
self.spaces = SpaceManagerV2(target_endpoint, credential_manager)
Expand All @@ -124,6 +125,7 @@ def __init__(self, cloud_controller_v3_url: str, credential_manager: "CloudFound
self.organization_quotas = OrganizationQuotaManager(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)
self.security_groups = SecurityGroupManager(target_endpoint, credential_manager)
self.service_brokers = ServiceBrokerManager(target_endpoint, credential_manager)
self.service_credential_bindings = ServiceCredentialBindingManager(target_endpoint, credential_manager)
Expand Down
58 changes: 58 additions & 0 deletions cloudfoundry_client/v3/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from enum import Enum
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 LoadBalancing(Enum):
ROUND_ROBIN = 'round-robin'
LEAST_CONNECTION = 'least-connection'


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

def create(self,
space_guid: str,
domain_guid: str,
host: str | None = None,
path: str | None = None,
port: int | None = None,
load_balancing: LoadBalancing | None = None,
meta_labels: dict | None = None,
meta_annotations: dict | None = None,
) -> Entity:
data: dict[str, Any] = {
"relationships": {
"space": ToOneRelationship(space_guid), "domain": ToOneRelationship(domain_guid)
},
}
if host is not None:
data["host"] = host
if port is not None:
data["port"] = port
if path is not None:
data["path"] = path
if load_balancing is not None:
data["options"] = {"loadbalancing": load_balancing.value}
self._metadata(data, meta_labels, meta_annotations)
return super(RouteManager, self)._create(data)

def update(self,
route_gid: str,
load_balancing: LoadBalancing | None = None,
meta_labels: dict | None = None,
meta_annotations: dict | None = None,
) -> Entity:
data: dict[str, Any] = {}
if load_balancing is not None:
data["options"] = {"loadbalancing": load_balancing.value}
self._metadata(data, meta_labels, meta_annotations)
return super(RouteManager, self)._update(route_gid, data)

def remove(self, route_gid: str):
return super(RouteManager, self)._remove(route_gid)
88 changes: 88 additions & 0 deletions tests/fixtures/v3/routes/GET_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"pagination": {
"total_results": 1,
"total_pages": 1,
"first": {
"href": "https://api.example.org/v3/routes?page=1&per_page=2"
},
"last": {
"href": "https://api.example.org/v3/routes?page=1&per_page=2"
},
"next": null,
"previous": null
},
"resources": [
{
"guid": "cbad697f-cac1-48f4-9017-ac08f39dfb31",
"protocol": "http",
"created_at": "2019-05-10T17:17:48Z",
"updated_at": "2019-05-10T17:17:48Z",
"host": "a-hostname",
"path": "/some_path",
"url": "a-hostname.a-domain.com/some_path",
"destinations": [
{
"guid": "385bf117-17f5-4689-8c5c-08c6cc821fed",
"app": {
"guid": "0a6636b5-7fc4-44d8-8752-0db3e40b35a5",
"process": {
"type": "web"
}
},
"weight": null,
"port": 8080,
"protocol": "http1",
"created_at": "2019-05-10T17:17:48Z",
"updated_at": "2019-05-10T17:17:48Z"
},
{
"guid": "27e96a3b-5bcf-49ed-8048-351e0be23e6f",
"app": {
"guid": "f61e59fa-2121-4217-8c7b-15bfd75baf25",
"process": {
"type": "web"
}
},
"weight": null,
"port": 8080,
"protocol": "http1",
"created_at": "2019-05-10T17:17:48Z",
"updated_at": "2019-05-10T17:17:48Z"
}
],
"options": {
"loadbalancing": "round-robin"
},
"metadata": {
"labels": {},
"annotations": {}
},
"relationships": {
"space": {
"data": {
"guid": "885a8cb3-c07b-4856-b448-eeb10bf36236"
}
},
"domain": {
"data": {
"guid": "0b5f3633-194c-42d2-9408-972366617e0e"
}
}
},
"links": {
"self": {
"href": "https://api.example.org/v3/routes/cbad697f-cac1-48f4-9017-ac08f39dfb31"
},
"space": {
"href": "https://api.example.org/v3/spaces/885a8cb3-c07b-4856-b448-eeb10bf36236"
},
"domain": {
"href": "https://api.example.org/v3/domains/0b5f3633-194c-42d2-9408-972366617e0e"
},
"destinations": {
"href": "https://api.example.org/v3/routes/cbad697f-cac1-48f4-9017-ac08f39dfb31/destinations"
}
}
}
]
}
73 changes: 73 additions & 0 deletions tests/fixtures/v3/routes/GET_{id}_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"guid": "cbad697f-cac1-48f4-9017-ac08f39dfb31",
"protocol": "tcp",
"port": 6666,
"created_at": "2019-05-10T17:17:48Z",
"updated_at": "2019-05-10T17:17:48Z",
"host": "a-hostname",
"path": "/some_path",
"url": "a-hostname.a-domain.com/some_path",
"destinations": [
{
"guid": "385bf117-17f5-4689-8c5c-08c6cc821fed",
"app": {
"guid": "0a6636b5-7fc4-44d8-8752-0db3e40b35a5",
"process": {
"type": "web"
}
},
"weight": null,
"port": 8080,
"protocol": "tcp",
"created_at": "2019-05-10T17:17:48Z",
"updated_at": "2019-05-10T17:17:48Z"
},
{
"guid": "27e96a3b-5bcf-49ed-8048-351e0be23e6f",
"app": {
"guid": "f61e59fa-2121-4217-8c7b-15bfd75baf25",
"process": {
"type": "web"
}
},
"weight": null,
"port": 8080,
"protocol": "tcp",
"created_at": "2019-05-10T17:17:48Z",
"updated_at": "2019-05-10T17:17:48Z"
}
],
"options": {
"loadbalancing": "round-robin"
},
"metadata": {
"labels": {},
"annotations": {}
},
"relationships": {
"space": {
"data": {
"guid": "885a8cb3-c07b-4856-b448-eeb10bf36236"
}
},
"domain": {
"data": {
"guid": "0b5f3633-194c-42d2-9408-972366617e0e"
}
}
},
"links": {
"self": {
"href": "https://api.example.org/v3/routes/cbad697f-cac1-48f4-9017-ac08f39dfb31"
},
"space": {
"href": "https://api.example.org/v3/spaces/885a8cb3-c07b-4856-b448-eeb10bf36236"
},
"domain": {
"href": "https://api.example.org/v3/domains/0b5f3633-194c-42d2-9408-972366617e0e"
},
"destinations": {
"href": "https://api.example.org/v3/routes/cbad697f-cac1-48f4-9017-ac08f39dfb31/destinations"
}
}
}
77 changes: 77 additions & 0 deletions tests/fixtures/v3/routes/PATCH_{id}_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"guid": "cbad697f-cac1-48f4-9017-ac08f39dfb31",
"protocol": "tcp",
"port": 6666,
"created_at": "2019-05-10T17:17:48Z",
"updated_at": "2019-05-10T17:17:48Z",
"host": "a-hostname",
"path": "/some_path",
"url": "a-hostname.a-domain.com/some_path",
"destinations": [
{
"guid": "385bf117-17f5-4689-8c5c-08c6cc821fed",
"app": {
"guid": "0a6636b5-7fc4-44d8-8752-0db3e40b35a5",
"process": {
"type": "web"
}
},
"weight": null,
"port": 8080,
"protocol": "tcp",
"created_at": "2019-05-10T17:17:48Z",
"updated_at": "2019-05-10T17:17:48Z"
},
{
"guid": "27e96a3b-5bcf-49ed-8048-351e0be23e6f",
"app": {
"guid": "f61e59fa-2121-4217-8c7b-15bfd75baf25",
"process": {
"type": "web"
}
},
"weight": null,
"port": 8080,
"protocol": "tcp",
"created_at": "2019-05-10T17:17:48Z",
"updated_at": "2019-05-10T17:17:48Z"
}
],
"options": {
"loadbalancing": "round-robin"
},
"metadata": {
"labels": {
"key": "value"
},
"annotations": {
"note": "detailed information"
}
},
"relationships": {
"space": {
"data": {
"guid": "885a8cb3-c07b-4856-b448-eeb10bf36236"
}
},
"domain": {
"data": {
"guid": "0b5f3633-194c-42d2-9408-972366617e0e"
}
}
},
"links": {
"self": {
"href": "https://api.example.org/v3/routes/cbad697f-cac1-48f4-9017-ac08f39dfb31"
},
"space": {
"href": "https://api.example.org/v3/spaces/885a8cb3-c07b-4856-b448-eeb10bf36236"
},
"domain": {
"href": "https://api.example.org/v3/domains/0b5f3633-194c-42d2-9408-972366617e0e"
},
"destinations": {
"href": "https://api.example.org/v3/routes/cbad697f-cac1-48f4-9017-ac08f39dfb31/destinations"
}
}
}
Loading
Loading