Skip to contentSkip to conversation

conga/luci site/luci/Extensions/StorageReport. ...

Cluster-devel [email protected] 1 participant 1 message Oct 15, 2006

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/cluster
Module name: conga
Changes by: kupcevic at sourceware.org 2006-10-15 22:34:54

Modified files:
luci/site/luci/Extensions: StorageReport.py Variable.py
conga_storage_constants.py storage_adapters.py
luci/storage : form-chooser form-macros

Log message:
luci storage:
- add "add sources" button to mappers' view
- add "add sources" form

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/StorageReport.py.diff?cvsroot=cluster&r1=1.16&r2=1.17
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/Variable.py.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/conga_storage_constants.py.diff?cvsroot=cluster&r1=1.7&r2=1.8
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/storage_adapters.py.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/storage/form-chooser.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/storage/form-macros.diff?cvsroot=cluster&r1=1.13&r2=1.14

luci/site/luci/Extensions/StorageReport.py +105 -3
@@ -4,7 +4,7 @@
 from xml.dom import minidom
 
 
-from Variable import parse_variable, Variable
+from Variable import parse_variable, Variable, VariableList
 from ricci_defines import *
 from PropsObject import PropsObject
 from conga_storage_constants import *
@@ -476,11 +476,16 @@
                   'msg'  : 'Are you sure you want to remove ' + pretty_type + ' \\\'' + pretty_name + '\\\'?',
                   'link' : ''}
         actions.append(action)
+    if type == MAPPER_VG_TYPE or type == MAPPER_MDRAID_TYPE or type == MAPPER_ATARAID_TYPE or type == MAPPER_MULTIPATH_TYPE:
+        action = {'name' : 'Add ' + mapper_ret['pretty_sources_name'], 
+                  'msg'  : '',
+                  'link' : './?' + PAGETYPE + '=' + ADD_SOURCES + '&' + PT_MAPPER_ID + '=' + mapper_ret['mapper_id'] + '&' + PT_MAPPER_TYPE + '=' + mapper_ret['mapper_type']}
+        actions.append(action)
     if type == MAPPER_VG_TYPE:
         for nt in mapper_ret['new_targets']:
             if nt['props']['snapshot']['value'] == 'false':
                 if nt['new']:
