pep8 added, lab_id and build_id added as a parameters to storage_api.load_data, additional params added to params combination
diff --git a/persistance/db_manage.py b/persistance/db_manage.py
index 118fe44..b9435d6 100644
--- a/persistance/db_manage.py
+++ b/persistance/db_manage.py
@@ -6,14 +6,10 @@
 import sys
 
 from os import remove
-
 from web_app.app import db
+from config import DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, basedir
 from migrate.versioning import api
 
-from config import basedir
-from config import DATABASE_URI
-from config import SQLALCHEMY_MIGRATE_REPO
-
 
 ACTIONS = {}
 
@@ -101,4 +97,4 @@
 
 
 if __name__ == '__main__':
-    exit(main(sys.argv[1:]))
\ No newline at end of file
+    exit(main(sys.argv[1:]))
diff --git a/persistance/keystone.py b/persistance/keystone.py
deleted file mode 100644
index e6308b5..0000000
--- a/persistance/keystone.py
+++ /dev/null
@@ -1,89 +0,0 @@
-from functools import partial
-import json
-import urllib2
-from keystoneclient.v2_0 import Client as keystoneclient
-from keystoneclient import exceptions
-
-
-class Urllib2HTTP(object):
-    """
-    class for making HTTP requests
-    """
-
-    allowed_methods = ('get', 'put', 'post', 'delete', 'patch', 'head')
-
-    def __init__(self, root_url, headers=None, echo=False):
-        """
-        """
-        if root_url.endswith('/'):
-            self.root_url = root_url[:-1]
-        else:
-            self.root_url = root_url
-
-        self.headers = headers if headers is not None else {}
-        self.echo = echo
-
-    def do(self, method, path, params=None):
-        if path.startswith('/'):
-            url = self.root_url + path
-        else:
-            url = self.root_url + '/' + path
-
-        if method == 'get':
-            assert params == {} or params is None
-            data_json = None
-        else:
-            data_json = json.dumps(params)
-
-        request = urllib2.Request(url,
-                                  data=data_json,
-                                  headers=self.headers)
-        if data_json is not None:
-            request.add_header('Content-Type', 'application/json')
-
-        request.get_method = lambda: method.upper()
-        response = urllib2.urlopen(request)
-
-        if response.code < 200 or response.code > 209:
-            raise IndexError(url)
-
-        content = response.read()
-
-        if '' == content:
-            return None
-
-        return json.loads(content)
-
-    def __getattr__(self, name):
-        if name in self.allowed_methods:
-            return partial(self.do, name)
-        raise AttributeError(name)
-
-
-class KeystoneAuth(Urllib2HTTP):
-    def __init__(self, root_url, creds, headers=None, echo=False,
-                 admin_node_ip=None):
-        super(KeystoneAuth, self).__init__(root_url, headers, echo)
-        self.keystone_url = "http://{0}:5000/v2.0".format(admin_node_ip)
-        self.keystone = keystoneclient(
-            auth_url=self.keystone_url, **creds)
-        self.refresh_token()
-
-    def refresh_token(self):
-        """Get new token from keystone and update headers"""
-        try:
-            self.keystone.authenticate()
-            self.headers['X-Auth-Token'] = self.keystone.auth_token
-        except exceptions.AuthorizationFailure:
-            print 'asdfsf'
-
-    def do(self, method, path, params=None):
-        """Do request. If gets 401 refresh token"""
-        try:
-            return super(KeystoneAuth, self).do(method, path, params)
-        except urllib2.HTTPError as e:
-            if e.code == 401:
-                self.refresh_token()
-                return super(KeystoneAuth, self).do(method, path, params)
-            else:
-                raise
diff --git a/persistance/models.py b/persistance/models.py
index f2b7c35..eb632e4 100644
--- a/persistance/models.py
+++ b/persistance/models.py
@@ -25,6 +25,23 @@
     param_1 = db.Column(db.Text())
     param_2 = db.Column(db.Text())
     param_3 = db.Column(db.Text())
+    param_4 = db.Column(db.Text())
+    param_5 = db.Column(db.Text())
+    param_6 = db.Column(db.Text())
+    param_7 = db.Column(db.Text())
+    param_8 = db.Column(db.Text())
+    param_9 = db.Column(db.Text())
+    param_10 = db.Column(db.Text())
+    param_11 = db.Column(db.Text())
+    param_12 = db.Column(db.Text())
+    param_13 = db.Column(db.Text())
+    param_14 = db.Column(db.Text())
+    param_15 = db.Column(db.Text())
+    param_16 = db.Column(db.Text())
+    param_17 = db.Column(db.Text())
+    param_18 = db.Column(db.Text())
+    param_19 = db.Column(db.Text())
+    param_20 = db.Column(db.Text())
 
     def __repr__(self):
         return self.param_1 + " " + self.param_2 + " " + self.param_3
