Esempio n. 1
0
    def test_waiting_for_job(self):
        """test Job.wait_for(<id>) works"""

        with open(self.json_file) as f:
            running_data = json.load(f)

        with open(self.json_file) as f:
            finished_data = json.load(f)

        running_data[self.cls.COLLECTION_NAME][:] = [d for d in running_data[self.cls.COLLECTION_NAME] if
                                                     d[camelize(self.cls.PRIMARY_KEY)] == 4]

        finished_data[self.cls.COLLECTION_NAME][:] = [d for d in finished_data[self.cls.COLLECTION_NAME] if
                                                     d[camelize(self.cls.PRIMARY_KEY)] == 4]

        finished_data[self.cls.COLLECTION_NAME][0]['status'] = 'COMPLETE'
        finished_data[self.cls.COLLECTION_NAME][0]['message'] = '12345'


        HTTPretty.register_uri(HTTPretty.GET,
            self.es_url+'/'+str(4),
            responses = [
                #HTTPretty.Response(body=json.dumps(running_data), status=200, content_type='application/json')
                HTTPretty.Response(body=json.dumps(finished_data), status=200, content_type='application/json')
            ])

        def validate(x):
            assert isinstance(x, self.cls)
            assert x.status == 'COMPLETE'
            assert x.message == '12345'

        y = self.cls.wait_for(4, callback=validate)
        z = self.cls.wait_for(4)
        assert z is True
Esempio n. 2
0
    def all(cls, **kwargs):
        """List all volumes

        :param account_id: Restrict to volumes owned by `account_id`
        :type account_id: int.
        :param datacenter_id: Restrict to volumes based in `datacenter_id`
        :type datacenter_id: int.
        :param region_id: Restrict to volumes in `region_id`
        :type region_id: int.
        :param keys_only: Return :attr:`snapshot_id` or :class:`Snapshot`
        :type keys_only: bool.
        :param detail: Level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :attr:`volume_id` or :class:`Volume`
        :raises: :class:`VolumeException`
        """
        params = {}
        r = Resource(cls.PATH)
        r.request_details = 'none'
        if 'detail' in kwargs:
            request_details = kwargs['detail']
        else:
            request_details = 'extended'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'datacenter_id' in kwargs:
            params['dataCenterId'] = kwargs['datacenter_id']
        if 'region_id' in kwargs:
            params['regionId'] = kwargs['region_id']
        if 'account_id' in kwargs:
            params['accountId'] = kwargs['account_id']

        x = r.get(params=params)
        if r.last_error is None:
            keys = [
                i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]
            ]
            if keys_only is True:
                volumes = keys
            else:
                volumes = []
                for i in x[cls.COLLECTION_NAME]:
                    key = i[camelize(cls.PRIMARY_KEY)]
                    volume = cls(key)
                    volume.request_details = request_details
                    volume.load()
                    volumes.append(volume)
            return volumes
        else:
            raise VolumeException(r.last_error)
Esempio n. 3
0
    def all(cls, **kwargs):
        """List all volumes

        :param account_id: Restrict to volumes owned by `account_id`
        :type account_id: int.
        :param datacenter_id: Restrict to volumes based in `datacenter_id`
        :type datacenter_id: int.
        :param region_id: Restrict to volumes in `region_id`
        :type region_id: int.
        :param keys_only: Return :attr:`snapshot_id` or :class:`Snapshot`
        :type keys_only: bool.
        :param detail: Level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :attr:`volume_id` or :class:`Volume`
        :raises: :class:`VolumeException`
        """
        params = {}
        r = Resource(cls.PATH)
        r.request_details = 'none'
        if 'detail' in kwargs:
            request_details = kwargs['detail']
        else:
            request_details = 'extended'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'datacenter_id' in kwargs:
            params['dataCenterId'] = kwargs['datacenter_id']
        if 'region_id' in kwargs:
            params['regionId'] = kwargs['region_id']
        if 'account_id' in kwargs:
            params['accountId'] = kwargs['account_id']

        x = r.get(params=params)
        if r.last_error is None:
            keys = [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            if keys_only is True:
                volumes = keys
            else:
                volumes = []
                for i in x[cls.COLLECTION_NAME]:
                    key = i[camelize(cls.PRIMARY_KEY)]
                    volume = cls(key)
                    volume.request_details = request_details
                    volume.load()
                    volumes.append(volume)
            return volumes
        else:
            raise VolumeException(r.last_error)
Esempio n. 4
0
    def all(cls, endpoint=None, **kwargs):
        """Return all regions

        :param account_id: Limit results to regions with the specified account
        :type account_id: int.
        :param jurisdiction: Limit results to the specified jurisdiction
        :type jurisdiction: str.
        :param scope: Limit results to `all` (Default - cross-cloud)
            or `account` (cloud-specific)
        :type scope: str.
        :param keys_only: Return :attr:`region_id` instead of :class:`Region`
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :class:`Region` or :attr:`region_id`
        :raises: :class:`RegionException`
        """
        r = Resource(cls.PATH, endpoint=endpoint)
        params = {}

        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        for x in ['account_id', 'jurisdiction', 'scope']:
            if x in kwargs:
                params[camelize(x)] = kwargs[x]

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[cls.COLLECTION_NAME]
                ]
        else:
            raise RegionException(r.last_error)
Esempio n. 5
0
    def test_has_one(self):
        """test Snapshot(<id>) returns a valid resource"""
        pk = 23237460
        with open(self.json_file) as f:
            data = json.load(f)
        data[self.cls.COLLECTION_NAME][:] = [d for d in data[self.cls.COLLECTION_NAME] if
                                             d[camelize(self.cls.PRIMARY_KEY)] == pk]

        HTTPretty.register_uri(HTTPretty.GET,
            self.es_url+'/'+str(pk),
            body=json.dumps(data),
            status=200,
            content_type="application/json")

        s = self.cls(pk)

        assert s.snapshot_id == 23237460
        assert s.available is True
        assert s.label is None
        assert s.budget  == 10287
        assert s.created_timestamp == '2012-11-20T01:31:53.000+0000'
        assert s.status == 'ACTIVE'
        assert s.region['region_id'] == 19556
        assert s.customer['customer_id'] == 12345
        assert s.encrypted is False
        assert s.description == 'snap-b0810e80'
        assert s.sharable is True
        assert s.name == 'snap-b0810e80'
        assert s.volume['volume_id'] == 209179
        assert s.provider_id == 'snap-b0810e80'
        assert s.cloud['cloud_id'] == 1
        assert s.owning_account['account_id'] == 16000
        assert s.removable is True
        assert s.size_in_gb -- 8
