[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/luci/site/luci/Extensions StorageReport.py



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	kupcevic sourceware org	2006-08-02 23:18:57

Modified files:
	luci/site/luci/Extensions: StorageReport.py 

Log message:
	luci: storage: pass plone context as self to all storage external methods (will be used for prefered size variables)

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/StorageReport.py.diff?cvsroot=cluster&r1=1.4&r2=1.5

--- conga/luci/site/luci/Extensions/StorageReport.py	2006/07/18 20:33:04	1.4
+++ conga/luci/site/luci/Extensions/StorageReport.py	2006/08/02 23:18:57	1.5
@@ -8,6 +8,7 @@
 from ricci_defines import *
 from PropsObject import PropsObject
 from conga_storage_constants import *
+from HelperFunctions import *
 
 from ricci_communicator import get_ricci_communicator
 
@@ -312,8 +313,8 @@
 
 
 
-def get_content_data(storage_report, mapper_id, bd_path, content_id):
-    bd_data = get_bd_data(storage_report, mapper_id, bd_path)
+def get_content_data(self, storage_report, mapper_id, bd_path, content_id):
+    bd_data = get_bd_data(self, storage_report, mapper_id, bd_path)
     for cont in bd_data['contents']:
         if cont['id'] == content_id:
             return cont
@@ -321,11 +322,11 @@
 
 
 
-def get_bd_data(storage_report, mapper_id, path):
+def get_bd_data(self, storage_report, mapper_id, path):
     if storage_report == None or mapper_id == None:
         return None
     
-    mapper = get_mapper_data(storage_report, mapper_id)
+    mapper = get_mapper_data(self, storage_report, mapper_id)
     if mapper == None:
         return None
     
@@ -341,7 +342,7 @@
 
 
 
-def get_mappers_data(storage_report):
+def get_mappers_data(self, storage_report):
     ret_dir = {}
     # mappers
     mappers_dir = storage_report.get_mappers_dir()
@@ -352,13 +353,13 @@
                 ret_dir[mapp_type] = {}
                 ret_dir[mapp_type]['mappers'] = []
                 ret_dir[mapp_type]['mapper_template'] = None
-            ret_dir[mapp_type]['mappers'].append(get_mapper_data(storage_report, id))
+            ret_dir[mapp_type]['mappers'].append(get_mapper_data(self, storage_report, id))
     # templates
     for mapp_type in storage_report.get_mapper_temps_dir():
         if mapp_type not in ret_dir:
             ret_dir[mapp_type] = {}
             ret_dir[mapp_type]['mappers'] = []
-        ret_dir[mapp_type]['mapper_template'] = get_mapper_template_data(storage_report, mapp_type)
+        ret_dir[mapp_type]['mapper_template'] = get_mapper_template_data(self, storage_report, mapp_type)
     
     # pretty stuff
     for mapp_type in ret_dir:
@@ -378,28 +379,30 @@
 
 
 
-def get_mapper_data(storage_report, mapper_id):
-    if storage_report == None or mapper_id == None:
+def get_mapper_data(self, storage_report, mapper_id):
+    if self == None or storage_report == None or mapper_id == None:
         return None
     
+    session = self.REQUEST.SESSION
+    
     mapper = storage_report.get_mapper(mapper_id)
     if mapper == None:
         return None
     
-    removable, props = get_props_data_internal(mapper)
+    removable, props = get_props_data_internal(session, mapper)
     
     new_targets = []
     for t_xml in storage_report.get_new_targets(mapper):
-        new_targets.append(get_bd_data_internal(t_xml, mapper))
+        new_targets.append(get_bd_data_internal(session, t_xml, mapper))
     new_sources = []
     for s_xml in storage_report.get_new_sources(mapper):
-        new_sources.append(get_bd_data_internal(s_xml, mapper))
+        new_sources.append(get_bd_data_internal(session, s_xml, mapper))
     targets = []
     for t_xml in storage_report.get_targets(mapper):
-        targets.append(get_bd_data_internal(t_xml, mapper))
+        targets.append(get_bd_data_internal(session, t_xml, mapper))
     sources = []
     for s_xml in storage_report.get_sources(mapper):
-        sources.append(get_bd_data_internal(s_xml, mapper))
+        sources.append(get_bd_data_internal(session, s_xml, mapper))
     
     type = mapper.getAttribute('mapper_type')
     pretty_type = 'Mapper'
@@ -567,10 +570,12 @@
 
 
 
-def get_mapper_template_data(storage_report, mapper_type):
-    if storage_report == None or mapper_type == None:
+def get_mapper_template_data(self, storage_report, mapper_type):
+    if self == None or storage_report == None or mapper_type == None:
         return None
     
+    session = self.REQUEST.SESSION
+    
     mapper_id = ''
     
     templ_xml_list = storage_report.get_mapper_temps(mapper_type)
@@ -580,20 +585,20 @@
     if mapper == None:
         return None
     
-    removable, props = get_props_data_internal(mapper)
+    removable, props = get_props_data_internal(session, mapper)
     
     new_targets = []
     for t_xml in storage_report.get_new_targets(mapper):
-        new_targets.append(get_bd_data_internal(t_xml, mapper))
+        new_targets.append(get_bd_data_internal(session, t_xml, mapper))
     new_sources = []
     for s_xml in storage_report.get_new_sources(mapper):
-        new_sources.append(get_bd_data_internal(s_xml, mapper))
+        new_sources.append(get_bd_data_internal(session, s_xml, mapper))
     targets = []
     for t_xml in storage_report.get_targets(mapper):
-        targets.append(get_bd_data_internal(t_xml, mapper))
+        targets.append(get_bd_data_internal(session, t_xml, mapper))
     sources = []
     for s_xml in storage_report.get_sources(mapper):
-        sources.append(get_bd_data_internal(s_xml, mapper))
+        sources.append(get_bd_data_internal(session, s_xml, mapper))
     
     type = mapper.getAttribute('mapper_type')
     pretty_type = 'Mapper'
@@ -685,7 +690,7 @@
 
 
 # TODO: implement
-def validate(storage_report, request):
+def validate(self, storage_report, request):
     #return 'size has to be within limits'
     #return request
     #return 'OK'
@@ -698,7 +703,7 @@
     
     if object_type == 'bd' or object_type == 'bd_template':
         path = request[PT_PATH]
-        bd_data = get_bd_data(storage_report, mapper_id, path)
+        bd_data = get_bd_data(self, storage_report, mapper_id, path)
         props = bd_data['props']
         if path != 'new_snapshot':
             selected_content_id = request['content_id']
@@ -706,10 +711,10 @@
                 if c_data['id'] == selected_content_id:
                     content_props = c_data['props']
     elif object_type == 'mapper':
-        props = get_mapper_data(storage_report, mapper_id)['props']
+        props = get_mapper_data(self, storage_report, mapper_id)['props']
     elif object_type == 'mapper_template':
         mapper_type = request['mapper_type']
-        data = get_mapper_template_data(storage_report, mapper_type)
+        data = get_mapper_template_data(self, storage_report, mapper_type)
         # find sources
         sources_num = 0
         for v in request.keys():
@@ -787,14 +792,16 @@
 
 
 # TODO: implement
-def apply(ricci, storage_report, request, main_URL):
-    if validate(storage_report, request) != 'OK':
+def apply(self, ricci, storage_report, request, main_URL):
+    if validate(self, storage_report, request) != 'OK':
         return 'Internal error: input not validated!!!'
     
     #return 'size has to be within limits'
     #return request
     #return main_URL
     
+    session = request.SESSION
+    
     storagename = request['storagename']
     
     object_type = request['object_type']
@@ -807,7 +814,7 @@
     
     
     if object_type == 'bd':
-        bd_data = get_bd_data(storage_report, mapper_id, path)
+        bd_data = get_bd_data(self, storage_report, mapper_id, path)
         bd_xml = bd_data['xml'].cloneNode(True)
         
         if action_type == 'Remove':
@@ -856,7 +863,7 @@
                                     node.setAttribute('value', request[var_name])
             
             # content
-            content_data_list = get_content_data_internal(bd_xml)
+            content_data_list = get_content_data_internal(session, bd_xml)
             current_content_id = content_data_list[0]['id']
             selected_content_id = request['content_id']
             selected_content = None
@@ -972,7 +979,7 @@
     
     elif object_type == 'bd_template':
         path = request[PT_PATH]
-        bd_data = get_bd_data(storage_report, mapper_id, path)
+        bd_data = get_bd_data(self, storage_report, mapper_id, path)
         bd_xml = bd_data['xml'].cloneNode(True)
         #return bd_xml.toprettyxml()
         
@@ -999,7 +1006,7 @@
             
             if path != 'new_snapshot':
                 # content
-                content_data_list = get_content_data_internal(bd_xml)
+                content_data_list = get_content_data_internal(session, bd_xml)
                 current_content_id = content_data_list[0]['id']
                 selected_content_id = request['content_id']
                 selected_content = None
@@ -1114,7 +1121,7 @@
     
     
     elif object_type == 'mapper':
-        mapper_data = get_mapper_data(storage_report, mapper_id)
+        mapper_data = get_mapper_data(self, storage_report, mapper_id)
         mapper_xml = mapper_data['xml'].cloneNode(True)
         #return mapper_xml.toprettyxml()
         
@@ -1225,7 +1232,7 @@
     
     
     elif object_type == 'mapper_template':
-        mapper_data = get_mapper_template_data(storage_report, mapper_type)
+        mapper_data = get_mapper_template_data(self, storage_report, mapper_type)
         mapper_xml = mapper_data['xml'].cloneNode(True)
         #return mapper_xml.toprettyxml()
         
@@ -1364,15 +1371,15 @@
 
 
 
-def get_bd_data_internal(bd_xml, mapper_xml):
+def get_bd_data_internal(session, bd_xml, mapper_xml):
     data = {}
     
-    removable, props = get_props_data_internal(bd_xml)
+    removable, props = get_props_data_internal(session, bd_xml)
     
     path = bd_xml.getAttribute('path')
     mapper_type = bd_xml.getAttribute('mapper_type')
     mapper_id = bd_xml.getAttribute('mapper_id')
-    contents = get_content_data_internal(bd_xml)
+    contents = get_content_data_internal(session, bd_xml)
     
     type = bd_xml.getAttribute('mapper_type')
     pretty_name = path.replace('/dev/','')
@@ -1459,7 +1466,7 @@
         for node in nts.childNodes:
             if node.nodeType == xml.dom.Node.ELEMENT_NODE:
                 if node.nodeName == BD_TEMPLATE:
-                    snap_lv = get_bd_data_internal(node, mapper_xml)
+                    snap_lv = get_bd_data_internal(session, node, mapper_xml)
         if snap_lv != None:
             if snap_lv['props']['snapshot']['value'] == 'true':
                 origs = snap_lv['props']['snapshot_origin']['value']
@@ -1474,7 +1481,7 @@
 
 
 
-def get_props_data_internal(xml_tag):
+def get_props_data_internal(session, xml_tag):
     data = {}
     removable = False
     
@@ -1506,9 +1513,16 @@
         if type == VARIABLE_TYPE_INT:
             d_type = 'int'
             d_value = value
-            validation_data['min'] = var.getAttribute('min')
-            validation_data['max'] = var.getAttribute('max')
-            validation_data['step'] = var.getAttribute('step')
+            min  = var.getAttribute('min')
+            max  = var.getAttribute('max')
+            step = var.getAttribute('step')
+            if d_units == 'bytes':
+                # modify units
+                
+                pass
+            validation_data['min']  = str(min)
+            validation_data['max']  = str(max)
+            validation_data['step'] = str(step)
         elif type == VARIABLE_TYPE_STRING:
             d_type = 'text'
             d_value = value
@@ -1567,7 +1581,7 @@
 
 
 
-def get_content_data_internal(bd_xml):
+def get_content_data_internal(session, bd_xml):
     c_xml = None
     for node in bd_xml.childNodes:
         if node.nodeType == xml.dom.Node.ELEMENT_NODE:
@@ -1589,7 +1603,7 @@
                 break
     
     current = {}
-    removable, props = get_props_data_internal(c_xml)
+    removable, props = get_props_data_internal(session, c_xml)
     current['props'] = props
     name, id = get_content_name_id(c_xml)
     current['name'] = name
@@ -1599,7 +1613,7 @@
     data = [current]
     for a_xml in a_xmls:
         available = {}
-        removable, props = get_props_data_internal(a_xml)
+        removable, props = get_props_data_internal(session, a_xml)
         available['props'] = props
         name, id = get_content_name_id(a_xml)
         available['name'] = name
@@ -1690,7 +1704,6 @@
     return name, id
 
 
-
 def build_systems_list(self, sort_by, allowed_systems):
     sysl = []
     for sys in allowed_systems:
@@ -1770,8 +1783,6 @@
     return sorted
 
 
-
-
 def get_mappings_info(self,
                       mapper_data,
                       length):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]