Пример #1
0
    def all(cls, keys_only=False, **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)
        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['billingCodeId'] for i in x[cls.COLLECTION_NAME]]
            else:
                return [
                    cls(i['billingCodeId']) for i in x[cls.COLLECTION_NAME]
                ]
        else:
            raise BillingCodeException(r.last_error)
Пример #2
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)
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
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)
    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)
Пример #8
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)
Пример #9
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)
Пример #10
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)
Пример #11
0
    def all(cls, keys_only=False, **kwargs):
        """Get all groups

        .. note::

            The keys used to make the request determine results visibility

        :param keys_only: Only return `group_id` instead of `Group` objects
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :param account_id: Restrict results to `account_id`
        :type account_id: int.
        :returns: `list` - List of :class:`Group` or :attr:`group_id`
        :raises: :class:`GroupException`
        """
        r = Resource(cls.PATH)
        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

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

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [i['groupId'] for i in x[cls.COLLECTION_NAME]]
            else:
                return [cls(i['groupId']) for i in x[cls.COLLECTION_NAME]]
        else:
            raise GroupException(r.last_error)
Пример #12
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)
Пример #13
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)
Пример #14
0
    def all(cls, keys_only=False, **kwargs):
        """Get all groups

        .. note::

            The keys used to make the request determine results visibility

        :param keys_only: Only return `group_id` instead of `Group` objects
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :param account_id: Restrict results to `account_id`
        :type account_id: int.
        :returns: `list` - List of :class:`Group` or :attr:`group_id`
        :raises: :class:`GroupException`
        """
        r = Resource(cls.PATH)
        if 'detail' in kwargs:
            r.request_details = kwargs['detail']
        else:
            r.request_details = 'basic'

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

        x = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                return [i['groupId'] for i in x[cls.COLLECTION_NAME]]
            else:
                return [cls(i['groupId']) for i in x[cls.COLLECTION_NAME]]
        else:
            raise GroupException(r.last_error)
Пример #15
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['userId'] for i in x[cls.COLLECTION_NAME]]
            else:
                return [cls(i['userId']) for i in x[cls.COLLECTION_NAME]]
        else:
            raise UserException(r.last_error)
Пример #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['userId'] for i in x[cls.COLLECTION_NAME]]
            else:
                return [cls(i['userId']) for i in x[cls.COLLECTION_NAME]]
        else:
            raise UserException(r.last_error)
Пример #17
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
    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