Esempio n. 6
0
 def test_has_one(self):
     '''test Tier(<id>) returns a valid resource'''
     pk = 10429
     with open(self.json_file) as f:
         data = json.load(f)
     data[self.cls.COLLECTION_NAME][:] = [
         d for d in data[self.cls.COLLECTION_NAME]
         if d[camelize(self.cls.PRIMARY_KEY)] == pk
     ]
     HTTPretty.register_uri(HTTPretty.GET,
                            self.es_url + '/' + str(pk),
                            body=json.dumps(data),
                            status=200,
                            content_type="application/json")
     s = self.cls(pk)
     assert s.tier_id == pk
     assert s.breach_increment == 1
     assert s.breach_period_in_minutes == 5
     assert s.cooldown_period_in_minutes == 5
     assert s.deployment['deployment_id'] == 13607
     assert s.description == 'This is what we call a tier.'
     assert s.last_breach_change_timestamp == '2012-12-18T18:42:06.160+0000'
     assert s.lower_cpu_threshold == 25
     assert s.lower_ram_threshold == 25
     assert s.maximum_servers == 1
     assert s.minimum_servers == 1
     assert s.name == 'Sample Tier'
     assert s.removable is False
     assert s.scaling_rules == 'BASIC'
     assert s.status == 'BREACH_LOWER'
     assert s.upper_cpu_threshold == 75
     assert s.upper_ram_threshold == 75
Esempio n. 7
0
    def all(cls, endpoint=None, **kwargs):
        r = Resource(cls.PATH,endpoint=endpoint)
        params = {}
        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'params' in kwargs:
            params = kwargs['params']

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                results = [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                results = [type(cls.__name__, (object,), i) for i in uncamel_keys(x)[cls.COLLECTION_NAME]]
            return results
        else:
            raise RelationalDatabaseException(r.last_error)
Esempio n. 8
0
 def test_has_one(self):
     '''test Tier(<id>) returns a valid resource'''
     pk = 10429
     with open(self.json_file) as f:
         data = json.load(f)
     data[self.cls.COLLECTION_NAME][:] = [d for d in data[self.cls.COLLECTION_NAME] if
                                          d[camelize(self.cls.PRIMARY_KEY)] == pk]
     HTTPretty.register_uri(HTTPretty.GET,
         self.es_url + '/' + str(pk),
         body=json.dumps(data),
         status=200,
         content_type="application/json")
     s = self.cls(pk)
     assert s.tier_id == pk
     assert s.breach_increment == 1
     assert s.breach_period_in_minutes == 5
     assert s.cooldown_period_in_minutes == 5
     assert s.deployment['deployment_id'] == 13607
     assert s.description == 'This is what we call a tier.'
     assert s.last_breach_change_timestamp == '2012-12-18T18:42:06.160+0000'
     assert s.lower_cpu_threshold == 25
     assert s.lower_ram_threshold == 25
     assert s.maximum_servers == 1
     assert s.minimum_servers == 1
     assert s.name == 'Sample Tier'
     assert s.removable is False
     assert s.scaling_rules == 'BASIC'
     assert s.status == 'BREACH_LOWER'
     assert s.upper_cpu_threshold == 75
     assert s.upper_ram_threshold == 75
Esempio n. 9
0
    def all(cls, **kwargs):
        r = Resource(cls.PATH)
        params = {}
        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'params' in kwargs:
            params = kwargs['params']

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                results = [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                results = [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[cls.COLLECTION_NAME]
                ]
            return results
        else:
            raise RelationalDatabaseException(r.last_error)
Esempio n. 10
0
    def all(cls, server_id, keys_only=False, **kwargs):
        """Get all analytics for `server_id`

        :param server_id: The server represented in the analytics
        :type server_id: int.
        :param data_only: Return only the datapoints
        :type data_only: bool.
        :param interval: The interval in minutes for the requested data points
        :type interval: int.
        :param period_start: The start time in UNIX milliseconds for the first datapoint
        :param period_start: int.
        :param period_end: The end time in UNIX milliseconds for the last datapoint
        :param period_end: int.
        :returns: :class:`ServerAnalytics` or `list` of :attr:`data_points`
        """
        r = Resource(cls.PATH)
        params = {}
        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'server_id' in kwargs:
            params['server_id'] = kwargs['server_id']

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                return [type(cls.__name__, (object,), i) for i in uncamel_keys(x)[cls.COLLECTION_NAME]]
        else:
            raise ServerAnalyticsException(r.last_error)
Esempio n. 11
0
    def all(cls, region_id, endpoint=None, **kwargs):
        """Return all data centers

        :param region_id: Required. The region to query against
        :type region_id: int.
        :param keys_only: Return :attr:`data_center_id` instead of :class:`DataCenter`
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :class:`DataCenter` or :attr:`data_center_id`
        :raises: :class:`DataCenterException`
        """
        r = Resource(cls.PATH, endpoint=endpoint)

        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        params = {'regionId': region_id}

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                return [type(cls.__name__, (object,), i) for i in uncamel_keys(x)[uncamel(cls.COLLECTION_NAME)]]
        else:
            raise DataCenterException(r.last_error)
Esempio n. 12
0
    def all(cls, keys_only=False, **kwargs):
        """Return all users

        .. note::

            The keys used to make the request determine results visibility

        :param keys_only: Return :attr:`user_id` instead of :class:`User`
        :type keys_only: bool.
        :param detail: str. The level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :class:`User` or :attr:`user_id`
        :raises: :class:`UserException`
        """
        r = Resource(cls.PATH)
        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        x = r.get()
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                return [type(cls.__name__, (object,), i) for i in uncamel_keys(x)[cls.COLLECTION_NAME]]
        else:
            raise UserException(r.last_error)
Esempio n. 13
0
    def all(cls, region_id, endpoint=None, **kwargs):
        """Return all server products

        :param region_id: The region id to search in
        :type region_id: int.
        :param keys_only: Return :attr:`product_id` or :class:`ServerProduct`
        :type keys_only: bool.
        :param detail: Level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :attr:`product_id` or :class:`ServerProduct`
        :raises: :class:`ServerProductException`
        """
        r = Resource(cls.PATH, endpoint=endpoint)
        r.request_details = 'basic'
        params = {'regionId': region_id}
        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                return [type(cls.__name__, (object,), i) for i in uncamel_keys(x)[uncamel(cls.COLLECTION_NAME)]]
        else:
            raise ServerProductException(r.last_error)
Esempio n. 14
0
 def test_has_one(self):
     '''test Volume(<id>) returns a valid resource'''
     pk = 211309
     with open(self.json_file) as f:
         data = json.load(f)
     data[self.cls.COLLECTION_NAME][:] = [d for d in data[self.cls.COLLECTION_NAME] if
                                          d[camelize(self.cls.PRIMARY_KEY)] == pk]
     HTTPretty.register_uri(HTTPretty.GET,
         self.es_url + '/' + str(pk),
         body=json.dumps(data),
         status=200,
         content_type="application/json")
     s = self.cls(pk)
     s.load()
     assert s.volume_id == pk
     assert s.available is True
     assert s.budget == 10287
     assert s.cloud['cloud_id'] == 1
     assert s.creation_timestamp == '1970-01-01T00:00:00.000+0000'
     assert s.customer['customer_id'] == 12345
     assert s.data_center['data_center_id'] == 64716
     assert s.description == 'vol-4816d27b'
     assert s.device_id == '/dev/sda1'
     assert s.encrypted is False
     assert s.name == 'vol-4816d27b'
     assert s.owning_account['account_id'] == 16000
     assert s.owning_groups[0]['group_id'] == 9465
     assert s.provider_id == 'vol-4816d27b'
     assert s.owning_user['user_id'] == 54321
     assert s.region['region_id'] == 19556
     assert s.removable is False
     assert s.server['server_id'] == 322765
     assert s.size_in_gb == 8
     assert s.size_string == '8GB'
     assert s.status == 'ACTIVE'
Esempio n. 15
0
    def all(cls, keys_only=False, **kwargs):
        """Get all customers"""
        r = Resource(cls.PATH)
        params = {}

        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'customer_id' in kwargs:
            params['customer_id'] = kwargs['customer_id']

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[cls.COLLECTION_NAME]
                ]
        else:
            raise CustomerException(r.last_error)
Esempio n. 16
0
    def all(cls, keys_only=False, **kwargs):
        """Return all users

        .. note::

            The keys used to make the request determine results visibility

        :param keys_only: Return :attr:`user_id` instead of :class:`User`
        :type keys_only: bool.
        :param detail: str. The level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :class:`User` or :attr:`user_id`
        :raises: :class:`UserException`
        """
        r = Resource(cls.PATH)
        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        x = r.get()
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[cls.COLLECTION_NAME]
                ]
        else:
            raise UserException(r.last_error)
