本文整理汇总了Python中mixcoatl.resource.Resource类的典型用法代码示例。如果您正苦于以下问题:Python Resource类的具体用法?Python Resource怎么用?Python Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: all
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)
示例2: all
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)
示例3: __init__
def __init__(self, network_id = None, *args, **kwargs):
Resource.__init__(self)
if 'detail' in kwargs:
self.request_details = kwargs['detail']
self.__network_id = network_id
示例4: all
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)
示例5: all
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)
示例6: all
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)
示例7: all
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)
示例8: __init__
def __init__(self, firewall_id=None, endpoint=None, **kwargs):
Resource.__init__(self, endpoint=endpoint)
if 'detail' in kwargs:
self.request_details = kwargs['detail']
self.__firewall_id = firewall_id
示例9: all
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
示例10: all
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)
示例11: all
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)
示例12: all
def all(cls, **kwargs):
"""Returns subscriptions for all regions"""
r = Resource(cls.PATH)
r.request_details = 'basic'
s = r.get()
return s
示例13: region
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
示例14: all
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)
示例15: all
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)