From mboxrd@z Thu Jan 1 00:00:00 1970 From: rmccabe@sourceware.org Date: 30 May 2007 22:04:34 -0000 Subject: [Cluster-devel] conga/luci site/luci/Extensions/StorageReport. ... Message-ID: <20070530220434.11782.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: conga Branch: EXPERIMENTAL Changes by: rmccabe at sourceware.org 2007-05-30 22:04:34 Modified files: luci/site/luci/Extensions: StorageReport.py luci/storage : form-macros Log message: Do not redefine built-ins Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/StorageReport.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.23.2.4&r2=1.23.2.5 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/storage/form-macros.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.20&r2=1.20.4.1 --- conga/luci/site/luci/Extensions/StorageReport.py 2007/05/18 02:36:59 1.23.2.4 +++ conga/luci/site/luci/Extensions/StorageReport.py 2007/05/30 22:04:33 1.23.2.5 @@ -23,8 +23,7 @@ from LuciZope import bytes_to_value_prefunits, get_systems_statuses -from ricci_communicator import get_ricci_communicator, \ - batch_status, extract_module_status +from ricci_communicator import extract_module_status SESSION_STORAGE_XML_REPORT = 'storage_xml_report_dir' @@ -74,12 +73,12 @@ return self.__report.cloneNode(True) - def get_mappers(self, type=''): + def get_mappers(self, mapper_type=''): l = [] - if type == '': + if mapper_type == '': l = self.__mappers - elif type in self.__mapp_dir: - l = self.__mapp_dir[type] + elif mapper_type in self.__mapp_dir: + l = self.__mapp_dir[mapper_type] r = [] for s in l: r.append(s.cloneNode(True)) @@ -88,39 +87,39 @@ def get_mappers_dir(self): r = {} - for type in self.__mapp_dir: + for mapper_type in self.__mapp_dir: l = [] - for m in self.__mapp_dir[type]: + for m in self.__mapp_dir[mapper_type]: l.append(m.cloneNode(True)) - r[type] = l + r[mapper_type] = l return r - def get_mapper(self, id): - if id == '': + def get_mapper(self, mapper_id): + if mapper_id == '': raise Exception, 'empty mapper_id!!!' for m in self.__mappers: - if m.getAttribute('mapper_id') == id: + if m.getAttribute('mapper_id') == mapper_id: return m.cloneNode(True) return None def get_mapper_temps_dir(self): r = {} - for type in self.__m_temps_dir: + for mapper_type in self.__m_temps_dir: l = [] - for m in self.__m_temps_dir[type]: + for m in self.__m_temps_dir[mapper_type]: l.append(m.cloneNode(True)) - r[type] = l + r[mapper_type] = l return r - def get_mapper_temps(self, type=''): + def get_mapper_temps(self, mapper_type=''): l = [] - if type == '': + if mapper_type == '': l = self.__m_temps - elif type in self.__m_temps_dir: - l = self.__m_temps_dir[type] + elif mapper_type in self.__m_temps_dir: + l = self.__m_temps_dir[mapper_type] r = [] for s in l: r.append(s.cloneNode(True)) @@ -371,12 +370,12 @@ mappers_dir = storage_report.get_mappers_dir() for mapp_type in mappers_dir: for m_xml in mappers_dir[mapp_type]: - id = m_xml.getAttribute('mapper_id') + mapper_id = m_xml.getAttribute('mapper_id') if mapp_type not in ret_dir: 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(self, storage_report, id)) + ret_dir[mapp_type]['mappers'].append(get_mapper_data(self, storage_report, mapper_id)) # templates for mapp_type in storage_report.get_mapper_temps_dir(): if mapp_type not in ret_dir: @@ -425,12 +424,12 @@ for s_xml in storage_report.get_sources(mapper): sources.append(get_bd_data_internal(session, s_xml, mapper)) - type = mapper.getAttribute('mapper_type') - pretty_type, pretty_target_name, pretty_source_name = get_pretty_mapper_info(type) - pretty_name = mapper_id.replace('%s:' % type, '').replace('/dev/', '') + mapper_type = mapper.getAttribute('mapper_type') + pretty_type, pretty_target_name, pretty_source_name = get_pretty_mapper_info(mapper_type) + pretty_name = mapper_id.replace('%s:' % mapper_type, '').replace('/dev/', '') pretty_targets_name = '%ss' % pretty_target_name pretty_sources_name = '%ss' % pretty_source_name - icon_name, dummy1, dummy2 = get_mapper_icons(type) + icon_name, dummy1, dummy2 = get_mapper_icons(mapper_type) color = 'black' mapper_ret = {} @@ -441,7 +440,7 @@ mapper_ret['pretty_source_name'] = pretty_source_name mapper_ret['pretty_sources_name'] = pretty_sources_name mapper_ret['mapper_id'] = mapper_id - mapper_ret['mapper_type'] = type + mapper_ret['mapper_type'] = mapper_type mapper_ret['props'] = props mapper_ret['props_ordered'] = get_ordered_props(props) mapper_ret['targets'] = targets @@ -460,12 +459,12 @@ 'msg' : 'Are you sure you want to remove %s \\\'%s\\\'?' % (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: + if mapper_type == MAPPER_VG_TYPE or mapper_type == MAPPER_MDRAID_TYPE or mapper_type == MAPPER_ATARAID_TYPE or mapper_type == MAPPER_MULTIPATH_TYPE: action = {'name' : 'Add %s' % mapper_ret['pretty_sources_name'], 'msg' : '', 'link' : './?%s=%s&%s=%s&%s=%s' % (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: + if mapper_type == MAPPER_VG_TYPE: for nt in mapper_ret['new_targets']: if nt['props']['snapshot']['value'] == 'false': if nt['new']: @@ -480,11 +479,11 @@ break mapper_ret['actions'] = actions - if type == MAPPER_VG_TYPE: + if mapper_type == MAPPER_VG_TYPE: link_snapshots(mapper_ret) # cylinders work properly for VGs only, for now - mapper_ret['graphical_view'] = type != MAPPER_PT_TYPE + mapper_ret['graphical_view'] = mapper_type != MAPPER_PT_TYPE if mapper_ret['graphical_view']: mapper_ret['mappings-view_css_classnames'] = {'graphical_view' : 'visible', 'textual_view' : 'invisible'} @@ -554,13 +553,13 @@ # TODO: place logical into extended # sort partitions - sorted = [] + p_sorted = [] while len(targets_all) != 0: smallest_num = 100000000000000000000 smallest_bd = None smallest_index = 0 i = 0 - for i in range(len(targets_all)): + for i in xrange(len(targets_all)): bd = targets_all[i] begin = int(bd['props']['partition_begin']['value']) if begin < smallest_num: @@ -568,8 +567,8 @@ smallest_bd = bd smallest_index = i targets_all.pop(smallest_index) - sorted.append(smallest_bd) - targets_all = sorted + p_sorted.append(smallest_bd) + targets_all = p_sorted else: for t in mdata['targets']: targets_all.append(t) @@ -608,12 +607,12 @@ for s_xml in storage_report.get_sources(mapper): sources.append(get_bd_data_internal(session, s_xml, mapper)) - type = mapper.getAttribute('mapper_type') - pretty_type, pretty_target_name, pretty_source_name = get_pretty_mapper_info(type) - pretty_name = mapper_id.replace('%s:' % type, '').replace('/dev/', '') + mapper_type = mapper.getAttribute('mapper_type') + pretty_type, pretty_target_name, pretty_source_name = get_pretty_mapper_info(mapper_type) + pretty_name = mapper_id.replace('%s:' % mapper_type, '').replace('/dev/', '') pretty_targets_name = '%ss' % pretty_target_name pretty_sources_name = '%ss' % pretty_source_name - icon_name, dummy1, dummy2 = get_mapper_icons(type) + icon_name, dummy1, dummy2 = get_mapper_icons(mapper_type) color = 'black' min_sources = '0' @@ -636,7 +635,7 @@ mapper_ret['pretty_source_name'] = pretty_source_name mapper_ret['pretty_sources_name'] = pretty_sources_name mapper_ret['mapper_id'] = mapper_id - mapper_ret['mapper_type'] = type + mapper_ret['mapper_type'] = mapper_type mapper_ret['props'] = props mapper_ret['props_ordered'] = get_ordered_props(props) #mapper_ret['removable'] = removable @@ -719,10 +718,11 @@ return '%s %s' % (res[1], res[2]) return 'OK' + def check_props(self, props, request): valid = True var_name = '' - msg = 'no message - BUG :(' + msg = 'no message - BUG' for prop_name in props: if prop_name in request: @@ -737,13 +737,13 @@ var_name = prop_name valid = False break - min = int(prop['validation']['min']) - max = int(prop['validation']['max']) + min_val = int(prop['validation']['min']) + max_val = int(prop['validation']['max']) step = int(prop['validation']['step']) r_val = (req_value / step) * step - if r_val > max or r_val < min: + if r_val > max_val or r_val < min_val: msg = '%s has to be within range %d-%d %s' \ - % (prop['pretty_name'], min, max, prop['units']) + % (prop['pretty_name'], min_val, max_val, prop['units']) var_name = prop_name valid = False break @@ -756,15 +756,15 @@ valid = False break dummy, units = bytes_to_value_prefunits(self, prop['value']) - min = float(convert_bytes(prop['validation']['min'], units)) - max = float(convert_bytes(prop['validation']['max'], units)) + min_val = float(convert_bytes(prop['validation']['min'], units)) + max_val = float(convert_bytes(prop['validation']['max'], units)) step = float(convert_bytes(prop['validation']['step'], units)) if step < 0.000001: step = 0.000001 r_val = (req_value / step) * step - if r_val > max or r_val < min: + if r_val > max_val or r_val < min_val: msg = '%s has to be within range %d-%d %s' \ - % (prop['pretty_name'], min, max, units) + % (prop['pretty_name'], min_val, max_val, units) var_name = prop_name valid = False break @@ -798,7 +798,7 @@ -def apply(self, ricci, storage_report, request): +def apply_storage_changes(self, ricci, storage_report, request): if validate(self, storage_report, request) != 'OK': raise Exception, 'Internal error: input not validated!!!' @@ -862,16 +862,16 @@ else: dummy, units = bytes_to_value_prefunits(self, bd_data['props'][var_name]['value']) - min = int(bd_data['props'][var_name]['validation']['min']) - max = int(bd_data['props'][var_name]['validation']['max']) + min_val = int(bd_data['props'][var_name]['validation']['min']) + max_val = int(bd_data['props'][var_name]['validation']['max']) step = int(bd_data['props'][var_name]['validation']['step']) val_units = float(request[var_name]) val = int(val_units * get_units_multiplier(units)) val = (val / step) * step - if val < min: - val = min - if val > max: - val = max + if val < min_val: + val = min_val + if val > max_val: + val = max_val node.setAttribute('value', str(val)) else: node.setAttribute('value', request[var_name]) @@ -908,16 +908,16 @@ else: dummy, units = bytes_to_value_prefunits(self, selected_content_data['props'][req_name]['value']) - min = int(selected_content_data['props'][req_name]['validation']['min']) - max = int(selected_content_data['props'][req_name]['validation']['max']) + min_val = int(selected_content_data['props'][req_name]['validation']['min']) + max_val = int(selected_content_data['props'][req_name]['validation']['max']) step = int(selected_content_data['props'][req_name]['validation']['step']) val_units = float(request[req_name]) val = int(val_units * get_units_multiplier(units)) val = (val / step) * step - if val < min: - val = min - if val > max: - val = max + if val < min_val: + val = min_val + if val > max_val: + val = max_val node.setAttribute('value', str(val)) else: node.setAttribute('value', request[req_name]) @@ -989,16 +989,16 @@ else: dummy, units = bytes_to_value_prefunits(self, bd_data['props'][var_name]['value']) - min = int(bd_data['props'][var_name]['validation']['min']) - max = int(bd_data['props'][var_name]['validation']['max']) + min_val = int(bd_data['props'][var_name]['validation']['min']) + max_val = int(bd_data['props'][var_name]['validation']['max']) step = int(bd_data['props'][var_name]['validation']['step']) val_units = float(request[var_name]) val = int(val_units * get_units_multiplier(units)) val = (val / step) * step - if val < min: - val = min - if val > max: - val = max + if val < min_val: + val = min_val + if val > max_val: + val = max_val node.setAttribute('value', str(val)) else: node.setAttribute('value', request[var_name]) @@ -1036,16 +1036,16 @@ else: dummy, units = bytes_to_value_prefunits(self, selected_content_data['props'][req_name]['value']) - min = int(selected_content_data['props'][req_name]['validation']['min']) - max = int(selected_content_data['props'][req_name]['validation']['max']) + min_val = int(selected_content_data['props'][req_name]['validation']['min']) + max_val = int(selected_content_data['props'][req_name]['validation']['max']) step = int(selected_content_data['props'][req_name]['validation']['step']) val_units = float(request[req_name]) val = int(val_units * get_units_multiplier(units)) val = (val / step) * step - if val < min: - val = min - if val > max: - val = max + if val < min_val: + val = min_val + if val > max_val: + val = max_val node.setAttribute('value', str(val)) else: node.setAttribute('value', request[req_name]) @@ -1137,16 +1137,16 @@ else: dummy, units = bytes_to_value_prefunits(self, mapper_data['props'][var_name]['value']) - min = int(mapper_data['props'][var_name]['validation']['min']) - max = int(mapper_data['props'][var_name]['validation']['max']) + min_val = int(mapper_data['props'][var_name]['validation']['min']) + max_val = int(mapper_data['props'][var_name]['validation']['max']) step = int(mapper_data['props'][var_name]['validation']['step']) val_units = float(request[var_name]) val = int(val_units * get_units_multiplier(units)) val = (val / step) * step - if val < min: - val = min - if val > max: - val = max + if val < min_val: + val = min_val + if val > max_val: + val = max_val node.setAttribute('value', str(val)) else: node.setAttribute('value', request[var_name]) @@ -1197,16 +1197,16 @@ else: dummy, units = bytes_to_value_prefunits(self, mapper_data['props'][var_name]['value']) - min = int(mapper_data['props'][var_name]['validation']['min']) - max = int(mapper_data['props'][var_name]['validation']['max']) + min_val = int(mapper_data['props'][var_name]['validation']['min']) + max_val = int(mapper_data['props'][var_name]['validation']['max']) step = int(mapper_data['props'][var_name]['validation']['step']) val_units = float(request[var_name]) val = int(val_units * get_units_multiplier(units)) val = (val / step) * step - if val < min: - val = min - if val > max: - val = max + if val < min_val: + val = min_val + if val > max_val: + val = max_val node.setAttribute('value', str(val)) else: node.setAttribute('value', request[var_name]) @@ -1456,11 +1456,11 @@ fr_r = node if fr_r is None: raise Exception, 'missing in ' - vars = {} + rvars = {} for node in fr_r.childNodes: try: var = parse_variable(node) - vars[var.get_name()] = var + rvars[var.get_name()] = var except: pass @@ -1468,12 +1468,12 @@ mapper_id = '' mapper_type = '' bd_path = '' - if 'mapper' in vars: - mapper = vars['mapper'].get_value() + if 'mapper' in rvars: + mapper = rvars['mapper'].get_value() mapper_type = mapper.getAttribute('mapper_type') mapper_id = mapper.getAttribute('mapper_id') - if 'bd' in vars: - bd = vars['bd'].get_value() + if 'bd' in rvars: + bd = rvars['bd'].get_value() bd_path = bd.getAttribute('path') mapper_type = bd.getAttribute('mapper_type') mapper_id = bd.getAttribute('mapper_id') @@ -1626,7 +1626,7 @@ for name in var_xmls: var = var_xmls[name] mutable = var.getAttribute('mutable') == 'true' - type = var.getAttribute('type') + var_type = var.getAttribute('type') value = var.getAttribute('value') d_units = '' @@ -1636,23 +1636,23 @@ d_units = '%' validation_data = {} - if type == VARIABLE_TYPE_INT: + if var_type == VARIABLE_TYPE_INT: d_type = 'int' d_value = value - min = var.getAttribute('min') - max = var.getAttribute('max') + min_val = var.getAttribute('min') + max_val = var.getAttribute('max') step = var.getAttribute('step') - validation_data['min'] = str(min) - validation_data['max'] = str(max) + validation_data['min'] = str(min_val) + validation_data['max'] = str(max_val) validation_data['step'] = str(step) - elif type == VARIABLE_TYPE_STRING: + elif var_type == VARIABLE_TYPE_STRING: d_type = 'text' d_value = value validation_data['min_length'] = var.getAttribute('min_length') validation_data['max_length'] = var.getAttribute('max_length') validation_data['illegal_chars'] = var.getAttribute('illegal_chars').replace('\'', '\\\'').replace('<', '<').replace('>', '>').replace('"', '\\\"').replace('&', '&') validation_data['reserved_words'] = var.getAttribute('reserved_words') - elif type == VARIABLE_TYPE_INT_SEL or type == VARIABLE_TYPE_STRING_SEL: + elif var_type == VARIABLE_TYPE_INT_SEL or var_type == VARIABLE_TYPE_STRING_SEL: d_type = 'select' d_value = [value] for node in var.childNodes: @@ -1661,14 +1661,14 @@ val = node.getAttribute('value') if val not in d_value: d_value.append(val) - elif type == VARIABLE_TYPE_BOOL: + elif var_type == VARIABLE_TYPE_BOOL: d_type = 'select' d_value = [value] if value == 'true': d_value.append('false') else: d_value.append('true') - elif type == VARIABLE_TYPE_LIST_INT or type == VARIABLE_TYPE_LIST_STR: + elif var_type == VARIABLE_TYPE_LIST_INT or var_type == VARIABLE_TYPE_LIST_STR: d_type = 'label' d_value = '' d_val_list = list() @@ -1680,7 +1680,7 @@ d_value = ''.join(d_val_list) if d_value != '': d_value = d_value[:len(d_value)-2] - elif type == 'hidden': + elif var_type == 'hidden': d_type = 'hidden' d_value = str(value) else: @@ -1692,7 +1692,7 @@ d_value = str(value) hidden = False - if type == 'hidden' or name in ['partition_begin', 'snapshot']: + if var_type == 'hidden' or name in ['partition_begin', 'snapshot']: hidden = True if name == 'removable': @@ -1756,8 +1756,8 @@ def mutable_props(props): for name in props: - type = props[name]['type'] - if type == 'int' or type == 'text' or type == 'select': + prop_type = props[name]['type'] + if prop_type == 'int' or prop_type == 'text' or prop_type == 'select': return True return False @@ -1787,9 +1787,9 @@ current = {} removable, props = get_props_data_internal(session, c_xml) current['props'] = props - name, id = get_content_name_id(c_xml) + name, content_id = get_content_name_id(c_xml) current['name'] = name - current['id'] = id + current['id'] = content_id current['xml'] = c_xml.cloneNode(True) data = [current] @@ -1797,9 +1797,9 @@ available = {} removable, props = get_props_data_internal(session, a_xml) available['props'] = props - name, id = get_content_name_id(a_xml) + name, content_id = get_content_name_id(a_xml) available['name'] = name - available['id'] = id + available['id'] = content_id available['xml'] = a_xml.cloneNode(True) data.append(available) @@ -1818,10 +1818,10 @@ # content's color and icon color = 'black' icon_name = '' - type = d['xml'].getAttribute('type') - if type == 'filesystem': + content_type = d['xml'].getAttribute('type') + if content_type == 'filesystem': icon_name = get_fs_icon(d['xml'].getAttribute('fs_type')) - elif type == 'mapper_source': + elif content_type == 'mapper_source': mapper_type = d['xml'].getAttribute('mapper_type') mapper_id = d['xml'].getAttribute('mapper_id') pretty_mapper_type, dummy1, dummy2 = get_pretty_mapper_info(mapper_type) @@ -1832,9 +1832,9 @@ d['mapper_type'] = mapper_type d['mapper_id'] = mapper_id d['pretty_mapper_type'] = pretty_mapper_type - elif type == 'none': + elif content_type == 'none': pass - elif type == 'hidden': + elif content_type == 'hidden': pass d['color'] = color @@ -1845,18 +1845,18 @@ def get_content_name_id(c_xml): - name = 'BUG, call authorities :)' - id = c_xml.getAttribute('type') - if id == CONTENT_FS_TYPE: + name = 'Unknown type' + content_id = c_xml.getAttribute('type') + if content_id == CONTENT_FS_TYPE: fs_type = c_xml.getAttribute('fs_type') - id = '%s_%s' % (id, fs_type) + content_id = '%s_%s' % (content_id, fs_type) name = get_pretty_fs_name(fs_type) - elif id == CONTENT_NONE_TYPE: + elif content_id == CONTENT_NONE_TYPE: name = 'Empty' - elif id == CONTENT_MS_TYPE: + elif content_id == CONTENT_MS_TYPE: mapper_type = c_xml.getAttribute('mapper_type') mapper_id = c_xml.getAttribute('mapper_id') - id = '%s_%s_%s' % (id, mapper_type, mapper_id.replace(':', '__colon__')) + content_id = '%s_%s_%s' % (content_id, mapper_type, mapper_id.replace(':', '__colon__')) if mapper_type == MAPPER_SYS_TYPE: pass elif mapper_type == MAPPER_VG_TYPE: @@ -1875,12 +1875,12 @@ pass else: name = 'Source of %s' % mapper_type - elif id == CONTENT_HIDDEN_TYPE: + elif content_id == CONTENT_HIDDEN_TYPE: name = 'Extended Partition' else: - name = "Unknown type" + name = 'Unknown type' - return name, id + return name, content_id @@ -2076,8 +2076,8 @@ # transform list of highlights high_list_js = [[mapper_data['mapper_id'], []]] - for id in high_list: - high_list_js.append([id, high_list[id]]) + for hl_id in high_list: + high_list_js.append([hl_id, high_list[hl_id]]) high_list_js = str(high_list_js).replace('L,', ',').replace('L]', ']').replace('u\'', '\'').replace('L]', ']') # put everything together --- conga/luci/storage/form-macros 2006/12/06 22:34:09 1.20 +++ conga/luci/storage/form-macros 2007/05/30 22:04:34 1.20.4.1 @@ -100,7 +100,7 @@