Esempio n. 17
0
 def test_has_one(self):
     '''test ConfigurationManagementAccount(<id>) returns a valid resource'''
     pk = 3610
     with open(self.json_file) as f:
         data = json.load(f)
     data[self.cls.COLLECTION_NAME][:] = [d for d in data[self.cls.COLLECTION_NAME] if
                                          d[camelize(self.cls.PRIMARY_KEY)] == pk]
     HTTPretty.register_uri(HTTPretty.GET,
         self.es_url + '/' + str(pk),
         body=json.dumps(data),
         status=200,
         content_type="application/json")
     s = self.cls(pk)
     assert s.cm_account_id == pk
     assert s.account_number == ''
     assert s.budget is -1
     assert s.cm_service['cm_service_id'] == 3710
     assert s.created_timestamp == '2013-01-06T06:50:29.326+0000'
     assert s.customer['customer_id'] == 12345
     assert s.description == 'a chef cm account'
     assert s.guid == '/customer/12345/cmAccount/3610'
     assert s.label == 'iconlightbulb'
     assert s.removable is True
     assert s.status == 'ACTIVE'
     assert s.last_modified_timestamp == '2013-01-06T06:50:29.326+0000'
Esempio n. 18
0
 def test_has_one(self):
     '''test ConfigurationManagementAccount(<id>) returns a valid resource'''
     pk = 3610
     with open(self.json_file) as f:
         data = json.load(f)
     data[self.cls.COLLECTION_NAME][:] = [
         d for d in data[self.cls.COLLECTION_NAME]
         if d[camelize(self.cls.PRIMARY_KEY)] == pk
     ]
     HTTPretty.register_uri(HTTPretty.GET,
                            self.es_url + '/' + str(pk),
                            body=json.dumps(data),
                            status=200,
                            content_type="application/json")
     s = self.cls(pk)
     assert s.cm_account_id == pk
     assert s.account_number == ''
     assert s.budget is -1
     assert s.cm_service['cm_service_id'] == 3710
     assert s.created_timestamp == '2013-01-06T06:50:29.326+0000'
     assert s.customer['customer_id'] == 12345
     assert s.description == 'a chef cm account'
     assert s.guid == '/customer/12345/cmAccount/3610'
     assert s.label == 'iconlightbulb'
     assert s.removable is True
     assert s.status == 'ACTIVE'
     assert s.last_modified_timestamp == '2013-01-06T06:50:29.326+0000'
Esempio n. 19
0
    def all(cls, **kwargs):
        """Get a list of all known servers

        >>> Server.all()
        [{'server_id':1,...},{'server_id':2,...}]

        :returns: list -- a list of :class:`Server`
        :raises: ServerException
        """
        r = Resource(cls.PATH)
        params = {}

        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'region_id' in kwargs:
            params['regionId'] = kwargs['region_id']

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                return [type(cls.__name__, (object,), i) for i in uncamel_keys(x)[cls.COLLECTION_NAME]]
        else:
            raise ServerException(r.last_error)
Esempio n. 20
0
    def all(cls, region_id, endpoint=None, **kwargs):
        """Return all server products

        :param region_id: The region id to search in
        :type region_id: int.
        :param keys_only: Return :attr:`product_id` or :class:`ServerProduct`
        :type keys_only: bool.
        :param detail: Level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :attr:`product_id` or :class:`ServerProduct`
        :raises: :class:`ServerProductException`
        """
        r = Resource(cls.PATH, endpoint=endpoint)
        r.request_details = 'basic'
        params = {'regionId': region_id}
        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[uncamel(cls.COLLECTION_NAME)]
                ]
        else:
            raise ServerProductException(r.last_error)
Esempio n. 21
0
 def test_has_one(self):
     '''test LoadBalancer(<id>) returns a valid resource'''
     pk = 12516
     with open(self.json_file) as f:
         data = json.load(f)
     data[self.cls.COLLECTION_NAME][:] = [d for d in data[self.cls.COLLECTION_NAME] if
                                          d[camelize(self.cls.PRIMARY_KEY)] == pk]
     HTTPretty.register_uri(HTTPretty.GET,
         self.es_url + '/' + str(pk),
         body=json.dumps(data),
         status=200,
         content_type="application/json")
     s = self.cls(pk)
     s.load()
     assert s.load_balancer_id == pk
     assert s.address == 'wordpress-lb.us-west-2.elb.amazonaws.com'
     assert s.budget == 10287
     assert s.cloud['cloud_id'] == 1
     assert s.cname_based is True
     assert s.customer['customer_id'] == 12345
     assert s.description == 'Cloud Load Balancer for wordpress demo deployment'
     assert s.owning_account['account_id'] == 16000
     assert s.owning_groups[0]['group_id'] == 9465
     assert s.owning_user['user_id'] == 54321
     assert s.provider_id == 'wordpress-deployment'
     assert s.region['region_id'] == 19344
     assert s.status == 'ACTIVE'
