Skip to content

Commit fb1dd74

Browse files
committed
Propagate asynchronous parameter where delete is asynchronous
1 parent e626a46 commit fb1dd74

9 files changed

Lines changed: 30 additions & 26 deletions

File tree

main/cloudfoundry_client/v3/apps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING
1+
from typing import TYPE_CHECKING, Optional
22

33
from cloudfoundry_client.json_object import JsonObject
44
from cloudfoundry_client.v3.entities import EntityManager
@@ -16,8 +16,8 @@ def restart(self, application_guid: str):
1616
self.entity_uri,
1717
application_guid))
1818

19-
def remove(self, application_guid: str):
20-
super(AppManager, self)._remove(application_guid)
19+
def remove(self, application_guid: str, asynchronous: bool = True) -> Optional[str]:
20+
return super(AppManager, self)._remove(application_guid, asynchronous)
2121

2222
def get_env(self, application_guid: str) -> JsonObject:
2323
return super(AppManager, self)._get("%s%s/%s/env" % (self.target_endpoint, self.entity_uri, application_guid))

main/cloudfoundry_client/v3/buildpacks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def create(
3030
}
3131
return super(BuildpackManager, self)._create(data)
3232

33-
def remove(self, buildpack_guid: str):
34-
super(BuildpackManager, self)._remove(buildpack_guid)
33+
def remove(self, buildpack_guid: str, asynchronous: bool = True) -> Optional[str]:
34+
return super(BuildpackManager, self)._remove(buildpack_guid, asynchronous)
3535

3636
def update(
3737
self,

main/cloudfoundry_client/v3/domains.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def update(self, domain_guid: str, meta_labels: Optional[dict] = None, meta_anno
5050
data = {"metadata": {"labels": meta_labels, "annotations": meta_annotations}}
5151
return super(DomainManager, self)._update(domain_guid, data)
5252

53-
def remove(self, domain_guid: str):
54-
super(DomainManager, self)._remove(domain_guid)
53+
def remove(self, domain_guid: str, asynchronous: bool = True) -> Optional[str]:
54+
return super(DomainManager, self)._remove(domain_guid, asynchronous)
5555

5656
def __create_shared_domain_url(self, domain_guid: str) -> str:
5757
# TODO use url parser for this

main/cloudfoundry_client/v3/entities.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ def _delete(self, url: str) -> Optional[str]:
148148
except (AttributeError, KeyError):
149149
return None
150150

151+
def _remove(self, resource_id: str, asynchronous: bool = True) -> Optional[str]:
152+
url = "%s%s/%s" % (self.target_endpoint, self.entity_uri, resource_id)
153+
job_location = self._delete(url)
154+
if job_location is not None:
155+
job_url = urlparse(job_location)
156+
job_guid = job_url.path.rsplit("/", 1)[-1]
157+
if not asynchronous:
158+
self.client.v3.jobs.wait_for_job_completion(job_guid)
159+
else:
160+
return job_guid
161+
return None
162+
151163
def _list(self, requested_path: str, entity_type: Optional[ENTITY_TYPE] = None, **kwargs) -> PaginateEntities:
152164
url_requested = EntityManager._get_url_with_encoded_params("%s%s" % (self.target_endpoint, requested_path), **kwargs)
153165
for element in self._paginate(url_requested, entity_type):
@@ -194,14 +206,6 @@ def _update(self, resource_id: str, data: dict) -> Entity:
194206
url = "%s%s/%s" % (self.target_endpoint, self.entity_uri, resource_id)
195207
return self._patch(url, data)
196208

197-
def _remove(self, resource_id: str, asynchronous: bool = True):
198-
url = "%s%s/%s" % (self.target_endpoint, self.entity_uri, resource_id)
199-
job_location = self._delete(url)
200-
if not asynchronous and job_location is not None:
201-
job_url = urlparse(job_location)
202-
job_guid = job_url.path.rsplit("/", 1)[-1]
203-
self.client.v3.jobs.wait_for_job_completion(job_guid)
204-
205209
def __iter__(self) -> PaginateEntities:
206210
return self.list()
207211

main/cloudfoundry_client/v3/organization_quotas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class OrganizationQuotaManager(EntityManager):
3737
def __init__(self, target_endpoint: str, client: "CloudFoundryClient"):
3838
super().__init__(target_endpoint, client, "/v3/organization_quotas")
3939

40-
def remove(self, guid: str):
41-
super()._remove(guid)
40+
def remove(self, guid: str, asynchronous: bool = True) -> Optional[str]:
41+
return super()._remove(guid, asynchronous)
4242

4343
def create(
4444
self,

main/cloudfoundry_client/v3/organizations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def update(
2727
data = {"name": name, "suspended": suspended, "metadata": {"labels": meta_labels, "annotations": meta_annotations}}
2828
return super(OrganizationManager, self)._update(guid, data)
2929

30-
def remove(self, guid: str):
31-
super(OrganizationManager, self)._remove(guid)
30+
def remove(self, guid: str, asynchronous: bool = True) -> Optional[str]:
31+
return super(OrganizationManager, self)._remove(guid, asynchronous)
3232

3333
def assign_default_isolation_segment(self, org_guid: str, iso_seg_guid: str) -> Entity:
3434
return ToOneRelationship.from_json_object(

main/cloudfoundry_client/v3/roles.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING
1+
from typing import TYPE_CHECKING, Optional
22

33
from cloudfoundry_client.v3.entities import EntityManager
44

@@ -10,5 +10,5 @@ class RoleManager(EntityManager):
1010
def __init__(self, target_endpoint: str, client: "CloudFoundryClient"):
1111
super(RoleManager, self).__init__(target_endpoint, client, "/v3/roles")
1212

13-
def remove(self, role_guid: str):
14-
super(RoleManager, self)._remove(role_guid)
13+
def remove(self, role_guid: str, asynchronous: bool = True) -> Optional[str]:
14+
return super(RoleManager, self)._remove(role_guid, asynchronous)

main/cloudfoundry_client/v3/security_groups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def update(self,
5858
payload = self._generate_payload(name, rules, globally_enabled, staging_spaces, running_spaces)
5959
return super()._update(security_group_id, payload)
6060

61-
def remove(self, security_group_id: str):
62-
return super()._remove(security_group_id)
61+
def remove(self, security_group_id: str, asynchronous: bool = True) -> Optional[str]:
62+
return super()._remove(security_group_id, asynchronous)
6363

6464
def bind_running_security_group_to_spaces(self, security_group_id: str, space_guids: ToManyRelationship) \
6565
-> ToManyRelationship:

main/cloudfoundry_client/v3/service_brokers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ def update(
5959
payload["metadata"] = metadata
6060
return super(ServiceBrokerManager, self)._update(guid, payload)
6161

62-
def remove(self, guid: str):
63-
super(ServiceBrokerManager, self)._remove(guid)
62+
def remove(self, guid: str, asynchronous: bool = True) -> Optional[str]:
63+
return super(ServiceBrokerManager, self)._remove(guid, asynchronous)

0 commit comments

Comments
 (0)