本文整理汇总了Python中scalrpy.LOG.warning方法的典型用法代码示例。如果您正苦于以下问题:Python LOG.warning方法的具体用法?Python LOG.warning怎么用?Python LOG.warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scalrpy.LOG
的用法示例。
在下文中一共展示了LOG.warning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_aws_billing_file
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [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
示例2: get_metrics
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def get_metrics(host, port, key, api_type, metrics, headers=None, timeout=5):
assert host, 'host'
assert port, 'port'
assert key, 'key'
assert api_type, 'api_type'
assert metrics, 'metrics'
data = dict()
endpoint = 'http://%s:%s' % (host, port)
security = rpc.Security(key)
hsp = rpc.HttpServiceProxy(endpoint, security=security, headers=headers)
getters = {
'cpu': get_cpu_stat,
'la': get_la_stat,
'mem': get_mem_info,
'net': get_net_stat,
'io': get_io_stat,
}
for metric in metrics:
try:
data.update({metric: getters[metric](hsp, api_type, timeout=timeout)})
except (urllib2.URLError, urllib2.HTTPError, socket.timeout):
msg = "Endpoint: {endpoint}, headers: {headers}, metric: '{metric}', reason: {err}"
msg = msg.format(
endpoint=endpoint, headers=headers, metric=metric, err=helper.exc_info())
raise Exception(msg)
except:
msg = "Endpoint: {endpoint}, headers: {headers}, metric '{metric}' failed, reason: {er}"
msg = msg.format(
endpoint=endpoint, headers=headers, metric=metric, err=helper.exc_info())
LOG.warning(msg)
continue
return data
示例3: do_iteration
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def do_iteration(self):
messages = self.get_messages()
if not messages:
raise exceptions.NothingToDoError()
servers = self.get_servers(messages)
servers_map = dict((server['server_id'], server) for server in servers)
for message in messages:
try:
if message['server_id'] not in servers_map:
msg = (
"Server '{server_id}' doesn't exist or not in right status, set message "
"status to 3"
).format(server_id=message['server_id'])
LOG.warning(msg)
message['status'] = 3
self._pool.wait()
self._pool.apply_async(self.update, (message,))
else:
server = servers_map[message['server_id']]
self._pool.wait()
self._pool.apply_async(self.process_message, (message, server))
except:
msg = "Unable to process message: {message_id}, reason: {error}"
msg = msg.format(message_id=message['messageid'], error=helper.exc_info())
LOG.warning(msg)
self._pool.join()
示例4: do_iteration
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def do_iteration(self):
while len(self._processing_messages) > self.max_processing_messages:
time.sleep(1)
messages = self.get_messages()
if not messages:
time.sleep(self.nothing_todo_sleep)
return
servers = self.get_servers(messages)
servers_map = dict((server['server_id'], server) for server in servers)
for message in messages:
try:
if message['messageid'] in self._processing_messages:
continue
self._processing_messages.add(message['messageid'])
if message['server_id'] not in servers_map:
msg = (
"Server '{server_id}' doesn't exist or not in right status, set message "
"status to 3"
).format(server_id=message['server_id'])
LOG.warning(msg)
message['status'] = 3
self._pool.wait()
self._pool.apply_async(self.update, (message,))
else:
server = servers_map[message['server_id']]
self._pool.wait()
self._pool.apply_async(self.process_message, (message, server))
except:
msg = "Unable to process message: {message_id}, reason: {error}"
msg = msg.format(message_id=message['messageid'], error=helper.exc_info())
LOG.warning(msg)
示例5: gce
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def gce(cred):
"""
:returns: list
[{'region': str, 'timestamp': int, 'nodes': list}]
"""
result = list()
project_id = cryptotool.decrypt_scalr(app.crypto_key, cred['project_id'])
key = _gce_key(cred)
conn, http = _gce_conn(cred, key=key)
request = conn.zones().list(project=project_id)
resp = request.execute(http=http)
zones = [_['name'] for _ in resp['items']] if 'items' in resp else []
app.pool.wait()
async_results = dict(
(zone, app.pool.apply_async(_gce_zone, args=(zone, key, cred,)))
for zone in zones
)
gevent.sleep(0) # force switch
for zone, async_result in async_results.iteritems():
try:
zone_nodes = async_result.get(timeout=app.config['cloud_connection_timeout'] + 1)
if zone_nodes:
result.append(zone_nodes)
except gevent.timeout.Timeout:
async_result.kill()
msg = 'platform: {platform}, zone: {zone}, env_id: {env_id}, reason: timeout'
msg = msg.format(platform=cred.platform, zone=zone, env_id=cred.env_id)
LOG.warning(msg)
return result
示例6: ver_from_rpm_repo
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def ver_from_rpm_repo(self, repo, branch=None):
out = {}
rpm_repo_url_template = repo["rpm_repo_url"]
if rpm_repo_url_template:
rpm_repo_url_template = rpm_repo_url_template.strip()
if branch:
rpm_repo_url_template = rpm_repo_url_template % branch
for release in ["5", "6", "7"]:
rpm_repo_url = rpm_repo_url_template.replace("$releasever", release)
rpm_repo_url = rpm_repo_url.replace("$basearch", "x86_64")
url = os.path.join(rpm_repo_url, "repodata/primary.xml.gz")
try:
r = requests.get(url)
r.raise_for_status()
assert r.text, "Empty primary.xml file"
s = StringIO.StringIO(r.content)
f = gzip.GzipFile(fileobj=s, mode="r")
f.seek(0)
xml = minidom.parse(f)
try:
out[rpm_repo_url_template] = self.rpm_pattern_1.findall(xml.toxml())[0].strip()
except:
out[rpm_repo_url_template] = self.rpm_pattern_2.findall(xml.toxml())[0].strip()
except (requests.exceptions.HTTPError, requests.exceptions.InvalidSchema):
msg = "RPM repository {0} failed, file not found: {1}"
msg = msg.format(repo["rpm_repo_url"], url)
LOG.warning(msg)
return out
示例7: sorted_data_update
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def sorted_data_update(sorted_data):
for region_data in sorted_data:
for server in region_data['managed']:
if server.get('os', None) is not None:
continue
query = (
"SELECT os_type os "
"FROM servers "
"WHERE server_id='{server_id}'"
).format(server_id=server['server_id'])
result = app.scalr_db.execute(query, retries=1)
if not result:
query = (
"SELECT value AS os "
"FROM server_properties "
"WHERE server_id='{server_id}' "
"AND name='os_type'"
).format(server_id=server['server_id'])
result = app.scalr_db.execute(query, retries=1)
if not result:
server['os'] = 'linux'
msg = "Can't detect OS type for server: {0}, set 'linux'".format(
server['server_id'])
LOG.warning(msg)
else:
server['os'] = result[0]['os']
for server in region_data['managed']:
server['os'] = analytics.os_map[server.get('os', None)]
for server in region_data['not_managed']:
server['os'] = analytics.os_map[server.get('os', None)]
示例8: _get_statuses
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def _get_statuses(self, servers):
async_results = {}
for server in servers:
if 'scalarizr.key' not in server:
msg = "Server: {0}, reason: Missing scalarizr key".format(server['server_id'])
LOG.warning(msg)
continue
if 'scalarizr.updc_port' not in server:
api_port = self.scalr_config['scalarizr_update'].get('api_port', 8008)
server['scalarizr.updc_port'] = api_port
self._pool.wait()
async_results[server['server_id']] = self._pool.apply_async(self._get_status, (server,))
gevent.sleep(0) # force switch
statuses = {}
timeout = self.config['instances_connection_timeout']
for server in servers:
try:
server_id = server['server_id']
statuses[server_id] = async_results[server_id].get(timeout=timeout)
except:
msg = 'Unable to get update client status, server: {0}, reason: {1}'
msg = msg.format(server['server_id'], helper.exc_info())
LOG.warning(msg)
return statuses
示例9: ver_from_rpm_repo
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def ver_from_rpm_repo(self, repo, branch=None):
out = {}
rpm_repo_url_template = repo['rpm_repo_url']
if rpm_repo_url_template:
rpm_repo_url_template = rpm_repo_url_template.strip()
if branch:
rpm_repo_url_template = rpm_repo_url_template % branch
for release in ['5', '6']:
rpm_repo_url = rpm_repo_url_template.replace('$releasever', release)
rpm_repo_url = rpm_repo_url.replace('$basearch', 'x86_64')
url = os.path.join(rpm_repo_url, 'repodata/primary.xml.gz')
try:
r = requests.get(url)
r.raise_for_status()
except (requests.exceptions.HTTPError, requests.exceptions.InvalidSchema):
msg = 'RPM repository {0} failed, file: {1} not found'.format(repo['rpm_repo_url'], url)
LOG.warning(msg)
return out
s = StringIO.StringIO(r.content)
f = gzip.GzipFile(fileobj=s, mode='r')
f.seek(0)
xml = minidom.parse(f)
try:
out[rpm_repo_url_template] = self.rpm_pattern_1.findall(xml.toxml())[0].strip()
except:
out[rpm_repo_url_template] = self.rpm_pattern_2.findall(xml.toxml())[0].strip()
return out
示例10: get_net_stat
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def get_net_stat(hsp, api_type='linux', timeout=5):
net = hsp.sysinfo.net_stats(timeout=timeout)
if api_type == 'linux':
ret = {
'in': float(net['eth0']['receive']['bytes']),
'out': float(net['eth0']['transmit']['bytes']),
}
elif api_type == 'windows':
for key in net:
if re.match(r'^.*Ethernet Adapter.*$', key) \
or re.match(r'^.*AWS PV Network Device.*$', key):
ret = {
'in': float(net[key]['receive']['bytes']),
'out': float(net[key]['transmit']['bytes']),
}
break
else:
msg = (
"Can't find ['^.* Ethernet Adapter.*$', '^.*AWS PV Network Device.*$'] "
"pattern in api response for endpoint: {0}, available: {1}, use {2}"
).format(hsp.endpoint, net.keys(), net.keys()[0])
LOG.warning(msg)
first_key = net.keys()[0]
ret = {
'in': float(net[first_key]['receive']['bytes']),
'out': float(net[first_key]['transmit']['bytes']),
}
else:
raise APIError("Unsupported API type '%s' for NET stat" % api_type)
return ret
示例11: _handle_webhook_exception
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def _handle_webhook_exception(self, webhook):
exc = sys.exc_info()[1]
if isinstance(exc, (
requests.exceptions.Timeout,
requests.exceptions.ProxyError,
requests.exceptions.ConnectionError)):
if webhook['handle_attempts'] < webhook['attempts']:
webhook['status'] = 0
else:
webhook['status'] = 2
webhook['error_msg'] = str(sys.exc_info()[0].__name__)
msg = "Unable to process webhook: {0}, reason: {1}"
msg = msg.format(webhook['history_id'], helper.exc_info())
LOG.warning(msg)
elif isinstance(exc, (
requests.exceptions.RequestException,
requests.packages.urllib3.exceptions.HTTPError,
requests.packages.urllib3.exceptions.HTTPWarning)):
webhook['status'] = 2
webhook['error_msg'] = str(sys.exc_info()[0].__name__)
msg = "Unable to process webhook: {0}, reason: {1}"
msg = msg.format(webhook['history_id'], helper.exc_info())
LOG.warning(msg)
else:
webhook['status'] = 2
webhook['error_msg'] = 'Internal error'
msg = "Unable to process webhook: {0}, reason: {1}"
msg = msg.format(webhook['history_id'], helper.exc_info())
LOG.error(msg)
示例12: delete_file
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [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())
示例13: _openstack
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def _openstack(provider, cred):
result = list()
username, password, auth_version, keystone_url, tenant_name = _openstack_cred(cred)
url = urlparse.urlparse(keystone_url)
cls = get_driver(provider)
driver = cls(
username,
password,
ex_force_auth_url=url.geturl(),
ex_force_base_url="%s://%s" % (url.scheme, url.netloc),
ex_tenant_name=tenant_name,
ex_force_auth_version=auth_version,
)
proxy_url = app.proxy_settings.get(cred.platform, {}).get("url")
driver.connection.set_http_proxy(proxy_url=proxy_url)
service_catalog = _libcloud_get_service_catalog(driver)
service_names = service_catalog.get_service_names(service_type="compute")
regions = service_catalog.get_regions(service_type="compute")
for service_name in service_names:
app.pool.wait()
async_results = dict(
(region, app.pool.apply_async(_openstack_region, args=(provider, service_name, region, cred)))
for region in regions
)
gevent.sleep(0) # force switch
for region, async_result in async_results.iteritems():
try:
region_nodes = async_result.get(timeout=app.config["cloud_connection_timeout"] + 1)
if region_nodes:
result.append(region_nodes)
except gevent.timeout.Timeout:
async_result.kill()
msg = (
"platform: '{platform}', envs_ids: {envs_ids}, url: '{url}', "
"tenant_name: '{tenant_name}', service_name='{service_name}', "
"region: '{region}', auth_version: {auth_version}. Reason: timeout"
)
msg = msg.format(
platform=cred.platform,
envs_ids=cred.envs_ids,
url=url,
tenant_name=tenant_name,
service_name=service_name,
region=region,
auth_version=auth_version,
)
LOG.warning(msg)
return result
示例14: _process_server
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def _process_server(self, server):
data = dict()
try:
data = self._get_metrics_api(server)
except:
msg = "Server: '%s' API failed: %s" % (server['server_id'], helper.exc_info())
LOG.warning(msg)
result = {
'farm_id': server['farm_id'],
'farm_role_id': server['farm_role_id'],
'index': server['index'],
'data': data,
}
return result
示例15: ec2
# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import warning [as 别名]
def ec2(cred):
"""
:returns: list
[{'region': str, 'timestamp': int, 'nodes': list}]
"""
result = list()
if cred['account_type'] == 'regular':
regions = [
'us-east-1',
'us-west-1',
'us-west-2',
'eu-west-1',
'eu-central-1',
'ap-southeast-1',
'ap-southeast-2',
'ap-northeast-1',
'sa-east-1',
]
elif cred['account_type'] == 'gov-cloud':
regions = [
'us-gov-west-1',
]
elif cred['account_type'] == 'cn-cloud':
regions = [
'cn-north-1',
]
else:
msg = 'Unsupported account type for ec2 platform: {0}'.format(cred['account_type'])
raise Exception(msg)
app.pool.wait()
async_results = dict(
(region, app.pool.apply_async(_ec2_region, args=(region, cred,)))
for region in regions
)
gevent.sleep(0) # force switch
timeout = app.config['cloud_connection_timeout']
for region, async_result in async_results.iteritems():
try:
region_nodes = async_result.get(timeout=timeout)
if region_nodes:
result.append(region_nodes)
except gevent.timeout.Timeout:
async_result.kill()
msg = 'platform: {platform}, region: {region}, env_id: {env_id}, reason: timeout'
msg = msg.format(platform=cred.platform, region=region, env_id=cred.env_id)
LOG.warning(msg)
return result