Esempio n. 22
0
    def test_has_one(self):
        '''test LaunchConfiguration(<id>) returns a valid resource'''
        pk = 16415
        with open(self.json_file) as f:
            data = json.load(f)

        data[self.cls.COLLECTION_NAME][:] = [d for d in data[self.cls.COLLECTION_NAME] if
                                             d[camelize(self.cls.PRIMARY_KEY)] == pk]
        HTTPretty.register_uri(HTTPretty.GET,
            self.es_url + '/' + str(pk),
            body=json.dumps(data),
            status=200,
            content_type="application/json")
        s = self.cls(pk)
        assert s.launch_configuration_id == 16415
        assert s.primary_product['product_id'] == 'm1.medium'
        assert s.secondary_product['product_id'] == 'm1.medium'
        assert s.primary_machine_image['machine_image_id'] == 281731
        assert s.secondary_machine_image['machine_image_id'] == 281731
        assert s.server_name_template == '{group}-{role}-{count}-{timestamp}'
        assert s.firewalls[0]['firewall_id'] == 116387
        assert s.array_volume_capacity == 0
        assert s.array_volume_count == 0
        assert s.customer['customer_id'] == 12345
        assert s.region['region_id'] == 19344
Esempio n. 23
0
    def all(cls, cmAccountId, **kwargs):
        r = Resource(cls.PATH)

        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        params = {'cmAccountId': cmAccountId}
        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[cls.COLLECTION_NAME]
                ]
        else:
            raise EnvironmentException(r.last_error)
Esempio n. 24
0
    def test_has_one(self):
        '''test LaunchConfiguration(<id>) returns a valid resource'''
        pk = 16415
        with open(self.json_file) as f:
            data = json.load(f)

        data[self.cls.COLLECTION_NAME][:] = [
            d for d in data[self.cls.COLLECTION_NAME]
            if d[camelize(self.cls.PRIMARY_KEY)] == pk
        ]
        HTTPretty.register_uri(HTTPretty.GET,
                               self.es_url + '/' + str(pk),
                               body=json.dumps(data),
                               status=200,
                               content_type="application/json")
        s = self.cls(pk)
        assert s.launch_configuration_id == 16415
        assert s.primary_product['product_id'] == 'm1.medium'
        assert s.secondary_product['product_id'] == 'm1.medium'
        assert s.primary_machine_image['machine_image_id'] == 281731
        assert s.secondary_machine_image['machine_image_id'] == 281731
        assert s.server_name_template == '{group}-{role}-{count}-{timestamp}'
        assert s.firewalls[0]['firewall_id'] == 116387
        assert s.array_volume_capacity == 0
        assert s.array_volume_count == 0
        assert s.customer['customer_id'] == 12345
        assert s.region['region_id'] == 19344
    def all(cls, region_id, engine, **kwargs):
        """Get a list of all known relational_databases

        >>> RelationalDatabaseProduct.all(region_id=100, engine='MYSQL51')
        [{'product_id':1,...},{'product_id':2,...}]

        :returns: list -- a list of :class:`RelationalDatabaseProduct`
        :raises: RelationalDatabaseProductException
        """
        r = Resource(cls.PATH)
        r.request_details = 'basic'
        params = {'regionId': region_id, 'engine': engine}

        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                results = [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                results = [type(cls.__name__, (object,), i) for i in uncamel_keys(x)[uncamel(cls.COLLECTION_NAME)]]
            return results
        else:
            raise RelationalDatabaseProductException(r.last_error)
Esempio n. 26
0
 def test_has_one(self):
     '''test Deployment(<id>) returns a valid resource'''
     pk = 13392
     with open(self.json_file) as f:
         data = json.load(f)
     data[self.cls.COLLECTION_NAME][:] = [d for d in data[self.cls.COLLECTION_NAME] if
                                          d[camelize(self.cls.PRIMARY_KEY)] == pk]
     HTTPretty.register_uri(HTTPretty.GET,
         self.es_url + '/' + str(pk),
         body=json.dumps(data),
         status=200,
         content_type="application/json")
     s = self.cls(pk)
     assert s.deployment_id == pk
     assert s.backup_window['days_of_week'] == ['SUNDAY', 'MONDAY', 'TUESDAY',
                                                'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY']
     assert s.budget == 9465
     assert s.creation_timestamp == '2012-11-13T22:57:45.622+0000'
     assert s.customer['customer_id'] == 12345
     assert s.description == 'Copied deployment'
     assert s.for_service_catalog is False
     assert s.launch_timestamp == '1970-01-01T00:00:00.000+0000'
     assert s.maintenance_window['days_of_week'] == ['SUNDAY', 'MONDAY', 'TUESDAY',
                                                     'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY']
     assert s.name == 'DemoDeployment'
     assert s.owning_groups[0]['group_id'] == 9465
     assert s.regions[0]['region_id'] == 19344
     assert s.removable is True
     assert s.status == 'STOPPED'
     assert s.e_type == 'DEDICATED'
Esempio n. 27
0
    def all(cls, region_id, endpoint=None, **kwargs):
        """Get a list of all known storage objects.

        >>> StorageObject.all(region_id=100)
        [{'storage_object_id':1,...},{'storage_object_id':2,...}]

        :returns: list -- a list of :class:`StorageObject`
        :raises: StorageObjectException
        """
        r = Resource(cls.PATH, endpoint=endpoint)
        params = {'regionId': region_id}

        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                results = [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                results = [type(cls.__name__, (object,), i) for i in uncamel_keys(x)[uncamel(cls.COLLECTION_NAME)]]
            return results
        else:
            raise StorageObjectException(r.last_error)
Esempio n. 28
0
    def all(cls, keys_only=False, endpoint=None, **kwargs):
        """Get all visible billing codes

        .. note::

            The keys used to make the original request determine result visibility

        :param keys_only: Only return :attr:`billing_code_id` instead of :class:`BillingCode` objects
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` - of :class:`BillingCode` or :attr:`billing_code_id`
        :raises: :class:`BillingCodeException`
        """
        r = Resource(cls.PATH, endpoint=endpoint)
        params = {}

        if 'details' in kwargs:
            r.request_details = kwargs['details']
        else:
            r.request_details = 'basic'

        x = r.get()
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                return [type(cls.__name__, (object,), i) for i in uncamel_keys(x)[uncamel(cls.COLLECTION_NAME)]]
        else:
            raise BillingCodeException(r.last_error)
Esempio n. 29
0
    def all(cls, **kwargs):
        r = Resource(cls.PATH)

        if 'details' in kwargs:
            r.request_details = kwargs['details']
        else:
            r.request_details = 'basic'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        x = r.get()
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[uncamel(cls.COLLECTION_NAME)]
                ]
        else:
            raise CMException(r.last_error)
Esempio n. 30
0
 def test_has_one(self):
     '''test LoadBalancer(<id>) returns a valid resource'''
     pk = 12516
     with open(self.json_file) as f:
         data = json.load(f)
     data[self.cls.COLLECTION_NAME][:] = [
         d for d in data[self.cls.COLLECTION_NAME]
         if d[camelize(self.cls.PRIMARY_KEY)] == pk
     ]
     HTTPretty.register_uri(HTTPretty.GET,
                            self.es_url + '/' + str(pk),
                            body=json.dumps(data),
                            status=200,
                            content_type="application/json")
     s = self.cls(pk)
     s.load()
     assert s.load_balancer_id == pk
     assert s.address == 'wordpress-lb.us-west-2.elb.amazonaws.com'
     assert s.budget == 10287
     assert s.cloud['cloud_id'] == 1
     assert s.cname_based is True
     assert s.customer['customer_id'] == 12345
     assert s.description == 'Cloud Load Balancer for wordpress demo deployment'
     assert s.owning_account['account_id'] == 16000
     assert s.owning_groups[0]['group_id'] == 9465
     assert s.owning_user['user_id'] == 54321
     assert s.provider_id == 'wordpress-deployment'
     assert s.region['region_id'] == 19344
     assert s.status == 'ACTIVE'
Esempio n. 31
0
    def all(cls, endpoint=None, **kwargs):
        """List all networks in `region_id`

        :param region_id: Limit results to `region_id`
        :type region_id: int.
        :param data_center_id: Limit results to `data_center_id`
        :type region_id: int.
        :param account_id: limit results to `account_id`
        :type account_id: int.
        :param detail: Level of detail to return - `basic` or `extended`
        :type detail: str.
        :param keys_only: Return only :attr:`network_id` in results
        :type keys_only: bool.
        :param active_only: Limits the list of networks to only active networks if true. Default is True.
        :type keys_only: bool.
        :returns: `list` of :attr:`network_id` or :class:`Network`
        :raises: :class:`NetworkException`
        """
        params = {}
        r = Resource(cls.PATH, endpoint=endpoint)

        if 'detail' in kwargs:
            request_details = kwargs['detail']
        else:
            request_details = 'extended'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'region_id' in kwargs:
            params['regionId'] = kwargs['region_id']

        if 'data_center_id' in kwargs:
            params['dataCenterId'] = kwargs['data_center_id']

        if 'account_id' in kwargs:
            params['accountId'] = kwargs['account_id']

        if 'active_only' in kwargs:
            params['activeOnly'] = kwargs['active_only']
        else:
            params['activeOnly'] = True

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[cls.COLLECTION_NAME]
                ]
        else:
            raise NetworkException(r.last_error)