@@ -46,7 +63,8 @@
     build_id = db.Column(db.Integer, ForeignKey('build.id'))
     lab_id = db.Column(db.Integer, ForeignKey('lab.id'))
     date = db.Column(db.DateTime)
-    param_combination_id = db.Column(db.Integer, ForeignKey('param_combination.id'))
+    param_combination_id = db.Column(db.Integer,
+                                     ForeignKey('param_combination.id'))
     bandwith = db.Column(db.Float)
     meta = db.Column(db.String(4096))
 
diff --git a/persistance/storage_api.py b/persistance/storage_api.py
index a1503d4..7394c6a 100644
--- a/persistance/storage_api.py
+++ b/persistance/storage_api.py
@@ -1,14 +1,13 @@
 import datetime
 import math
-from urlparse import urlparse
-
 from flask import json
-from persistance.keystone import KeystoneAuth
+from meta_info import collect_lab_data, total_lab_info
 from sqlalchemy import sql
 from persistance.models import *
 
 
-#class displays measurement. Moved from storage_api_v_1 to avoid circular imports.
+# class displays measurement. Moved from storage_api_v_1
+# to avoid circular imports.
 class Measurement(object):
     def __init__(self):
         self.build = ""
@@ -36,75 +35,10 @@
     return math.sqrt(sum(map(lambda x: (x - m) ** 2, l)))
 
 
-
-def total_lab_info(data):
-    # <koder>: give 'd' meaningful name
-    d = {}
-    d['nodes_count'] = len(data['nodes'])
-    d['total_memory'] = 0
-    d['total_disk'] = 0
-    d['processor_count'] = 0
-
-    for node in data['nodes']:
-        d['total_memory'] += node['memory']['total']
-        d['processor_count'] += len(node['processors'])
-
-        for disk in node['disks']:
-            d['total_disk'] += disk['size']
-
-    to_gb = lambda x: x / (1024 ** 3)
-    d['total_memory'] = format(to_gb(d['total_memory']), ',d')
-    d['total_disk'] = format(to_gb(d['total_disk']), ',d')
-    return d
-
-
-def collect_lab_data(url, cred):
-    u = urlparse(url)
-    keystone = KeystoneAuth(root_url=url, creds=cred, admin_node_ip=u.hostname)
-    lab_info = keystone.do(method='get', path="/api/nodes")
-    fuel_version = keystone.do(method='get', path="/api/version/")
-
-    nodes = []
-    result = {}
-
-    for node in lab_info:
-        # <koder>: give p,i,d,... vars meaningful names
-        d = {}
-        d['name'] = node['name']
-        p = []
-        i = []
-        disks = []
-        devices = []
-
-        for processor in node['meta']['cpu']['spec']:
-             p.append(processor)
-
-        for iface in node['meta']['interfaces']:
-            i.append(iface)
-
-        m = node['meta']['memory'].copy()
-
-        for disk in node['meta']['disks']:
-            disks.append(disk)
-
-        d['memory'] = m
-        d['disks'] = disks
-        d['devices'] = devices
-        d['interfaces'] = i
-        d['processors'] = p
-
-        nodes.append(d)
-
-    result['nodes'] = nodes
-    # result['name'] = 'Perf-1 Env'
-    result['fuel_version'] = fuel_version['release']
-
-    return result
-
-
 def get_build_info(build_name):
     session = db.session()
-    result = session.query(Result, Build).join(Build).filter(Build.name == build_name).first()
+    result = session.query(Result, Build).join(Build).\
+        filter(Build.name == build_name).first()
     lab = session.query(Lab).filter(Lab.id == result[0].lab_id).first()
     return eval(lab.lab_general_info)
 
@@ -122,11 +56,16 @@
             build[item[0]] = [m, s]
 
 
-#filling Param table with initial parameters.
+# filling Param table with initial parameters.
 def add_io_params(session):
-    param1 = Param(name="operation", type='{"write", "randwrite", "read", "randread"}', descr="type of write operation")
-    param2 = Param(name="sync", type='{"a", "s"}', descr="Write mode synchronous/asynchronous")
-    param3 = Param(name="block size", type='{"1k", "2k", "4k", "8k", "16k", "32k", "64k", "128k", "256k"}')
+    param1 = Param(name="operation", type='{"write", "randwrite", '
+                                          '"read", "randread"}',
+                   descr="type of write operation")
+    param2 = Param(name="sync", type='{"a", "s"}',
+                   descr="Write mode synchronous/asynchronous")
+    param3 = Param(name="block size",
+                   type='{"1k", "2k", "4k", "8k", "16k", '
+                        '"32k", "64k", "128k", "256k"}')
 
     session.add(param1)
     session.add(param2)
