Xos Auto-scaling app changes (partial)
diff --git a/xos/configurations/cord/ceilometer.yaml b/xos/configurations/cord/ceilometer.yaml
index 5384b4f..82e697a 100644
--- a/xos/configurations/cord/ceilometer.yaml
+++ b/xos/configurations/cord/ceilometer.yaml
@@ -51,6 +51,9 @@
     mysite:
       type: tosca.nodes.Site
 
+    trusty-server-multi-nic:
+      type: tosca.nodes.Image
+
     mysite_ceilometer:
       description: Ceilometer Proxy Slice
       type: tosca.nodes.Slice
@@ -61,6 +64,11 @@
           - site:
               node: mysite
               relationship: tosca.relationships.MemberOfSite
+          - default_image:
+                node: trusty-server-multi-nic
+                relationship: tosca.relationships.DefaultImage
+      properties:
+          default_flavor: m1.small
 
     my_ceilometer_tenant:
       description: Ceilometer Service default Tenant
diff --git a/xos/core/xoslib/methods/ceilometerview.py b/xos/core/xoslib/methods/ceilometerview.py
index 5e0ac35..a65bd11 100644
--- a/xos/core/xoslib/methods/ceilometerview.py
+++ b/xos/core/xoslib/methods/ceilometerview.py
@@ -1078,6 +1078,18 @@
         query.append({"field": "meter", "op": "eq", "value": meter_name})
         samples = sample_list(request, meter_name,
                            ceilometer_url=tenant_ceilometer_url, query=query, limit=limit) 
+        if samples:
+            tenant_map = getTenantControllerTenantMap(request.user)
+            resource_map = get_resource_map(request, ceilometer_url=tenant_ceilometer_url)
+            for sample in samples:
+                 if sample["project_id"] in tenant_map.keys():
+                     sample["slice"] = tenant_map[sample["project_id"]]["slice"]
+                 else:
+                     sample["slice"] = sample["project_id"]
+                 if sample["resource_id"] in resource_map.keys():
+                     sample["resource_name"] = resource_map[sample["resource_id"]]
+                 else:
+                     sample["resource_name"] = sample["resource_id"]
         return Response(samples)
 
 class ServiceAdjustScale(APIView):
@@ -1085,7 +1097,7 @@
     method_name = "serviceadjustscale"
 
     def get(self, request, format=None):
-        if (not request.user.is_authenticated()) or (not request.user.is_admin()):
+        if (not request.user.is_authenticated()) or (not request.user.is_admin):
             raise PermissionDenied("You must be authenticated admin user in order to use this API")
         service = request.QUERY_PARAMS.get('service', None)
         slice_hint = request.QUERY_PARAMS.get('slice_hint', None)
@@ -1097,5 +1109,5 @@
         if not services or (not services.get(name=service)):
             raise XOSMissingField("Service not found")
         service = services.get(name=service)
-        service.adjust_scale(slice_hint, scale)
+        service.adjust_scale(slice_hint, int(scale))
         return Response("Success")
diff --git a/xos/observers/monitoring_channel/templates/ceilometer_pub_sub_consumer.py b/xos/observers/monitoring_channel/templates/ceilometer_pub_sub_consumer.py
index ecbabb9..7d111e3 100644
--- a/xos/observers/monitoring_channel/templates/ceilometer_pub_sub_consumer.py
+++ b/xos/observers/monitoring_channel/templates/ceilometer_pub_sub_consumer.py
@@ -7,6 +7,8 @@
 import time, thread, threading
 
 projects_map = {}
+xos_tenant_info_map = {}
+xos_instances_info_map = {}
 
 UDP_IP = "0.0.0.0"
 UDP_PORT = 12346
@@ -43,10 +45,10 @@
    print ""
    print ""
    for project in projects_map.keys():