Esempio n. 32
0
    def all(cls, firewall_id, **kwargs):
        """List all rules for `firewall_id`

        :param firewall_id: The id of the firewall to list rules for
        :type firewall_id: int.
        :param detail: Level of detail to return - `basic` or `extended`
        :type detail: str.
        :param keys_only: Return only :attr:`firewall_rule_id` in results
        :type keys_only: bool.
        :returns: `list` of :attr:`firewall_rule_id` or :class:`FirewallRule`
        :raises: :class:`FirewallRuleException`
        """

        params = {}
        r = Resource(cls.PATH)
        r.request_details = 'none'
        if 'detail' in kwargs:
            request_details = kwargs['detail']
        else:
            request_details = 'extended'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        params['firewallId'] = firewall_id
        x = r.get(params=params)
        if r.last_error is None:
            keys = [
                i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]
            ]
            if keys_only is True:
                rules = keys
            else:
                rules = []
                for i in x[cls.COLLECTION_NAME]:
                    key = i[camelize(cls.PRIMARY_KEY)]
                    rule = cls(key)
                    rule.request_details = request_details
                    rule.load()
                    rules.append(rule)
            return rules
        else:
            raise FirewallRuleException(r.last_error)
Esempio n. 33
0
    def all(cls, keys_only=False):
        """Get all jobs


        :param keys_only: Only return :attr:`job_id` instead of :class:`Job`
        :type keys_only: bool.
        :returns: `list` of :class:`Job` or :attr:`job_id`
        :raises: :class:`JobException`
        """
        r = Resource(cls.PATH)
        x = r.get()
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                return [cls(i[camelize(cls.PRIMARY_KEY)]) for i in x[cls.COLLECTION_NAME]]
        else:
            raise JobException(r.last_error)
Esempio n. 34
0
    def all(cls, keys_only=False, **kwargs):
        """Get all accounts

        >>> Account.all(detail='basic')
        [{'account_id':12345,....}]

        >>> Account.all(keys_only=True)
        [12345]

        :param keys_only: Only return `account_id` instead of `Account` objects
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :param cloud_id: Only show accounts tied to the given cloud
        :type cloud_id: int.
        :returns: `list` of :class:`Account` or :attr:`account_id`
        :raises: :class:`AccountException`
        """

        r = Resource(cls.PATH)
        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'cloud_id' in kwargs:
            params = {'cloudId': kwargs['cloud_id']}
        else:
            params = {}

        c = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in c[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    cls(i[camelize(cls.PRIMARY_KEY)])
                    for i in c[cls.COLLECTION_NAME]
                ]
        else:
            raise AccountException(r.last_error)
