예제 #1
0
    def __init__(self,
                 target_endpoint,
                 client_id='cf',
                 client_secret='',
                 proxy=None,
                 skip_verification=False):
        info = self.get_info(target_endpoint, proxy, skip_verification)
        if not info['api_version'].startswith('2.'):
            raise AssertionError(
                'Only version 2 is supported for now. Found %s' %
                info['api_version'])

        service_informations = ServiceInformation(
            None, '%s/oauth/token' % info['authorization_endpoint'], client_id,
            client_secret, [], skip_verification)
        super(CloudFoundryClient, self).__init__(service_informations, proxy)
        self.service_plans = ServicePlanManager(target_endpoint, self)
        self.service_instances = ServiceInstanceManager(target_endpoint, self)
        self.service_keys = ServiceKeyManager(target_endpoint, self)
        self.service_bindings = ServiceBindingManager(target_endpoint, self)
        self.service_brokers = ServiceBrokerManager(target_endpoint, self)
        self.apps = AppManager(target_endpoint, self)
        self.buildpacks = BuildpackManager(target_endpoint, self)
        self.stacks = StackManager(target_endpoint, self)
        # Default implementations
        self.organizations = EntityManager(target_endpoint, self,
                                           '/v2/organizations')
        self.spaces = EntityManager(target_endpoint, self, '/v2/spaces')
        self.services = EntityManager(target_endpoint, self, '/v2/services')
        self.routes = EntityManager(target_endpoint, self, '/v2/routes')
        self._loggregator_endpoint = info['logging_endpoint']
        self._loggregator = None
예제 #2
0
 def get_recent(self, application_guid):
     url = '%s/recent?app=%s' % (re.sub(r'^ws', 'http', self.logging_endpoint), application_guid)
     response = EntityManager._check_response(self.credentials_manager.get(url, stream=True))
     boundary = LoggregatorManager._extract_boundary(response)
     for part in LoggregatorManager._read_multi_part_response(response, boundary):
         message_read = LogMessage()
         message_read.ParseFromString(part)
         yield message_read
    def test_list(self):
        client = mock.MagicMock()
        entity_manager = EntityManager(TARGET_ENDPOINT, client, '/fake/first')

        first_response = mock_response(
            '/fake/first?q=space_guid%20IN%20some-id&results-per-page=20&page=1&order-direction=asc',
            httplib.OK,
            None,
            'fake', 'GET_multi_page_0_response.json')
        second_response = mock_response('/fake/next?order-direction=asc&page=2&results-per-page=50',
                                        httplib.OK,
                                        None,
                                        'fake', 'GET_multi_page_1_response.json')

        client.get.side_effect = [first_response, second_response]
        cpt = reduce(lambda increment, _: increment + 1, entity_manager.list(**{"results-per-page": 20,
                                                                                'order-direction': 'asc',
                                                                                'page': 1,
                                                                                "space_guid": 'some-id'}), 0)
        client.get.assert_has_calls([mock.call(first_response.url),
                                     mock.call(second_response.url)],
                                    any_order=False)
        self.assertEqual(cpt, 3)
 def test_query(self):
     url = EntityManager._get_url_filtered('/v2/apps', **{"results-per-page": 20,
                                                          'order-direction': 'asc', 'page': 1,
                                                          "space_guid": 'some-id'})
     self.assertEqual(url, '/v2/apps?q=space_guid%20IN%20some-id&results-per-page=20&page=1&order-direction=asc')
예제 #5
0
 def restage(self, application_guid, check_time=0.5, timeout=500):
     url = '%s%s/%s/restage' % (self.target_endpoint, self.entity_uri,
                                application_guid)
     response = EntityManager._check_response(self.client.post(url))
     _logger.debug('POST - %s - %s', url, response.text)
     return self._read_response(response)