-                    action = {'name' : 'New Logical Volume',
+                    action = {'name' : 'New ' + mapper_ret['pretty_target_name'], 
                               'msg'  : '',
                               'link' : './?' + PAGETYPE + '=' + VIEW_BD + '&' + PT_MAPPER_ID + '=' + mapper_ret['mapper_id'] + '&' + PT_MAPPER_TYPE + '=' + mapper_ret['mapper_type'] + '&' + PT_PATH + '=' + nt['path']}
                     actions.append(action)
@@ -491,7 +496,7 @@
         link_snapshots(mapper_ret)
     
     # cylinders work properly for VGs only, for now
-    mapper_ret['graphical_view'] = type == MAPPER_VG_TYPE
+    mapper_ret['graphical_view'] = type != MAPPER_PT_TYPE
     if mapper_ret['graphical_view']:
         mapper_ret['mappings-view_css_classnames'] = {'graphical_view' : 'visible',
                                                       'textual_view'   : 'invisible'}
@@ -709,6 +714,17 @@
             return 'BAD: Invalid number of ' + data['pretty_sources_name'] + ' selected'
         props = data['props']
         pass
+    elif object_type == 'add_sources':
+        data = get_mapper_data(self, storage_report, mapper_id)
+        # find sources
+        sources_num = 0
+        for v in request.keys():
+            if v.find('source_bd_') == 0:
+                if request[v] == 'on':
+                    sources_num += 1
+        if sources_num == 0 or sources_num > len(data['new_sources']):
+            return 'BAD: Invalid number of ' + data['pretty_sources_name'] + ' selected'
+        pass
     
     if props != None:
         res = check_props(self, props, request)
@@ -1420,6 +1436,90 @@
     
     
     
+    elif object_type == 'add_sources':
+        mapper_data = get_mapper_data(self, storage_report, mapper_id)
+        mapper_xml = mapper_data['xml'].cloneNode(True)
+        new_sources = []
+        #return mapper_xml.toprettyxml()
+        
+        if action_type == 'Apply':
+            # find sources
+            for v in request.keys():
+                if v.find('source_bd_') == 0:
+                    if request[v] == 'on':
+                        path = v[len('source_bd_'):]
+                        for ns in mapper_data['new_sources']:
+                            if ns['path'] == path:
+                                new_sources.append(ns['xml'].cloneNode(True))
+            #return mapper_xml.toprettyxml()
+            doc = minidom.Document()
+            batch = doc.createElement("batch")
+            module = doc.createElement("module")
+            module.setAttribute("name", "storage")
+            req = doc.createElement("request")
+            req.setAttribute("API_version", "1.0")
+            req.setAttribute("sequence", "11")
+            f_call = doc.createElement("function_call")
+            f_call.setAttribute('name', 'add_mapper_sources')
+            f_call.appendChild(Variable('mapper_type', mapper_type).export_xml(doc))
+            f_call.appendChild(Variable('mapper_id', mapper_id).export_xml(doc))
+            f_call.appendChild(Variable('mapper_state_ind', mapper_xml.getAttribute('state_ind')).export_xml(doc))
+            f_call.appendChild(VariableList('bds', new_sources, [], VARIABLE_TYPE_LIST_XML).export_xml(doc))
+            
+            req.appendChild(f_call)
+            module.appendChild(req)
+            batch.appendChild(module)
+            
+            #return batch.toprettyxml()
+            
+            res = ricci.process_batch(batch, False)
+            if res.getAttribute('status') != '0':
+                invalidate_storage_report(request.SESSION, storagename)
+                err_msg = 'Error adding sources to ' + mapper_type + ' ' + mapper_id + '\n' + res.toprettyxml()
+                return err_msg
+            module_r = None
+            for node in res.childNodes:
+                if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+                    if node.nodeName == 'module':
+                        module_r = node
+            if module_r == None:
+                raise 'missing <module/> in <batch/>'
+            if module_r.getAttribute('status') != '0':
+                raise 'error retrieving storage report'
+            resp_r = None
+            for node in module_r.childNodes:
+                if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+                    if node.nodeName == RESPONSE_TAG:
+                        resp_r = node
+            if resp_r == None:
+                raise 'missing <response/> in <module/>'
+            fr_r = None
+            for node in resp_r.childNodes:
+                if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+                    if node.nodeName == FUNC_RESP_TAG:
+                        fr_r = node
+            if fr_r == None:
+                raise 'missing <function_response/> in <response/>'
+            mapper_var = None
+            for node in fr_r.childNodes:
+                if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+                    if node.nodeName == VARIABLE_TAG:
+                        if node.getAttribute('name') == 'mapper':
+                            mapper_var = node
+            if mapper_var == None:
+                raise 'missing <var name="mapper"/> in <function_response/>'
+            mapper_xml = None
+            for node in mapper_var.childNodes:
+                if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+                    if node.nodeName == 'mapper':
+                        mapper_xml = node.cloneNode(True)
+            mapper_id = mapper_xml.getAttribute('mapper_id')
+            pass
+        pass
+    
+    
+    
+    
     
     
     invalidate_storage_report(request.SESSION, storagename)
@@ -1441,6 +1541,8 @@
             goto_url += '&pagetype=' + VIEW_MAPPER
     elif object_type == 'mapper_template':
         goto_url += '&pagetype=' + VIEW_MAPPER
+    elif object_type == 'add_sources':
+        goto_url += '&pagetype=' + VIEW_MAPPER
     goto_url += '&' + PT_MAPPER_TYPE  + '=' + mapper_type
     goto_url += '&' + PT_MAPPER_ID  + '=' + mapper_id
     redirect_html = '<head>\n'
luci/site/luci/Extensions/Variable.py +7 -6
@@ -262,12 +262,13 @@
         elem.setAttribute('type', self.type())
         
         l = self.get_value()
-        for i in range(len(l)):
-            x = l[i]
-            e2 = doc.createElement(VARIABLE_TYPE_LISTENTRY)
-            e2.setAttribute('value', str(x))
-            e2.setAttribute('list_index', str(i))
-            elem.appendChild(e2)
+        for x in l:
+            if self.type() == VARIABLE_TYPE_LIST_XML:
+                elem.appendChild(x.cloneNode(True))
+            else:
+                e2 = doc.createElement(VARIABLE_TYPE_LISTENTRY)
+                e2.setAttribute('value', str(x))
+                elem.appendChild(e2)
         for mod in self.__mods:
             elem.setAttribute(str(mod), str(self.__mods[mod]))
         return elem
luci/site/luci/Extensions/conga_storage_constants.py +1 -1
@@ -70,7 +70,7 @@
 
 
 CREATE_MAPPER = '101'
-
+ADD_SOURCES   = '102'
 
 
 
luci/site/luci/Extensions/storage_adapters.py +2 -2
@@ -180,7 +180,7 @@
   srs_p['cfg_type'] = "nodes"
   srs_p['absolute_url'] = url + '?' + PAGETYPE + '=' + VIEW_MAPPERS + '&' + STONAME + '=' + hostname + '&' + PT_MAPPER_TYPE + '=' + mapper_type
   srs_p['Description'] = pretty_names_desc
-  if (pagetype_req == VIEW_MAPPERS or pagetype_req == VIEW_MAPPER or pagetype_req == CREATE_MAPPER or pagetype_req == VIEW_BD) and mapper_type_req == mapper_type:
+  if (pagetype_req == VIEW_MAPPERS or pagetype_req == VIEW_MAPPER or pagetype_req == ADD_SOURCES or pagetype_req == CREATE_MAPPER or pagetype_req == VIEW_BD) and mapper_type_req == mapper_type:
     srs_p['show_children'] = True
   else:
     srs_p['show_children'] = False
@@ -222,7 +222,7 @@
     sr['absolute_url'] = url + '?' + PAGETYPE + '=' + VIEW_MAPPER + '&' + STONAME + '=' + hostname + '&' + PT_MAPPER_TYPE + '=' + mapper_type + '&' + PT_MAPPER_ID + '=' + sr_id
     sr['Description'] = pretty_name_desc
     
-    if (pagetype_req == VIEW_MAPPER or pagetype_req == VIEW_BD) and mapper_id_req == sr_id:
+    if (pagetype_req == VIEW_MAPPER or pagetype_req == ADD_SOURCES or pagetype_req == VIEW_BD) and mapper_id_req == sr_id:
       sr['currentItem'] = True
     else:
       sr['currentItem'] = False
luci/storage/form-chooser +4 -0
@@ -70,6 +70,10 @@
       <div metal:use-macro="here/form-macros/macros/create-mapper-form"/>
     </span>
 
+    <span tal:omit-tag="" tal:condition="python: pagetype == '102' and storage_report != None">
+      <div metal:use-macro="here/form-macros/macros/add-sources-form"/>
+    </span>
+
   </metal:choose-form>
 
   </body>
luci/storage/form-macros +130 -0

141 lines not on this page · raw message