Esempio n. 35
0
    def all(cls, firewall_id, **kwargs):
        """List all rules for `firewall_id`

        :param firewall_id: The id of the firewall to list rules for
        :type firewall_id: int.
        :param detail: Level of detail to return - `basic` or `extended`
        :type detail: str.
        :param keys_only: Return only :attr:`firewall_rule_id` in results
        :type keys_only: bool.
        :returns: `list` of :attr:`firewall_rule_id` or :class:`FirewallRule`
        :raises: :class:`FirewallRuleException`
        """

        params = {}
        r = Resource(cls.PATH)
        r.request_details = 'none'
        if 'detail' in kwargs:
            request_details = kwargs['detail']
        else:
            request_details = 'extended'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        params['firewallId'] = firewall_id
        x = r.get(params=params)
        if r.last_error is None:
            keys = [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            if keys_only is True:
                rules = keys
            else:
                rules = []
                for i in x[cls.COLLECTION_NAME]:
                    key = i[camelize(cls.PRIMARY_KEY)]
                    rule = cls(key)
                    rule.request_details = request_details
                    rule.load()
                    rules.append(rule)
            return rules
        else:
            raise FirewallRuleException(r.last_error)
Esempio n. 36
0
    def all(cls, endpoint=None, **kwargs):
        """Return all regions

        :param account_id: Limit results to regions with the specified account
        :type account_id: int.
        :param jurisdiction: Limit results to the specified jurisdiction
        :type jurisdiction: str.
        :param scope: Limit results to `all` (Default - cross-cloud)
            or `account` (cloud-specific)
        :type scope: str.
        :param keys_only: Return :attr:`region_id` instead of :class:`Region`
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :class:`Region` or :attr:`region_id`
        :raises: :class:`RegionException`
        """
        r = Resource(cls.PATH, endpoint=endpoint)
        params = {}

        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        for x in ['account_id', 'jurisdiction', 'scope']:
            if x in kwargs:
                params[camelize(x)] = kwargs[x]

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                return [type(cls.__name__, (object,), i) for i in uncamel_keys(x)[cls.COLLECTION_NAME]]
        else:
            raise RegionException(r.last_error)
Esempio n. 37
0
    def all(cls, endpoint=None, **kwargs):
        """Return all machine images

        :param machine_image_id: The id of the machine image
        :type machine_image_id: int.
        :param region_id: The region to search for machine images
        :type region_id: int.
        :param keys_only: Return :attr:`machine_image_id` instead of :class:`MachineImage`
        :type keys_only: bool.
        :param available: Return only available images. Default is `true`
        :type available: str.
        :param registered: Return only images with the DCM agent installed. Default is `false`
        :type registered: str.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :class:`MachineImage` or :attr:`machine_image_id`
        :raises: :class:`MachineImageException`
        """
        if 'machine_image_id' in kwargs:
            r = Resource(cls.PATH + "/" + str(kwargs['machine_image_id']),
                         endpoint=endpoint)
        else:
            r = Resource(cls.PATH, endpoint=endpoint)

        params = {}

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'region_id' in kwargs:
            params['regionId'] = kwargs['region_id']

        if 'available' in kwargs:
            params['active'] = kwargs['available']

        if 'registered' in kwargs:
            params['registered'] = kwargs['registered']

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[cls.COLLECTION_NAME]
                ]
        else:
            raise MachineImageException(r.last_error)
Esempio n. 38
0
    def all(cls, tier_id, endpoint=None, **kwargs):
        r = Resource(cls.PATH+'/'+str(tier_id), endpoint=endpoint)
        if 'details' in kwargs:
            r.request_details = kwargs['details']
        else:
            r.request_details = 'basic'

        x = r.get()
        if r.last_error is None:
            return [cls(i[camelize(cls.PRIMARY_KEY)]) for i in x[cls.COLLECTION_NAME]]
        else:
            return r.last_error
Esempio n. 39
0
    def all(cls, **kwargs):
        """List all networks in `region_id`

        :param region_id: Limit results to `region_id`
        :type region_id: int.
        :param data_center_id: Limit results to `data_center_id`
        :type region_id: int.
        :param account_id: limit results to `account_id`
        :type account_id: int.
        :param detail: Level of detail to return - `basic` or `extended`
        :type detail: str.
        :param keys_only: Return only :attr:`network_id` in results
        :type keys_only: bool.
        :param active_only: Limits the list of networks to only active networks if true. Default is True.
        :type keys_only: bool.
        :returns: `list` of :attr:`network_id` or :class:`Network`
        :raises: :class:`NetworkException`
        """
        params = {}
        r = Resource(cls.PATH)

        if 'detail' in kwargs:
            request_details = kwargs['detail']
        else:
            request_details = 'extended'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'region_id' in kwargs:
            params['regionId'] = kwargs['region_id']

        if 'data_center_id' in kwargs:
            params['dataCenterId'] = kwargs['data_center_id']

        if 'account_id' in kwargs:
            params['accountId'] = kwargs['account_id']

        if 'active_only' in kwargs:
            params['activeOnly'] = kwargs['active_only']
        else:
            params['activeOnly'] = True

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                return [type(cls.__name__, (object,), i) for i in uncamel_keys(x)[cls.COLLECTION_NAME]]
        else:
            raise NetworkException(r.last_error)
    def all(cls, **kwargs):
        r = Resource(cls.PATH)
        if 'details' in kwargs:
            r.request_details = kwargs['details']
        else:
            r.request_details = 'basic'

        x = r.get()
        if r.last_error is None:
            return [cls(i[camelize(cls.PRIMARY_KEY)]) for i in x[cls.COLLECTION_NAME]]
        else:
            return x.last_error
Esempio n. 41
0
    def all(cls, **kwargs):
        r = Resource(cls.PATH)
        if 'details' in kwargs:
            r.request_details = kwargs['details']
        else:
            r.request_details = 'basic'

        x = r.get()
        if r.last_error is None:
            return [cls(i[camelize(cls.PRIMARY_KEY)]) for i in x[cls.COLLECTION_NAME]]
        else:
            return r.last_error
Esempio n. 42
0
    def all(cls, keys_only=False, endpoint=None, **kwargs):
        """Get all api keys

        .. note::

            The keys used to make the request determine results visibility

        :param keys_only: Only return `access_key` instead of `ApiKey` objects
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :param account_id: Display all system keys belonging to `account_id`
        :type account_id: int.
        :param user_id: Display all keys belonging to `user_id`
        :type user_id: int.
        :returns: `list` - of :class:`ApiKey` or :attr:`access_key`
        """

        if 'access_key' in kwargs:
            r = Resource(cls.PATH + "/" + kwargs['access_key'],
                         endpoint=endpoint)
            params = {}
        else:
            r = Resource(cls.PATH, endpoint=endpoint)

            if 'detail' in kwargs:
                r.request_details = kwargs['detail']
            else:
                r.request_details = 'basic'

            if 'account_id' in kwargs:
                params = {'accountId': kwargs['account_id']}
            elif 'user_id' in kwargs:
                params = {'userId': kwargs['user_id']}
            else:
                params = {}

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[uncamel(cls.COLLECTION_NAME)]
                ]
        else:
            raise ApiKeyException(r.last_error)
Esempio n. 43
0
    def all(cls, keys_only = False, **kwargs):
        """Get all accounts

        >>> Account.all(detail='basic')
        [{'account_id':12345,....}]

        >>> Account.all(keys_only=True)
        [12345]

        :param keys_only: Only return `account_id` instead of `Account` objects
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :param cloud_id: Only show accounts tied to the given cloud
        :type cloud_id: int.
        :returns: `list` of :class:`Account` or :attr:`account_id`
        :raises: :class:`AccountException`
        """

        r = Resource(cls.PATH)
        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'cloud_id' in kwargs:
            params = {'cloudId': kwargs['cloud_id']}
        else:
            params = {}

        c = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)] for i in c[cls.COLLECTION_NAME]]
            else:
                return [cls(i[camelize(cls.PRIMARY_KEY)]) for i in c[cls.COLLECTION_NAME]]
        else:
            raise AccountException(r.last_error)
