def assign_isolation_segment(self, space_guid: str, isolation_segment_guid: Optional[str]) -> ToOneRelationship: return ToOneRelationship.from_json_object( super(SpaceManager, self)._patch( "%s%s/%s/relationships/isolation_segment" % (self.target_endpoint, self.entity_uri, space_guid), dict(data=None) if isolation_segment_guid is None else ToOneRelationship(isolation_segment_guid), ) )
def create( self, name: str, space_guid: str, service_plan_guid: str, meta_labels: Optional[dict] = None, meta_annotations: Optional[dict] = None, parameters: Optional[dict] = None, tags: Optional[List[str]] = None, ) -> Entity: data = { "name": name, "type": "managed", "relationships": { "space": ToOneRelationship(space_guid), "service_plan": ToOneRelationship(service_plan_guid) }, } if parameters: data["parameters"] = parameters if tags: data["tags"] = tags if meta_labels or meta_annotations: metadata = dict() if meta_labels: metadata["labels"] = meta_labels if meta_annotations: metadata["annotations"] = meta_annotations data["metadata"] = metadata return super(ServiceInstanceManager, self)._create(data)
def assign_default_isolation_segment(self, org_guid: str, iso_seg_guid: str) -> Entity: return ToOneRelationship.from_json_object( super(OrganizationManager, self)._patch( "%s%s/%s/relationships/default_isolation_segment" % (self.target_endpoint, self.entity_uri, org_guid), data=ToOneRelationship(iso_seg_guid), ))
def update(self, instance_guid: str, name: Optional[str] = None, parameters: Optional[dict] = None, service_plan: Optional[str] = None, maintenance_info: Optional[str] = None, meta_labels: Optional[dict] = None, meta_annotations: Optional[dict] = None, tags: Optional[List[str]] = None) -> Entity: data = {} if name: data["name"] = name if parameters: data["parameters"] = parameters if service_plan: data["relationships"] = { "service_plan": ToOneRelationship(service_plan) } if maintenance_info: data["maintenance_info"] = {"version": maintenance_info} if tags: data["tags"] = tags if meta_labels or meta_annotations: metadata = dict() if meta_labels: metadata["labels"] = meta_labels if meta_annotations: metadata["annotations"] = meta_annotations data["metadata"] = metadata return super(ServiceInstanceManager, self)._update(instance_guid, data)
def test_create(self): self.client.post.return_value = self.mock_response( '/v3/domains', HTTPStatus.OK, None, 'v3', 'domains', 'POST_response.json') result = self.client.v3.domains.create( 'domain_id', internal=False, organization=ToOneRelationship('organization-guid'), shared_organizations=None, meta_labels=None, meta_annotations=None) self.client.post.assert_called_with(self.client.post.return_value.url, files=None, json={ 'name': 'domain_id', 'internal': False, 'organization': { 'data': { 'guid': 'organization-guid' } }, 'shared_organizations': None, 'metadata': { 'labels': None, 'annotations': None } }) self.assertIsNotNone(result) self.assertIsInstance(result, Domain)
def create( self, name: str, url: str, auth_username: str, auth_password: str, space_guid: Optional[str] = None, meta_labels: Optional[dict] = None, meta_annotations: Optional[dict] = None, ) -> Entity: credentials = { "type": "basic", "credentials": { "username": auth_username, "password": auth_password } } payload = dict(name=name, url=url, authentication=credentials) if meta_labels or meta_annotations: metadata = dict() if meta_labels: metadata["labels"] = meta_labels if meta_annotations: metadata["annotations"] = meta_annotations payload["metadata"] = metadata if space_guid: payload["relationships"] = dict( space=ToOneRelationship(space_guid)) return super(ServiceBrokerManager, self)._create(payload)
def test_create(self): self.client.post.return_value = self.mock_response( "/v3/domains", HTTPStatus.OK, None, "v3", "domains", "POST_response.json") result = self.client.v3.domains.create( "domain_id", internal=False, organization=ToOneRelationship("organization-guid"), shared_organizations=None, meta_labels=None, meta_annotations=None, ) self.client.post.assert_called_with( self.client.post.return_value.url, files=None, json={ "name": "domain_id", "internal": False, "organization": { "data": { "guid": "organization-guid" } }, "shared_organizations": None, "metadata": { "labels": None, "annotations": None }, }, ) self.assertIsNotNone(result) self.assertIsInstance(result, Domain)
def __init__(self, target_endpoint: str, entity_manager: 'EntityManager', **kwargs): super(Domain, self).__init__(target_endpoint, entity_manager, **kwargs) relationships = self['relationships'] if 'organization' in relationships: self['relationships']['organization'] = ToOneRelationship.from_json_object(relationships['organization'].get('data')) if 'shared_organizations' in relationships: self['relationships']['shared_organizations'] \ = ToManyRelationship.from_json_object(relationships['shared_organizations'])
def test_unbind_staging_from_space(self): self.client.delete.return_value = self.mock_response( "/v3/security_groups/security_group_guid/relationships/staging_spaces/space-guid", HTTPStatus.NO_CONTENT, None) self.client.v3.security_groups.unbind_staging_security_group_from_space( "security_group_guid", ToOneRelationship("space-guid")) self.client.delete.assert_called_with( self.client.delete.return_value.url)
def __init__(self, target_endpoint: str, client: "CloudFoundryClient", **kwargs): super(Domain, self).__init__(target_endpoint, client, **kwargs) relationships = self["relationships"] if "organization" in relationships: self["relationships"]["organization"] = ToOneRelationship.from_json_object(relationships["organization"]) if "shared_organizations" in relationships: self["relationships"]["shared_organizations"] = ToManyRelationship.from_json_object( relationships["shared_organizations"] )
def create( self, name: str, service_credential_binding_type: str, service_instance_guid: str, application_guid: Optional[str], parameters: Optional[dict], meta_labels: Optional[dict], meta_annotations: Optional[dict], asynchronous: bool = True, ) -> Union[str, Entity, None]: data = { "name": name, "type": service_credential_binding_type, "relationships": { "service_instance": ToOneRelationship(service_instance_guid) }, } if application_guid: data["relationships"]["app"] = ToOneRelationship(application_guid) if parameters: data["parameters"] = parameters if meta_labels or meta_annotations: metadata = dict() if meta_labels: metadata["labels"] = meta_labels if meta_annotations: metadata["annotations"] = meta_annotations data["metadata"] = metadata url = "%s%s" % (self.target_endpoint, self.entity_uri) response = self.client.post(url, json=data) location = super(ServiceCredentialBindingManager, self)._location(response) if location: job_guid = super(ServiceCredentialBindingManager, self)._extract_job_guid(location) if asynchronous: return job_guid else: self.client.v3.jobs.wait_for_job_completion(job_guid) return None return super(ServiceCredentialBindingManager, self)._read_response(response, None)
def get_default_isolation_segment(self, guid: str) -> ToOneRelationship: return ToOneRelationship.from_json_object( super(OrganizationManager, self).get(guid, 'relationships', 'default_isolation_segment'))
def get_assigned_isolation_segment(self, space_guid: str) -> ToOneRelationship: return ToOneRelationship.from_json_object( super(SpaceManager, self)._get( "%s%s/%s/relationships/isolation_segment" % (self.target_endpoint, self.entity_uri, space_guid) ) )
def create(self, name: str, org_guid: str) -> Entity: return super(SpaceManager, self)._create(dict(name=name, relationships=dict(organization=ToOneRelationship(org_guid))))