예제 #1
0
 def entitle_organizations(self, isolation_segment_guid: str,
                           *org_guids: str) -> ToManyRelationship:
     data = ToManyRelationship(*org_guids)
     return ToManyRelationship.from_json_object(
         super(IsolationSegmentManager,
               self)._post("%s%s/%s/relationships/organizations" %
                           (self.target_endpoint, self.entity_uri,
                            isolation_segment_guid),
                           data=data))
예제 #2
0
 def apply_to_organizations(
         self, guid: str,
         organizations: ToManyRelationship) -> ToManyRelationship:
     return ToManyRelationship.from_json_object(
         super()._post("%s%s/%s/relationships/organizations" %
                       (self.target_endpoint, self.entity_uri, guid),
                       data=organizations))
 def test_share_domain(self):
     self.client.post.return_value = self.mock_response(
         "/v3/domains/domain_id/relationships/shared_organizations",
         HTTPStatus.CREATED,
         None,
         "v3",
         "domains",
         "POST_{id}_relationships_shared_organizations_response.json",
     )
     result = self.client.v3.domains.share_domain(
         "domain_id",
         ToManyRelationship("organization-guid-1", "organization-guid-2"))
     self.client.post.assert_called_with(
         self.client.post.return_value.url,
         files=None,
         json={
             "data": [{
                 "guid": "organization-guid-1"
             }, {
                 "guid": "organization-guid-2"
             }]
         },
     )
     self.assertIsNotNone(result)
     self.assertIsInstance(result, ToManyRelationship)
     result.guids[0] = "organization-guid-1"
     result.guids[1] = "organization-guid-1"
예제 #4
0
 def test_apply_to_organizations(self):
     self.client.post.return_value = self.mock_response(
         "/v3/organization_quotas/quota_id/relationships/organizations",
         HTTPStatus.OK,
         None,
         "v3",
         "organization_quotas",
         "POST_{id}_organizations_response.json",
     )
     result = self.client.v3.organization_quotas.apply_to_organizations(
         "quota_id",
         organizations=ToManyRelationship("org-guid1", "org-guid2"),
     )
     self.client.post.assert_called_with(
         self.client.post.return_value.url,
         files=None,
         json={"data": [{
             "guid": "org-guid1"
         }, {
             "guid": "org-guid2"
         }]})
     self.assertIsInstance(result, ToManyRelationship)
     # Endpoint adds to existing list of orgs so 1 existing + 2 new
     self.assertEqual(3, len(result.guids))
     self.assertIsNotNone(result["links"])
예제 #5
0
 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'])
예제 #6
0
 def list_entitled_spaces(
     self,
     isolation_segment_guid: str,
 ) -> ToManyRelationship:
     return ToManyRelationship.from_json_object(
         super(IsolationSegmentManager,
               self)._get("%s%s/%s/relationships/spaces" %
                          (self.target_endpoint, self.entity_uri,
                           isolation_segment_guid)))
 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"]
         )
예제 #8
0
 def test_create(self):
     self.client.post.return_value = self.mock_response(
         "/v3/organization_quotas", HTTPStatus.OK, None, "v3",
         "organization_quotas", "POST_response.json")
     result = self.client.v3.organization_quotas.create(
         "don-quixote",
         apps_quota=AppsQuota(total_memory_in_mb=5120,
                              per_process_memory_in_mb=1024,
                              total_instances=10,
                              per_app_tasks=5),
         services_quota=ServicesQuota(paid_services_allowed=True,
                                      total_service_instances=10,
                                      total_service_keys=20),
         routes_quota=RoutesQuota(total_routes=8, total_reserved_ports=4),
         domains_quota=DomainsQuota(total_domains=7),
         assigned_organizations=ToManyRelationship("assigned-org"),
     )
     self.client.post.assert_called_with(
         self.client.post.return_value.url,
         files=None,
         json={
             "name": "don-quixote",
             "apps": {
                 "total_memory_in_mb": 5120,
                 "per_process_memory_in_mb": 1024,
                 "total_instances": 10,
                 "per_app_tasks": 5
             },
             "services": {
                 "paid_services_allowed": True,
                 "total_service_instances": 10,
                 "total_service_keys": 20
             },
             "routes": {
                 "total_routes": 8,
                 "total_reserved_ports": 4
             },
             "domains": {
                 "total_domains": 7
             },
             "relationships": {
                 "organizations": {
                     "data": [{
                         "guid": "assigned-org"
                     }]
                 }
             },
         },
     )
     self.assertIsNotNone(result)
 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=ToManyRelationship("other-org-guid-1",
                                                 "other-org-guid-2"),
         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,
             "relationships": {
                 "organization": {
                     "data": {
                         "guid": "organization-guid"
                     }
                 },
                 "shared_organizations": {
                     "data": [
                         {
                             "guid": "other-org-guid-1"
                         },
                         {
                             "guid": "other-org-guid-2"
                         },
                     ]
                 },
             },
             "metadata": {
                 "labels": None,
                 "annotations": None
             },
         },
     )
     self.assertIsNotNone(result)
     self.assertIsInstance(result, Domain)
예제 #10
0
 def test_share_domain(self):
     self.client.post.return_value = mock_response(
         '/v3/domains/domain_id/relationships/shared_organizations',
         HTTPStatus.CREATED,
         None,
         'v3', 'domains', 'POST_{id}_relationships_shared_organizations_response.json')
     result = self.client.v3.domains.share_domain('domain_id',
                                                  ToManyRelationship('organization-guid-1', 'organization-guid-2'))
     self.client.post.assert_called_with(self.client.post.return_value.url,
                                         files=None,
                                         json={
                                             'data': [
                                                 {'guid': 'organization-guid-1'},
                                                 {'guid': 'organization-guid-2'}
                                             ]
                                         })
     self.assertIsNotNone(result)
     self.assertIsInstance(result, ToManyRelationship)
     result.guids[0] = 'organization-guid-1'
     result.guids[1] = 'organization-guid-1'
    def test_bind_staging_spaces(self):
        self.client.post.return_value = self.mock_response(
            "/v3/security_groups/security_group_guid/relationships/staging_spaces",
            HTTPStatus.OK, None, "v3", "security_groups",
            "POST_{id}_relationships_staging_spaces_response.json")
        result = self.client.v3.security_groups.bind_staging_security_group_to_spaces(
            "security_group_guid",
            ToManyRelationship("space-guid1", "space-guid2"))

        self.client.post.assert_called_with(
            self.client.post.return_value.url,
            json={"data": [{
                "guid": "space-guid1"
            }, {
                "guid": "space-guid2"
            }]},
            files=None)
        self.assertIsInstance(result, ToManyRelationship)
        self.assertListEqual(
            ["space-guid1", "space-guid2", "previous-space-guid"],
            result.guids)
예제 #12
0
 def _bind_spaces(self, security_group_id: str, space_guids: ToManyRelationship, relationship: str) \
         -> ToManyRelationship:
     url = "%s%s/%s/relationships/%s" % (self.target_endpoint, self.entity_uri, security_group_id, relationship)
     return ToManyRelationship.from_json_object(super()._post(url, space_guids))
예제 #13
0
 def share_domain(self, domain_guid: str, organization_guids: ToManyRelationship):
     url = self.__create_shared_domain_url(domain_guid)
     return ToManyRelationship.from_json_object(super(DomainManager, self)._post(url, data=organization_guids))