Esempio n. 44
0
    def all(cls, endpoint=None, **kwargs):
        """Return a list of snapshots

        :param account_id: Restrict to snapshots owned by `account_id`
        :type account_id: int.
        :param volume_id: Restrict to snapshots based on `volume_id`
        :type volume_id: int.
        :param region_id: Restrict to snapshots in `region_id`
        :type region_id: int.
        :param keys_only: Return :attr:`snapshot_id` or :class:`Snapshot`
        :type keys_only: bool.
        :param detail: Level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :attr:`snapshot_id` or :class:`Snapshot`
        :raises: :class:`SnapshotException`
        """
        r = Resource(cls.PATH, endpoint=endpoint)
        params = {}

        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'region_id' in kwargs:
            params['regionId'] = kwargs['region_id']
        if 'account_id' in kwargs:
            params['accountId'] = kwargs['account_id']
        if 'volume_id' in kwargs:
            params['volumeId'] = kwargs['volume_id']

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[cls.COLLECTION_NAME]
                ]
        else:
            raise SnapshotException(r.last_error)
Esempio n. 45
0
    def all(cls, **kwargs):
        """List all firewalls in `region_id`

        :param region_id: Limit results to `region_id`
        :type region_id: int.
        :param account_id: limit results to `account_id`
        :type account_id: int.
        :param detail: Level of detail to return - `basic` or `extended`
        :type detail: str.
        :param keys_only: Return only :attr:`firewall_id` in results
        :type keys_only: bool.
        :returns: `list` of :attr:`firewall_id` or :class:`Firewall`
        :raises: :class:`FirewallException`
        """

        params = {}
        r = Resource(cls.PATH)
        r.request_details = 'none'

        if 'detail' in kwargs:
            request_details = kwargs['detail']
        else:
            request_details = 'extended'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'region_id' in kwargs:
            params['regionId'] = kwargs['region_id']

        if 'account_id' in kwargs:
            params['accountId'] = kwargs['account_id']

        x = r.get(params=params)
        if r.last_error is None:
            keys = [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            if keys_only is True:
                firewalls = keys
            else:
                firewalls = []
                for key in keys:
                    fw = cls(key, detail=request_details)
                    fw.load()
                    firewalls.append(fw)
            return firewalls
        else:
            raise FirewallException(r.last_error)
Esempio n. 46
0
    def all(cls, endpoint=None, **kwargs):
        """Return all machine images

        :param machine_image_id: The id of the machine image
        :type machine_image_id: int.
        :param region_id: The region to search for machine images
        :type region_id: int.
        :param keys_only: Return :attr:`machine_image_id` instead of :class:`MachineImage`
        :type keys_only: bool.
        :param available: Return only available images. Default is `true`
        :type available: str.
        :param registered: Return only images with the DCM agent installed. Default is `false`
        :type registered: str.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :class:`MachineImage` or :attr:`machine_image_id`
        :raises: :class:`MachineImageException`
        """
        if 'machine_image_id' in kwargs:
            r = Resource(cls.PATH + "/" + str(kwargs['machine_image_id']), endpoint=endpoint)
        else:
            r = Resource(cls.PATH, endpoint=endpoint)

        params = {}

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'region_id' in kwargs:
            params['regionId'] = kwargs['region_id']

        if 'available' in kwargs:
            params['active'] = kwargs['available']

        if 'registered' in kwargs:
            params['registered'] = kwargs['registered']

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)]
                        for i in x[cls.COLLECTION_NAME]]
            else:
                return [type(cls.__name__, (object,), i)
                        for i in uncamel_keys(x)[cls.COLLECTION_NAME]]
        else:
            raise MachineImageException(r.last_error)
Esempio n. 47
0
    def all(cls, **kwargs):
        """List all firewalls in `region_id`

        :param region_id: Limit results to `region_id`
        :type region_id: int.
        :param account_id: limit results to `account_id`
        :type account_id: int.
        :param detail: Level of detail to return - `basic` or `extended`
        :type detail: str.
        :param keys_only: Return only :attr:`firewall_id` in results
        :type keys_only: bool.
        :returns: `list` of :attr:`firewall_id` or :class:`Firewall`
        :raises: :class:`FirewallException`
        """

        params = {}
        r = Resource(cls.PATH)
        r.request_details = 'none'

        if 'detail' in kwargs:
            request_details = kwargs['detail']
        else:
            request_details = 'extended'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'region_id' in kwargs:
            params['regionId'] = kwargs['region_id']

        if 'account_id' in kwargs:
            params['accountId'] = kwargs['account_id']

        x = r.get(params=params)
        if r.last_error is None:
            keys = [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            if keys_only is True:
                firewalls = keys
            else:
                firewalls = []
                for key in keys:
                    fw = cls(key, detail=request_details)
                    fw.load()
                    firewalls.append(fw)
            return firewalls
        else:
            raise FirewallException(r.last_error)
Esempio n. 48
0
    def test_dont_launch_running_server(self):
        pk = 331810
        with open(self.json_file) as f:
            data = json.load(f)
        data[self.cls.COLLECTION_NAME][:] = [d for d in data[self.cls.COLLECTION_NAME] if
                                             d[camelize(self.cls.PRIMARY_KEY)] == pk]
        HTTPretty.register_uri(HTTPretty.GET,
            self.es_url+'/'+str(pk),
            body = json.dumps(data),
            status = 200,
            content_type = "application/json")

        s = self.cls(pk)
        with self.assertRaises(rsrc.ServerLaunchException):
            s.launch()
Esempio n. 49
0
 def test_has_one(self):
     """test Deployment(<id>) returns a valid resource"""
     pk = 13392
     with open(self.json_file) as f:
         data = json.load(f)
     data[self.cls.COLLECTION_NAME][:] = [
         d for d in data[self.cls.COLLECTION_NAME] if d[camelize(self.cls.PRIMARY_KEY)] == pk
     ]
     HTTPretty.register_uri(
         HTTPretty.GET,
         self.es_url + "/" + str(pk),
         body=json.dumps(data),
         status=200,
         content_type="application/json",
     )
     s = self.cls(pk)
     assert s.deployment_id == pk
     assert s.backup_window["days_of_week"] == [
         "SUNDAY",
         "MONDAY",
         "TUESDAY",
         "WEDNESDAY",
         "THURSDAY",
         "FRIDAY",
         "SATURDAY",
     ]
     assert s.budget == 9465
     assert s.creation_timestamp == "2012-11-13T22:57:45.622+0000"
     assert s.customer["customer_id"] == 12345
     assert s.description == "Copied deployment"
     assert s.for_service_catalog is False
     assert s.launch_timestamp == "1970-01-01T00:00:00.000+0000"
     assert s.maintenance_window["days_of_week"] == [
         "SUNDAY",
         "MONDAY",
         "TUESDAY",
         "WEDNESDAY",
         "THURSDAY",
         "FRIDAY",
         "SATURDAY",
     ]
     assert s.name == "DemoDeployment"
     assert s.owning_groups[0]["group_id"] == 9465
     assert s.regions[0]["region_id"] == 19344
     assert s.removable is True
     assert s.status == "STOPPED"
     assert s.e_type == "DEDICATED"
Esempio n. 50
0
    def all(cls, keys_only=False, endpoint=None, **kwargs):
        """Get all roles

        .. note::

            The keys used to make the request determine results visibility

        :param keys_only: Only return :attr:`role_id` instead of :class:`Group` objects
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :param account_id: List roles with mappings to groups in the specified account
        :type account_id: int.
        :param group_id: Provides the role associated with the specified group
        :type group_id: int.
        :returns: `list` of :attr:`role_id` or :class:`Role`
        :raises: :class:`RoleException`
        """
        r = Resource(cls.PATH, endpoint=endpoint)
        params = {}

        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'account_id' in kwargs:
            params['account_id'] = kwargs['account_id']

        if 'group_id' in kwargs:
            params['group_id'] = kwargs['group_id']

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[cls.COLLECTION_NAME]
                ]
        else:
            raise RoleException(r.last_error)
