def main(): lg = None try: lg, err = logger.get_script_logger( 'Poll for alerts', '/var/log/integralstor/scripts.log', level=logging.DEBUG) logger.log_or_print('Poll for alerts initiated.', lg, level='info') lck, err = lock.get_lock('poll_for_alerts') if err: raise Exception(err) if not lck: raise Exception('Could not acquire lock. Exiting.') active, err = grid_ops.is_active_admin_gridcell() if err: raise Exception(err) if not active: logger.log_or_print( 'Not active admin GRIDCell so exiting.', lg, level='info') sys.exit(0) gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) si, err = system_info.load_system_config() if err: raise Exception(err) if not si: raise Exception('Could not load system information') alerts_list = [] alerts_list, err = check_quotas() if err: raise Exception("Error getting quota information : %s" % err) lock.release_lock('gluster_commands') common_alerts, err = check_for_gridcell_errors(si) if err: raise Exception(err) alerts_list.extend(common_alerts) if alerts_list: alerts.raise_alert(alerts_list) str = ' | '.join(alerts_list) logger.log_or_print(str, lg, level='info') else: logger.log_or_print('No alerts to raise', lg, level='info') lock.release_lock('poll_for_alerts') except Exception, e: str = 'Error running poll for alerts : %s' % e logger.log_or_print(str, lg, level='critical') sys.exit(-1)
def main(): try: if len(sys.argv) < 2: print 'Usage : python gluster_volume_start_stop.py [start|stop|restart_all] <vol_name>' sys.exit(0) if sys.argv[1] not in ['start', 'stop', 'restart_all']: print 'Usage : python gluster_volume_start_stop.py [start|stop|restart_all] <vol_name>' sys.exit(0) if sys.argv[1] in ['start', 'stop'] and (len(sys.argv) != 3): print 'Usage : python gluster_volume_start_stop.py [start|stop|restart_all] <vol_name>' sys.exit(0) gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if sys.argv[1] == 'restart_all': ret, err = gluster_volumes.restart_all_volumes() if err: raise Exception(err) sys.exit(0) else: vol_name = sys.argv[2] ret, err = volume_start_stop(vol_name, sys.argv[1]) if err: raise Exception(err) except Exception, e: print e sys.exit(-1)
def gen_manifest(path): try: lck, err = lock.get_lock('generate_manifest') if err: raise Exception(err) if not lck: raise Exception('Could not acquire lock.') ret, err = manifest_status.generate_manifest_info() if not ret: if err: raise Exception(err) else: raise Exception('No manifest info obtained') else: fullpath = os.path.normpath("%s/master.manifest" % path) fulltmppath = "/tmp/master.manifest.tmp" fullcopypath = os.path.normpath( "%s/master.manifest.%s" % (path, datetime.datetime.now().strftime("%B_%d_%Y_%H_%M_%S"))) # Generate into a tmp file with open(fulltmppath, 'w') as fd: json.dump(ret, fd, indent=2) # Copy original to a backup if os.path.isfile(fullpath): shutil.copyfile(fullpath, fullcopypath) # Now move the tmp to the actual manifest file name shutil.move(fulltmppath, fullpath) except Exception, e: lock.release_lock('generate_manifest') return -1, 'Error generating manifest : %s' % str(e)
def gen_status(path, lg=None): try: lck, err = lock.get_lock('generate_status') if err: raise Exception(err) if not lck: raise Exception('Generate Status : Could not acquire lock.') fullmanifestpath = os.path.normpath("%s/master.manifest" % path) ret, err = manifest_status.generate_status_info(fullmanifestpath) if not ret: if err: raise Exception(err) else: raise Exception('No status info obtained') fullpath = os.path.normpath("%s/master.status" % path) fulltmppath = "/tmp/master.status.tmp" # Generate into a tmp file with open(fulltmppath, 'w') as fd: json.dump(ret, fd, indent=2) # Now move the tmp to the actual manifest file name # print 'fullpath is ', fullpath shutil.move(fulltmppath, fullpath) except Exception, e: logger.log_or_print('Error generating status : %s' % e, lg, level='critical') lock.release_lock('generate_status') return -1, 'Error generating status : %s' % e
def gen_status(path, lg=None): try: lck, err = lock.get_lock('generate_status') if err: raise Exception(err) if not lck: raise Exception('Generate Status : Could not acquire lock.') fullmanifestpath = os.path.normpath("%s/master.manifest" % path) ret, err = manifest_status.generate_status_info(fullmanifestpath) if not ret: if err: raise Exception(err) else: raise Exception('No status info obtained') fullpath = os.path.normpath("%s/master.status" % path) fulltmppath = "/tmp/master.status.tmp" # Generate into a tmp file with open(fulltmppath, 'w') as fd: json.dump(ret, fd, indent=2) # Now move the tmp to the actual manifest file name # print 'fullpath is ', fullpath shutil.move(fulltmppath, fullpath) except Exception, e: logger.log_or_print('Error generating status : %s' % e, lg, level='critical') lock.release_lock('generate_status') return -1, 'Error generating status : %s' % e
def gen_manifest(path): try: lck, err = lock.get_lock('generate_manifest') if err: raise Exception(err) if not lck: raise Exception('Could not acquire lock.') ret, err = manifest_status.generate_manifest_info() if not ret: if err: raise Exception(err) else: raise Exception('No manifest info obtained') else: fullpath = os.path.normpath("%s/master.manifest" % path) fulltmppath = "/tmp/master.manifest.tmp" fullcopypath = os.path.normpath( "%s/master.manifest.%s" % (path, datetime.datetime.now().strftime("%B_%d_%Y_%H_%M_%S"))) # Generate into a tmp file with open(fulltmppath, 'w') as fd: json.dump(ret, fd, indent=2) # Copy original to a backup if os.path.isfile(fullpath): shutil.copyfile(fullpath, fullcopypath) # Now move the tmp to the actual manifest file name shutil.move(fulltmppath, fullpath) except Exception, e: lock.release_lock('generate_manifest') return -1, 'Error generating manifest : %s' % str(e)
def main(): try: lck, err = lock.get_lock('integralstor_poll_for_alerts') if err: raise Exception(err) if not lck: raise Exception('Could not acquire lock. Exiting.') alert_list = [] now = int(time.time()) db_path, err = config.get_db_path() if err: raise Exception(err) tasks_query = "select * from tasks where last_run_time > '%d' and (status = 'error-retrying' or status = 'failed');" % ( now - 110) # print "\ntasks_query: ", tasks_query rows, err = db.get_multiple_rows(db_path, tasks_query) # print "\nrows: ", rows if err: raise Exception(err) if rows: for row in rows: msg = "%s: %s." % (row['status'], row['description']) alert_list.append(msg) # print "\nalert_list: ", alert_list if alert_list: alerts.raise_alert(alert_list) lock.release_lock('integralstor_poll_for_alerts') except Exception, e: print "Error generating alerts : %s ! Exiting." % str(e) sys.exit(-1)
def create_volume(request): """ Used to actually create the volume""" return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.' ) return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'Create a volume' return_dict['tab'] = 'view_volumes_tab' return_dict["error"] = 'Error creating a volume' if request.method != "POST": raise Exception("Invalid access method. Please use the menus.") if 'cmd' not in request.POST or 'dataset_list' not in request.POST: raise Exception('Required parameters not passed.') # cmd represents the actual gluster volume creation command built using # the wizard choices. cmd = request.POST['cmd'] # print cmd # dataset_list is a list of hostname:dataset components of the datasets # that need to br created on various gridcells. dsl = request.POST.getlist('dataset_list') dataset_dict = {} for ds in dsl: tl = ds.split(':') dataset_dict[tl[0]] = tl[1] iv_logging.info("create volume command %s" % cmd) # First create the datasets on which the bricks will reside. # revert_list will consist of the set of node:command components to # perform to undo dataset creation in case of some failures. client = salt.client.LocalClient() revert_list = [] errors = "" for node, dataset in dataset_dict.items(): dataset_cmd = 'zfs create %s' % dataset dataset_revert_cmd = 'zfs destroy %s' % dataset r1 = client.cmd(node, 'cmd.run_all', [dataset_cmd]) if r1: for node, ret in r1.items(): # print ret if ret["retcode"] != 0: errors += ", Error creating the underlying storage brick on %s" % node # print errors else: revert_list.append({node: dataset_revert_cmd}) if errors != "": # print errors if revert_list: # Undo the creation of the datasets for revert in revert_list: for node, dsr_cmd in revert.items(): r1 = client.cmd(node, 'cmd.run_all', [dsr_cmd]) if r1: for node, ret in r1.items(): # print ret if ret["retcode"] != 0: errors += ", Error undoing the creating the underlying storage brick on %s" % node raise Exception(errors) # Underlying storage created so now create the volume d, errors = xml_parse.run_gluster_command("%s force" % cmd) # print d, errors if not errors: # All ok so mount and change the owner and group of the volume to # integralstor (ret, rc), err = command.execute_with_rc("gluster volume set " + request.POST['vol_name'] + " storage.owner-gid 1000") if err: raise Exception('Error setting volume owner : %s' % err) # Now start the volume (ret, rc), err = command.execute_with_rc("gluster volume start " + request.POST['vol_name']) if err: raise Exception('Error starting volume : %s' % err) ''' #Set the client side quorum count cmd = "gluster volume set %s quorum-count 2 --xml"%request.POST['vol_name'] d, err = xml_parse.run_gluster_command(cmd) if err: raise Exception('Error setting volume client side quorum count : %s'%err) #Set the client side quorum type cmd = "gluster volume set %s quorum-type fixed --xml"%request.POST['vol_name'] d, err = xml_parse.run_gluster_command(cmd) if err: raise Exception('Errot setting volume client side quorum type : %s'%err) ''' # Temporarily mount the volume (ret, rc), err = command.execute_with_rc( "mount -t glusterfs localhost:/" + request.POST['vol_name'] + " /mnt") if err: raise Exception(err) # Set the volume permissions (ret, rc), err = command.execute_with_rc("chmod 770 /mnt") if err: raise Exception(err) #..and unmount the volume (ret, rc), err = command.execute_with_rc("umount /mnt") if err: raise Exception(err) # If it is an ISCSI volume, then add it to the iscsi volume list.. # print request.POST['vol_access'] if request.POST["vol_access"] == "iscsi": ret, err = iscsi.add_iscsi_volume(request.POST["vol_name"]) if err: raise Exception(err) # Success so audit the change audit_str = "Create " if request.POST["vol_type"] in ["replicated"]: audit_str = audit_str + \ "replicated (count %d) " % int(request.POST["repl_count"]) else: audit_str = audit_str + "distributed " audit_str = audit_str + \ " volume named %s" % request.POST["vol_name"] ret, err = audit.audit("create_volume", audit_str, request) if err: raise Exception(err) else: # Volume creation itself failed so try and delete the underlying # datasets if they were created.. if not errors: errors = "" if revert_list: # Undo the creation of the datasets for revert in revert_list: for node, dsr_cmd in revert.items(): r1 = client.cmd(node, 'cmd.run_all', [dsr_cmd]) if r1: for node, ret in r1.items(): print ret if ret["retcode"] != 0: errors += ", Error undoing the creating the underlying storage brick on %s" % node if errors: raise Exception(errors) if request.POST['vol_type'] == 'replicated': return_dict['repl_count'] = request.POST['repl_count'] return_dict['vol_type'] = request.POST['vol_type'] return_dict['vol_name'] = request.POST['vol_name'] return_dict['node_list_str'] = request.POST['node_list_str'] return_dict['cmd'] = cmd return_dict['result_dict'] = d return django.shortcuts.render_to_response( 'vol_create_wiz_result.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict[ "error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict[ "error_details"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_volume_conf(request): """ Used to confirm volume creation parameters""" return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.' ) return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'Create a volume - confirmation' return_dict['tab'] = 'view_volumes_tab' return_dict[ "error"] = 'Error getting information for creating a volume' si, err = system_info.load_system_config() if err: raise Exception(err) if not si: raise Exception('Could not load system information') form = integral_view.forms.volume_creation_forms.VolOndiskStorageForm( request.POST or None) if form.is_valid(): cd = form.cleaned_data vol_type = cd['vol_type'] vol_name = cd['vol_name'] ondisk_storage = cd['ondisk_storage'] vol_access = cd['vol_access'] repl_count = 2 if vol_type == "replicated": # repl_count = int(cd["repl_count"]) # Hardcoded to 2 for now till we resolve the hot spare issue repl_count = 2 transport = "TCP" iv_logging.info( "create volume initiated for vol_type %s, vol_name %s, ondisk_storage %s, vol_access %s" % (vol_type, vol_name, ondisk_storage, vol_access)) d, err = gluster_volumes.build_create_volume_command( vol_name, vol_type, ondisk_storage, repl_count, transport, si) if err: raise Exception(err) if d and "error" in d: return_dict[ "error"] = "Error creating the volume : %s" % d["error"] return django.shortcuts.render_to_response( 'logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext( request)) node_list_str = ('<ul>') for n in d["node_list"]: node_list_str += '<li>' for i in n: node_list_str += str(i) node_list_str += ', ' node_list_str += '</li>' node_list_str += '</ul>' iv_logging.debug("create vol node list %s" % node_list_str) return_dict['cmd'] = d['cmd'] return_dict['dataset_list'] = d['dataset_list'] return_dict['node_list_str'] = node_list_str return_dict['vol_type'] = vol_type return_dict['vol_name'] = vol_name return_dict['vol_access'] = vol_access return_dict['ondisk_storage'] = ondisk_storage if vol_type == "replicated": return_dict['repl_count'] = str(repl_count) else: # Invalid form url = 'vol_create_wiz_vol_type.html' return_dict['form'] = form return django.shortcuts.render_to_response( url, return_dict, context_instance=django.template.context.RequestContext( request)) if settings.APP_DEBUG: return_dict['app_debug'] = True return_dict['form'] = form return django.shortcuts.render_to_response( 'vol_create_wiz_confirm.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict[ "error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict[ "error_details"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def edit_cifs_share(request): return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.') return_dict['base_template'] = "shares_and_targets_base.html" return_dict["page_title"] = 'Edit CIFS share details' return_dict['tab'] = 'view_cifs_shares_tab' return_dict["error"] = 'Error editing CIFS share details' vil, err = gluster_volumes.get_basic_volume_info_all() if err: raise Exception(err) if not vil: raise Exception('Could not load volume information') user_list, err = cifs_gridcell.get_user_list() if err: raise Exception(err) group_list, err = cifs_gridcell.get_group_list() if err: raise Exception(err) if request.method == "GET": # Shd be an edit request if "share_id" not in request.GET: raise Exception("Unknown share specified") share_id = request.GET["share_id"] share_dict, err = cifs_utils.get_share_info("by_id", share_id) if err: raise Exception(err) valid_users_list, err = cifs_gridcell.get_valid_users_list( share_dict["share_id"]) if err: raise Exception(err) # Set initial form values initial = {} initial["share_id"] = share_dict["share_id"] initial["name"] = share_dict["name"] initial["path"] = share_dict["path"] initial["display_path"] = share_dict["display_path"] initial["vol"] = share_dict["vol"] if share_dict["guest_ok"]: initial["guest_ok"] = True else: initial["guest_ok"] = False if share_dict["browseable"]: initial["browseable"] = True else: initial["browseable"] = False if share_dict["read_only"]: initial["read_only"] = True else: initial["read_only"] = False initial["comment"] = share_dict["comment"] if valid_users_list: vgl = [] vul = [] for u in valid_users_list: if u["grp"]: vgl.append(u["name"]) else: vul.append(u["name"]) initial["users"] = vul initial["groups"] = vgl form = cifs_shares_forms.ShareForm( initial=initial, user_list=user_list, group_list=group_list, volume_list=vil) return_dict["form"] = form return django.shortcuts.render_to_response('edit_cifs_share.html', return_dict, context_instance=django.template.context.RequestContext(request)) else: # Shd be an save request form = cifs_shares_forms.ShareForm( request.POST, user_list=user_list, group_list=group_list, volume_list=vil) return_dict["form"] = form if form.is_valid(): cd = form.cleaned_data name = cd["name"] share_id = cd["share_id"] path = cd["path"] if "comment" in cd: comment = cd["comment"] else: comment = None if "read_only" in cd: read_only = cd["read_only"] else: read_only = False if "browseable" in cd: browseable = cd["browseable"] else: browseable = False if "guest_ok" in cd: guest_ok = cd["guest_ok"] else: guest_ok = False if "users" in cd: users = cd["users"] else: users = None if "groups" in cd: groups = cd["groups"] else: groups = None vol = cd["vol"] ret, err = cifs_utils.update_share( share_id, name, comment, guest_ok, read_only, path, browseable, users, groups) if err: raise Exception(err) if not ret: raise Exception('Error saving share') ret, err = cifs_gridcell.generate_smb_conf() if err: raise Exception(err) if not ret: raise Exception('Error generating CIFS configuration file') audit_str = "Modified share %s" % cd["name"] ret, err = audit.audit("modify_share", audit_str, request) if err: raise Exception(err) return django.http.HttpResponseRedirect('/view_cifs_share?access_mode=by_id&index=%s&ack=saved' % cd["share_id"]) else: # Invalid form return django.shortcuts.render_to_response('edit_cifs_share.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error_details"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_cifs_share(request): return_dict = {} try: return_dict['base_template'] = "shares_and_targets_base.html" return_dict["page_title"] = 'Create a Windows share' return_dict['tab'] = 'view_cifs_shares_tab' return_dict["error"] = 'Error creating a Windows share' gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.') user_list, err = cifs_gridcell.get_user_list() if err: raise Exception(err) group_list, err = cifs_gridcell.get_group_list() if err: raise Exception(err) if 'vol_name' in request.REQUEST: return_dict['vol_name'] = request.REQUEST['vol_name'] vil, err = gluster_volumes.get_basic_volume_info_all() if err: raise Exception(err) if not vil: raise Exception( 'No volumes have been created. Please create a volume before creating shares.') il, err = iscsi.load_iscsi_volumes_list(vil) if err: raise Exception(err) vl = [] for v in vil: # Get only file based volumes that have been started if il and v["name"] in il: continue if v['status'] != 1: continue vl.append(v) if not vl: raise Exception( 'Shares can only be created on volumes that are file based and that are started. No volumes seem to match these criteria.') if request.method == "GET": # Return the form form = cifs_shares_forms.CreateShareForm( user_list=user_list, group_list=group_list, volume_list=vl) return_dict["form"] = form return django.shortcuts.render_to_response("create_cifs_share.html", return_dict, context_instance=django.template.context.RequestContext(request)) else: # Form submission so create form = cifs_shares_forms.CreateShareForm( request.POST, user_list=user_list, group_list=group_list, volume_list=vl) return_dict["form"] = form # print request.POST if form.is_valid(): # print return_dict cd = form.cleaned_data # print cd name = cd["name"] path = "%s" % cd["path"] if "comment" in cd: comment = cd["comment"] else: comment = None if "read_only" in cd: read_only = cd["read_only"] else: read_only = None if "browseable" in cd: browseable = cd["browseable"] else: browseable = None if "guest_ok" in cd: guest_ok = cd["guest_ok"] else: guest_ok = None if "users" in cd: users = cd["users"] else: users = None if "groups" in cd: groups = cd["groups"] else: groups = None vol = cd["vol"] if 'new_dir_name' in cd and cd['new_dir_name'].strip(): path = os.path.join(path, cd['new_dir_name']) # print path ret, err = gluster_gfapi.create_gluster_dir(vol, path) if err: raise Exception(err) # print users, groups ret, err = cifs_utils.create_share( name, comment, guest_ok, read_only, path, "", browseable, users, groups, vol) if err: raise Exception(err) if not ret: raise Exception('Error creating share') ret, err = cifs_gridcell.generate_smb_conf() if err: raise Exception(err) if not ret: raise Exception('Error generating CIFS configuration file') audit_str = "Created Windows share %s" % name ret, err = audit.audit("create_share", audit_str, request) if err: raise Exception(err) return django.http.HttpResponseRedirect('/view_cifs_shares?ack=created') else: return django.shortcuts.render_to_response("create_cifs_share.html", return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error_details"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_volume(request): """ Used to actually create the volume""" return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.') return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'Create a volume' return_dict['tab'] = 'view_volumes_tab' return_dict["error"] = 'Error creating a volume' if request.method != "POST": raise Exception("Invalid access method. Please use the menus.") if 'cmd' not in request.POST or 'dataset_list' not in request.POST: raise Exception('Required parameters not passed.') # cmd represents the actual gluster volume creation command built using # the wizard choices. cmd = request.POST['cmd'] # print cmd # dataset_list is a list of hostname:dataset components of the datasets # that need to br created on various gridcells. dsl = request.POST.getlist('dataset_list') dataset_dict = {} for ds in dsl: tl = ds.split(':') dataset_dict[tl[0]] = tl[1] iv_logging.info("create volume command %s" % cmd) # First create the datasets on which the bricks will reside. # revert_list will consist of the set of node:command components to # perform to undo dataset creation in case of some failures. client = salt.client.LocalClient() revert_list = [] errors = "" for node, dataset in dataset_dict.items(): dataset_cmd = 'zfs create %s' % dataset dataset_revert_cmd = 'zfs destroy %s' % dataset r1 = client.cmd(node, 'cmd.run_all', [dataset_cmd]) if r1: for node, ret in r1.items(): # print ret if ret["retcode"] != 0: errors += ", Error creating the underlying storage brick on %s" % node # print errors else: revert_list.append({node: dataset_revert_cmd}) if errors != "": # print errors if revert_list: # Undo the creation of the datasets for revert in revert_list: for node, dsr_cmd in revert.items(): r1 = client.cmd(node, 'cmd.run_all', [dsr_cmd]) if r1: for node, ret in r1.items(): # print ret if ret["retcode"] != 0: errors += ", Error undoing the creating the underlying storage brick on %s" % node raise Exception(errors) # Underlying storage created so now create the volume d, errors = xml_parse.run_gluster_command("%s force" % cmd) # print d, errors if not errors: # All ok so mount and change the owner and group of the volume to # integralstor (ret, rc), err = command.execute_with_rc("gluster volume set " + request.POST['vol_name'] + " storage.owner-gid 1000") if err: raise Exception('Error setting volume owner : %s' % err) # Now start the volume (ret, rc), err = command.execute_with_rc( "gluster volume start " + request.POST['vol_name']) if err: raise Exception('Error starting volume : %s' % err) ''' #Set the client side quorum count cmd = "gluster volume set %s quorum-count 2 --xml"%request.POST['vol_name'] d, err = xml_parse.run_gluster_command(cmd) if err: raise Exception('Error setting volume client side quorum count : %s'%err) #Set the client side quorum type cmd = "gluster volume set %s quorum-type fixed --xml"%request.POST['vol_name'] d, err = xml_parse.run_gluster_command(cmd) if err: raise Exception('Errot setting volume client side quorum type : %s'%err) ''' # Temporarily mount the volume (ret, rc), err = command.execute_with_rc( "mount -t glusterfs localhost:/" + request.POST['vol_name'] + " /mnt") if err: raise Exception(err) # Set the volume permissions (ret, rc), err = command.execute_with_rc("chmod 770 /mnt") if err: raise Exception(err) #..and unmount the volume (ret, rc), err = command.execute_with_rc("umount /mnt") if err: raise Exception(err) # If it is an ISCSI volume, then add it to the iscsi volume list.. # print request.POST['vol_access'] if request.POST["vol_access"] == "iscsi": ret, err = iscsi.add_iscsi_volume(request.POST["vol_name"]) if err: raise Exception(err) # Success so audit the change audit_str = "Create " if request.POST["vol_type"] in ["replicated"]: audit_str = audit_str + \ "replicated (count %d) " % int(request.POST["repl_count"]) else: audit_str = audit_str + "distributed " audit_str = audit_str + \ " volume named %s" % request.POST["vol_name"] ret, err = audit.audit("create_volume", audit_str, request) if err: raise Exception(err) else: # Volume creation itself failed so try and delete the underlying # datasets if they were created.. if not errors: errors = "" if revert_list: # Undo the creation of the datasets for revert in revert_list: for node, dsr_cmd in revert.items(): r1 = client.cmd(node, 'cmd.run_all', [dsr_cmd]) if r1: for node, ret in r1.items(): print ret if ret["retcode"] != 0: errors += ", Error undoing the creating the underlying storage brick on %s" % node if errors: raise Exception(errors) if request.POST['vol_type'] == 'replicated': return_dict['repl_count'] = request.POST['repl_count'] return_dict['vol_type'] = request.POST['vol_type'] return_dict['vol_name'] = request.POST['vol_name'] return_dict['node_list_str'] = request.POST['node_list_str'] return_dict['cmd'] = cmd return_dict['result_dict'] = d return django.shortcuts.render_to_response('vol_create_wiz_result.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error_details"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def show(request, page, info=None): return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.' ) assert request.method == 'GET' vil, err = gluster_volumes.get_basic_volume_info_all() if err: raise Exception(err) si, err = system_info.load_system_config() if err: raise Exception(err) if not si: raise Exception('Could not obtain system information') #assert False return_dict['system_info'] = si return_dict['volume_info_list'] = vil # By default show error page if page == "dir_contents": dir_name = None error = False path_base = None vol_name = "" dir_list = [] try: if ("vol_name" in request.GET) and ("dir" in request.GET): vol_name = request.GET.get("vol_name") dir_name = request.GET.get("dir") first = request.GET.get("first") # print first else: raise Exception("No volume or Directory Specified") if first: dirs, err = gluster_gfapi.get_gluster_dir_list( vol_name, "") else: dirs, err = gluster_gfapi.get_gluster_dir_list( vol_name, dir_name) if err: raise Exception(err) dir_list = json.dumps(dirs) except Exception as e: return django.http.HttpResponse("Exception Occured : %s" % str(e)) #iv_logging.debug("Exception while getting dir listing : "%e) return django.http.HttpResponse(dir_list, mimetype='application/json') elif page == "integral_view_log_level": template = "view_integral_view_log_level.html" log_level, err = iv_logging.get_log_level_str() if err: raise Exception(err) return_dict["log_level_str"] = log_level if "saved" in request.REQUEST: return_dict["saved"] = request.REQUEST["saved"] elif page == "batch_start_conf": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View batch job' return_dict['tab'] = 'volume_background_tab' return_dict[ "error"] = 'Error displaying batch job creation confirmation' # Display a confirmation that the batch job has been scheduled. # info contains the filename of the batch job template = "batch_start_conf.html" return_dict["fname"] = info elif page == "batch_status": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View batch jobs' return_dict['tab'] = 'volume_background_tab' return_dict["error"] = 'Error loading batch jobs' # Load the list of entries from all the files in the start and # process directories file_list, err = batch.load_all_files() if err: raise Exception(err) return_dict["file_list"] = file_list template = "view_batch_process_list.html" elif page == "batch_status_details": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View batch job status' return_dict['tab'] = 'volume_background_tab' return_dict["error"] = 'Error loading batch job status' d, err = batch.load_specific_file(info) if err: raise Exception(err) if not d: raise Exception('Unknown batch job specified') else: return_dict["process_info"] = d template = "view_batch_status_details.html" elif page == "volume_info": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume information' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume information' vol, err = gluster_volumes.get_complete_volume_info(info) if err: raise Exception(err) if not vol: raise Exception("Could not locate information for volume %s" % info) quota_enabled = False if "options" in vol: for o in vol["options"]: if "features.quota" == o["name"] and o["value"] == "on": quota_enabled = True break return_dict['quota_enabled'] = quota_enabled template = "view_volume_info.html" return_dict["vol"] = vol data_locations_list, err = gluster_volumes.get_brick_hostname_list( vol) if err: raise Exception(err) # print data_locations_list return_dict["data_locations_list"] = data_locations_list ivl, err = iscsi.load_iscsi_volumes_list(vil) if err: raise Exception(err) if ivl and vol["name"] in ivl: return_dict["iscsi"] = True # To accomodate django template quirks # if vol["type"] in ["Replicate", "Distributed-Replicate"]: # elif vol["type"] in ["Distribute", "Distributed-Replicate"]: if 'replicate' in vol["type"].lower(): return_dict["replicate"] = True if 'distribute' in vol["type"].lower(): return_dict["distribute"] = True elif page == "volume_status": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume status' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume status' vol, err = gluster_volumes.get_volume_status(vil, info) if err: raise Exception(err) if not vol: raise Exception("Could not locate information for volume %s" % info) template = "view_volume_status.html" return_dict["vol"] = vol # To accomodate django template quirks if vol["type"] in ["Replicate", "Distributed-Replicate"]: return_dict["replicate"] = True if vol["type"] in ["Distribute", "Distributed-Replicate"]: return_dict["distribute"] = True elif page == "node_info": return_dict['base_template'] = "gridcell_base.html" return_dict["page_title"] = 'View GRIDCell information' return_dict['tab'] = 'gridcell_list_tab' return_dict["error"] = 'Error loading GRIDCell information' template = "view_node_info.html" if "from" in request.GET: frm = request.GET["from"] return_dict['frm'] = frm vol_list, err = gluster_volumes.get_volumes_on_node(info, vil) if err: raise Exception(err) return_dict['node'] = si[info] return_dict['vol_list'] = vol_list elif page == "manifest": # Read a generated manifest file and display the results. if "manifest" not in request.GET: raise Exception('Invalid request. No manifest file specified') manifest = request.GET["manifest"] ss_path, err = config.get_system_status_path() if err: raise Exception(err) with open("%s/%s" % (ss_path, manifest), "r") as f: nodes = json.load(f) return_dict["manifest"] = nodes return_dict["manifest_file"] = manifest return django.shortcuts.render_to_response( 'view_manifest.html', return_dict, context_instance=django.template.context.RequestContext( request)) elif page == "iscsi_auth_access_info": return_dict['base_template'] = "shares_and_targets_base.html" return_dict["page_title"] = 'View ISCSI authorized access info' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading ISCSI authorized access info' if 'id' not in request.GET: raise Exception('Invalid request. No auth access id specified') id = int(request.GET['id']) l, err = iscsi.load_auth_access_users_info(id) if err: raise Exception(err) if not l: raise Exception( 'No auth access information for the id specified') istr = "<b>Authorized access group users : </b>" for i in l: istr += i["user"] istr += ", " # return django.http.HttpResponse("<b>Authorized access details # </b><br>User : %s, Peer user : %s"%(d["user"],d["peer_user"] )) return django.http.HttpResponse("%s" % istr) elif page == "iscsi_initiator_info": return_dict['base_template'] = "shares_and_targets_base.html" return_dict["page_title"] = 'View ISCSI initiator info' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading ISCSI initiator info' if 'id' not in request.GET: raise Exception( 'Invalid request. No initiator access id specified') id = int(request.GET['id']) d, err = iscsi.load_initiator_info(id) if err: raise Exception(err) if not d: raise Exception( 'No initiator information for the id specified') return django.http.HttpResponse( "<b>Initiator details</b><br>Initiators : %s, Auth network : %s, Comment : %s" % (d["initiators"], d["auth_network"], d["comment"])) elif page == "system_config": template = "view_system_config.html" elif page == "system_status": return_dict['base_template'] = "gridcell_base.html" return_dict["page_title"] = 'View system status' return_dict['tab'] = 'gridcell_list_tab' return_dict["error"] = 'Error loading system status' # Disk Status page and system status page has been integrated. # Get the disk status disk_status = {} disk_new = {} if request.GET.get("node_id") is not None: disk_status = si[request.GET.get("node_id")] return_dict["disk_status"] = {} return_dict["disk_status"][request.GET.get( "node_id")] = disk_status template = "view_disk_status_details.html" else: """ Iterate the system information, and get the following data : 1. The status of every disk 2. The status of the pool 3. The name of the pool 4. Calcualte the background_color Format : {'node_id':{'name':'pool_name','background_color':'background_color','disks':{disks_pool}}} """ for key, value in si.iteritems(): # count the failures in case of Offline or degraded disk_failures = 0 # Default background color background_color = "bg-green" if not si[key]["in_cluster"]: disk_new[key] = {} disk_new[key]["disks"] = {} disk_new[key]["in_cluster"] = si[key]["in_cluster"] for disk_key, disk_value in si[key]["disks"].iteritems( ): # print disk_key, disk_value if disk_value["rotational"]: disk_new[key]["disks"][disk_key] = disk_value[ "status"] # print disk_value["status"] if disk_value["status"] != "PASSED": disk_failures += 1 if disk_failures >= 1: background_color = "bg-yellow" if disk_failures >= 4: background_color == "bg-red" if si[key]['node_status_str'] == "Degraded": background_color = "bg-yellow" # print type(si[key]["pools"][0]["state"]) if si[key]["pools"][0]["state"] == unicode("ONLINE"): background_color == "bg-red" disk_new[key]["background_color"] = background_color disk_new[key]["name"] = si[key]["pools"][0][ "pool_name"] sorted_disks = [] for key1, value1 in sorted( si[key]["disks"].iteritems(), key=lambda (k, v): v["position"]): sorted_disks.append(key1) disk_new[key]["disk_pos"] = sorted_disks # print disk_new #disk_new[key]["info"] = pool_status else: disk_status[key] = {} if si[key]["node_status"] != -1: disk_status[key]["disks"] = {} disk_status[key]["in_cluster"] = si[key][ "in_cluster"] for disk_key, disk_value in si[key][ "disks"].iteritems(): # print disk_key, disk_value if disk_value["rotational"]: disk_status[key]["disks"][ disk_key] = disk_value["status"] # print disk_value["status"] if disk_value["status"] != "PASSED": disk_failures += 1 if disk_failures >= 1: background_color = "bg-yellow" if disk_failures >= 4: background_color == "bg-red" if si[key]['node_status_str'] == "Degraded": background_color = "bg-yellow" # print type(si[key]["pools"][0]["state"]) if si[key]["pools"][0]["state"] == unicode( "ONLINE"): background_color == "bg-red" disk_status[key][ "background_color"] = background_color disk_status[key]["name"] = si[key]["pools"][0][ "pool_name"] sorted_disks = [] for key1, value1 in sorted( si[key]["disks"].iteritems(), key=lambda (k, v): v["position"]): sorted_disks.append(key1) disk_status[key]["disk_pos"] = sorted_disks # print disk_status #disk_status[key]["info"] = pool_status else: disk_status[key] = {} disk_status[key]["background_color"] = "bg-red" disk_status[key]["disk_pos"] = {} disk_status[key]["name"] = "Unknown" template = "view_disk_status.html" return_dict["disk_status"] = disk_status return_dict["disk_new"] = disk_new elif page == "pool_status": template = "view_pool_status.html" num_free_nodes = 0 for name, node in si.items(): if node["node_status"] >= 0 and (not node["in_cluster"]): num_free_nodes += 1 return_dict['num_free_nodes'] = num_free_nodes elif page == "alerts": return_dict['base_template'] = "system_log_base.html" return_dict["page_title"] = 'View alerts' return_dict['tab'] = 'system_log_alert_tab' return_dict["error"] = 'Error loading system alerts' template = "view_alerts.html" alerts_list, err = alerts.get_alerts() if err: raise Exception(err) return_dict['alerts_list'] = alerts_list elif page == "volume_info_all": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume info' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume info' template = "view_volume_info_all.html" return_dict['volume_info_list'] = vil ivl, err = iscsi.load_iscsi_volumes_list(vil) if err: raise Exception(err) return_dict['iscsi_volumes'] = ivl elif page == "volume_status_all": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume status' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume status' template = "view_volume_status_all.html" return_dict['volume_info_list'] = vil return django.shortcuts.render_to_response( template, return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict[ "error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error_details"] = s return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def dashboard(request): return_dict = {} try: return_dict['base_template'] = "dashboard_base.html" return_dict["page_title"] = 'Dashboard' return_dict['tab'] = 'dashboard_tab' return_dict["error"] = 'Error loading dashboard' gluster_lock, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lock: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.') num_nodes_bad = 0 num_pools_bad = 0 num_vols_bad = 0 total_pool = 0 nodes = {} storage_pool = {} bad_nodes = [] bad_node_pools = [] bad_volumes = [] num_bad_ctdb_nodes = 0 bad_ctdb_nodes = [] num_quotas_exceeded = 0 soft_quota_exceeded_vols = [] hard_quota_exceeded_vols = [] num_shares = 0 si, err = system_info.load_system_config() if err: raise Exception(err) if not si: raise Exception('Could not obtain system information') total_nodes = len(si) for k, v in si.items(): nodes[k] = v["node_status"] if v["node_status"] != 0: num_nodes_bad += 1 bad_nodes.append(k) if v["in_cluster"]: total_pool += 1 if v["cluster_status"] != 1: num_pools_bad += 1 bad_node_pools.append(k) storage_pool[k] = v["cluster_status_str"] # Get all the volume info including process status and other status complete_vil, err = gluster_volumes.get_complete_volume_info_all() if err: raise Exception(err) total_vols = len(complete_vil) for vol in complete_vil: if vol["status"] == 1: if vol["data_access_status_code"] != 0 or (not vol["processes_ok"]): bad_volumes.append(vol['name']) num_vols_bad += 1 if 'quotas' in vol and vol['quotas']: for k, v in vol['quotas'].items(): # print vol['name'], k, v if v: for quota_key, quota_val in v.items(): if quota_key.lower() in ['sl_exceeded', 'hl_exceeded'] and quota_val.lower() == 'yes': if quota_key.lower() == 'sl_exceeded': soft_quota_exceeded_vols.append( vol['name']) if quota_key.lower() == 'hl_exceeded': hard_quota_exceeded_vols.append( vol['name']) num_quotas_exceeded += 1 # print soft_quota_exceeded_vols # print hard_quota_exceeded_vols shares_list, err = cifs_utils.get_shares_list() if err: raise Exception(err) if shares_list: num_shares = len(shares_list) return_dict['num_shares'] = num_shares targets_list, err = iscsi_stgt.get_targets() if err: raise Exception(err) if targets_list: return_dict['num_targets'] = len(targets_list) else: return_dict['num_targets'] = 0 ''' #Commenting out as we wont use ctdb for this build ctdb_status, err = ctdb.get_status() #print ctdb_status, err if err: raise Exception(err) if ctdb_status: num_ctdb_nodes = len(ctdb_status) for n, v in ctdb_status.items(): if v.lower() != 'ok': num_bad_ctdb_nodes += 1 return_dict["ctdb_status"] = ctdb_status ''' return_dict["num_quotas_exceeded"] = num_quotas_exceeded return_dict["soft_quota_exceeded_vols"] = soft_quota_exceeded_vols return_dict["hard_quota_exceeded_vols"] = hard_quota_exceeded_vols #return_dict["num_ctdb_nodes"] = num_ctdb_nodes return_dict["num_bad_ctdb_nodes"] = num_bad_ctdb_nodes return_dict["num_nodes_bad"] = num_nodes_bad return_dict["bad_nodes"] = bad_nodes return_dict["bad_node_pools"] = bad_node_pools return_dict["num_pools_bad"] = num_pools_bad return_dict["num_vols_bad"] = num_vols_bad return_dict["total_nodes"] = total_nodes return_dict["total_pool"] = total_pool return_dict["total_vols"] = total_vols return_dict["nodes"] = nodes return_dict['system_info'] = si return_dict['volume_info_list'] = complete_vil return_dict["storage_pool"] = storage_pool return django.shortcuts.render_to_response('view_dashboard.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error_details"] = s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def show(request, page, info=None): return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.') assert request.method == 'GET' vil, err = gluster_volumes.get_basic_volume_info_all() if err: raise Exception(err) si, err = system_info.load_system_config() if err: raise Exception(err) if not si: raise Exception('Could not obtain system information') #assert False return_dict['system_info'] = si return_dict['volume_info_list'] = vil # By default show error page if page == "dir_contents": dir_name = None error = False path_base = None vol_name = "" dir_list = [] try: if ("vol_name" in request.GET) and ("dir" in request.GET): vol_name = request.GET.get("vol_name") dir_name = request.GET.get("dir") first = request.GET.get("first") # print first else: raise Exception("No volume or Directory Specified") if first: dirs, err = gluster_gfapi.get_gluster_dir_list( vol_name, "") else: dirs, err = gluster_gfapi.get_gluster_dir_list( vol_name, dir_name) if err: raise Exception(err) dir_list = json.dumps(dirs) except Exception as e: return django.http.HttpResponse("Exception Occured : %s" % str(e)) #iv_logging.debug("Exception while getting dir listing : "%e) return django.http.HttpResponse(dir_list, mimetype='application/json') elif page == "integral_view_log_level": template = "view_integral_view_log_level.html" log_level, err = iv_logging.get_log_level_str() if err: raise Exception(err) return_dict["log_level_str"] = log_level if "saved" in request.REQUEST: return_dict["saved"] = request.REQUEST["saved"] elif page == "batch_start_conf": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View batch job' return_dict['tab'] = 'volume_background_tab' return_dict["error"] = 'Error displaying batch job creation confirmation' # Display a confirmation that the batch job has been scheduled. # info contains the filename of the batch job template = "batch_start_conf.html" return_dict["fname"] = info elif page == "batch_status": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View batch jobs' return_dict['tab'] = 'volume_background_tab' return_dict["error"] = 'Error loading batch jobs' # Load the list of entries from all the files in the start and # process directories file_list, err = batch.load_all_files() if err: raise Exception(err) return_dict["file_list"] = file_list template = "view_batch_process_list.html" elif page == "batch_status_details": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View batch job status' return_dict['tab'] = 'volume_background_tab' return_dict["error"] = 'Error loading batch job status' d, err = batch.load_specific_file(info) if err: raise Exception(err) if not d: raise Exception('Unknown batch job specified') else: return_dict["process_info"] = d template = "view_batch_status_details.html" elif page == "volume_info": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume information' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume information' vol, err = gluster_volumes.get_complete_volume_info(info) if err: raise Exception(err) if not vol: raise Exception( "Could not locate information for volume %s" % info) quota_enabled = False if "options" in vol: for o in vol["options"]: if "features.quota" == o["name"] and o["value"] == "on": quota_enabled = True break return_dict['quota_enabled'] = quota_enabled template = "view_volume_info.html" return_dict["vol"] = vol data_locations_list, err = gluster_volumes.get_brick_hostname_list( vol) if err: raise Exception(err) # print data_locations_list return_dict["data_locations_list"] = data_locations_list ivl, err = iscsi.load_iscsi_volumes_list(vil) if err: raise Exception(err) if ivl and vol["name"] in ivl: return_dict["iscsi"] = True # To accomodate django template quirks # if vol["type"] in ["Replicate", "Distributed-Replicate"]: # elif vol["type"] in ["Distribute", "Distributed-Replicate"]: if 'replicate' in vol["type"].lower(): return_dict["replicate"] = True if 'distribute' in vol["type"].lower(): return_dict["distribute"] = True elif page == "volume_status": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume status' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume status' vol, err = gluster_volumes.get_volume_status(vil, info) if err: raise Exception(err) if not vol: raise Exception( "Could not locate information for volume %s" % info) template = "view_volume_status.html" return_dict["vol"] = vol # To accomodate django template quirks if vol["type"] in ["Replicate", "Distributed-Replicate"]: return_dict["replicate"] = True if vol["type"] in ["Distribute", "Distributed-Replicate"]: return_dict["distribute"] = True elif page == "node_info": return_dict['base_template'] = "gridcell_base.html" return_dict["page_title"] = 'View GRIDCell information' return_dict['tab'] = 'gridcell_list_tab' return_dict["error"] = 'Error loading GRIDCell information' template = "view_node_info.html" if "from" in request.GET: frm = request.GET["from"] return_dict['frm'] = frm vol_list, err = gluster_volumes.get_volumes_on_node(info, vil) if err: raise Exception(err) return_dict['node'] = si[info] return_dict['vol_list'] = vol_list elif page == "manifest": # Read a generated manifest file and display the results. if "manifest" not in request.GET: raise Exception('Invalid request. No manifest file specified') manifest = request.GET["manifest"] ss_path, err = config.get_system_status_path() if err: raise Exception(err) with open("%s/%s" % (ss_path, manifest), "r") as f: nodes = json.load(f) return_dict["manifest"] = nodes return_dict["manifest_file"] = manifest return django.shortcuts.render_to_response('view_manifest.html', return_dict, context_instance=django.template.context.RequestContext(request)) elif page == "iscsi_auth_access_info": return_dict['base_template'] = "shares_and_targets_base.html" return_dict["page_title"] = 'View ISCSI authorized access info' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading ISCSI authorized access info' if 'id' not in request.GET: raise Exception('Invalid request. No auth access id specified') id = int(request.GET['id']) l, err = iscsi.load_auth_access_users_info(id) if err: raise Exception(err) if not l: raise Exception( 'No auth access information for the id specified') istr = "<b>Authorized access group users : </b>" for i in l: istr += i["user"] istr += ", " # return django.http.HttpResponse("<b>Authorized access details # </b><br>User : %s, Peer user : %s"%(d["user"],d["peer_user"] )) return django.http.HttpResponse("%s" % istr) elif page == "iscsi_initiator_info": return_dict['base_template'] = "shares_and_targets_base.html" return_dict["page_title"] = 'View ISCSI initiator info' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading ISCSI initiator info' if 'id' not in request.GET: raise Exception( 'Invalid request. No initiator access id specified') id = int(request.GET['id']) d, err = iscsi.load_initiator_info(id) if err: raise Exception(err) if not d: raise Exception( 'No initiator information for the id specified') return django.http.HttpResponse("<b>Initiator details</b><br>Initiators : %s, Auth network : %s, Comment : %s" % (d["initiators"], d["auth_network"], d["comment"])) elif page == "system_config": template = "view_system_config.html" elif page == "system_status": return_dict['base_template'] = "gridcell_base.html" return_dict["page_title"] = 'View system status' return_dict['tab'] = 'gridcell_list_tab' return_dict["error"] = 'Error loading system status' # Disk Status page and system status page has been integrated. # Get the disk status disk_status = {} disk_new = {} if request.GET.get("node_id") is not None: disk_status = si[request.GET.get("node_id")] return_dict["disk_status"] = {} return_dict["disk_status"][request.GET.get( "node_id")] = disk_status template = "view_disk_status_details.html" else: """ Iterate the system information, and get the following data : 1. The status of every disk 2. The status of the pool 3. The name of the pool 4. Calcualte the background_color Format : {'node_id':{'name':'pool_name','background_color':'background_color','disks':{disks_pool}}} """ for key, value in si.iteritems(): # count the failures in case of Offline or degraded disk_failures = 0 # Default background color background_color = "bg-green" if not si[key]["in_cluster"]: disk_new[key] = {} disk_new[key]["disks"] = {} disk_new[key]["in_cluster"] = si[key]["in_cluster"] for disk_key, disk_value in si[key]["disks"].iteritems(): # print disk_key, disk_value if disk_value["rotational"]: disk_new[key]["disks"][disk_key] = disk_value["status"] # print disk_value["status"] if disk_value["status"] != "PASSED": disk_failures += 1 if disk_failures >= 1: background_color = "bg-yellow" if disk_failures >= 4: background_color == "bg-red" if si[key]['node_status_str'] == "Degraded": background_color = "bg-yellow" # print type(si[key]["pools"][0]["state"]) if si[key]["pools"][0]["state"] == unicode("ONLINE"): background_color == "bg-red" disk_new[key]["background_color"] = background_color disk_new[key]["name"] = si[key]["pools"][0]["pool_name"] sorted_disks = [] for key1, value1 in sorted(si[key]["disks"].iteritems(), key=lambda (k, v): v["position"]): sorted_disks.append(key1) disk_new[key]["disk_pos"] = sorted_disks # print disk_new #disk_new[key]["info"] = pool_status else: disk_status[key] = {} if si[key]["node_status"] != -1: disk_status[key]["disks"] = {} disk_status[key]["in_cluster"] = si[key]["in_cluster"] for disk_key, disk_value in si[key]["disks"].iteritems(): # print disk_key, disk_value if disk_value["rotational"]: disk_status[key]["disks"][disk_key] = disk_value["status"] # print disk_value["status"] if disk_value["status"] != "PASSED": disk_failures += 1 if disk_failures >= 1: background_color = "bg-yellow" if disk_failures >= 4: background_color == "bg-red" if si[key]['node_status_str'] == "Degraded": background_color = "bg-yellow" # print type(si[key]["pools"][0]["state"]) if si[key]["pools"][0]["state"] == unicode("ONLINE"): background_color == "bg-red" disk_status[key]["background_color"] = background_color disk_status[key]["name"] = si[key]["pools"][0]["pool_name"] sorted_disks = [] for key1, value1 in sorted(si[key]["disks"].iteritems(), key=lambda (k, v): v["position"]): sorted_disks.append(key1) disk_status[key]["disk_pos"] = sorted_disks # print disk_status #disk_status[key]["info"] = pool_status else: disk_status[key] = {} disk_status[key]["background_color"] = "bg-red" disk_status[key]["disk_pos"] = {} disk_status[key]["name"] = "Unknown" template = "view_disk_status.html" return_dict["disk_status"] = disk_status return_dict["disk_new"] = disk_new elif page == "pool_status": template = "view_pool_status.html" num_free_nodes = 0 for name, node in si.items(): if node["node_status"] >= 0 and (not node["in_cluster"]): num_free_nodes += 1 return_dict['num_free_nodes'] = num_free_nodes elif page == "alerts": return_dict['base_template'] = "system_log_base.html" return_dict["page_title"] = 'View alerts' return_dict['tab'] = 'system_log_alert_tab' return_dict["error"] = 'Error loading system alerts' template = "view_alerts.html" alerts_list, err = alerts.get_alerts() if err: raise Exception(err) return_dict['alerts_list'] = alerts_list elif page == "volume_info_all": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume info' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume info' template = "view_volume_info_all.html" return_dict['volume_info_list'] = vil ivl, err = iscsi.load_iscsi_volumes_list(vil) if err: raise Exception(err) return_dict['iscsi_volumes'] = ivl elif page == "volume_status_all": return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'View volume status' return_dict['tab'] = 'volume_configuration_tab' return_dict["error"] = 'Error loading volume status' template = "view_volume_status_all.html" return_dict['volume_info_list'] = vil return django.shortcuts.render_to_response(template, return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error_details"] = s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def download_vol_log(request): """ Used to download the volume log of a particular volume whose name is in the vol_name post parameter""" return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.') return_dict['base_template'] = 'log_base.html' return_dict["page_title"] = 'Download volume logs' return_dict['tab'] = 'volume_log_download_tab' return_dict["error"] = 'Error downloading volume logs' vil, err = gluster_volumes.get_basic_volume_info_all() if err: raise Exception(err) if not vil: raise Exception('No volumes detected') l = [] for v in vil: l.append(v["name"]) if request.method == 'POST': form = volume_management_forms.VolumeNameForm( request.POST, vol_list=l) if form.is_valid(): cd = form.cleaned_data vol_name = cd['vol_name'] iv_logging.debug( "Got volume log download request for %s" % vol_name) file_name = None v, err = gluster_volumes.get_basic_volume_info(vol_name) if err: raise Exception(err) if not v: raise Exception("Could not retrieve volume info") brick = v["bricks"][0][0] if not brick: raise Exception( "Could not retrieve volume log location - no brick") l = brick.split(':') if not l: raise Exception( "Could not retrieve volume log location - malformed brick 1") l1 = l[1].split('/') if not l1: raise Exception( "Could not retrieve volume log location - malformed brick 2") file_name = '/var/log/glusterfs/bricks/%s-%s-%s.log' % ( l1[1], l1[2], vol_name) display_name = 'integralstor_gridcell-%s.log' % vol_name # Formulate the zip file name zf_name = '/tmp/integralstor_gridcell_volume_%s_log' % vol_name dt = datetime.datetime.now() dt_str = dt.strftime("%d%m%Y%H%M%S") zf_name = zf_name + dt_str + ".zip" try: zf = zipfile.ZipFile(zf_name, 'w') zf.write(file_name, arcname=display_name) zf.write('/var/log/glusterfs/cli.log', arcname='cli.log') zf.write('/var/log/glusterfs/cmd_history.log', arcname='cmd_history.log') zf.write('/var/log/glusterfs/etc-glusterfs-glusterd.vol.log', arcname='etc-glusterfs-glusterd.vol.log') zf.write('/var/log/glusterfs/', arcname='') zf.write('/var/log/glusterfs/', arcname='') zf.close() except Exception as e: raise Exception("Error generating zip file : %s" % str(e)) response = django.http.HttpResponse() response['Content-disposition'] = 'attachment; filename=integralstor_gridcell_volume_%s_log_%s.zip' % ( vol_name, dt_str) response['Content-type'] = 'application/x-compressed' try: with open(zf_name, 'rb') as f: byte = f.read(1) while byte: response.write(byte) byte = f.read(1) response.flush() except Exception as e: raise Exception( "Error compressing remote log file : %s" % str(e)) return response else: form = volume_management_forms.VolumeNameForm(vol_list=l) # either a get or an invalid form so send back form return_dict['form'] = form return_dict['op'] = 'download_log' return django.shortcuts.render_to_response('download_vol_log_form.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def download_sys_log(request): """ Download the system log of the type specified in sys_log_type POST param for the node specified in the hostname POST parameter. This calls the /sys_log via an http request on that node to get the info""" return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.') return_dict['base_template'] = "log_base.html" return_dict["page_title"] = 'Download system logs' return_dict['tab'] = 'download_system_logs_tab' return_dict["error"] = 'Error downloading system logs' si, err = system_info.load_system_config() if err: raise Exception(err) if not si: raise Exception('Could not load system configuration') form = log_management_forms.SystemLogsForm( request.POST or None, system_config=si) if request.method == 'POST': if form.is_valid(): cd = form.cleaned_data sys_log_type = cd['sys_log_type'] hostname = cd["hostname"] iv_logging.debug("Got sys log download request for type %s hostname %s" % ( sys_log_type, hostname)) #fn = {'boot':'/var/log/boot.log', 'dmesg':'/var/log/dmesg', 'message':'/var/log/messages', 'smb':'/var/log/smblog.vfs', 'winbind':'/var/log/samba/log.winbindd','ctdb':'/var/log/log.ctdb'} #dn = {'boot':'boot.log', 'dmesg':'dmesg', 'message':'messages','smb':'samba_logs','winbind':'winbind_logs','ctdb':'ctdb_logs'} fn = {'boot': '/var/log/boot.log', 'dmesg': '/var/log/dmesg', 'message': '/var/log/messages', 'smb': '/var/log/smblog.vfs', 'winbind': '/var/log/samba/log.winbindd'} dn = {'boot': 'boot.log', 'dmesg': 'dmesg', 'message': 'messages', 'smb': 'samba_logs', 'winbind': 'winbind_logs'} file_name = fn[sys_log_type] display_name = dn[sys_log_type] client = salt.client.LocalClient() ret = client.cmd('%s' % (hostname), 'cp.push', [file_name]) print ret zf_name = '%s.zip' % display_name try: zf = zipfile.ZipFile(zf_name, 'w') zf.write("/var/cache/salt/master/minions/%s/files/%s" % (hostname, file_name), arcname=display_name) zf.close() except Exception as e: raise Exception( "Error compressing remote log file : %s" % str(e)) response = django.http.HttpResponse() response['Content-disposition'] = 'attachment; filename=%s.zip' % ( display_name) response['Content-type'] = 'application/x-compressed' with open(zf_name, 'rb') as f: byte = f.read(1) while byte: response.write(byte) byte = f.read(1) response.flush() return response # either a get or an invalid form so send back form return_dict['form'] = form return django.shortcuts.render_to_response('download_sys_log_form.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def dashboard(request): return_dict = {} try: return_dict['base_template'] = "dashboard_base.html" return_dict["page_title"] = 'Dashboard' return_dict['tab'] = 'dashboard_tab' return_dict["error"] = 'Error loading dashboard' gluster_lock, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lock: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.' ) num_nodes_bad = 0 num_pools_bad = 0 num_vols_bad = 0 total_pool = 0 nodes = {} storage_pool = {} bad_nodes = [] bad_node_pools = [] bad_volumes = [] num_bad_ctdb_nodes = 0 bad_ctdb_nodes = [] num_quotas_exceeded = 0 soft_quota_exceeded_vols = [] hard_quota_exceeded_vols = [] num_shares = 0 si, err = system_info.load_system_config() if err: raise Exception(err) if not si: raise Exception('Could not obtain system information') total_nodes = len(si) for k, v in si.items(): nodes[k] = v["node_status"] if v["node_status"] != 0: num_nodes_bad += 1 bad_nodes.append(k) if v["in_cluster"]: total_pool += 1 if v["cluster_status"] != 1: num_pools_bad += 1 bad_node_pools.append(k) storage_pool[k] = v["cluster_status_str"] # Get all the volume info including process status and other status complete_vil, err = gluster_volumes.get_complete_volume_info_all() if err: raise Exception(err) total_vols = len(complete_vil) for vol in complete_vil: if vol["status"] == 1: if vol["data_access_status_code"] != 0 or ( not vol["processes_ok"]): bad_volumes.append(vol['name']) num_vols_bad += 1 if 'quotas' in vol and vol['quotas']: for k, v in vol['quotas'].items(): # print vol['name'], k, v if v: for quota_key, quota_val in v.items(): if quota_key.lower() in [ 'sl_exceeded', 'hl_exceeded' ] and quota_val.lower() == 'yes': if quota_key.lower() == 'sl_exceeded': soft_quota_exceeded_vols.append( vol['name']) if quota_key.lower() == 'hl_exceeded': hard_quota_exceeded_vols.append( vol['name']) num_quotas_exceeded += 1 # print soft_quota_exceeded_vols # print hard_quota_exceeded_vols shares_list, err = cifs_utils.get_shares_list() if err: raise Exception(err) if shares_list: num_shares = len(shares_list) return_dict['num_shares'] = num_shares targets_list, err = iscsi_stgt.get_targets() if err: raise Exception(err) if targets_list: return_dict['num_targets'] = len(targets_list) else: return_dict['num_targets'] = 0 ''' #Commenting out as we wont use ctdb for this build ctdb_status, err = ctdb.get_status() #print ctdb_status, err if err: raise Exception(err) if ctdb_status: num_ctdb_nodes = len(ctdb_status) for n, v in ctdb_status.items(): if v.lower() != 'ok': num_bad_ctdb_nodes += 1 return_dict["ctdb_status"] = ctdb_status ''' return_dict["num_quotas_exceeded"] = num_quotas_exceeded return_dict["soft_quota_exceeded_vols"] = soft_quota_exceeded_vols return_dict["hard_quota_exceeded_vols"] = hard_quota_exceeded_vols #return_dict["num_ctdb_nodes"] = num_ctdb_nodes return_dict["num_bad_ctdb_nodes"] = num_bad_ctdb_nodes return_dict["num_nodes_bad"] = num_nodes_bad return_dict["bad_nodes"] = bad_nodes return_dict["bad_node_pools"] = bad_node_pools return_dict["num_pools_bad"] = num_pools_bad return_dict["num_vols_bad"] = num_vols_bad return_dict["total_nodes"] = total_nodes return_dict["total_pool"] = total_pool return_dict["total_vols"] = total_vols return_dict["nodes"] = nodes return_dict['system_info'] = si return_dict['volume_info_list'] = complete_vil return_dict["storage_pool"] = storage_pool return django.shortcuts.render_to_response( 'view_dashboard.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict[ "error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error_details"] = s return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def download_vol_log(request): """ Used to download the volume log of a particular volume whose name is in the vol_name post parameter""" return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.' ) return_dict['base_template'] = 'log_base.html' return_dict["page_title"] = 'Download volume logs' return_dict['tab'] = 'volume_log_download_tab' return_dict["error"] = 'Error downloading volume logs' vil, err = gluster_volumes.get_basic_volume_info_all() if err: raise Exception(err) if not vil: raise Exception('No volumes detected') l = [] for v in vil: l.append(v["name"]) if request.method == 'POST': form = volume_management_forms.VolumeNameForm(request.POST, vol_list=l) if form.is_valid(): cd = form.cleaned_data vol_name = cd['vol_name'] iv_logging.debug("Got volume log download request for %s" % vol_name) file_name = None v, err = gluster_volumes.get_basic_volume_info(vol_name) if err: raise Exception(err) if not v: raise Exception("Could not retrieve volume info") brick = v["bricks"][0][0] if not brick: raise Exception( "Could not retrieve volume log location - no brick") l = brick.split(':') if not l: raise Exception( "Could not retrieve volume log location - malformed brick 1" ) l1 = l[1].split('/') if not l1: raise Exception( "Could not retrieve volume log location - malformed brick 2" ) file_name = '/var/log/glusterfs/bricks/%s-%s-%s.log' % ( l1[1], l1[2], vol_name) display_name = 'integralstor_gridcell-%s.log' % vol_name # Formulate the zip file name zf_name = '/tmp/integralstor_gridcell_volume_%s_log' % vol_name dt = datetime.datetime.now() dt_str = dt.strftime("%d%m%Y%H%M%S") zf_name = zf_name + dt_str + ".zip" try: zf = zipfile.ZipFile(zf_name, 'w') zf.write(file_name, arcname=display_name) zf.write('/var/log/glusterfs/cli.log', arcname='cli.log') zf.write('/var/log/glusterfs/cmd_history.log', arcname='cmd_history.log') zf.write( '/var/log/glusterfs/etc-glusterfs-glusterd.vol.log', arcname='etc-glusterfs-glusterd.vol.log') zf.write('/var/log/glusterfs/', arcname='') zf.write('/var/log/glusterfs/', arcname='') zf.close() except Exception as e: raise Exception("Error generating zip file : %s" % str(e)) response = django.http.HttpResponse() response[ 'Content-disposition'] = 'attachment; filename=integralstor_gridcell_volume_%s_log_%s.zip' % ( vol_name, dt_str) response['Content-type'] = 'application/x-compressed' try: with open(zf_name, 'rb') as f: byte = f.read(1) while byte: response.write(byte) byte = f.read(1) response.flush() except Exception as e: raise Exception("Error compressing remote log file : %s" % str(e)) return response else: form = volume_management_forms.VolumeNameForm(vol_list=l) # either a get or an invalid form so send back form return_dict['form'] = form return_dict['op'] = 'download_log' return django.shortcuts.render_to_response( 'download_vol_log_form.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict[ "error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict[ "error"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_volume_conf(request): """ Used to confirm volume creation parameters""" return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.') return_dict['base_template'] = "volume_base.html" return_dict["page_title"] = 'Create a volume - confirmation' return_dict['tab'] = 'view_volumes_tab' return_dict["error"] = 'Error getting information for creating a volume' si, err = system_info.load_system_config() if err: raise Exception(err) if not si: raise Exception('Could not load system information') form = integral_view.forms.volume_creation_forms.VolOndiskStorageForm( request.POST or None) if form.is_valid(): cd = form.cleaned_data vol_type = cd['vol_type'] vol_name = cd['vol_name'] ondisk_storage = cd['ondisk_storage'] vol_access = cd['vol_access'] repl_count = 2 if vol_type == "replicated": # repl_count = int(cd["repl_count"]) # Hardcoded to 2 for now till we resolve the hot spare issue repl_count = 2 transport = "TCP" iv_logging.info("create volume initiated for vol_type %s, vol_name %s, ondisk_storage %s, vol_access %s" % ( vol_type, vol_name, ondisk_storage, vol_access)) d, err = gluster_volumes.build_create_volume_command( vol_name, vol_type, ondisk_storage, repl_count, transport, si) if err: raise Exception(err) if d and "error" in d: return_dict["error"] = "Error creating the volume : %s" % d["error"] return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request)) node_list_str = ('<ul>') for n in d["node_list"]: node_list_str += '<li>' for i in n: node_list_str += str(i) node_list_str += ', ' node_list_str += '</li>' node_list_str += '</ul>' iv_logging.debug("create vol node list %s" % node_list_str) return_dict['cmd'] = d['cmd'] return_dict['dataset_list'] = d['dataset_list'] return_dict['node_list_str'] = node_list_str return_dict['vol_type'] = vol_type return_dict['vol_name'] = vol_name return_dict['vol_access'] = vol_access return_dict['ondisk_storage'] = ondisk_storage if vol_type == "replicated": return_dict['repl_count'] = str(repl_count) else: # Invalid form url = 'vol_create_wiz_vol_type.html' return_dict['form'] = form return django.shortcuts.render_to_response(url, return_dict, context_instance=django.template.context.RequestContext(request)) if settings.APP_DEBUG: return_dict['app_debug'] = True return_dict['form'] = form return django.shortcuts.render_to_response('vol_create_wiz_confirm.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error_details"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def download_sys_log(request): """ Download the system log of the type specified in sys_log_type POST param for the node specified in the hostname POST parameter. This calls the /sys_log via an http request on that node to get the info""" return_dict = {} try: gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.' ) return_dict['base_template'] = "log_base.html" return_dict["page_title"] = 'Download system logs' return_dict['tab'] = 'download_system_logs_tab' return_dict["error"] = 'Error downloading system logs' si, err = system_info.load_system_config() if err: raise Exception(err) if not si: raise Exception('Could not load system configuration') form = log_management_forms.SystemLogsForm(request.POST or None, system_config=si) if request.method == 'POST': if form.is_valid(): cd = form.cleaned_data sys_log_type = cd['sys_log_type'] hostname = cd["hostname"] iv_logging.debug( "Got sys log download request for type %s hostname %s" % (sys_log_type, hostname)) #fn = {'boot':'/var/log/boot.log', 'dmesg':'/var/log/dmesg', 'message':'/var/log/messages', 'smb':'/var/log/smblog.vfs', 'winbind':'/var/log/samba/log.winbindd','ctdb':'/var/log/log.ctdb'} #dn = {'boot':'boot.log', 'dmesg':'dmesg', 'message':'messages','smb':'samba_logs','winbind':'winbind_logs','ctdb':'ctdb_logs'} fn = { 'boot': '/var/log/boot.log', 'dmesg': '/var/log/dmesg', 'message': '/var/log/messages', 'smb': '/var/log/smblog.vfs', 'winbind': '/var/log/samba/log.winbindd' } dn = { 'boot': 'boot.log', 'dmesg': 'dmesg', 'message': 'messages', 'smb': 'samba_logs', 'winbind': 'winbind_logs' } file_name = fn[sys_log_type] display_name = dn[sys_log_type] client = salt.client.LocalClient() ret = client.cmd('%s' % (hostname), 'cp.push', [file_name]) print ret zf_name = '%s.zip' % display_name try: zf = zipfile.ZipFile(zf_name, 'w') zf.write("/var/cache/salt/master/minions/%s/files/%s" % (hostname, file_name), arcname=display_name) zf.close() except Exception as e: raise Exception("Error compressing remote log file : %s" % str(e)) response = django.http.HttpResponse() response[ 'Content-disposition'] = 'attachment; filename=%s.zip' % ( display_name) response['Content-type'] = 'application/x-compressed' with open(zf_name, 'rb') as f: byte = f.read(1) while byte: response.write(byte) byte = f.read(1) response.flush() return response # either a get or an invalid form so send back form return_dict['form'] = form return django.shortcuts.render_to_response( 'download_sys_log_form.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict[ "error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict[ "error"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def schedule_scrub(request): return_dict = {} try: return_dict['base_template'] = "system_base.html" return_dict["page_title"] = 'Schedule filesystem scrub' return_dict['tab'] = 'initiate_scrub_tab' return_dict["error"] = 'Error scheduling filesystem scrub' gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception( 'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.' ) if "ack" in request.GET: if request.GET["ack"] == "success": return_dict[ 'ack_message'] = "Filesystem scrub successfully scheduled." if request.method == "GET": return django.shortcuts.render_to_response( "schedule_scrub.html", return_dict, context_instance=django.template.context.RequestContext( request)) elif request.method == "POST": dt = request.POST.get('timestamp') poolname = 'frzpool' db_path, err = config.get_db_path() # Doing this to make sure each node has a zfs scrub scheduled si, err = system_info.load_system_config() if err: raise Exception(err) err_list = [] success = 0 for node in si.keys(): status, err = scheduler_utils.create_task( 'ZFS Scrub on %s' % node, [{ 'scrub': '/sbin/zpool scrub frzpool' }], task_type_id=3, node=node, initiate_time=int(dt)) if err: err_list.append(err) else: success += 1 if err_list: if success > 0: # Some succeeded return django.http.HttpResponseRedirect( '/view_tasks?ack=scheduled&err=%s' % ','.join(err_list)) else: # All failed raise Exception(','.join(err_list)) # All succeeded return django.http.HttpResponseRedirect( '/view_tasks?ack=scheduled') except Exception, e: return_dict["error"] = 'Unable to retrive the status of services' return_dict[ "error_details"] = "An error occurred when processing your request : %s" % e return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def main(): lg = None try: lg, err = logger.get_script_logger( 'Gluster batch processing', '/var/log/integralstor/scripts.log', level=logging.DEBUG) logger.log_or_print('Batch processing initiated.', lg, level='info') active, err = grid_ops.is_active_admin_gridcell() if err: raise Exception(err) if not active: logger.log_or_print( 'Not active admin GRIDCell so exiting.', lg, level='info') sys.exit(0) batch_files_path, err = config.get_batch_files_path() if err: raise Exception(err) ret, err = lock.get_lock('batch_process') if err: raise Exception(err) if not ret: raise Exception('Could not acquire batch lock. Exiting.') gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception('Could not acquire gluster lock. Exiting.') fl = os.listdir(os.path.normpath(batch_files_path)) if fl: for file in fl: if not file.startswith("bp_"): # unknown file type so ignore continue else: logger.log_or_print('Processing file %s/%s' % (batch_files_path, file), lg, level='info') with open(os.path.normpath("%s/%s" % (batch_files_path, file)), "r") as f: # print 'a' # print # os.path.normpath("%s/%s"%(batch_files_path,file)) d = json.load(f) # print 'a1' ret, err = process_batch(d, file, logger) if err: str = "Error loading json content for %s/%s : %s" % ( batch_files_path, file, err) logger.log_or_print(str, lg, level='error') continue else: logger.log_or_print( 'No batch processes pending.', lg, level='info') ret, err = lock.release_lock('gluster_commands') if err: raise Exception(err) ret, err = lock.release_lock('batch_process') if err: raise Exception(err) except Exception, e: str = "Error processing batch files : %s" % e logger.log_or_print(str, lg, level='critical') sys.exit(-1)
def main(): try: platform, err = config.get_platform() if err: raise Exception(err) lck, err = lock.get_lock('poll_for_alerts') if err: raise Exception(err) if not lck: raise Exception('Could not acquire lock. Exiting.') if platform == 'gridcell': from integralstor_gridcell import system_info gluster_lck, err = lock.get_lock('gluster_commands') else: from integralstor import system_info si, err = system_info.load_system_config() if platform == 'gridcell': lock.release_lock('gluster_commands') if err: raise Exception(err) if not si: raise Exception('Could not load system information') alert_list = [] for node_name, node in si.items(): if 'errors' in node and node['errors']: if platform == 'gridcell': msg = 'GRIDCell : %s. ' % node_name else: msg = '' msg += '. '.join(node['errors']) alert_list.append(msg) hw_platform, err = config.get_hardware_platform() if hw_platform: if hw_platform == 'dell': from integralstor_utils.platforms import dell alerts_dict, err = dell.get_alert_logs() if alerts_dict: current_time = int(time.time()) for time_stamp, alerts_list in alerts_dict.items(): for alert_dict in alerts_list: if alert_dict['Severity'] == 'Critical': if (current_time - time_stamp) < (60 * 60): alert_list.append( alert_dict['description']) # print time_stamp, alert_dict # print "======================" # print alert_list # print "======================" if alert_list: alerts.raise_alert(alert_list) lock.release_lock('poll_for_alerts') except Exception, e: print "Error generating alerts : %s ! Exiting." % str(e) sys.exit(-1)
def main(): lg = None try: lg, err = logger.get_script_logger('Gluster batch processing', '/var/log/integralstor/scripts.log', level=logging.DEBUG) logger.log_or_print('Batch processing initiated.', lg, level='info') active, err = grid_ops.is_active_admin_gridcell() if err: raise Exception(err) if not active: logger.log_or_print('Not active admin GRIDCell so exiting.', lg, level='info') sys.exit(0) batch_files_path, err = config.get_batch_files_path() if err: raise Exception(err) ret, err = lock.get_lock('batch_process') if err: raise Exception(err) if not ret: raise Exception('Could not acquire batch lock. Exiting.') gluster_lck, err = lock.get_lock('gluster_commands') if err: raise Exception(err) if not gluster_lck: raise Exception('Could not acquire gluster lock. Exiting.') fl = os.listdir(os.path.normpath(batch_files_path)) if fl: for file in fl: if not file.startswith("bp_"): # unknown file type so ignore continue else: logger.log_or_print('Processing file %s/%s' % (batch_files_path, file), lg, level='info') with open( os.path.normpath( "%s/%s" % (batch_files_path, file)), "r") as f: # print 'a' # print # os.path.normpath("%s/%s"%(batch_files_path,file)) d = json.load(f) # print 'a1' ret, err = process_batch(d, file, logger) if err: str = "Error loading json content for %s/%s : %s" % ( batch_files_path, file, err) logger.log_or_print(str, lg, level='error') continue else: logger.log_or_print('No batch processes pending.', lg, level='info') ret, err = lock.release_lock('gluster_commands') if err: raise Exception(err) ret, err = lock.release_lock('batch_process') if err: raise Exception(err) except Exception, e: str = "Error processing batch files : %s" % e logger.log_or_print(str, lg, level='critical') sys.exit(-1)