-        print "project=%s, alarm_state=%s" % (project, projects_map[project]['alarm'])
+        print "service=%s slice=%s, alarm_state=%s" % (projects_map[project]['xos_tenant_info']['service'] if projects_map[project]['xos_tenant_info'] else None, projects_map[project]['xos_tenant_info']['slice'] if projects_map[project]['xos_tenant_info'] else project, projects_map[project]['alarm'])
         for resource in projects_map[project]['resources'].keys():
-             print "resource=%s" % resource
-             for i in projects_map[project]['resources'][resource]:
+             print "resource=%s" % (projects_map[project]['resources'][resource]['xos_instance_info']['instance_name'] if projects_map[project]['resources'][resource]['xos_instance_info'] else resource)
+             for i in projects_map[project]['resources'][resource]['queue']:
                   print "    time=%s val=%s" % ( i['timestamp'],i['counter_volume'])
 
 def periodic_print():
@@ -64,23 +66,51 @@
 SCALE_UP_ALARM = 'scale_up'
 SCALE_DOWN_ALARM = 'scale_down'
 
-def getXosTenantInfo(project):
-    print "SRIKANTH: Getting XOS info for openstack Project %s" % project
+def loadAllXosTenantInfo():
+    print "SRIKANTH: Loading all XOS tenant info"
     url = "http://ctl:9999/xos/controllerslices/"
     admin_auth=("padmin@vicci.org", "letmein")   # use your XOS username and password
     controller_slices = requests.get(url, auth=admin_auth).json()
     for cslice in controller_slices:
-         if cslice['tenant_id'] == project:
-             print "SRIKANTH: Matching controller_slice=%s" % cslice['humanReadableName']
-             slice = requests.get(cslice['slice'], auth=admin_auth).json()
-             slice_name = slice['humanReadableName']
-             print "SRIKANTH: Matching slice=%s" % slice_name
+         slice = requests.get(cslice['slice'], auth=admin_auth).json()
+         slice_name = slice['humanReadableName']
+         if slice['service']:
              service = requests.get(slice['service'], auth=admin_auth).json()
              service_name = service['humanReadableName']
-             print "SRIKANTH: Matching service=%s" % service_name
-             return {'service':service_name, 'slice':slice_name}
-    logger.warn("SRIKANTH: Project %(project)s has no associated XOS slice" % {'project':project})
-    return None
+         else:
+             service_name = None
+         xos_tenant_info_map[cslice['tenant_id']] = {'service':service_name, 'slice':slice_name}
+         print "SRIKANTH: Project: %s Service:%s Slice:%s" % (cslice['tenant_id'],service_name,slice_name)
+
+def loadAllXosInstanceInfo():
+    print "SRIKANTH: Loading all XOS instance info"
+    url = "http://130.127.133.87:9999/xos/instances/"
+    admin_auth=("padmin@vicci.org", "letmein")   # use your XOS username and password
+    xos_instances = requests.get(url, auth=admin_auth).json()
+    for instance in xos_instances:
+         xos_instances_info_map[instance['instance_uuid']] = {'instance_name':instance['instance_name']}
+
+def getXosTenantInfo(project):
+    xos_tenant_info = xos_tenant_info_map.get(project, None)
+    if xos_tenant_info:
+        return xos_tenant_info
+    else:
+        loadAllXosTenantInfo()
+        xos_tenant_info = xos_tenant_info_map.get(project, None)
+        if not xos_tenant_info:
+            print "SRIKANTH: Project %s has no associated XOS slice" % project
+        return xos_tenant_info
+
+def getXosInstanceInfo(resource):
+    xos_instance_info = xos_instances_info_map.get(resource, None)
+    if xos_instance_info:
+        return xos_instance_info
+    else:
+        loadAllXosInstanceInfo()
+        xos_instance_info = xos_instances_info_map.get(resource, None)
+        if not xos_instance_info:
+            print "SRIKANTH: Resource %s has no associated XOS instance" % project
+        return xos_instance_info
 
 def handle_adjust_scale(project, adjust):
     if (adjust != 'up') and (adjust != 'down'):
