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)
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)
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)
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)
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
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)
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)
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)
def all(cls, **kwargs): """Returns subscriptions for all regions""" r = Resource(cls.PATH) r.request_details = 'basic' s = r.get() return s
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)
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)
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
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)
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)
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)
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)
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
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)
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
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, 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
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, 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)
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)
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)
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)
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)
def all(cls): """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) r.request_details = 'basic' s = r.get() if r.last_error is None: servers = [cls(server['serverId']) for server in s[cls.COLLECTION_NAME]] return servers else: raise ServerException(r.last_error)
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)
def all(cls, keys_only=False, endpoint=None): """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, endpoint=endpoint) 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 JobException(r.last_error)
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) r.request_details = 'basic' 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 'account_id' in kwargs: params['accountId'] = kwargs['account_id'] if 'volume_id' in kwargs: params['volumeId'] = kwargs['volume_id'] c = r.get(params=params) if r.last_error is None: if keys_only is True: snapshots = [item['snapshotId'] for item in c[cls.COLLECTION_NAME]] else: snapshots = [] for i in c[cls.COLLECTION_NAME]: snapshot = cls(i['snapshotId']) if 'detail' in kwargs: snapshot.request_details = kwargs['detail'] snapshot.load() snapshots.append(snapshot) return snapshots else: raise SnapshotException(r.last_error)
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)
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)
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)
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)