Esempio n. 51
0
    def all(cls, keys_only=False, endpoint=None, **kwargs):
        """Get all api keys

        .. note::

            The keys used to make the request determine results visibility

        :param keys_only: Only return `access_key` instead of `ApiKey` objects
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :param account_id: Display all system keys belonging to `account_id`
        :type account_id: int.
        :param user_id: Display all keys belonging to `user_id`
        :type user_id: int.
        :returns: `list` - of :class:`ApiKey` or :attr:`access_key`
        """

        if 'access_key' in kwargs:
            r = Resource(cls.PATH + "/" + kwargs['access_key'], endpoint=endpoint)
            params = {}
        else:
            r = Resource(cls.PATH, endpoint=endpoint)

            if 'detail' in kwargs:
                r.request_details = kwargs['detail']
            else:
                r.request_details = 'basic'

            if 'account_id' in kwargs:
                params = {'accountId': kwargs['account_id']}
            elif 'user_id' in kwargs:
                params = {'userId': kwargs['user_id']}
            else:
                params = {}

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)]
                        for i in x[cls.COLLECTION_NAME]]
            else:
                return [type(cls.__name__, (object,), i)
                        for i in uncamel_keys(x)[uncamel(cls.COLLECTION_NAME)]]
        else:
            raise ApiKeyException(r.last_error)
Esempio n. 52
0
    def all(cls, endpoint=None, **kwargs):
        """List all firewalls in `region_id`
        :param region_id: Limit results to `region_id`
        :type region_id: int.
        :param account_id: limit results to `account_id`
        :type account_id: int.
        :param detail: Level of detail to return - `basic` or `extended`
        :type detail: str.
        :param keys_only: Return only :attr:`firewall_id` in results
        :type keys_only: bool.
        :returns: `list` of :attr:`firewall_id` or :class:`Firewall`
        :raises: :class:`FirewallException`
        """
        r = Resource(cls.PATH, endpoint=None)
        params = {}

        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        if 'region_id' in kwargs:
            params['regionId'] = kwargs['region_id']

        if 'account_id' in kwargs:
            params['accountId'] = kwargs['account_id']

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [
                    i[camelize(cls.PRIMARY_KEY)]
                    for i in x[cls.COLLECTION_NAME]
                ]
            else:
                return [
                    type(cls.__name__, (object, ), i)
                    for i in uncamel_keys(x)[cls.COLLECTION_NAME]
                ]
        else:
            raise FirewallException(r.last_error)
Esempio n. 53
0
 def test_has_one(self):
     '''test ServerAnalytics(<id>) returns a valid resource'''
     pk = 331810
     with open(self.json_file) as f:
         data = json.load(f)
     data[self.cls.COLLECTION_NAME][:] = [d for d in data[self.cls.COLLECTION_NAME] if
                                          d[camelize(self.cls.PRIMARY_KEY)] == pk]
     HTTPretty.register_uri(HTTPretty.GET,
         self.es_url + '/' + str(pk),
         body=json.dumps(data),
         status=200,
         content_type="application/json")
     s = self.cls(pk)
     assert s.server_id == pk
     assert len(s.data_points) == 53
     assert s.interval_in_minutes == 1
     assert s.period_start == '2013-01-07T19:43:40.406+0000'
     assert s.period_end == '2013-01-07T20:37:12.333+0000'
Esempio n. 54
0
 def test_has_one(self):
     '''test TierAnalytics(<id>) returns a valid resource'''
     pk = 10429
     with open(self.json_file) as f:
         data = json.load(f)
     data[self.cls.COLLECTION_NAME][:] = [d for d in data[self.cls.COLLECTION_NAME] if
                                          d[camelize(self.cls.PRIMARY_KEY)] == pk]
     HTTPretty.register_uri(HTTPretty.GET,
         self.es_url + '/' + str(pk),
         body=json.dumps(data),
         status=200,
         content_type="application/json")
     s = self.cls(pk)
     assert s.tier_id == pk
     assert len(s.data_points) == 9
     assert s.interval_in_minutes == 5
     assert s.period_start == '2013-01-08T03:01:39.992+0000'
     assert s.period_end == '2013-01-08T03:51:34.996+0000'
Esempio n. 55
0
    def all(cls, keys_only=False, **kwargs):
        if 'region_id' in kwargs:
            r = Resource(cls.PATH + "/" + str(kwargs['region_id']))
        else:
            r = Resource(cls.PATH)

        if 'details' in kwargs:
            r.request_details = kwargs['details']
        else:
            r.request_details = 'basic'

        x = r.get()
        if r.last_error is None:
            if keys_only is True:
                return [i[camelize(cls.PRIMARY_KEY)] for i in x[cls.COLLECTION_NAME]]
            else:
                return [type(cls.__name__, (object,), i) for i in uncamel_keys(x)[cls.COLLECTION_NAME]]
        else:
            raise SubscriptionException(r.last_error)