@@ -93,7 +123,8 @@
     if (current_instances >=2 and adjust == 'up'):
         print "SRIKANTH: %s is running with already maximum instances and can not scale up further " % project
         return
-    xos_tenant = getXosTenantInfo(project)
+    #xos_tenant = getXosTenantInfo(project)
+    xos_tenant = projects_map[project]['xos_tenant_info']
     if not xos_tenant:
         print "SRIKANTH: Can not handle adjust_scale for Project %s because not associated with any slice" % project
         return
@@ -111,8 +142,8 @@
 
 def periodic_cpu_threshold_evaluator():
      for project in projects_map.keys():
-          aggregate_cpu_util = sum([resource_queue[-1]['counter_volume'] \
-                                     for resource_queue in projects_map[project]['resources'].values()]) \
+          aggregate_cpu_util = sum([resource['queue'][-1]['counter_volume'] \
+                                     for resource in projects_map[project]['resources'].values()]) \
                                      /len(projects_map[project]['resources'].keys())
 
           if (projects_map[project]['alarm'] == INITIAL_STATE or
@@ -172,14 +203,17 @@
               continue
          if sample['project_id'] not in projects_map.keys():
               projects_map[sample['project_id']] = {}
+              projects_map[sample['project_id']]['xos_tenant_info'] = getXosTenantInfo(sample['project_id'])
               projects_map[sample['project_id']]['resources'] = {}
               projects_map[sample['project_id']]['uthreadshold_count'] = 0
               projects_map[sample['project_id']]['lthreadshold_count'] = 0
               projects_map[sample['project_id']]['alarm'] = INITIAL_STATE
          resource_map = projects_map[sample['project_id']]['resources']
          if sample['resource_id'] not in resource_map.keys():
-              resource_map[sample['resource_id']] = collections.deque(maxlen=10)
-         samples_map = resource_map[sample['resource_id']]
+              resource_map[sample['resource_id']] = {}
+              resource_map[sample['resource_id']]['xos_instance_info'] = getXosInstanceInfo(sample['resource_id'])
+              resource_map[sample['resource_id']]['queue'] = collections.deque(maxlen=10)
+         samples_map = resource_map[sample['resource_id']]['queue']
          sample = {'counter_name':sample['counter_name'],
                    'project_id':sample['project_id'],
                    'resource_id':sample['resource_id'],
@@ -195,6 +229,8 @@
    if not monitoring_channel:
         print 'SRIKANTH: XOS monitoring_channel is not created... Create it before using this app'
         return
+   loadAllXosTenantInfo()
+   loadAllXosInstanceInfo()
    thread.start_new(read_notification_from_ceilometer,(UDP_IP,UDP_PORT,))
    ceilometer_url = monitoring_channel['ceilometer_url']
    subscribe_data = {"sub_info":"cpu_util","app_id":"xos_auto_scale","target":"udp://10.11.10.1:12346"}
diff --git a/xos/tosca/samples/helloworld-chain.yaml b/xos/tosca/samples/helloworld-chain.yaml
index c72aa3d..8959f7f 100644
--- a/xos/tosca/samples/helloworld-chain.yaml
+++ b/xos/tosca/samples/helloworld-chain.yaml
@@ -16,6 +16,9 @@
     mysite:
       type: tosca.nodes.Site
 
+    trusty-server-multi-nic:
+      type: tosca.nodes.Image
+
     service_vcpe:
       type: tosca.nodes.Service
       requirements:
@@ -50,6 +53,11 @@
           - site:
               node: mysite
               relationship: tosca.relationships.MemberOfSite
+          - default_image:
+                node: trusty-server-multi-nic
+                relationship: tosca.relationships.DefaultImage
+      properties:
+          default_flavor: m1.small
 
     helloworld_access:
       type: tosca.nodes.network.Network