@@ -135,27 +74,30 @@
     session.commit()
 
 
-#function which adds particular build to database.
+# function which adds particular build to database.
 def add_build(session, build_id, build_name, build_type, md5):
-    build = Build(type=build_type, build_id=build_id, name=build_name, md5=md5)
+    build = Build(type=build_type, build_id=build_id,
+                  name=build_name, md5=md5)
     session.add(build)
     session.commit()
 
     return build.id
 
 
-#function insert particular result.
+# function insert particular result.
 def insert_results(session, build_id, lab_id, params_combination_id,
                    time=None, bandwith=0.0, meta=""):
-    result = Result(build_id=build_id, lab_id=lab_id, params_combination_id=params_combination_id, time=time,
+    result = Result(build_id=build_id, lab_id=lab_id,
+                    params_combination_id=params_combination_id, time=time,
                     bandwith=bandwith, meta=meta)
     session.add(result)
     session.commit()
 
 
-#function responsible for adding particular params combination to database
+# function responsible for adding particular params combination to database
 def add_param_comb(session, *params):
-    params_names = sorted([s for s in dir(ParamCombination) if s.startswith('param_')])
+    params_names = sorted([s for s in dir(ParamCombination)
+                           if s.startswith('param_')])
     d = zip(params_names, params)
     where = ""
 
@@ -165,20 +107,20 @@
     query = session.query(ParamCombination).filter(where)
     rs = session.execute(query).fetchall()
 
-
     if len(rs) == 0:
         param_comb = ParamCombination()
 
         for p in params_names:
             i = int(p.split('_')[1])
-            param_comb.__setattr__('param_' + str(i), params[i - 1])
 
-            param = session.query(Param).filter(Param.id == i).one()
-            values = eval(param.type)
+            if i - 1 < len(params):
+                param_comb.__setattr__('param_' + str(i), params[i - 1])
+                param = session.query(Param).filter(Param.id == i).one()
+                values = eval(param.type)
 
-            if params[i - 1] not in values:
-                values.add(params[i - 1])
-                param.type = str(values)
+                if params[i - 1] not in values:
+                    values.add(params[i - 1])
+                    param.type = str(values)
 
         session.add(param_comb)
         session.commit()
@@ -187,19 +129,22 @@
         return rs[0][0]
 
 
-def add_lab(session, lab_url, lab_name, ceph_version, fuel_version, data, info):
+def add_lab(session, lab_url, lab_name, ceph_version,
+            fuel_version, data, info):
     result = session.query(Lab).filter(Lab.name == lab_name).all()
 
     if len(result) != 0:
         return result[0].id
     else:
         lab = Lab(name=lab_name, url=lab_url, ceph_version=ceph_version,
-                  fuel_version=fuel_version, lab_general_info=str(data), lab_meta=str(info))
+                  fuel_version=fuel_version, lab_general_info=str(data),
+                  lab_meta=str(info))
         session.add(lab)
         session.commit()
         return lab.id
 
-#function store list of builds in database
+
+# function store list of builds in database
 def add_data(data):
     data = json.loads(data)
     session = db.session()
@@ -212,10 +157,11 @@
                              build_data.pop("type"),
                              build_data.pop("iso_md5"),
                              )
+
         creds = {"username": build_data.pop("username"),
                  "password": build_data.pop("password"),
-                 "tenant_name": build_data.pop("tenant_name")
-        }
+                 "tenant_name": build_data.pop("tenant_name")}
+
         lab_url = build_data.pop("lab_url")
         lab_name = build_data.pop("lab_name")
         ceph_version = build_data.pop("ceph_version")
@@ -223,23 +169,27 @@
         data['name'] = lab_name
         info = total_lab_info(data)
         lab_id = add_lab(session, lab_url=lab_name, lab_name=lab_url,
-                ceph_version=ceph_version, fuel_version=data['fuel_version'], data=data, info=info)
+                         ceph_version=ceph_version,
+                         fuel_version=data['fuel_version'],
+                         data=data, info=info)
 
         date = build_data.pop("date")
         date = datetime.datetime.strptime(date, "%a %b %d %H:%M:%S %Y")
 
         for params, [bw, dev] in build_data.items():
             param_comb_id = add_param_comb(session, *params.split(" "))