Пример #19
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
Пример #20
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)
Пример #21
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)
Пример #22
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)
Пример #23
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)
Пример #24
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)
Пример #25
0
    def all(cls, region_id, **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`
        """
        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        r = Resource(cls.PATH)
        r.request_details = 'basic'
        params = {'regionId':region_id}
        c = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                dcs = [i['dataCenterId'] for i in c[cls.COLLECTION_NAME]]
            else:
                dcs = []
                for i in c[cls.COLLECTION_NAME]:
                    dc = cls(i['dataCenterId'])
                    if 'detail' in kwargs:
                        dc.request_details = kwargs['detail']
                    dc.load()
                    dcs.append(dc)
            return dcs
        else:
            raise DataCenterException(r.last_error)
Пример #26
0
    def all(cls, **kwargs):
        """Get a list of all known relational_databases

        >>> RelationalDatabase.all()
        [{'relational_database_id':1,...},{'relational_database_id':2,...}]

        :returns: list -- a list of :class:`RelationalDatabase`
        :raises: RelationalDatabaseException
        """
        r = Resource(cls.PATH)
        r.request_details = 'basic'

        if 'params' in kwargs:
            params = kwargs['params']
        else:
            params = []
        s = r.get(params=params)
        if r.last_error is None:
            relational_databases = [
                cls(relational_database['relationalDatabaseId'])
                for relational_database in s[cls.COLLECTION_NAME]
            ]
            return relational_databases
        else:
            raise RelationalDatabaseException(r.last_error)
Пример #27
0
    def all(cls, keys_only=False, **kwargs):
        """Return all clouds

        :param keys_only: Return :attr:`cloud_id` instead of :class:`Cloud`
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :class:`Cloud` or :attr:`cloud_id`
        """
        r = Resource(cls.PATH)
        r.request_details = 'basic'
        params = {}

        if 'public_only' in kwargs:
            params['publicOnly'] = kwargs['public_only']
        if 'status' in kwargs:
            params['status'] = kwargs['status']

        c = r.get(params=params)

        if r.last_error is None:
            if keys_only is True:
                return [i['cloudId'] for i in c[cls.COLLECTION_NAME]]
            else:
                clouds = []
                for i in c[cls.COLLECTION_NAME]:
                    cloud = cls(i['cloudId'])
                    if 'detail' in kwargs:
                        cloud.request_details = kwargs['detail']
                    cloud.params = params
                    cloud.load()
                    clouds.append(cloud)
                return clouds
        else:
            return r.last_error
Пример #28
0
    def all(cls, region_id, **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`
        """
        if 'keys_only' in kwargs:
            keys_only = kwargs['keys_only']
        else:
            keys_only = False

        r = Resource(cls.PATH)
        r.request_details = 'basic'
        params = {'regionId': region_id}
        c = r.get(params=params)
        if r.last_error is None:
            if keys_only is True:
                dcs = [i['dataCenterId'] for i in c[cls.COLLECTION_NAME]]
            else:
                dcs = []
                for i in c[cls.COLLECTION_NAME]:
                    dc = cls(i['dataCenterId'])
                    if 'detail' in kwargs:
                        dc.request_details = kwargs['detail']
                    dc.load()
                    dcs.append(dc)
            return dcs
        else:
            raise DataCenterException(r.last_error)
Пример #29
0
    def all(cls, keys_only=False, **kwargs):
        """Return all clouds

        :param keys_only: Return :attr:`cloud_id` instead of :class:`Cloud`
        :type keys_only: bool.
        :param detail: The level of detail to return - `basic` or `extended`
        :type detail: str.
        :returns: `list` of :class:`Cloud` or :attr:`cloud_id`
        """
        r = Resource(cls.PATH)
        r.request_details = 'basic'
        params = {}

        if 'public_only' in kwargs:
            params['publicOnly'] = kwargs['public_only']
        if 'status' in kwargs:
            params['status'] = kwargs['status']

        c = r.get(params=params)

        if r.last_error is None:
            if keys_only is True:
                return [i['cloudId'] for i in c[cls.COLLECTION_NAME]]
            else:
                clouds = []
                for i in c[cls.COLLECTION_NAME]:
                    cloud = cls(i['cloudId'])
                    if 'detail' in kwargs:
                        cloud.request_details = kwargs['detail']
                    cloud.params = params
                    cloud.load()
                    clouds.append(cloud)
                return clouds
        else:
            return r.last_error
Пример #30
0
    def all(cls, **kwargs):
        """Returns subscriptions for all regions"""

        r = Resource(cls.PATH)
        r.request_details = 'basic'
        s = r.get()
        return s
Пример #31
0
    def region(cls, region_id, **kwargs):
        """Returns subscription for given Region"""

        r = Resource(cls.PATH+"/"+str(region_id))
        r.request_details = 'basic'
        s = r.get()
        return s
Пример #32
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)
Пример #33
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)
Пример #34
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)
Пример #35
0
 def all(cls, cmAccountId, **kwargs):
     r = Resource(cls.PATH)
     r.request_details = 'basic'
     params = {'cmAccountId':cmAccountId}
     x = r.get(params=params)
     if r.last_error is None:
     	return x[cls.COLLECTION_NAME]
     else:
     	return r.last_error
Пример #36
0
 def all(cls, cmAccountId, **kwargs):
     r = Resource(cls.PATH)
     r.request_details = "basic"
     params = {"cmAccountId": cmAccountId}
     c = r.get(params=params)
     if r.last_error is None:
         return c[cls.COLLECTION_NAME]
     else:
         raise PersonalityException(r.last_error)
Пример #37
0
 def all(cls, cmAccountId, **kwargs):
     r = Resource(cls.PATH)
     r.request_details = 'basic'
     params = {'cmAccountId': cmAccountId}
     c = r.get(params=params)
     if r.last_error is None:
         return c[cls.COLLECTION_NAME]
     else:
         raise PersonalityException(r.last_error)
Пример #38
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)
Пример #39
0
    def all(cls, **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)
        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)
Пример #40
0
    def all(cls, endpoint=None, **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`
        """
        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 "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:
            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 VolumeException(r.last_error)
Пример #41
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)
Пример #42
0
    def all(cls, firewall_id, endpoint=None, **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`
        """

        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

        params['firewallId'] = firewall_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 FirewallRuleException(r.last_error)
Пример #43
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)
Пример #44
0
    def all(cls, keys_only=False, endpoint=None, **kwargs):
        """Return all clouds

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

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

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

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

        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)[cls.COLLECTION_NAME]
                ]
        else:
            raise CloudException(r.last_error)
Пример #45
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)
Пример #46
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)
    def all(cls, endpoint=None, **kwargs):
        r = Resource(cls.PATH, endpoint=endpoint)
        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 ConfigurationManagementAccountException(r.last_error)
Пример #48
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 LoadBalancerException(r.last_error)
Пример #49
0
    def all(cls, keys_only=False, endpoint=None, **kwargs):
        """Get all customers"""
        r = Resource(cls.PATH, endpoint=endpoint)
        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)
Пример #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)
Пример #51
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)
Пример #52
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)
Пример #53
0
    def all(cls, keys_only=False, endpoint=None, **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,endpoint=endpoint)
        params = {}

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

        if 'cloud_id' in kwargs:
            params = {'cloudId': kwargs['cloud_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 AccountException(r.last_error)
Пример #54
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)