From 88a4aa3733017c94839079702708b0b701d5c4c9 Mon Sep 17 00:00:00 2001
From: Roma Koshel <roman@scalr.com>
Date: Wed, 18 Mar 2015 11:03:41 +0300
Subject: [PATCH] * change logging, code format

---
 app/python/scalrpy/util/szr_api.py | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/app/python/scalrpy/util/szr_api.py b/app/python/scalrpy/util/szr_api.py
index ac56988..1863b74 100644
--- a/app/python/scalrpy/util/szr_api.py
+++ b/app/python/scalrpy/util/szr_api.py
@@ -19,7 +19,6 @@ def get_cpu_stat(hsp, api_type='linux', timeout=5):
     return cpu
 
 
-
 def get_la_stat(hsp, api_type='linux', timeout=5):
     assert_msg = "Unsupported API type '%s' for LA stat" % api_type
     assert api_type == 'linux', assert_msg
@@ -31,12 +30,10 @@ def get_la_stat(hsp, api_type='linux', timeout=5):
     }
 
 
-
 class APIError(Exception):
     pass
 
 
-
 def get_mem_info(hsp, api_type='linux', timeout=5):
     mem = hsp.sysinfo.mem_info(timeout=timeout)
     if api_type == 'linux':
@@ -63,7 +60,6 @@ def get_mem_info(hsp, api_type='linux', timeout=5):
     return ret
 
 
-
 def get_net_stat(hsp, api_type='linux', timeout=5):
     net = hsp.sysinfo.net_stats(timeout=timeout)
     if api_type == 'linux':
@@ -82,8 +78,8 @@ def get_net_stat(hsp, api_type='linux', timeout=5):
                 break
         else:
             msg = (
-                    "Can't find ['^.* Ethernet Adapter.*$', '^.*AWS PV Network Device.*$'] "
-                    "pattern in api response for endpoint: {0}, available: {1}, use {2}"
+                "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]
@@ -96,7 +92,6 @@ def get_net_stat(hsp, api_type='linux', timeout=5):
     return ret
 
 
-
 def get_io_stat(hsp, api_type='linux', timeout=5):
     assert_msg = "Unsupported API type '%s' for IO stat" % api_type
     assert api_type == 'linux', assert_msg
@@ -118,7 +113,6 @@ def get_io_stat(hsp, api_type='linux', timeout=5):
     return ret
 
 
-
 def get_metrics(host, port, key, api_type, metrics, headers=None, timeout=5):
     assert host, 'host'
     assert port, 'port'
@@ -141,9 +135,14 @@ def get_metrics(host, port, key, api_type, metrics, headers=None, timeout=5):
         try:
             data.update({metric: getters[metric](hsp, api_type, timeout=timeout)})
         except (urllib2.URLError, urllib2.HTTPError, socket.timeout):
-            raise
+            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: %s, metric '%s' failed: %s" % (endpoint, metric, helper.exc_info())
+            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
-- 
2.2.2

