Beispiel #1
0
def show(request, page, info=None):

    return_dict = {}
    try:

        si, err = system_info.load_system_config()
        if err:
            raise Exception(err)

        #assert False
        return_dict['system_info'] = si

        #By default show error page
        template = "logged_in_error.html"

        if page == "dir_contents":
            #CHANGE THIS TO SHOW LOCAL DIR LISTINGS!!
            return django.http.HttpResponse(dir_list,
                                            content_type == 'application/json')

        elif page == "integral_view_log_level":

            template = "view_integral_view_log_level.html"
            try:
                log_level = iv_logging.get_log_level_str()
            except Exception, e:
                return_dict["error"] = str(e)
            else:
                return_dict["log_level_str"] = log_level
            if "saved" in request.REQUEST:
                return_dict["saved"] = request.REQUEST["saved"]
        '''
    elif page == "node_info":
      return_dict['base_template'] = "system_base.html"
      return_dict["page_title"] = 'System configuration'
      return_dict['tab'] = 'node_info_tab'
      return_dict["error"] = 'Error loading system configuration'
      template = "view_node_info.html"
      if "from" in request.GET:
        frm = request.GET["from"]
        return_dict['frm'] = frm
      #return_dict['node'] = si[info]
      return_dict['node'] = si[si.keys()[0]]
    '''

        return django.shortcuts.render_to_response(
            template,
            return_dict,
            context_instance=django.template.context.RequestContext(request))
def show(request, page, info = None):

  return_dict = {}
  try:

    assert request.method == 'GET'

    si = system_info.load_system_config()

    #assert False
    return_dict['system_info'] = si

    #By default show error page
    template = "logged_in_error.html"

    if page == "dir_contents":
      #CHANGE THIS TO SHOW LOCAL DIR LISTINGS!!
      return django.http.HttpResponse(dir_list,mimetype='application/json')

    elif page == "ntp_settings":

      template = "view_ntp_settings.html"
      try:
        ntp_servers = ntp.get_ntp_servers()
      except Exception, e:
        return_dict["error"] = str(e)
      else:
        return_dict["ntp_servers"] = ntp_servers
      if "saved" in request.REQUEST:
        return_dict["saved"] = request.REQUEST["saved"]

    elif page == "integral_view_log_level":

      template = "view_integral_view_log_level.html"
      try:
        log_level = iv_logging.get_log_level_str()
      except Exception, e:
        return_dict["error"] = str(e)
Beispiel #3
0
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 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 show(request, page, info = None):

  return_dict = {}
  try:

    si,err = system_info.load_system_config()
    if err:
      raise Exception(err)

    #assert False
    return_dict['system_info'] = si

    #By default show error page
    template = "logged_in_error.html"

    if page == "dir_contents":
      #CHANGE THIS TO SHOW LOCAL DIR LISTINGS!!
      return django.http.HttpResponse(dir_list,mimetype='application/json')

    elif page == "ntp_settings":

      return_dict['base_template'] = "services_base.html"
      return_dict["page_title"] = 'Network Time Protocol(NTP) settings '
      return_dict['tab'] = 'ntp_settings_tab'
      return_dict["error"] = 'Error loading Network Time Protocol(NTP) settings '
      template = "view_ntp_settings.html"
      ntp_servers, err = ntp.get_ntp_servers()
      if err:
        raise Exception(err)
      return_dict["ntp_servers"] = ntp_servers
      if "saved" in request.REQUEST:
        return_dict["saved"] = request.REQUEST["saved"]

    elif page == "integral_view_log_level":

      template = "view_integral_view_log_level.html"
      try:
        log_level = iv_logging.get_log_level_str()
      except Exception, e:
        return_dict["error"] = str(e)
      else:
        return_dict["log_level_str"] = log_level
      if "saved" in request.REQUEST:
        return_dict["saved"] = request.REQUEST["saved"]

    elif page == "email_settings":

      #print "here"
      return_dict['base_template'] = "system_base.html"
      return_dict["page_title"] = 'Email notifications settings '
      return_dict['tab'] = 'email_tab'
      return_dict["error"] = 'Error loading email notifications settings '
      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
      if "saved" in request.REQUEST:
        return_dict["saved"] = request.REQUEST["saved"]
      if "not_saved" in request.REQUEST:
        return_dict["not_saved"] = request.REQUEST["not_saved"]
      if "err" in request.REQUEST:
        return_dict["err"] = request.REQUEST["err"]
      template = "view_email_settings.html"