Index: /branches/amp_4_0/platform/config/init_db.sql
===================================================================
--- /branches/amp_4_0/platform/config/init_db.sql	(revision 2689)
+++ /branches/amp_4_0/platform/config/init_db.sql	(working copy)
@@ -423,4 +423,21 @@
     result TEXT DEFAULT NULL,
     FOREIGN KEY (report_id) REFERENCES REPORT(id) ON DELETE CASCADE
 );
+
+CREATE TABLE public.host (
+    id               VARCHAR(64)   NOT NULL,
+    name             VARCHAR(32)   NOT NULL,
+    ip               VARCHAR(64)   NOT NULL,
+    restapi_port     INTEGER       NOT NULL DEFAULT 9997,
+    restapi_username VARCHAR(16)   NOT NULL,
+    restapi_password VARCHAR(256)  NOT NULL,
+    connection       VARCHAR(16)   NOT NULL DEFAULT 'Unconnected',
+    version          VARCHAR(8192) DEFAULT NULL,
+    vm_number        INTEGER       NOT NULL DEFAULT 0,
+    cpu_usage        NUMERIC       NOT NULL DEFAULT 0.0,
+    mem_usage        NUMERIC       NOT NULL DEFAULT 0.0,
+    disk_usage       NUMERIC       NOT NULL DEFAULT 0.0,
+    CONSTRAINT host_pkey PRIMARY KEY (id),
+    CONSTRAINT host_name_key UNIQUE (name)
+);
 -- psql -U amp_admin -d cm -f /path/to/your/init_db.sql
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/cm/models/virtualization/__init__.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/cm/models/virtualization/__init__.py	(revision 2689)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/cm/models/virtualization/__init__.py	(working copy)
@@ -1,3 +1,6 @@
+import uuid
+import json
+
 from django.db.models.query import QuerySet
 from django.utils.translation import gettext_lazy as _
 
@@ -9,6 +12,8 @@
 from hive.model.action import Action
 from hive.model.fields import *
 from hive.model.manager import CLIManager
+from hive.model.legacycli import cli_parse, RegexParser, MATCHONE, CLICmdError
+from hive.exceptions import ModelQueryException
 
 __ = _
 
@@ -73,68 +78,92 @@
     class Manager(CLIManager):
         def _get_query_set(self):
             db = DB.get_connected_db()
-            fetchall_sql = '''SELECT id, name, ip, restapi_port, restapi_username, restapi_password, connection, version, vm_number, cpu_usage, mem_usage, disk_usage FROM host'''
-            data = db.fetchall(fetchall_sql)
+            sql = '''
+                SELECT id, name, ip, restapi_port, restapi_username, restapi_password,
+                       connection, version, vm_number, cpu_usage, mem_usage, disk_usage
+                FROM host
+            '''
+            rows = db.fetchall(sql)  # returns list of tuples
             db.close()
