def reset_to_factory_defaults(request): return_dict = {} try: if request.method == "GET": #Send a confirmation screen return django.shortcuts.render_to_response('reset_factory_defaults_conf.html', return_dict, context_instance = django.template.context.RequestContext(request)) else: iv_logging.info("Got a request to reset to factory defaults") #Post request so from conf screen #Reset the ntp config file try : shutil.copyfile("%s/factory_defaults/ntp.conf"%fractalio.common.get_factory_defaults_path(), '%s/ntp.conf'%fractalio.common.get_ntp_conf_path()) pass except Exception, e: return_dict["error"] = "Error reseting NTP configuration : %s"%e return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request)) #Remove email settings try: mail.delete_email_settings() except Exception, e: #print str(e) return_dict["error"] = "Error reseting mail configuration : %s."%e return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request)) try: audit.rotate_audit_trail() except Exception, e: #print str(e) return_dict["error"] = "Error rotating the audit trail : %s."%e return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request))
def logout(request): """ Used to logout a user into the management utility""" iv_logging.info("User '%s' logged out"%request.user) # Clear the session if the user has been logged in anywhere else. sessions = Session.objects.all() for s in sessions: if s.get_decoded() and (s.get_decoded()['_auth_user_id'] == request.user.id or not s.get_decoded()): s.delete() django.contrib.auth.logout(request) return django.http.HttpResponseRedirect('/login/')
def raise_alert(request): return_dict = {} template = "logged_in_error.html" if "msg" not in request.REQUEST: return_dict["error"] = "No alert message specified." else: try: msg = request.REQUEST["msg"] alerts.raise_alert(msg) except Exception, e: return_dict["error"] = "Error logging alert : %s"%e iv_logging.info("Error logging alert %s"%str(e)) else:
def update_admin_password(request): """ Used to change a user's password for the management utility""" try: return_dict = {} if request.user and request.user.is_authenticated(): if request.method == 'POST': iv_logging.debug("Admin password change posted") # user has submitted the password info form = admin_forms.ChangeAdminPasswordForm(request.POST) if form.is_valid(): cd = form.cleaned_data oldPasswd = cd['oldPasswd'] newPasswd1 = cd['newPasswd1'] newPasswd2 = cd['newPasswd2'] # Checking for old password is done in the form itself if request.user.check_password(oldPasswd): if newPasswd1 == newPasswd2: # all systems go so now change password request.user.set_password(newPasswd1) request.user.save() return_dict['ack_message'] = 'Password changed sucessful.' iv_logging.info( "Admin password change request successful.") audit_str = "Changed admin password" audit.audit("modify_admin_password", audit_str, request) else: return_dict['error'] = 'New passwords do not match' # else invalid form or error so existing form data to return_dict and # fall through to redisplay the form if 'success' not in return_dict: return_dict['form'] = form iv_logging.info("Admin password change request failed.") else: form = admin_forms.ChangeAdminPasswordForm() return_dict['form'] = form return django.shortcuts.render_to_response('update_admin_password_form.html', return_dict, context_instance=django.template.context.RequestContext(request)) else: # User not authenticated so return a login screen return django.http.HttpResponseRedirect('/login/') except Exception, e: return_dict['base_template'] = "system_base.html" return_dict["page_title"] = 'Change admininistrator password' return_dict['tab'] = 'system_info_tab' return_dict["error"] = 'Error changing administrator password' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request))
def logout(request): """ Used to logout a user into the management utility""" try: iv_logging.info("User '%s' logged out"%request.user) # Clear the session if the user has been logged in anywhere else. sessions = Session.objects.all() for s in sessions: if s.get_decoded() and (s.get_decoded()['_auth_user_id'] == request.user.id or not s.get_decoded()): s.delete() django.contrib.auth.logout(request) return django.http.HttpResponseRedirect('/login/') except Exception, e: return_dict['base_template'] = "dashboard_base.html" return_dict["page_title"] = 'Logout' return_dict['tab'] = 'disks_tab' return_dict["error"] = 'Error logging out' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request))
def change_admin_password(request): """ Used to change a user's password for the management utility""" return_dict = {} if request.user and request.user.is_authenticated(): if request.method == 'POST': iv_logging.debug("Admin password change posted") #user has submitted the password info form = admin_forms.ChangeAdminPasswordForm(request.POST) if form.is_valid(): cd = form.cleaned_data oldPasswd = cd['oldPasswd'] newPasswd1 = cd['newPasswd1'] newPasswd2 = cd['newPasswd2'] #Checking for old password is done in the form itself if request.user.check_password(oldPasswd): if newPasswd1 == newPasswd2: # all systems go so now change password request.user.set_password(newPasswd1); request.user.save() return_dict['success'] = True iv_logging.info("Admin password change request successful.") audit_str = "Changed admin password" audit.audit("modify_admin_password", audit_str, request.META["REMOTE_ADDR"]) else: return_dict['error'] = 'New passwords do not match' # else invalid form or error so existing form data to return_dict and # fall through to redisplay the form if 'success' not in return_dict: return_dict['form'] = form iv_logging.info("Admin password change request failed.") else: form = admin_forms.ChangeAdminPasswordForm() return_dict['form'] = form return django.shortcuts.render_to_response('change_admin_password_form.html', return_dict, context_instance = django.template.context.RequestContext(request)) else: #User not authenticated so return a login screen return django.http.HttpResponseRedirect('/login/')
def logout(request): """ Used to logout a user into the management utility""" try: iv_logging.info("User '%s' logged out" % request.user) # Clear the session if the user has been logged in anywhere else. sessions = Session.objects.all() for s in sessions: if (s.get_decoded() and int(s.get_decoded()['_auth_user_id']) == request.user.id) or not s.get_decoded(): s.delete() django.contrib.auth.logout(request) return django.http.HttpResponseRedirect('/login/') except Exception, e: return_dict['base_template'] = "dashboard_base.html" return_dict["page_title"] = 'Logout' return_dict['tab'] = 'disks_tab' return_dict["error"] = 'Error logging out' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( 'logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request))
def login(request): """ Used to login a user into the management utility""" return_dict = {} authSucceeded = False if request.method == 'POST': iv_logging.info("Login request posted") # Someone is submitting info so check it form = admin_forms.LoginForm(request.POST) if form.is_valid(): # submitted form is valid so now try to authenticate # if not valid then fall out to end of function and return form to user # with existing data cd = form.cleaned_data username = cd['username'] password = cd['password'] # Try to authenticate user = django.contrib.auth.authenticate(username=username, password=password) if user is not None and user.is_active: # Clear the session if the user has been logged in anywhere else. sessions = Session.objects.all() for s in sessions: if s.get_decoded() and (s.get_decoded()['_auth_user_id'] == user.id): s.delete() # authentication succeeded! Login and send to home screen django.contrib.auth.login(request, user) iv_logging.info("Login request from user '%s' succeeded"%username) authSucceeded = True else: iv_logging.info("Login request from user '%s' failed"%username) return_dict['invalidUser'] = True else: #Invalid form iv_logging.debug("Invalid login information posted") else: # GET request so create a new form and send back to user form = admin_forms.LoginForm() # Clear the session if the user has been logged in anywhere else. sessions = Session.objects.all() for s in sessions: if s.get_decoded() is not None and s.get_decoded().get('_auth_user_id') is not None: return_dict['session_active'] = True return_dict['form'] = form if authSucceeded: return django.http.HttpResponseRedirect('/show/dashboard/') # For all other cases, return to login screen with return_dict # appropriately populated return django.shortcuts.render_to_response('login_form.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 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 login(request): """ Used to login a user into the management utility""" try: return_dict = {} authSucceeded = False if request.method == 'POST': iv_logging.info("Login request posted") # Someone is submitting info so check it form = admin_forms.LoginForm(request.POST) if form.is_valid(): # submitted form is valid so now try to authenticate # if not valid then fall out to end of function and return form to user # with existing data cd = form.cleaned_data username = cd['username'] password = cd['password'] # Try to authenticate user = django.contrib.auth.authenticate(username=username, password=password) if user is not None and user.is_active: ''' #Uncomment if we want to kick out an already logged in user. # Clear the session if the user has been logged in anywhere else. sessions = Session.objects.all() for s in sessions: if s.get_decoded() and (int(s.get_decoded()['_auth_user_id']) == user.id): s.delete() ''' # authentication succeeded! Login and send to home screen django.contrib.auth.login(request, user) iv_logging.info("Login request from user '%s' succeeded" % username) authSucceeded = True else: iv_logging.info("Login request from user '%s' failed" % username) return_dict['invalidUser'] = True else: # Invalid form iv_logging.debug("Invalid login information posted") else: # GET request so create a new form and send back to user form = admin_forms.LoginForm() # Clear the session if the user has been logged in anywhere else. sessions = Session.objects.all() for s in sessions: if s.get_decoded() is not None and s.get_decoded().get( '_auth_user_id') is not None: return_dict['session_active'] = True return_dict['form'] = form if authSucceeded: return django.http.HttpResponseRedirect( '/view_dashboard/sys_health') # For all other cases, return to login screen with return_dict # appropriately populated return django.shortcuts.render_to_response( 'login_form.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) 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(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))