def delete_remote_replication(request): return_dict = {} try: ret, err = django_utils.get_request_parameter_values( request, ['remote_replication_id']) if err: raise Exception(err) if 'remote_replication_id' not in ret: raise Exception( "Requested remote replication not found, please use the menus." ) remote_replication_id = ret['remote_replication_id'] return_dict['remote_replication_id'] = remote_replication_id replications, err = remote_replication.get_remote_replications( remote_replication_id) if err: raise Exception(err) if not replications: raise Exception( 'Specified remote replication definition not found') if request.method == "GET": return_dict['replication'] = replications[0] return django.shortcuts.render_to_response( "delete_zfs_replication_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: ret, err = django_utils.get_request_parameter_values( request, ['cron_task_id']) if err: raise Exception(err) if 'cron_task_id' not in ret: raise Exception("Request not found, please use the menus.") cron_task_id = ret['cron_task_id'] cron_remove, err = scheduler_utils.delete_cron(int(cron_task_id)) if err: raise Exception(err) ret, err = remote_replication.delete_remote_replication( remote_replication_id) if err: raise Exception(err) audit.audit("remove_remote_replication", replications[0]['description'], request) return django.http.HttpResponseRedirect( '/view_remote_replications?ack=cancelled') except Exception as e: return_dict['base_template'] = "snapshot_replication_base.html" return_dict["page_title"] = 'Cancel ZFS replication' return_dict['tab'] = 'view_remote_replications_tab' return_dict["error"] = 'Error cancelling ZFS replication' 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 delete_remote_monitoring_server(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values(request, [ 'view', 'ip']) if err: raise Exception(err) if 'ip' not in req_ret: raise Exception('Invalid request, please use the menus.') ip = req_ret['ip'] servers, err = remote_monitoring.get_servers() if err: raise Exception(err) if ip not in servers.keys(): raise Exception( 'Specified server is currently not being remote monitored.') name = servers[ip]['name'] ret, err = remote_monitoring.delete_server(ip) if err: raise Exception(err) audit_str = 'Removed the remote monitoring server with IP : %s name : %s' % ( ip, name) audit.audit("delete_remote_monitoring_server", audit_str, request) return django.http.HttpResponseRedirect('/view_remote_monitoring_servers?ack=deleted') except Exception, e: return_dict["page_title"] = 'Remove remote server monitoring server' return_dict['tab'] = 'remote_monitoring_tab' return_dict["error"] = 'Error removing remote monitoring server' return_dict['base_template'] = "dashboard_base.html" 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 view_ntp_settings(request): return_dict = {} try: ntp_servers, err = ntp.get_ntp_servers() if err: raise Exception(err) return_dict["ntp_servers"] = ntp_servers req_ret, err = django_utils.get_request_parameter_values( request, ['ack', 'server_used']) if err: raise Exception(err) if 'ack' in req_ret and req_ret['ack'] == 'saved': return_dict["ack_message"] = 'NTP settings have successfully been updated.' elif 'ack' in req_ret and req_ret['ack'] == 'ntp_synced': if 'server_used' in req_ret: return_dict["ack_message"] = 'One time ntp sync with server %s successfully completed.' % req_ret['server_used'] return django.shortcuts.render_to_response('view_ntp_settings.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "services_base.html" return_dict["page_title"] = 'View NTP settings' return_dict['tab'] = 'ntp_settings_tab' return_dict["error"] = 'Error retrieving NTP settings' 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 delete_ssl_certificate(request): return_dict = {} try: ret, err = django_utils.get_request_parameter_values(request, ['name']) if err: raise Exception(err) if 'name' not in ret: raise Exception("Invalid request, please use the menus.") name = ret['name'] return_dict["name"] = name if request.method == "GET": # Return the conf page return django.shortcuts.render_to_response("delete_ssl_certificate_conf.html", return_dict, context_instance=django.template.context.RequestContext(request)) else: ret, err = pki.delete_ssl_certificate(name) if err: raise Exception(err) audit_str = "Deleted SSL certificate name '%s'" % name audit.audit("delete_certificate", audit_str, request) return django.http.HttpResponseRedirect('/view_ssl_certificates?ack=deleted') except Exception, e: return_dict['base_template'] = "key_management_base.html" return_dict["page_title"] = 'Delete a SSL certificate' return_dict['tab'] = 'certificates_tab' return_dict["error"] = 'Error deleting SSL certificate' 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 view_samba_server_settings(request): return_dict = {} try: d, err = cifs_common.get_auth_settings() if err: raise Exception(err) return_dict["samba_global_dict"] = d ret, err = django_utils.get_request_parameter_values(request, ['ack']) if err: raise Exception(err) if 'ack' in ret and ret['ack'] == 'saved': return_dict["ack_message"] = "Information updated successfully" return django.shortcuts.render_to_response( 'view_samba_server_settings.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "services_base.html" return_dict["page_title"] = 'Modify CIFS authentication settings' return_dict['tab'] = 'auth_server_settings_tab' return_dict["error"] = 'Error modifying CIFS authentication settings' 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 delete_background_task(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values( request, ['task_id']) if err: raise Exception(err) if 'task_id' not in req_ret: raise Exception('Invalid request. Please use the menus.') task, err = scheduler_utils.get_task(req_ret['task_id']) if err: raise Exception(err) ret, err = scheduler_utils.delete_task(req_ret['task_id']) if err: raise Exception(err) audit.audit("remove_background_task", task['description'], request) return django.http.HttpResponseRedirect( '/view_background_tasks?ack=deleted') except Exception, e: return_dict['base_template'] = "scheduler_base.html" return_dict["page_title"] = 'Background tasks' return_dict['tab'] = 'view_background_tasks_tab' return_dict["error"] = 'Error removing background task' 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 view_interface(request): return_dict = {} try: template = 'logged_in_error.html' req_ret, err = django_utils.get_request_parameter_values( request, ['name']) if err: raise Exception(err) if 'name' not in req_ret: raise Exception('Invalid request, please use the menus') name = req_ret['name'] interfaces, err = networking.get_interfaces() if err: raise Exception(err) elif name not in interfaces: raise Exception("Specified interface not found") if interfaces[name]['vlan']: if '.' not in name: raise Exception('Invalid VLAN name : %s' % name) comps = name.split('.') if len(comps) != 2: raise Exception('Invalid VLAN name : %s' % name) return_dict['parent_nic'] = comps[0] return_dict['nic'] = interfaces[name] if interfaces[name]['vlan_ids']: return_dict['vlans'] = [] for vlan_id in interfaces[name]['vlan_ids']: if '%s.%d' % (name, vlan_id) in interfaces: return_dict['vlans'].append({ 'name': '%s.%d' % (name, vlan_id), 'vlan_id': vlan_id, 'info': interfaces['%s.%d' % (name, vlan_id)] }) return_dict['interfaces'] = interfaces return_dict['name'] = name template = "view_interface.html" return django.shortcuts.render_to_response( template, return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'View network interface details' return_dict['tab'] = 'view_interfaces_tab' return_dict["error"] = 'Error loading interface details' 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 delete_iscsi_user_authentication(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values( request, ['target_name', 'authentication_type', 'username']) if err: raise Exception(err) if ('target_name' and 'authentication_type' and 'username') not in req_ret: raise Exception("Invalid request, please use the menus.") authentication_type = req_ret['authentication_type'] target_name = req_ret['target_name'] username = req_ret['username'] if authentication_type not in ['incoming', 'outgoing']: raise Exception("Invalid user type. Please use the menus.") if request.method == "GET": return_dict["target_name"] = target_name return_dict["username"] = username return_dict["authentication_type"] = authentication_type return django.shortcuts.render_to_response( "delete_iscsi_user_auth_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: ret, err = iscsi_stgt.remove_user_authentication( target_name, username, authentication_type) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") if authentication_type == 'incoming': audit_str = "Removed ISCSI initiator authentication user %s for target %s" % ( username, target_name) url = '/view_iscsi_target?name=%s&ack=removed_initiator_authentication' % target_name else: audit_str = "Removed ISCSI target authentication user %s for target %s" % ( username, target_name) url = '/view_iscsi_target?name=%s&ack=removed_target_authentication' % target_name audit.audit("remove_iscsi_target_authentication", audit_str, request) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Remove ISCSI authentication user' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error removing ISCSI authentication user' 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 delete_local_group(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values( request, ['grpname']) if err: raise Exception(err) if 'grpname' not in req_ret: raise Exception('Invalid request, please use the menus.') gd, err = local_users.get_local_group(req_ret['grpname']) if err or (not gd): if err: raise Exception(err) else: raise Exception("Could not retrieve group information") if gd['members']: raise Exception( "Cannot delete this group as it has the following members : %s" % (','.join(gd['members']))) if request.method == "GET": # Return the form return_dict["grpname"] = request.GET["grpname"] return django.shortcuts.render_to_response( "delete_local_group_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: # Form submission so create return_dict = {} ret, err = local_users.delete_local_group(request.POST["grpname"]) if not ret: if err: raise Exception('Error deleting group : %s' % err) else: raise Exception('Error deleting group') audit_str = "Deleted a local group %s" % request.POST["grpname"] audit.audit("delete_local_group", audit_str, request) url = '/view_local_groups?ack=deleted' return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = 'users_groups_base.html' return_dict["page_title"] = 'Delete a local user group' return_dict['tab'] = 'view_local_groups_tab' return_dict["error"] = 'Error deleting a local user group' 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 update_remote_monitoring_server(request): return_dict = {} try: if request.method == "GET": servers, err = remote_monitoring.get_servers() if err: raise Exception(err) req_ret, err = django_utils.get_request_parameter_values(request, [ 'view', 'ip']) if err: raise Exception(err) initial = {} if 'ip' in req_ret: ip = req_ret['ip'] if ip in servers.keys(): initial['ip'] = ip initial['name'] = servers[ip]['name'] return_dict['action'] = 'update' else: return_dict['action'] = 'create' form = system_forms.RemoteMonitoringServerForm(initial=initial) return_dict['form'] = form return django.shortcuts.render_to_response("update_remote_monitoring_server.html", return_dict, context_instance=django.template.context.RequestContext(request)) else: form = system_forms.RemoteMonitoringServerForm(request.POST) return_dict["form"] = form if form.is_valid(): cd = form.cleaned_data res, err = remote_monitoring.update_server( cd['ip'], cd['name']) if not res: if err: raise Exception(err) else: raise Exception( 'Error updating remote monitoring server list') audit_str = 'Updated the remote monitoring server with IP : %s and name : %s' % ( cd['ip'], cd['name']) audit.audit("update_remote_monitoring_server", audit_str, request) return django.http.HttpResponseRedirect('/view_remote_monitoring_servers?ack=updated') else: # invalid form return django.shortcuts.render_to_response("update_remote_monitoring_server.html", return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict["page_title"] = 'Update remote server monitoring server' return_dict['tab'] = 'remote_monitoring_tab' return_dict["error"] = 'Error updating remote monitoring server' return_dict['base_template'] = "dashboard_base.html" 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 identify_disk(request): return_dict = {} try: action = None channel = None enclosure_id = None controller_number = None target_id = None ret, err = django_utils.get_request_parameter_values( request, [ 'hw_platform', 'action', 'controller_number', 'channel', 'enclosure_id', 'target_id' ]) if err: raise Exception(err) if 'hw_platform' not in ret or ret['hw_platform'].lower() != 'dell': raise Exception( 'Unknown hardware platform so cannot toggle identification LED' ) if 'action' not in ret or ret['action'] not in ['blink', 'unblink']: raise Exception( 'Unknown action specified so cannot toggle identification LED') if ('channel' and 'enclosure_id' and 'target_id' and 'controller_number') not in ret: raise Exception('Invalid request, please use the menus.') action = ret['action'] channel = ret['channel'] enclosure_id = ret['enclosure_id'] target_id = ret['target_id'] controller_number = ret['controller_number'] from integralstor_utils.platforms import dell result, err = dell.blink_unblink_disk(action, controller_number, channel, enclosure_id, target_id) if not result: raise Exception(err) return django.http.HttpResponseRedirect('/view_disks?ack=%s' % action) except Exception, e: return_dict['base_template'] = "storage_base.html" return_dict["page_title"] = 'Disks' return_dict['tab'] = 'view_disks_tab' return_dict["error"] = 'Error toggling disk identification' 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 update_interface_state(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values( request, ['name', 'state']) if err: raise Exception(err) if ('name' and 'state') not in req_ret: raise Exception('Invalid request, please use the menus') name = req_ret['name'] return_dict["name"] = name state = req_ret['state'] return_dict["state"] = state if request.method == "GET" and state == 'down': # Return the conf page return django.shortcuts.render_to_response( "update_interface_state_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: result, err = networking.update_interface_state(name, state) if not result: if err: raise Exception(err) else: raise Exception("Error setting interface state") audit_str = "Set the state of network interface %s to %s" % (name, state) audit.audit("set_interface_state", audit_str, request) return django.http.HttpResponseRedirect( '/view_interfaces?ack=state_%s' % state) except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Set interface state' return_dict['tab'] = 'view_interfaces_tab' return_dict["error"] = 'Error setting interface state' 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 delete_vlan(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values( request, ['name']) if err: raise Exception(err) if 'name' not in req_ret: raise Exception('Invalid request, please use the menus') name = req_ret['name'] return_dict["name"] = name if request.method == "GET": # Return the conf page return django.shortcuts.render_to_response( "delete_vlan_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: result, err = networking.delete_vlan(name) if not result: if not err: raise Exception("Error removing VLAN") else: raise Exception(err) result, err = networking.restart_networking() if err: raise Exception(err) audit_str = "Removed VLAN %s" % (name) audit.audit("remove_vlan", audit_str, request) return django.http.HttpResponseRedirect( '/view_interfaces?ack=removed_vlan') except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Remove a VLAN' return_dict['tab'] = 'view_interfaces_tab' return_dict["error"] = 'Error removing a VLAN' 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 view_bond(request): return_dict = {} try: template = 'logged_in_error.html' req_ret, err = django_utils.get_request_parameter_values( request, ['name']) if err: raise Exception(err) if 'name' not in req_ret: raise Exception('Invalid request, please use the menus') name = req_ret['name'] interfaces, err = networking.get_interfaces() if err: raise Exception(err) elif name not in interfaces: raise Exception("Specified interface not found") bond, err = networking.get_bonding_info(name) if err: raise Exception(err) if not bond: raise Exception("Specified bond not found") return_dict['nic'] = interfaces[name] return_dict['bond'] = bond return_dict['name'] = name template = "view_bond.html" return django.shortcuts.render_to_response( template, return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'View network bond details' return_dict['tab'] = 'view_interfaces_tab' return_dict["error"] = 'Error loading network bond details' 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 delete_iscsi_acl(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values( request, ['target_name', 'acl']) if err: raise Exception(err) if ('target_name' and 'acl') not in req_ret: raise Exception("Invalid request, please use the menus.") target_name = req_ret['target_name'] acl = req_ret['acl'] if request.method == "GET": return_dict["target_name"] = target_name return_dict["acl"] = acl return django.shortcuts.render_to_response( "delete_iscsi_acl_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: ret, err = iscsi_stgt.remove_acl(target_name, acl) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Removed ISCSI ACL %s for target %s" % (acl, target_name) url = '/view_iscsi_target?name=%s&ack=removed_acl' % target_name audit.audit("remove_iscsi_acl", audit_str, request) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Remove ISCSI ACL' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'error Removing ISCSI ACL' 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 view_email_settings(request): return_dict = {} try: d, err = mail.load_email_settings() if err: raise Exception(err) if not d: return_dict["email_not_configured"] = True else: if d["tls"]: d["tls"] = True else: d["tls"] = False if d["email_alerts"]: d["email_alerts"] = True else: d["email_alerts"] = False return_dict["email_settings"] = d ret, err = django_utils.get_request_parameter_values( request, ['ack', 'err', 'sent_mail']) if err: raise Exception(err) if 'ack' in ret and ret['ack'] == 'saved': return_dict[ "ack_message"] = 'Email settings have successfully been updated.' if 'err' in ret: return_dict["err"] = ret['err'] if 'sent_mail' in ret: return_dict["sent_mail"] = ret['sent_mail'] return django.shortcuts.render_to_response( 'view_email_settings.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "system_base.html" return_dict["page_title"] = 'View email notification settings' return_dict['tab'] = 'email_tab' return_dict["error"] = 'Error viewing email notification settings' 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 delete_iscsi_lun(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values( request, ['target_name', 'store']) if err: raise Exception(err) if ('target_name' and 'store') not in req_ret: raise Exception("Invalid request, please use the menus.") store = req_ret['store'] target_name = req_ret['target_name'] if request.method == "GET": return_dict["target_name"] = target_name return_dict["store"] = store return django.shortcuts.render_to_response( "delete_iscsi_lun_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: ret, err = iscsi_stgt.delete_lun(target_name, store) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Deleted ISCSI LUN %s from target %s" % (store, target_name) url = '/view_iscsi_target?name=%s&ack=lun_deleted' % target_name audit.audit("delete_iscsi_lun", audit_str, request) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Remove an ISCSI LUN' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error removing an ISCSI LUN' 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 delete_local_user(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values( request, ['username']) if err: raise Exception(err) if 'username' not in req_ret: raise Exception('Invalid request, please use the menus.') if request.method == "GET": # Return the form return_dict["username"] = request.GET["username"] return django.shortcuts.render_to_response( "delete_local_user_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: # Form submission so create return_dict = {} ret, err = local_users.delete_local_user(request.POST["username"]) if not ret: if err: raise Exception(err) else: raise Exception('Error deleting local user') audit_str = "Deleted a local user %s" % request.POST["username"] audit.audit("delete_local_user", audit_str, request) url = '/view_local_users?ack=deleted' return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = 'users_groups_base.html' return_dict["page_title"] = 'Delete a local user' return_dict['tab'] = 'view_local_users_tab' return_dict["error"] = 'Error deleting a local user' 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 reboot_or_shutdown(request): return_dict = {} audit_str = "" try: minutes_to_wait = 1 return_dict['minutes_to_wait'] = minutes_to_wait ret, err = django_utils.get_request_parameter_values(request, ['do']) if err: raise Exception(err) if 'do' not in ret: raise Exception("Invalid request, please use the menus.") do = ret['do'] return_dict['do'] = do if request.method == "GET": return django.shortcuts.render_to_response( "reboot_or_shutdown.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: if 'conf' not in request.POST: raise Exception('Unknown action. Please use the menus') audit.audit('reboot_shutdown', 'System %s initiated' % do, request) if do == 'reboot': command.execute_with_rc('shutdown -r +%d' % minutes_to_wait) elif do == 'shutdown': command.execute_with_rc('shutdown -h +%d' % minutes_to_wait) return django.shortcuts.render_to_response( "reboot_or_shutdown_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) except Exception, e: return_dict['base_template'] = "system_base.html" return_dict["page_title"] = 'Reboot or Shutdown Failure' return_dict['tab'] = 'reboot_tab' return_dict["error"] = 'Error Rebooting' 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 view_remote_monitoring_server_status(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values(request, [ 'view', 'ip']) if err: raise Exception(err) if 'ip' not in req_ret: raise Exception('Invalid request, please use the menus.') status, err = remote_monitoring.get_status(req_ret['ip']) if err: raise Exception(err) print status return_dict['status'] = status return django.shortcuts.render_to_response("view_remote_monitoring_server_status.html", return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict["page_title"] = 'View remote server monitoring server status' return_dict['tab'] = 'remote_monitoring_tab' return_dict["error"] = 'Error viewing remote monitoring server status' return_dict['base_template'] = "dashboard_base.html" 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 create_cifs_share(request): return_dict = {} try: pools, err = zfs.get_pools() if err: raise Exception( 'No ZFS pools available. Please create a pool and dataset before creating shares.' ) ds_list = [] for pool in pools: for ds in pool["datasets"]: if ds['properties']['type']['value'] == 'filesystem': ds_list.append( (ds['properties']['mountpoint']['value'], ds["name"])) if not ds_list: raise Exception( 'No ZFS datasets available. Please create a dataset before creating shares.' ) dataset = path = None ret, err = django_utils.get_request_parameter_values( request, ['dataset', 'path']) if err: raise Exception(err) if 'dataset' not in ret: dataset = ds_list[0][0] elif 'dataset' in ret: dataset = ret['dataset'] if 'path' not in ret: path = dataset elif 'path' in ret: path = ret['path'] return_dict['path'] = path return_dict["dataset"] = ds_list initial = {} initial['path'] = path initial['dataset'] = dataset if request.method == "GET": # Return the form initial['guest_ok'] = True if 'name' in request.GET: initial['name'] = request.GET['name'] form = samba_shares_forms.CreateShareForm(dataset_list=ds_list, initial=initial) 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 = samba_shares_forms.CreateShareForm(request.POST, initial=initial, dataset_list=ds_list) return_dict["form"] = form if form.is_valid(): cd = form.cleaned_data # print cd name = cd["name"] path = cd["path"] if not path: return_dict["path_error"] = "Please select a dataset." return django.shortcuts.render_to_response( "create_cifs_share.html", return_dict, context_instance=django.template.context. RequestContext(request)) if 'new_folder' in cd and cd['new_folder']: try: path = '%s/%s' % (cd['path'], cd['new_folder']) # print path os.mkdir(path) audit_str = 'Created new directory "%s" in "%s"' % ( cd['new_folder'], cd['path']) audit.audit("create_dir", audit_str, request) except Exception, e: raise Exception('Error creating subfolder %s : %s' % (cd['new_folder'], str(e))) owner_dict, err = config.get_default_file_dir_owner() if err: raise Exception(err) owner_uid, err = config.get_system_uid_gid( owner_dict['user'], 'user') if err: raise Exception(err) owner_gid, err = config.get_system_uid_gid( owner_dict['group'], 'group') if err: raise Exception(err) os.chown(path, owner_uid, owner_gid) 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 'hosts_allow_choice' in cd and cd[ 'hosts_allow_choice'] == 'restricted': if 'hosts_allow' not in cd or not cd['hosts_allow']: raise Exception( 'Please enter a valid list of allowed hosts') hosts_allow = cd['hosts_allow'] else: hosts_allow = None # print hosts_allow if 'hosts_deny_choice' in cd and cd[ 'hosts_deny_choice'] == 'restricted': if 'hosts_deny' not in cd or not cd['hosts_deny']: raise Exception( 'Please enter a valid list of denied hosts') hosts_deny = cd['hosts_deny'] else: hosts_deny = None # print hosts_deny guest_ok = True ret, err = cifs_common.create_share(name, comment, True, read_only, path, path, browseable, None, None, "integralstor_novol", hosts_allow=hosts_allow, hosts_deny=hosts_deny) if err: raise Exception(err) ret, err = cifs_integralstor.generate_smb_conf() if err: raise Exception(err) audit_str = "Created Samba share %s" % name audit.audit("create_cifs_share", audit_str, request) return django.http.HttpResponseRedirect( '/view_cifs_shares?ack=created') else:
def update_https_mode(request): return_dict = {} try: ret, err = django_utils.get_request_parameter_values( request, ['change_to']) if err: raise Exception(err) if 'change_to' not in ret: raise Exception("Invalid request, please use the menus.") change_to = ret['change_to'] return_dict['change_to'] = change_to cert_list, err = certificates.get_certificates() if err: raise Exception(err) if not cert_list: raise Exception( 'No certificates have been created. Please create a certificate/key pair before you change the access method' ) if request.method == "GET": if change_to == 'secure': form = pki_forms.SetHttpsModeForm(cert_list=cert_list) return_dict['form'] = form return django.shortcuts.render_to_response( "update_https_mode.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: return_dict[ 'conf_message'] = 'Are you sure you want to disable the secure access mode for IntegralView?' return django.shortcuts.render_to_response( "update_http_mode_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: if change_to == 'secure': form = pki_forms.SetHttpsModeForm(request.POST, cert_list=cert_list) return_dict['form'] = form if not form.is_valid(): return django.shortcuts.render_to_response( "update_https_mode.html", return_dict, context_instance=django.template.context. RequestContext(request)) cd = form.cleaned_data if change_to == 'secure': pki_dir, err = config.get_pki_dir() if err: raise Exception(err) cert_loc = '%s/%s/%s.cert' % (pki_dir, cd['cert_name'], cd['cert_name']) if not os.path.exists(cert_loc): raise Exception('Error locating certificate') ret, err = nginx.generate_nginx_conf(True, cert_loc, cert_loc) if err: raise Exception(err) else: ret, err = nginx.generate_nginx_conf(False) if err: raise Exception(err) audit_str = "Changed the IntegralView access mode to '%s'" % change_to audit.audit("set_https_mode", audit_str, request) redirect_url = "https://" if change_to == "secure" else "http://" redirect_url = redirect_url + \ request.META["HTTP_HOST"] + \ "/view_https_mode?ack=set_to_%s" % change_to restart, err = scheduler_utils.create_task( 'Chaging IntegralView access mode', [{ 'Restarting Web Server': 'service nginx restart' }], 2) if err: raise Exception(err) return django.http.HttpResponseRedirect(redirect_url) except Exception, e: return_dict['base_template'] = "admin_base.html" return_dict["page_title"] = 'Set Integralview access mode' return_dict['tab'] = 'https_tab' return_dict["error"] = 'Error setting IntegralView access mode' 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 delete_bond(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values( request, ['name']) if err: raise Exception(err) if 'name' not in req_ret: raise Exception('Invalid request, please use the menus') name = req_ret['name'] return_dict["name"] = name if request.method == "GET": # Return the conf page return django.shortcuts.render_to_response( "delete_bond_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: result, err = networking.delete_bond(name) if not result: if not err: raise Exception("Error removing bond") else: raise Exception(err) python_scripts_path, err = config.get_python_scripts_path() if err: raise Exception(err) common_python_scripts_path, err = config.get_common_python_scripts_path( ) if err: raise Exception(err) status_path, err = config.get_system_status_path() if err: raise Exception(err) ret, err = command.get_command_output( "python %s/generate_manifest.py %s" % (common_python_scripts_path, status_path)) if err: raise Exception(err) ret, err = command.get_command_output( "python %s/generate_status.py %s" % (common_python_scripts_path, status_path)) if err: raise Exception(err) audit_str = "Removed network bond %s" % (name) audit.audit("remove_bond", audit_str, request) return django.http.HttpResponseRedirect( '/view_interfaces?ack=removed_bond') except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Remove a network interface bond' return_dict['tab'] = 'view_interfaces_tab' return_dict["error"] = 'Error removing a network interface bond' 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 reset_to_factory_defaults(request): return_dict = {} try: component_descriptions = { 'delete_cifs_shares': 'Windows shares', 'delete_nfs_exports': 'NFS exports', 'delete_rsync_shares': 'Rsync shares', 'delete_iscsi_targets': 'ISCSI targets', 'delete_local_users': 'local users', 'delete_local_groups': 'local groups', 'delete_dns_settings': 'DNS settings', 'delete_network_interface_settings': 'network interface settings', 'delete_network_bonds': 'network bonds', #'delete_network_vlans':'network VLANs', 'reset_hostname': 'hostname and domain name', 'delete_ssl_certificates': 'SSL certificates', 'delete_ssh_authorized_keys': 'SSH authorized keys', 'delete_ssh_fingerprints': 'SSH host fingerprints', 'delete_audits': 'audit trail', 'delete_alerts': 'alerts', 'delete_logs': 'logs', 'delete_remote_replications': 'scheduled remote replications', 'delete_tasks_and_logs': 'background tasks and logs', 'reset_cifs_settings': 'Windows access settings', 'reset_ntp_settings': 'NTP settings', 'reset_ftp_settings': 'FTP settings', 'delete_email_settings': 'email server settings', 'delete_zfs_pools': 'ZFS pools (user data)', 'delete_zfs_datasets_and_snapshots': 'ZFS datasets and snapshots (user data)', 'delete_zfs_zvols_and_snapshots': 'ZFS block device volumes and snapshots (user data)' } if request.method == 'GET': form = system_forms.FactoryDefaultsForm() return_dict['form'] = form return django.shortcuts.render_to_response( 'reset_to_factory_defaults.html', return_dict, context_instance=django.template.context.RequestContext( request)) else: req_ret, err = django_utils.get_request_parameter_values( request, ['conf']) if err: raise Exception(err) form = system_forms.FactoryDefaultsForm(request.POST) if form.is_valid(): cd = form.cleaned_data if 'conf' not in req_ret: # No confirmation yet so process the form selected_components = [] for key in cd.keys(): if cd[key]: selected_components.append( component_descriptions[key]) if ('delete_zfs_pools' in cd and cd['delete_zfs_pools'] ) or ('delete_zfs_datasets_and_snapshots' in cd and cd['delete_zfs_datasets_and_snapshots']) or ( 'delete_zfs_zvols_and_snapshots' in cd and cd['delete_zfs_zvols_and_snapshots']): return_dict['data_loss'] = 'yes' return_dict['selected_components_str'] = ','.join( selected_components) return_dict['form'] = form return django.shortcuts.render_to_response( 'reset_to_factory_defaults_conf.html', return_dict, context_instance=django.template.context. RequestContext(request)) else: # Got the confirmation so now do the work. success_list = [] failed_list = [] error_dict = {} for key in cd.keys(): result = False if not cd[key]: continue if key == 'delete_cifs_shares' and cd[key]: result, err = cifs_utils.delete_all_shares() if result: cifs_integralstor.reload_configuration() elif key == 'delete_nfs_exports': result, err = nfs.delete_all_exports() elif key == 'delete_rsync_shares': result, err = rsync.delete_all_rsync_shares() elif key == 'delete_iscsi_targets': result, err = iscsi_stgt.delete_all_targets() elif key == 'delete_local_users': result, err = local_users.delete_all_local_users() elif key == 'delete_local_groups': result, err = local_users.delete_all_local_groups() elif key == 'delete_ssl_certificates': result, err = pki.delete_all_ssl_certificates() elif key == 'delete_ssh_authorized_keys': result, err = pki.delete_authorized_keys( 'replicator') elif key == 'delete_ssh_fingerprints': result, err = pki.delete_fingerprints('replicator') elif key == 'delete_audits': result, err = audit.delete_all_audits() elif key == 'delete_alerts': result, err = alerts.delete_all_alerts() elif key == 'delete_logs': result, err = logger.zero_logs() elif key == 'delete_remote_replications': result, err = remote_replication.delete_all_remote_replications( ) elif key == 'delete_tasks_and_logs': res1, err1 = scheduler_utils.delete_all_tasks() res2, err2 = scheduler_utils.delete_all_logs() err = None result = False if err1 and err2: err = '%s\t%s' % (err1, err2) elif err1: err = 'Sucessfully deleted all tasks logs. \t%s' % err1 elif err2: err = 'Sucessfully deleted all tasks. \t%s' % err2 else: result = True elif key == 'reset_cifs_settings': result, err = cifs_utils.delete_auth_settings() if not err: cifs_integralstor.reload_configuration() elif key == 'reset_ntp_settings': result, err = ntp.update_integralstor_ntp_servers([ '0.centos.pool.ntp.org', '1.centos.pool.ntp.org', '2.centos.pool.ntp.org', '3.centos.pool.ntp.org' ]) elif key == 'reset_ftp_settings': result, err = vsftp.delete_ftp_config() elif key == 'delete_email_settings': result, err = mail.delete_email_settings() elif key == 'delete_zfs_pools': result, err = zfs.delete_all_pools(force=True) elif key == 'delete_zfs_datasets_and_snapshots': result, err = zfs.delete_all_datasets( dataset_type='filesystem', recursive=True, force=True) elif key == 'delete_zfs_zvols_and_snapshots': result, err = zfs.delete_all_datasets( dataset_type='volume', recursive=True, force=True) elif key == 'reset_hostname': result, err = networking.update_hostname( 'localhost', 'localdomain') elif key == 'delete_dns_settings': result, err = networking.delete_name_servers() # TODO: get vlans sorted out # elif key == 'delete_network_vlans': # pass elif key == 'delete_network_interface_settings': result, err = networking.delete_interfaces_connection( ) elif key == 'delete_network_bonds': result, err = networking.delete_all_bonds() if result: success_list.append(component_descriptions[key]) else: failed_list.append(component_descriptions[key]) error_dict[component_descriptions[key]] = err audit_str = '' if success_list: audit_str += 'Factory defaults reset of the following components succeeded : ' audit_str += ', '.join(success_list) audit_str += '. ' if failed_list: audit_str += 'Factory defaults reset of the following components failed : ' audit_str += ', '.join(failed_list) audit_str += '. ' audit.audit('factory_defaults_reset', audit_str, request) return_dict['success_list'] = success_list return_dict['error_dict'] = error_dict return django.shortcuts.render_to_response( 'reset_to_factory_defaults_result.html', return_dict, context_instance=django.template.context. RequestContext(request)) else: # Bad form return_dict['form'] = form return django.shortcuts.render_to_response( 'reset_to_factory_defaults.html', return_dict, context_instance=django.template.context.RequestContext( request)) except Exception, e: return_dict["base_template"] = 'system_base.html' return_dict['tab'] = 'system_info_tab' return_dict['page_title'] = 'Reset to factory defaults' return_dict["error"] = 'Error resetting to factory defaults' 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 create_nfs_share(request): return_dict = {} try: pools, err = zfs.get_pools() if err: raise Exception(err) ds_list = [] for pool in pools: for ds in pool["datasets"]: if ds['properties']['type']['value'] == 'filesystem': ds_list.append( {'name': ds["name"], 'mountpoint': ds["mountpoint"]}) if not ds_list: raise Exception( 'No ZFS datasets available. Please create a dataset before creating shares.') req_ret, err = django_utils.get_request_parameter_values( request, ['dataset', 'path']) if err: raise Exception(err) if 'dataset' in req_ret: dataset = req_ret['dataset'] else: dataset = ds_list[0]['mountpoint'] if 'path' in req_ret: path = req_ret['path'] else: path = dataset return_dict['path'] = path return_dict["dataset"] = ds_list if request.method == "GET": # Return the conf page initial = {} initial['path'] = path initial['dataset'] = dataset form = nfs_shares_forms.CreateShareForm( initial=initial, dataset_list=ds_list) return_dict['form'] = form return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request)) else: form = nfs_shares_forms.CreateShareForm( request.POST, dataset_list=ds_list) return_dict['form'] = form if not form.is_valid(): return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request)) cd = form.cleaned_data if 'new_folder' in cd and cd['new_folder']: try: os.mkdir('%s/%s' % (cd['path'], cd['new_folder'])) audit_str = 'Created new directory "%s" in "%s"' % ( cd['new_folder'], cd['path']) audit.audit("create_dir", audit_str, request) cd['path'] = '%s/%s' % (cd['path'], cd['new_folder']) except Exception, e: raise Exception('Error creating subfolder %s : %s' % ( cd['new_folder'], str(e))) result, err = nfs.save_share(cd, True) if err: raise Exception(err) audit_str = "Created NFS share %s" % cd['path'] audit.audit("create_nfs_share", audit_str, request) return django.http.HttpResponseRedirect('/view_nfs_shares?ack=created') except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Create a NFS share ' return_dict['tab'] = 'view_nfs_shares_tab' return_dict["error"] = 'Error creating a NFS share' 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 create_iscsi_acl(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values( request, ['target_name']) if err: raise Exception(err) if 'target_name' not in req_ret: raise Exception("Invalid request, please use the menus.") target_name = req_ret['target_name'] target, err = iscsi_stgt.get_target(target_name) if err: raise Exception(err) if not target: raise Exception('Specified target not found') if request.method == "GET": # Return the form initial = {} initial['target_name'] = target_name form = iscsi_stgt_forms.IscsiAclForm(initial=initial) return_dict["form"] = form return django.shortcuts.render_to_response( "create_iscsi_acl.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: # Form submission so create return_dict = {} form = iscsi_stgt_forms.IscsiAclForm(request.POST) if form.is_valid(): cd = form.cleaned_data ret, err = iscsi_stgt.add_acl(cd['target_name'], cd['acl']) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Added ISCSI ACL %s for target %s" % ( cd["acl"], cd['target_name']) url = '/view_iscsi_target?name=%s&ack=added_acl' % target_name audit.audit("add_iscsi_acl", audit_str, request) return django.http.HttpResponseRedirect(url) else: return_dict["form"] = form return django.shortcuts.render_to_response( "create_iscsi_acl.html", return_dict, context_instance=django.template.context.RequestContext( request)) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Add ISCSI ACL' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error adding ISCSI ACL' 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 create_iscsi_user_authentication(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values( request, ['target_name', 'authentication_type']) if err: raise Exception(err) if ('target_name' and 'authentication_type') not in req_ret: raise Exception("Invalid request, please use the menus.") authentication_type = req_ret['authentication_type'] target_name = req_ret['target_name'] if authentication_type not in ['incoming', 'outgoing']: raise Exception("Invalid user type. Please use the menus.") if request.method == "GET": # Return the form initial = {} initial['authentication_type'] = authentication_type initial['target_name'] = target_name form = iscsi_stgt_forms.IscsiAuthenticationForm(initial=initial) return_dict["form"] = form return django.shortcuts.render_to_response( "create_iscsi_target_user.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: # Form submission so create return_dict = {} form = iscsi_stgt_forms.IscsiAuthenticationForm(request.POST) if form.is_valid(): cd = form.cleaned_data ret, err = iscsi_stgt.add_user_authentication( cd['target_name'], cd['authentication_type'], cd["username"], cd["password"]) if not ret: if err: raise Exception(err) else: raise Exception("Error adding the ISCSI target user.") if cd['authentication_type'] == 'incoming': audit_str = "Added ISCSI initiator authentication user %s for target %s" % ( cd["username"], cd['target_name']) url = '/view_iscsi_target?name=%s&ack=added_initiator_authentication' % target_name else: audit_str = "Added ISCSI target authentication user %s for target %s" % ( cd["username"], cd['target_name']) url = '/view_iscsi_target?name=%s&ack=added_target_authentication' % target_name audit.audit("add_iscsi_target_authentication", audit_str, request) return django.http.HttpResponseRedirect(url) else: return_dict["form"] = form return django.shortcuts.render_to_response( "create_iscsi_target_user.html", return_dict, context_instance=django.template.context.RequestContext( request)) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Add ISCSI authentication user' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error adding ISCSI authentication user' 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 view_read_write_stats(request): return_dict = {} try: req_params, err = django_utils.get_request_parameter_values( request, ['last_x_seconds', 'refresh_interval']) if err: raise Exception(err) if 'refresh_interval' in req_params: return_dict['refresh_interval'] = req_params['refresh_interval'] if 'last_x_seconds' in req_params: actions = ['access', 'modify', 'create', 'delete', 'move'] count_dict = {} for action in actions: count, err = inotify.get_count( action, int(req_params['last_x_seconds'])) if err: raise Exception(err) count_dict[action] = count # print count_dict return_dict['count_dict'] = count_dict return_dict['last_x_seconds'] = int(req_params['last_x_seconds']) return_dict['last_x_minutes'] = int( req_params['last_x_seconds']) / 60 lines, err = command.get_command_output('/usr/bin/arc_summary.py -d') if not err: return_dict['arc_summary_lines'] = lines else: return_dict['arc_error'] = err lines, err = command.get_command_output('zpool iostat -T d -v') if not err: return_dict['zpool_iostat_lines'] = lines else: return_dict['zpool_iostat_error'] = err lines, err = command.get_command_output('iostat -dm') if not err: return_dict['iostat_lines'] = lines else: return_dict['iostat_error'] = err lines, err = command.get_command_output('iostat -c') if not err: return_dict['cpu_iostat_lines'] = lines else: return_dict['cpu_iostat_error'] = err lines, err = command.get_command_output('free -h') if not err: return_dict['mem_lines'] = lines else: return_dict['mem_error'] = err lines, err = command.get_command_output('free -h') if not err: return_dict['mem_lines'] = lines else: return_dict['mem_error'] = err ''' local_timezone, err = system_date_time.get_current_timezone() if err: raise Exception(err) if 'timezone_str' not in local_timezone: timezone_str = 'UTC' else: timezone_str = local_timezone['timezone_str'] tz = pytz.timezone(timezone_str) django.utils.timezone.activate(tz) now_local = datetime.datetime.now(tz) now = int(now_local.strftime('%s')) ''' if err: raise Exception(err) return django.shortcuts.render_to_response('view_read_write_stats.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "system_base.html" return_dict["page_title"] = 'Monitoring' return_dict['tab'] = 'dir_manager_tab' return_dict["error"] = 'Error loading read and write stats' 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 create_iscsi_lun(request): return_dict = {} try: req_ret, err = django_utils.get_request_parameter_values( request, ['target_name']) if err: raise Exception(err) if 'target_name' not in req_ret: raise Exception("Invalid request, please use the menus.") target_name = req_ret['target_name'] zvols, err = zfs.get_all_zvols() if err: raise Exception(err) if not zvols: raise Exception( "There are no block device volumes created. Please create one first before adding a LUN." ) if request.method == "GET": # Return the form initial = {} initial['target_name'] = target_name form = iscsi_stgt_forms.IscsiLunForm(initial=initial, zvols=zvols) return_dict["form"] = form return django.shortcuts.render_to_response( "create_iscsi_lun.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: # Form submission so create return_dict = {} form = iscsi_stgt_forms.IscsiLunForm(request.POST, zvols=zvols) if form.is_valid(): cd = form.cleaned_data ret, err = iscsi_stgt.create_lun(cd["target_name"], cd['path']) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Created an ISCSI LUN in target %s with path %s" % ( cd["target_name"], cd['path']) audit.audit("create_iscsi_lun", audit_str, request) url = '/view_iscsi_target?name=%s&ack=lun_created' % target_name return django.http.HttpResponseRedirect(url) else: return_dict["form"] = form return django.shortcuts.render_to_response( "create_iscsi_lun.html", return_dict, context_instance=django.template.context.RequestContext( request)) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Create an ISCSI LUN' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error creating an ISCSI LUN' 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 update_remote_replication(request): return_dict = {} try: ret, err = django_utils.get_request_parameter_values( request, ['remote_replication_id']) if err: raise Exception(err) if 'remote_replication_id' not in ret: raise Exception( "Requested remote replication not found, please use the menus." ) remote_replication_id = ret['remote_replication_id'] replications, err = remote_replication.get_remote_replications( remote_replication_id) if err: raise Exception(err) if not replications: raise Exception('Specified replication definition not found') if request.method == "GET": return_dict['replication'] = replications[0] return django.shortcuts.render_to_response( 'update_remote_replication.html', return_dict, context_instance=django.template.context.RequestContext( request)) elif request.method == "POST": if 'scheduler' not in request.POST: raise Exception("Incomplete request.") scheduler = request.POST.get('scheduler') schedule = scheduler.split() replication = replications[0] description = 'Replication of %s to pool %s on machine %s' % ( replication['source_dataset'], replication['destination_pool'], replication['destination_ip']) py_scripts_path, err = config.get_python_scripts_path() if err: raise Exception(err) cmd = '%s/add_remote_replication_task.py %s %s %s %s' % ( py_scripts_path, replications[0]['source_dataset'], replications[0]['destination_ip'], replications[0]['destination_user_name'], replications[0]['destination_pool']) # print cmd new_cron_task_id, err = scheduler_utils.create_cron_task( cmd, description, schedule[0], schedule[1], schedule[2], schedule[3], schedule[4]) if err: raise Exception(err) ret, err = remote_replication.update_remote_replication( replications[0]['remote_replication_id'], new_cron_task_id) if err: raise Exception(err) cron_remove, err = scheduler_utils.delete_cron( int(replication['cron_task_id'])) if err: raise Exception(err) crons, err = scheduler_utils.get_cron_tasks(new_cron_task_id) if err: raise Exception(err) description += ' Scheduled for %s' % crons[0][ 'schedule_description'] audit.audit("modify_remote_replication", description, request) return django.http.HttpResponseRedirect( '/view_remote_replications?ack=updated') except Exception as e: return_dict['base_template'] = "snapshot_replication_base.html" return_dict["page_title"] = 'Configure ZFS replication' return_dict['tab'] = 'view_remote_replications_tab' return_dict["error"] = 'Error configuring ZFS replication' 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))