-            key = ['id', 'name', 'ip', 'restapi_port', 'restapi_username', 'restapi_password', 'connection', 'version',
-                   'vm_number', 'cpu_usage', 'memory_usage', 'disk_usage']
-            result = [dict(zip(key, each)) for each in data]
-            for each in result:
-                each['cpu_usage'] = float(each['cpu_usage'])
-                each['memory_usage'] = float(each['memory_usage'])
-                each['disk_usage'] = float(each['disk_usage'])
-                each['restapi_account'] = {'restapi_username': each['restapi_username'],
-                                           'restapi_password': each['restapi_password']}
-                del each['restapi_username']
-                del each['restapi_password']
-                # each['console_account'] = {'console_username':each['console_username'], 'console_password':each['console_password']}
-                # del each['console_username']
-                # del each['console_password']
-                if each['version']:
-                    replace_result = each['version'].replace('\\n', '\n')
-                    rtn = cli_parse(replace_result, [
-                        RegexParser('Host name : (.+?)\n', MATCHONE),
-                        RegexParser('System CPU : (.+?)\n', MATCHONE),
-                        RegexParser('System RAM : (.+?)\n', MATCHONE),
-                        RegexParser('System boot time : (.+?)\n', MATCHONE),
-                        RegexParser('System up time : (.+?)\n', MATCHONE),
-                        RegexParser('Platform Bld Date : (.+?)\n', MATCHONE),
-                        RegexParser('SSL HW : (.+?)\n', MATCHONE),
-                        RegexParser('Compression HW : (.+?)\n', MATCHONE),
-                        RegexParser('Power supply : (.+?)\n', MATCHONE),
-                        RegexParser('Network Interface : (.+?)\n', MATCHONE),
-                        RegexParser('Model : (.+?)\n', MATCHONE),
-                        RegexParser('Serial Number : (.+?)\n', MATCHONE),
-                        RegexParser('License Key : (.*?)\n', MATCHONE),
-                        RegexParser('Expiration Date : (.*?)\n', MATCHONE),
-                        RegexParser('(AVX.+?)\n', MATCHONE),
+
+            # Columns in the same order as the SELECT
+            cols = [
+                'id', 'name', 'ip', 'restapi_port', 'restapi_username', 'restapi_password',
+                'connection', 'version', 'vm_number', 'cpu_usage', 'mem_usage', 'disk_usage'
+            ]
+
+            hosts = []
+
+            for each in rows:
+                row = dict(zip(cols, each))
+
+                host = Host()
+
+                # Base Settings
+                host.id = row.get('id') or ''
+                host.name = row.get('name') or ''
+                host.ip = row.get('ip') or ''
+                host.restapi_port = int(row.get('restapi_port') or 9997)
+                host.restapi_account = {
+                    'restapi_username': row.get('restapi_username') or '',
+                    'restapi_password': row.get('restapi_password') or '',
+                }
+                host.connection = row.get('connection') or 'Unconnected'
+                host.vm_number = int(row.get('vm_number') or 0)
+
+                # Metrics (mem_usage -> memory_usage in model)
+                host.cpu_usage = float(row.get('cpu_usage') or 0.0)
+                host.memory_usage = float(row.get('mem_usage') or 0.0)
+                host.disk_usage = float(row.get('disk_usage') or 0.0)
+
+                # Parse "version" text into stats fields (if present)
+                version_blob = row.get('version')
+                if version_blob:
+                    txt = version_blob.replace('\\n', '\n')
+                    rtn = cli_parse(txt, [
+                        RegexParser('Host name : (.+?)\\n', MATCHONE),
+                        RegexParser('System CPU : (.+?)\\n', MATCHONE),
+                        RegexParser('System RAM : (.+?)\\n', MATCHONE),
+                        RegexParser('System boot time : (.+?)\\n', MATCHONE),
+                        RegexParser('System up time : (.+?)\\n', MATCHONE),
+                        RegexParser('Platform Bld Date : (.+?)\\n', MATCHONE),
+                        RegexParser('SSL HW : (.+?)\\n', MATCHONE),
+                        RegexParser('Compression HW : (.+?)\\n', MATCHONE),
+                        RegexParser('Power supply : (.+?)\\n', MATCHONE),
+                        RegexParser('Network Interface : (.+?)\\n', MATCHONE),
+                        RegexParser('Model : (.+?)\\n', MATCHONE),
+                        RegexParser('Serial Number : (.+?)\\n', MATCHONE),
+                        RegexParser('License Key : (.*?)\\n', MATCHONE),
+                        RegexParser('Expiration Date : (.*?)\\n', MATCHONE),
+                        RegexParser('(AVX.+?)\\n', MATCHONE),
                     ])
-                    each['host_name'] = rtn[0][0] if rtn[0] else ''
-                    each['system_cpu'] = rtn[1][0] if rtn[1] else ''
-                    each['system_ram'] = rtn[2][0] if rtn[2] else ''
-                    each['system_boot_time'] = rtn[3][0] if rtn[3] else ''
-                    each['system_up_time'] = rtn[4][0] if rtn[4] else ''
-                    each['platform_bld_date'] = rtn[5][0] if rtn[5] else ''
-                    each['ssl_hw'] = rtn[6][0] if rtn[6] else ''
-                    each['compression_hw'] = rtn[7][0] if rtn[7] else ''
-                    each['power_supply'] = rtn[8][0] if rtn[8] else ''
-                    each['network_interface'] = rtn[9][0] if rtn[9] else ''
-                    each['model'] = rtn[10][0].split(',')[0] if rtn[10] else ''
-                    each['serial_number'] = rtn[11][0] if rtn[11] else ''
-                    each['license_key'] = rtn[12][0] if rtn[12] else ''
-                    each['license_date'] = rtn[13][0] if rtn[13] else ''
-                    each['build_version'] = rtn[14][0] if rtn[14] else ''
-                del each['version']
-                self._model._meta.mark_delay_query(each)
-            return QuerySet(self._model, result)
+                    host.host_name = rtn[0][0] if rtn[0] else ''
+                    host.system_cpu = rtn[1][0] if rtn[1] else ''
+                    host.system_ram = rtn[2][0] if rtn[2] else ''
+                    host.system_boot_time = rtn[3][0] if rtn[3] else ''
+                    host.system_up_time = rtn[4][0] if rtn[4] else ''
+                    host.platform_bld_date = rtn[5][0] if rtn[5] else ''
+                    host.ssl_hw = rtn[6][0] if rtn[6] else ''
+                    host.compression_hw = rtn[7][0] if rtn[7] else ''
+                    host.power_supply = rtn[8][0] if rtn[8] else ''
+                    host.network_interface = rtn[9][0] if rtn[9] else ''
+                    host.model = rtn[10][0].split(',')[0] if rtn[10]x else ''
+                    host.serial_number = rtn[11][0] if rtn[11] else ''
+                    host.license_key = rtn[12][0] if rtn[12] else ''
+                    host.license_date = rtn[13][0] if rtn[13] else ''
+                    host.build_version = rtn[14][0] if rtn[14] else ''
 
+                hosts.append(host)
+
+            return hosts
+
         def _get_stats(self):
             return self._get_query_set()
 
         def _insert(self, instance):
             data = instance.get_field_dict()
             data['id'] = uuid.uuid1()
-            data['ip'] = data['ip'].values()[0]
+            data['ip'] = next(iter(data['ip'].values()), None)
             data['restapi_username'] = data['restapi_account']['restapi_username']
             data['restapi_password'] = data['restapi_account']['restapi_password']
 
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/router.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/router.py	(revision 2691)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/router.py	(working copy)
@@ -546,29 +546,30 @@
     sess = get_current_session()
     manager = sess.get_model_manager('cm', ['virtualization', 'Host'])
     host_name = request.META.get('HTTP_CM_DATA', '')
+    req_path = request.path
     if host_name:
         host = manager.get({"id": host_name})
         cookie = ''
         if host:
             proxy_ip = host.ip
             if isinstance(proxy_ip, dict):
-                host_ip = proxy_ip.values()[0]
+                host_ip = next(iter(proxy_ip.values()), None)
             else:
                 host_ip = proxy_ip
-            if request.META['REQUEST_URI'][0:14] == '/proxy_req/api':
-                new_url = '/aest' + request.META['REQUEST_URI'][14:]
-            elif request.META['REQUEST_URI'][0:19] == '/proxy_req/composer':
-                new_url = request.META['REQUEST_URI'][10:]
+            if req_path.startswith('/proxy_req/api'):
+                new_url = '/aest' + req_path[len('/proxy_req/api'):]
+            elif req_path.startswith('/proxy_req/composer'):
+                new_url = req_path[len('/proxy_req'):]
                 cookie = 'ComposerUICookie=f1f713c9e000f5d3f280adbd124df4f5'
             else:
-                new_url = '/pest' + request.META['REQUEST_URI'][10:]
+                new_url = '/pest' + req_path[len('/proxy_req'):]
             rest_response_data = call_restapi(request.method, new_url, request.body, host_ip, host.restapi_port,
                                               host.restapi_account['restapi_username'],
                                               host.restapi_account['restapi_password'], 'https', cookie)
             return HttpResponse(rest_response_data["body"])
     else:
-        if request.META['REQUEST_URI'][0:17] == '/proxy_req/image/':
-            tmp_url = request.META['REQUEST_URI'][17:].split('/')
+        if req_path.startswith('/proxy_req/image/'):
+            tmp_url = req_path[len('/proxy_req/image/'):].split('/')
             new_url = "/" + "/".join(tmp_url[1:])
             host_name = tmp_url[0]
             host = manager.get({"id": host_name})
