本文整理汇总了Python中scalrpy.LOG.debug方法的典型用法代码示例。如果您正苦于以下问题:Python LOG.debug方法的具体用法?Python LOG.debug怎么用?Python LOG.debug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scalrpy.LOG
的用法示例。
在下文中一共展示了LOG.debug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _is_server_for_update
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def _is_server_for_update(self, server, status):
repo_url = status["repo_url"]
devel_branch = server.get("user-data.scm_branch", None)
ver_info = self.get_szr_ver_from_repo(devel_branch=devel_branch)
try:
szr_ver_repo = ver_info[repo_url]
except KeyError:
pkg_type = helper.pkg_type_by_name(status["dist"].split()[0])
szr_ver_repo = ver_info[status["repository"]][pkg_type]
if parse_version(server["scalarizr.version"]) >= parse_version(szr_ver_repo):
return False
if "in-progress" in status["state"]:
# skip in-progress server
return False
if status["executed_at"]:
last_update_dt = datetime.datetime.strptime(status["executed_at"], "%a %d %b %Y %H:%M:%S %Z")
last_update_dt = last_update_dt.replace(minute=0, second=0, microsecond=0)
utcnow_dt = datetime.datetime.utcnow()
utcnow_dt = utcnow_dt.replace(minute=0, second=0, microsecond=0)
if last_update_dt == utcnow_dt and status["state"] == "error":
# skip failed server
LOG.debug("Skip server: {0}, reason: server in error state".format(server["server_id"]))
return False
return True
示例2: _is_server_for_update
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def _is_server_for_update(self, server, status):
repo_url = status['repo_url']
devel_branch = server.get('user-data.scm_branch', None)
ver_info = self.get_szr_ver_from_repo(devel_branch=devel_branch)
try:
szr_ver_repo = ver_info[repo_url]
except KeyError:
pkg_type = helper.pkg_type_by_name(status['dist'].split()[0])
szr_ver_repo = ver_info[status['repository']][pkg_type]
if parse_version(server['scalarizr.version']) >= parse_version(szr_ver_repo):
return False
if 'in-progress' in status['state']:
# skip in-progress server
return False
if status['executed_at']:
last_update_dt = datetime.datetime.strptime(
status['executed_at'], '%a %d %b %Y %H:%M:%S %Z')
last_update_dt = last_update_dt.replace(minute=0, second=0, microsecond=0)
utcnow_dt = datetime.datetime.utcnow()
utcnow_dt = utcnow_dt.replace(minute=0, second=0, microsecond=0)
if last_update_dt == utcnow_dt and status['state'] == 'error':
# skip failed server
LOG.debug(
'Skip server: {0}, reason: server in error state'.format(server['server_id']))
return False
return True
示例3: download_aws_billing_file
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def download_aws_billing_file(self, cred, bucket_name, date=None):
if date is None:
date = datetime.datetime.utcnow().date()
conn = get_s3_conn(cred)
bucket = conn.get_bucket(bucket_name)
account_id = cryptotool.decrypt_scalr(app.crypto_key, cred['account_id'])
file_name = get_aws_csv_file_name(account_id, date)
key = bucket.get_key(file_name)
if not key:
msg = "AWS detailed billing CSV file {0} wasn't found in bucket {1}"
msg = msg.format(file_name, bucket_name)
if datetime.datetime.utcnow().day == 1:
LOG.warning(msg)
return None
else:
raise Exception(msg)
last_modified_dt = datetime.datetime.strptime(key.last_modified, self.last_modified_format)
update_interval = self.config['interval']
utcnow = datetime.datetime.utcnow()
delta = datetime.timedelta(seconds=update_interval)
condition1 = utcnow > last_modified_dt and utcnow < last_modified_dt + delta
condition2 = ((utcnow - last_modified_dt).seconds / 3600) % 8 == 0
if condition1 or condition2:
local_file_path = os.path.join(self.tmp_dir, file_name)
LOG.debug('Downloading {0}'.format(file_name))
key.get_contents_to_filename(local_file_path)
return local_file_path
else:
return None
示例4: _serve_forever
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def _serve_forever(self):
LOG.debug('Starting plotter')
try:
cherrypy.quickstart(self, '/', {'/': {}})
except:
LOG.error(helper.exc_info())
thread.interrupt_main()
示例5: daemonize
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
LOG.debug("Daemonize")
# first fork
pid = os.fork()
if pid > 0:
sys.exit(0)
os.chdir('/')
os.setsid()
os.umask(0)
# second fork
pid = os.fork()
if pid > 0:
sys.exit(0)
# redirect standard file descriptors
sys.stdout.flush()
sys.stderr.flush()
si = file(stdin, 'r')
so = file(stdout, "a+")
se = file(stderr, "a+", 0)
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
示例6: handle_error
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def handle_error(message=None, level='exception'):
c, e, t = sys.exc_info()
if message:
message = message.rstrip().rstrip('.') + '. Reason: {}'.format(exc_info())
else:
message = exc_info()
if isinstance(e, (
KeyboardInterrupt,
GeneratorExit,
greenlet_mod.GreenletExit,
gevent.Timeout,
)
):
LOG.debug(message)
raise
if isinstance(e, SystemExit) and sys.exc_info()[1].args[0] == 0:
raise
logging_map = {
'debug': LOG.debug,
'info': LOG.info,
'warning': LOG.warning,
'error': LOG.error,
'critical': LOG.critical,
'exception': LOG.exception,
}
if isinstance(e, pymysql.err.Error):
logging_map[min(level, 'error')](message)
else:
logging_map[level](message)
示例7: _handle_exception
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def _handle_exception(e, msg):
if isinstance(e, boto.exception.EC2ResponseError) and e.status in (401, 403):
LOG.warning(msg)
elif isinstance(
e,
(
libcloud.common.types.InvalidCredsError,
libcloud.common.types.LibcloudError,
libcloud.common.types.MalformedResponseError,
libcloud.common.exceptions.BaseHTTPError,
oauth2client.client.AccessTokenRefreshError,
gevent.timeout.Timeout,
socket.timeout,
socket.gaierror,
),
):
LOG.warning(msg)
elif isinstance(e, socket.error):
LOG.warning(msg)
elif isinstance(e, googleapiclient.errors.HttpError) and e.resp["status"] in ("403",):
LOG.warning(msg)
elif isinstance(e, ssl.SSLError):
LOG.warning(msg)
elif isinstance(e, greenlet.GreenletExit):
pass
elif "userDisabled" in str(e):
LOG.warning(msg)
elif isinstance(e, exceptions.MissingCredentialsError):
LOG.debug(msg)
else:
LOG.exception(msg)
示例8: __call__
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def __call__(self):
self.change_permissions()
while True:
try:
self.iteration_timestamp = time.time()
self.before_iteration()
g = self._do_iteration()
try:
g.get(timeout=self.iteration_timeout)
except:
self.on_iteration_error()
raise
finally:
if not g.ready():
g.kill()
self.after_iteration()
iteration_time = time.time() - self.iteration_timestamp
msg = 'End iteration: {0:.1f} seconds'.format(iteration_time)
LOG.debug(msg)
except:
LOG.exception('Iteration failed')
time.sleep(self.error_sleep)
finally:
if self.config['interval']:
next_iteration_time = self.iteration_timestamp + self.config['interval']
time.sleep(next_iteration_time - time.time())
示例9: __call__
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def __call__(self):
self.change_permissions()
while True:
try:
self.iteration_timestamp = time.time()
self.before_iteration()
g = self._do_iteration()
try:
g.get(timeout=self.iteration_timeout)
except:
self.on_iteration_error()
raise
finally:
if not g.ready():
g.kill()
self.after_iteration()
except:
try:
helper.handle_error(message='Iteration failed')
except (SystemExit, KeyboardInterrupt):
return
except:
pass
time.sleep(self.error_sleep)
finally:
iteration_time = time.time() - self.iteration_timestamp
msg = 'End iteration: {0:.1f} seconds'.format(iteration_time)
LOG.debug(msg)
if self.config['interval']:
next_iteration_time = self.iteration_timestamp + self.config['interval']
sleep_time = next_iteration_time - time.time()
if sleep_time:
time.sleep(sleep_time)
示例10: _ec2_region
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def _ec2_region(region, cred):
try:
access_key = cryptotool.decrypt_scalr(app.crypto_key, cred["access_key"])
secret_key = cryptotool.decrypt_scalr(app.crypto_key, cred["secret_key"])
kwds = {"aws_access_key_id": access_key, "aws_secret_access_key": secret_key}
proxy_settings = app.proxy_settings.get(cred.platform, {})
kwds["proxy"] = proxy_settings.get("host")
kwds["proxy_port"] = proxy_settings.get("port")
kwds["proxy_user"] = proxy_settings.get("user")
kwds["proxy_pass"] = proxy_settings.get("pass")
msg = "List nodes for platform: 'ec2', region: '{}', envs_ids: {}"
msg = msg.format(region, cred.envs_ids)
LOG.debug(msg)
conn = boto.ec2.connect_to_region(region, **kwds)
cloud_nodes = _ec2_get_only_instances(conn)
timestamp = int(time.time())
nodes = list()
for cloud_node in cloud_nodes:
node = {
"instance_id": cloud_node.id,
"instance_type": cloud_node.instance_type,
"os": cloud_node.platform if cloud_node.platform else "linux",
}
nodes.append(node)
return {"region": region, "timestamp": timestamp, "nodes": nodes} if nodes else dict()
except:
e = sys.exc_info()[1]
msg = "platform: '{platform}', region: '{region}', envs_ids: {envs_ids}. Reason: {error}"
msg = msg.format(
platform=cred.platform, region=region, envs_ids=cred.envs_ids, error=helper.exc_info(where=False)
)
_handle_exception(e, msg)
示例11: do_iteration
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def do_iteration(self):
for envs in self.analytics.load_envs():
msg = "Processing environments: {}".format([env['id'] for env in envs])
LOG.debug(msg)
try:
self.analytics.load_env_credentials(envs)
unique = {}
for env in envs:
try:
credentials = self.analytics.get_credentials([env])
for cred in credentials:
if cred.platform == 'ec2' and env.get('ec2.detailed_billing.enabled', '0') == '1':
continue
unique.setdefault(cred.unique, {'envs_ids': [], 'cred': cred})
unique[cred.unique]['envs_ids'].append(env['id'])
except:
msg = 'Processing environment: {} failed'.format(env['id'])
LOG.exception(msg)
for data in unique.values():
while len(self.pool) > self.config['pool_size'] * 5 / 10:
gevent.sleep(0.1)
self.pool.apply_async(process_credential,
args=(data['cred'],),
kwds={'envs_ids': data['envs_ids']})
gevent.sleep(0) # force switch
except:
msg = 'Processing environments: {} failed'.format([env['id'] for env in envs])
LOG.exception(msg)
self.pool.join()
示例12: execute
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def execute(self, query, retries=0, retry_timeout=10):
while True:
try:
if self._autocommit or not self._connection:
self._local.connection = self._connection_pool.get(timeout=10)
self._local.connection.autocommit(self._autocommit)
self._local.cursor = self._connection.cursor()
try:
start_time = time.time()
self._local.cursor.execute(query)
end_time = time.time()
if end_time - start_time > 1:
LOG.debug('Query too slow: %s\n%s...' %
(end_time - start_time, query[:150]))
results = self._local.cursor.fetchall()
if results is not None:
results = tuple(results)
return results
finally:
if self._autocommit:
self._local.cursor.close()
self._connection_pool.put(self._local.connection)
self._local.connection = None
self._local.cursor = None
except (pymysql.err.OperationalError, pymysql.err.InternalError, socket.timeout):
if not retries:
raise
retries -= 1
time.sleep(retry_timeout)
示例13: create_pid_file
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def create_pid_file(pid_file):
pid = str(os.getpid())
msg = "Creating pid file: %s" % pid_file
LOG.debug(msg)
if not os.path.exists(os.path.dirname(pid_file)):
os.makedirs(os.path.dirname(pid_file), mode=0o755)
file(pid_file, 'w+').write('%s\n' % pid)
示例14: do_iteration
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def do_iteration(self):
for envs in self.analytics.load_envs():
msg = "Processing environments: {}".format([env["id"] for env in envs])
LOG.debug(msg)
try:
self.analytics.load_env_credentials(envs)
unique = {}
for env in envs:
try:
credentials = self.analytics.get_credentials([env])
for cred in credentials:
if cred.platform == "ec2" and env.get("ec2.detailed_billing.enabled", "0") == "1":
continue
unique.setdefault(cred.unique, {"envs_ids": [], "cred": cred})
unique[cred.unique]["envs_ids"].append(env["id"])
except:
msg = "Processing environment: {} failed".format(env["id"])
LOG.exception(msg)
for data in unique.values():
while len(self.pool) > self.config["pool_size"] * 5 / 10:
gevent.sleep(0.1)
self.pool.apply_async(process_credential, args=(data["cred"],), kwds={"envs_ids": data["envs_ids"]})
gevent.sleep(0) # force switch
except:
msg = "Processing environments: {} failed".format([env["id"] for env in envs])
LOG.exception(msg)
self.pool.join()
示例15: delete_file
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import debug [as 别名]
def delete_file(file_path):
msg = "Deleting file: %s" % file_path
LOG.debug(msg)
if os.path.exists(file_path):
try:
os.remove(file_path)
except:
LOG.warning(exc_info())