-            result = Result(param_combination_id=param_comb_id, build_id=build_id,
-                            bandwith=bw, date=date, lab_id=lab_id)
+            result = Result(param_combination_id=param_comb_id,
+                            build_id=build_id, bandwith=bw,
+                            date=date, lab_id=lab_id)
             session.add(result)
             session.commit()
 
 
-#function loads data by parametres described in *params tuple.
-def load_data(*params):
+# function loads data by parameters described in *params tuple.
+def load_data(lab_id=None, build_id=None, *params):
     session = db.session()
-    params_names = sorted([s for s in dir(ParamCombination) if s.startswith('param_')])
+    params_names = sorted([s for s in dir(ParamCombination)
+                           if s.startswith('param_')])
     d = zip(params_names, params)
     where = ""
 
@@ -251,22 +201,28 @@
 
     ids = [r[0] for r in rs]
 
-    results = session.query(Result).filter(Result.param_combination_id.in_(ids))
-    rs = session.execute(results).fetchall()
+    rs = session.query(Result).\
+        filter(Result.param_combination_id.in_(ids)).all()
 
-    return [r[5] for r in rs]
+    if lab_id is not None:
+        rs = [r for r in rs if r.lab_id == lab_id]
+
+    if build_id is not None:
+        rs = [r for r in rs if r.build_id == build_id]
+
+    return rs
 
 
-#load all builds from database
+# load all builds from database
 def load_all():
     session = db.session()
-    r = session.query(Param).filter(Param.id == 1).all()
-    results = session.query(Result, Build, ParamCombination).join(Build).join(ParamCombination).all()
+    results = session.query(Result, Build, ParamCombination).\
+        join(Build).join(ParamCombination).all()
 
     return results
 
 
-#function collecting all builds from database and filter it by names
+# function collecting all builds from database and filter it by names
 def collect_builds_from_db(*names):
     results = load_all()
     d = {}
@@ -277,7 +233,8 @@
         param_combination_data = item[2]
 
         if build_data.name not in d:
-            d[build_data.name] = [build_data, result_data, param_combination_data]
+            d[build_data.name] = \
+                [build_data, result_data, param_combination_data]
         else:
             d[build_data.name].append(result_data)
             d[build_data.name].append(param_combination_data)
@@ -288,7 +245,7 @@
     return {k: v for k, v in d.items() if k in names}
 
 
-#function creates measurement from data was extracted from database.
+# function creates measurement from data was extracted from database.
 def create_measurement(data):
     build_data = data[0]
 
@@ -323,11 +280,11 @@
     if build.type == 'GA':
         names = [build_name]
     else:
-        res = session.query(Build).filter(Build.type.in_(['GA', 'master', build.type])).all()
+        res = session.query(Build).\
+            filter(Build.type.in_(['GA', 'master', build.type])).all()
         for r in res:
             names.append(r.name)
 
-
     d = collect_builds_from_db()
     d = {k: v for k, v in d.items() if k in names}
     results = {}
@@ -362,10 +319,11 @@
     return res
 
 
-#Processing data from database.
-#List of dicts, where each dict contains build meta info and kev-value measurements.
-#key - param combination.
-#value - [mean, deviation]
+# Processing data from database.
+# List of dicts, where each dict contains build meta
+# info and kev-value measurements.
+# key - param combination.
+# value - [mean, deviation]
 def get_builds_data(names=None):
     d = collect_builds_from_db()
 
@@ -400,20 +358,21 @@
     return output
 
 
-#Function for getting result to display table
+# Function for getting result to display table
 def get_data_for_table(build_name=""):
     session = db.session()
     build = session.query(Build).filter(Build.name == build_name).one()
     names = []
 
-    #Get names of build that we need.
+    # Get names of build that we need.
     if build.type == 'GA':
         names = [build_name]
     else:
-        res = session.query(Build).filter(Build.type.in_(['GA', 'master', build.type])).all()
+        res = session.query(Build).filter(
+            Build.type.in_(['GA', 'master', build.type])).all()
         for r in res:
             names.append(r.name)
-    #get data for particular builds.
+    # get data for particular builds.
     return get_builds_data(names)
 
 
@@ -533,10 +492,5 @@
     }]'
 
     # json_to_db(json_data)
-    # print load_data()
-    add_data(json_data)
-
-    print collect_builds_from_db()
-    print prepare_build_data('6.1 Dev')
-    print builds_list()
-    print get_data_for_table('somedev')
\ No newline at end of file
+    print load_data(1, 2)
+    # add_data(json_data)