in aliyun/log/logclient_core.py [0:0]
def create_entity(entity_name, logstore_level=None, root_resource=None):
def do_create(self, project, detail, resource_prefix=None):
params = {}
headers = {"x-log-bodyrawsize": '0', "Content-Type": "application/json"}
if hasattr(detail, 'to_json'):
detail = detail.to_json()
body_str = six.b(json.dumps(detail))
elif isinstance(detail, six.binary_type):
body_str = detail
elif isinstance(detail, six.text_type):
body_str = detail.encode('utf8')
else:
body_str = six.b(json.dumps(detail))
resource_path = (root_resource and root_resource.rstrip('/')) or "/" + pluralize(entity_name)
if resource_prefix:
resource_path = resource_prefix + resource_path
(resp, header) = self._send("POST", project, body_str, resource_path, params, headers)
return GetEntityResponse(header, resp)
if not logstore_level:
def fn(self, project, detail):
""" Create {entity_title}.
Unsuccessful opertaion will cause an LogException.
:type project: string
:param project: project name
:type detail: dict/string
:param detail: json string
:return: CreateEntityResponse
:raise: LogException
"""
return do_create(self, project, detail)
else:
def fn(self, project, logstore, detail):
""" Create {entity_title}.
Unsuccessful opertaion will cause an LogException.
:type project: string
:param project: project name
:type logstore: string
:param logstore: logstore name
:type detail: dict/string
:param detail: json string
:return: CreateEntityResponse
:raise: LogException
"""
resource_prefix = "/logstores/" + logstore
return do_create(self, project, detail, resource_prefix)
fn.__name__ = 'create_' + entity_name
fn.__doc__ = fn.__doc__.format(entity_title=entity_name.title())
return fn