本文整理汇总了Python中util.get_uuid函数的典型用法代码示例。如果您正苦于以下问题:Python get_uuid函数的具体用法?Python get_uuid怎么用?Python get_uuid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_uuid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_file
def create_file(self, file):
if self.validate_file(file, action='create') == False:
raise IOError('validation failed')
folder = self.session.query(Folder).filter_by(id=file.get('folder_id'), user_id=self.uid).first()
uuid = get_uuid(str(self.uid), folder.path, file['name'])
#content = unicode(file.get('content'), "ISO-8859-1")
content = file.get('content').encode("ISO-8859-1")
child_files = self.read_folder(folder.path)['files']
for i in child_files:
if file['name'] == i['name']:
return 'file already exists'
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
file_rec = File(folder_id=folder.id, name=file['name'], user_id=self.uid, location=uuid,
type=self.storage_type, deleted=False, ctime=now)
try:
upload_result = self.storage.create_object(content=content, uuid=uuid)
if upload_result:
self.session.add(file_rec)
self.session.commit()
return file_rec.serialize
else:
self.session.rollback()
except IOError:
self.session.rollback()
示例2: _postMetrics
def _postMetrics(self):
if len(self._metrics) > 0:
self._metrics["uuid"] = get_uuid()
self._metrics["internalHostname"] = get_hostname(self._agentConfig)
self._metrics["apiKey"] = self._agentConfig["api_key"]
MetricTransaction(json.dumps(self._metrics), headers={"Content-Type": "application/json"})
self._metrics = {}
示例3: _postMetrics
def _postMetrics(self):
if len(self._metrics) > 0:
self._metrics['uuid'] = get_uuid()
self._metrics['internalHostname'] = gethostname(self._agentConfig)
self._metrics['apiKey'] = self._agentConfig['api_key']
MetricTransaction(self._metrics, {})
self._metrics = {}
示例4: _postMetrics
def _postMetrics(self):
if len(self._metrics) > 0:
self._metrics['uuid'] = get_uuid()
self._metrics['internalHostname'] = get_hostname(self._agentConfig)
self._metrics['apiKey'] = self._agentConfig['api_key']
MetricTransaction(json.dumps(self._metrics),
headers={'Content-Type': 'application/json'})
self._metrics = {}
示例5: _build_payload
def _build_payload(self, start_event=True):
"""
Return an dictionary that contains all of the generic payload data.
"""
now = time.time()
payload = {
'collection_timestamp': now,
'os' : self.os,
'python': sys.version,
'agentVersion' : self.agentConfig['version'],
'apiKey': self.agentConfig['api_key'],
'events': {},
'metrics': [],
'service_checks': [],
'resources': {},
'internalHostname' : get_hostname(self.agentConfig),
'uuid' : get_uuid(),
'host-tags': {},
}
# Include system stats on first postback
if start_event and self._is_first_run():
payload['systemStats'] = self.agentConfig.get('system_stats', {})
# Also post an event in the newsfeed
payload['events']['System'] = [{'api_key': self.agentConfig['api_key'],
'host': payload['internalHostname'],
'timestamp': now,
'event_type':'Agent Startup',
'msg_text': 'Version %s' % get_version()
}]
# Periodically send the host metadata.
if self._is_first_run() or self._should_send_metadata():
payload['systemStats'] = get_system_stats()
payload['meta'] = self._get_metadata()
self.metadata_cache = payload['meta']
# Add static tags from the configuration file
host_tags = []
if self.agentConfig['tags'] is not None:
host_tags.extend([unicode(tag.strip()) for tag in self.agentConfig['tags'].split(",")])
if self.agentConfig['collect_ec2_tags']:
host_tags.extend(EC2.get_tags())
if host_tags:
payload['host-tags']['system'] = host_tags
GCE_tags = GCE.get_tags()
if GCE_tags is not None:
payload['host-tags'][GCE.SOURCE_TYPE_NAME] = GCE_tags
# Log the metadata on the first run
if self._is_first_run():
log.info("Hostnames: %s, tags: %s" % (repr(self.metadata_cache), payload['host-tags']))
return payload
示例6: _build_payload
def _build_payload(self, start_event=True):
"""
Return an dictionary that contains all of the generic payload data.
"""
now = time.time()
payload = {
"collection_timestamp": now,
"os": self.os,
"python": sys.version,
"agentVersion": self.agentConfig["version"],
"apiKey": self.agentConfig["api_key"],
"events": {},
"metrics": [],
"resources": {},
"internalHostname": get_hostname(self.agentConfig),
"uuid": get_uuid(),
"host-tags": {},
}
# Include system stats on first postback
if start_event and self._is_first_run():
payload["systemStats"] = self.agentConfig.get("system_stats", {})
# Also post an event in the newsfeed
payload["events"]["System"] = [
{
"api_key": self.agentConfig["api_key"],
"host": payload["internalHostname"],
"timestamp": now,
"event_type": "Agent Startup",
"msg_text": "Version %s" % get_version(),
}
]
# Periodically send the host metadata.
if self._is_first_run() or self._should_send_metadata():
payload["systemStats"] = get_system_stats()
payload["meta"] = self._get_metadata()
self.metadata_cache = payload["meta"]
# Add static tags from the configuration file
host_tags = []
if self.agentConfig["tags"] is not None:
host_tags.extend([unicode(tag.strip()) for tag in self.agentConfig["tags"].split(",")])
if self.agentConfig["collect_ec2_tags"]:
host_tags.extend(EC2.get_tags())
if host_tags:
payload["host-tags"]["system"] = host_tags
# Log the metadata on the first run
if self._is_first_run():
log.info(u"Hostnames: %s, tags: %s" % (repr(self.metadata_cache), payload["host-tags"]))
return payload
示例7: _build_payload
def _build_payload(self, start_event=True):
"""
Return an dictionary that contains all of the generic payload data.
"""
now = time.time()
payload = {
'collection_timestamp': now,
'os' : self.os,
'python': sys.version,
'agentVersion' : self.agentConfig['version'],
'apiKey': self.agentConfig['api_key'],
'events': {},
'metrics': [],
'resources': {},
'internalHostname' : get_hostname(self.agentConfig),
'uuid' : get_uuid(),
}
# Include system stats on first postback
if start_event and self._is_first_run():
payload['systemStats'] = self.agentConfig.get('system_stats', {})
# Also post an event in the newsfeed
payload['events']['System'] = [{'api_key': self.agentConfig['api_key'],
'host': payload['internalHostname'],
'timestamp': now,
'event_type':'Agent Startup',
'msg_text': 'Version %s' % get_version()
}]
# Periodically send the host metadata.
if self._is_first_run() or self._should_send_metadata():
payload['systemStats'] = get_system_stats()
payload['meta'] = self._get_metadata()
self.metadata_cache = payload['meta']
# Add static tags from the configuration file
if self.agentConfig['tags'] is not None:
payload['tags'] = self.agentConfig['tags']
# Log the metadata on the first run
if self._is_first_run():
if self.agentConfig['tags'] is not None:
log.info(u"Hostnames: %s, tags: %s" \
% (repr(self.metadata_cache),
self.agentConfig['tags']))
else:
log.info(u"Hostnames: %s" % repr(self.metadata_cache))
return payload
示例8: submit_events
def submit_events(self, events):
headers = {"Content-Type": "application/json"}
event_chunk_size = self.event_chunk_size
for chunk in chunks(events, event_chunk_size):
payload = {
"apiKey": self.api_key,
"events": {"api": chunk},
"uuid": get_uuid(),
"internalHostname": get_hostname(),
}
params = {}
if self.api_key:
params["api_key"] = self.api_key
url = "%s/intake?%s" % (self.api_host, urlencode(params))
self.submit_http(url, json.dumps(payload), headers)
示例9: submit_events
def submit_events(self, events):
headers = {'Content-Type':'application/json'}
event_chunk_size = self.event_chunk_size
for chunk in chunks(events, event_chunk_size):
payload = {
'apiKey': self.api_key,
'events': {
'api': chunk
},
'uuid': get_uuid(),
'internalHostname': get_hostname()
}
params = {}
if self.api_key:
params['api_key'] = self.api_key
url = '%s/intake?%s' % (self.api_host, urlencode(params))
self.submit_http(url, json.dumps(payload), headers)
示例10: _build_payload
def _build_payload(self, payload):
"""
Build the payload skeleton, so it contains all of the generic payload data.
"""
now = time.time()
payload["collection_timestamp"] = now
payload["os"] = self.os
payload["python"] = sys.version
payload["agentVersion"] = self.agentConfig["version"]
payload["apiKey"] = self.agentConfig["api_key"]
payload["events"] = {}
payload["metrics"] = []
payload["service_checks"] = []
payload["resources"] = {}
payload["internalHostname"] = self.hostname
payload["uuid"] = get_uuid()
payload["host-tags"] = {}
payload["external_host_tags"] = {}
示例11: create_file
def create_file(self, folder_id, file_name):
folder = self.session.query(Folder).filter_by(id=folder_id, user_id=self.uid).first()
uuid = get_uuid(folder.path, file_name)
child_files = self.read_folder(folder_id)['files']
for i in child_files:
if file_name == i['name']:
return 'file already exists'
file = File(folder_id=folder.id, name=file_name, user_id=self.uid, location=uuid, type='sheepdog', deleted=False)
upload_result = self.storage.create_object(file=file_name, uuid=uuid)
if upload_result:
self.session.add(file)
self.session.commit()
else:
self.session.rollback()
示例12: _build_payload
def _build_payload(self):
"""
Return an dictionary that contains all of the generic payload data.
"""
payload = {
'collection_timestamp': time.time(),
'os' : self.os,
'python': sys.version,
'agentVersion' : self.agentConfig['version'],
'apiKey': self.agentConfig['api_key'],
'events': {},
'metrics': [],
'resources': {},
'internalHostname' : gethostname(self.agentConfig),
'uuid' : get_uuid(),
}
# Include system stats on first postback
if self._is_first_run():
payload['systemStats'] = self.agentConfig.get('system_stats', {})
# Also post an event in the newsfeed
payload['events']['System'] = [{'api_key': self.agentConfig['api_key'],
'host': payload['internalHostname'],
'timestamp': int(time.mktime(datetime.datetime.now().timetuple())),
'event_type':'Agent Startup',
'msg_text': 'Version %s' % get_version()
}]
# Periodically send the host metadata.
if self._is_first_run() or self._should_send_metadata():
payload['meta'] = self._get_metadata()
self.metadata_cache = payload['meta']
# Add static tags from the configuration file
if self.agentConfig['tags'] is not None:
payload['tags'] = self.agentConfig['tags']
return payload
示例13: submit_events
def submit_events(self, events):
headers = {'Content-Type':'application/json'}
method = 'POST'
events_len = len(events)
event_chunk_size = self.event_chunk_size
for chunk in chunks(events, event_chunk_size):
payload = {
'apiKey': self.api_key,
'events': {
'api': chunk
},
'uuid': get_uuid(),
'internalHostname': get_hostname()
}
params = {}
if self.api_key:
params['api_key'] = self.api_key
url = '/intake?%s' % urlencode(params)
status = None
conn = self.http_conn_cls(self.api_host)
try:
start_time = time()
conn.request(method, url, json.dumps(payload), headers)
response = conn.getresponse()
status = response.status
response.close()
duration = round((time() - start_time) * 1000.0, 4)
log.debug("%s %s %s%s (%sms)" % (
status, method, self.api_host, url, duration))
finally:
conn.close()
示例14: handler
def handler(event, context):
log.debug("Received event {}".format(json.dumps(event)))
if "Records" in event:
# from SNS/CFN
snsData = json.loads(event["Records"][0]["Sns"]["Message"]["message"])
log.debug("From SNS: %s" % snsData)
message = snsData["message"]
else:
# from APIG or CLI call
if "httpMethod" in event:
log.debug("Context: %s" % event['httpMethod'])
if event["httpMethod"] == "POST":
# create
#env_name = event['params']['path']['envname']
env_name = "dev"
config_path = os.path.join(here, ENV_CONFIG_FILENAME)
with open(config_path) as json_file:
config_dict = json.load(json_file)
env_dict = config_dict[env_name]
app_name = config_dict['app_name']
app_env = '%s-%s' % (app_name, env_name)
table = dynamodb.Table('BlargotronJobs')
jobId = get_uuid()
timestamp = int(time.time())
log.debug("timestamp: %s" % timestamp)
table.put_item(
Item={
'jobId': jobId,
'timestamp': timestamp,
'env_name': env_name,
'steps': [
{
'name': 'createEnvironment',
'template': ENV_CONFIG_FILENAME,
'status': 'WAITING'
},
{
'name': 'deployBeanstalkApp',
'template': 'ebapp.json',
'status': 'WAITING'
}
]
}
)
# now, actually do work
template_body = generate_application_template(config_dict)
apply_template(app_name, template_body, wait=True)
#
# template_body = generate_env_template(app_env, env_dict)
# apply_template(app_env, template_body, notify=True)
elif event["httpMethod"] == "PUT":
# update
log.debug("APIG call: PUT")
else:
# CLI call
log.debug("CLI call")
return {}
示例15: upload_crop
def upload_crop(image_path, ext):
response = {}
pin_width = 0
pin_height = 0
if not os.path.exists(image_path):
response["status"] = True
response["message"] = "Not found: %s" % image_path
return response
image_ext = ext[1:].upper()
if image_ext == "JPG": image_ext = "JPEG"
store_dir = _get_image_dir(PHOTO_PATH)
base_name = get_uuid()
source_name = "%s_source%s" % (base_name, ext)
source_path = os.path.join(store_dir, source_name)
thumb_name = "%s_thumb%s" % (base_name, ext)
thumb_path = os.path.join(store_dir, thumb_name)
middle_name = "%s_mid%s" % (base_name, ext)
middle_path = os.path.join(store_dir, middle_name)
# source
try:
os.rename(image_path, source_path)
except Exception:
Log.error("Save source error: %s" % image_path)
response["status"] = False
response["message"] = "Save source error: %s" % image_path
return response
img = Image.open(source_path)
# middle
dest_width = MIDDLE_WIDTH
width, height = img.size
if width < dest_width or height < dest_width:
response["status"] = False
response["message"] = "Image size too small"
return response
dest_height = int(float(dest_width) * float(height) / float(width))
img_mid = img.resize((dest_width, dest_height), Image.ANTIALIAS)
img_mid.save(middle_path, image_ext, quality=150)
pin_width, pin_height = (dest_width, dest_height)
# thumb
dest_width, dest_height = THUMB_SIZE
left, upper, right, lowwer = 0, 0, dest_width, dest_height
crop_width, crop_height = dest_width, dest_height
if float(dest_width)/float(dest_height) < float(width)/float(height):
crop_height = height
crop_width = int(height * (float(dest_width) / float(dest_height)))
left = int((width - crop_width) / 2)
right = left + crop_width
lowwer = height
else:
crop_width = width
crop_height = int(width * (float(dest_height) / float(dest_width)))
upper = int((height - crop_height) / 2)
lowwer = upper + crop_height
right = width
box = (left, upper, right, lowwer)
img_thumb = img.crop(box)
img_thumb = img_thumb.resize((dest_width, dest_height), Image.ANTIALIAS)
img_thumb.save(thumb_path, image_ext, quality=150)
response["status"] = True
response["source_path"] = source_path
response["thumb_path"] = thumb_path
response["middle_path"] = middle_path
response["height"] = pin_height
response["width"] = pin_width
return response