コード例 #1
0
def main():

    lg = None
    try:
        lg, err = logger.get_script_logger('Generate manifest',
                                           '/var/log/integralstor/scripts.log',
                                           level=logging.DEBUG)
        logger.log_or_print('Generate manifest initiated.', lg, level='info')

        num_args = len(sys.argv)
        if num_args > 1:
            path = sys.argv[1]
        else:
            path, err = config.get_system_status_path()
            if err:
                raise Exception(err)
            if not path:
                path = '/tmp'
        logger.log_or_print("Generating the manifest in %s" % path,
                            lg,
                            level='info')
        rc, err = gen_manifest(path)
        if err:
            raise Exception(err)
        # print rc
    except Exception, e:
        str = "Error generating manifest file : %s" % e
        logger.log_or_print(str, lg, level='critical')
        return -1
コード例 #2
0
def main():

    lg = None
    try:
        lg, err = logger.get_script_logger(
            'Generate manifest', '/var/log/integralstor/scripts.log', level=logging.DEBUG)
        logger.log_or_print('Generate manifest initiated.', lg, level='info')

        num_args = len(sys.argv)
        if num_args > 1:
            path = sys.argv[1]
        else:
            path, err = config.get_system_status_path()
            if err:
                raise Exception(err)
            if not path:
                path = '/tmp'
        logger.log_or_print("Generating the manifest in %s" %
                            path, lg, level='info')
        rc, err = gen_manifest(path)
        if err:
            raise Exception(err)
        # print rc
    except Exception, e:
        str = "Error generating manifest file : %s" % e
        logger.log_or_print(str, lg, level='critical')
        return -1
コード例 #3
0
def main():

    lg = None
    try:
        lg, err = logger.get_script_logger('Generate status',
                                           '/var/log/integralstor/scripts.log',
                                           level=logging.DEBUG)

        logger.log_or_print('Generate status initiated.', lg, level='info')

        platform, err = config.get_platform()
        if err:
            raise Exception(err)

        default_path = False

        num_args = len(sys.argv)

        if num_args > 1:
            path = sys.argv[1]
        else:
            default_path = True
            path, err = config.get_system_status_path()
            if err:
                raise Exception(err)
            if not path:
                path = '/tmp'
        # print platform, path

        if platform == 'gridcell' and default_path:
            # This means that I must've been called from a cron script so need
            # to check if I really need to execute..
            from integralstor_gridcell import grid_ops
            active, err = grid_ops.is_active_admin_gridcell()
            if err:
                raise Exception(err)
            if not active:
                logger.log_or_print('Not active admin GRIDCell so exiting.',
                                    lg,
                                    level='info')
                sys.exit(0)

        logger.log_or_print("Generating the status in %s" % path,
                            lg,
                            level='info')
        rc, err = gen_status(path, lg)
        if err:
            raise Exception(err)
        # print rc
    except Exception, e:
        str = "Error generating status file : %s" % e
        logger.log_or_print(str, lg, level='critical')
        sys.exit(-1)
コード例 #4
0
def update_manifest(request):
    return_dict = {}
    try:
        if request.method == "GET":
            from integralstor_utils import manifest_status as iu
            mi, err = iu.generate_manifest_info()
            # print mi, err
            if err:
                raise Exception(err)
            if not mi:
                raise Exception('Could not load new configuration')
            return_dict["mi"] = mi[mi.keys()[0]]  # Need the hostname here.
            return django.shortcuts.render_to_response(
                "update_manifest.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        elif request.method == "POST":
            common_python_scripts_path, err = config.get_common_python_scripts_path(
            )
            if err:
                raise Exception(err)
            ss_path, err = config.get_system_status_path()
            if err:
                raise Exception(err)
            #(ret,rc), err = command.execute_with_rc("python %s/generate_manifest.py %s"%(common_python_scripts_path, ss_path))
            ret, err = command.get_command_output(
                "python %s/generate_manifest.py %s" %
                (common_python_scripts_path, ss_path))
            # print 'mani', ret, err
            if err:
                raise Exception(err)
            #(ret,rc), err = command.execute_with_rc("python %s/generate_status.py %s"%(config.get_python_scripts_path(),config.get_system_status_path()))
            ret, err = command.get_command_output(
                "python %s/generate_status.py %s" %
                (common_python_scripts_path, ss_path))
            # print 'stat', ret, err
            if err:
                raise Exception(err)
            return django.http.HttpResponseRedirect("/view_system_info/")
    except Exception, e:
        return_dict['base_template'] = "system_base.html"
        return_dict["page_title"] = 'Reload system configuration'
        return_dict['tab'] = 'node_info_tab'
        return_dict["error"] = 'Error reloading system configuration'
        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))
コード例 #5
0
def main():

    lg = None
    try:
        lg, err = logger.get_script_logger(
            'Generate status', '/var/log/integralstor/scripts.log', level=logging.DEBUG)

        logger.log_or_print('Generate status initiated.', lg, level='info')

        platform, err = config.get_platform()
        if err:
            raise Exception(err)

        default_path = False

        num_args = len(sys.argv)

        if num_args > 1:
            path = sys.argv[1]
        else:
            default_path = True
            path, err = config.get_system_status_path()
            if err:
                raise Exception(err)
            if not path:
                path = '/tmp'
        # print platform, path

        if platform == 'gridcell' and default_path:
            # This means that I must've been called from a cron script so need
            # to check if I really need to execute..
            from integralstor_gridcell import grid_ops
            active, err = grid_ops.is_active_admin_gridcell()
            if err:
                raise Exception(err)
            if not active:
                logger.log_or_print(
                    'Not active admin GRIDCell so exiting.', lg, level='info')
                sys.exit(0)

        logger.log_or_print("Generating the status in %s" %
                            path, lg, level='info')
        rc, err = gen_status(path, lg)
        if err:
            raise Exception(err)
        # print rc
    except Exception, e:
        str = "Error generating status file : %s" % e
        logger.log_or_print(str, lg, level='critical')
        sys.exit(-1)
コード例 #6
0
def load_system_config(first_time=False):
    """Returns a dictionary with the configuration and status of all the nodes and their components. This is done by comparing the originally generated master.manifest with a master.status that is generated every minute and combining them into one large dict.

    first_time - This indicates whether it is being called during the initial setup. If so, there is no admin volume that has been created and so no admin volume mountpoint. So we need to pick up the files from a tmp directory.
    """

    return_dict = {}
    try:
        ctdb_status = None
        if first_time:
            system_status_path, err = config.get_tmp_path()
            if err:
                raise Exception(err)
        else:
            system_status_path, err = config.get_system_status_path()
            if err:
                raise Exception(err)

        status_filename = "%s/master.status" % system_status_path
        manifest_filename = "%s/master.manifest" % system_status_path

        with open(status_filename, "r") as f:
            status_nodes = json.load(f)
        with open(manifest_filename, "r") as f:
            manifest_nodes = json.load(f)

        # First initialize it with the master nodes
        return_dict = manifest_nodes
        '''
    #Commenting out as we wont use CTDB for this build
    #Get the CTDB status so we can populate it into each node's dict
    if not first_time:
      ctdb_status, err = ctdb.get_status()
    #print ctdb_status, err
    if err:
      raise Exception(err)
    '''

        # Generate the gluster trusted pool peer list and add the localhost
        # onto it. Need this info to update the cluster status.
        peer_list, err = gluster_trusted_pools.get_peer_list()
        # print 'peer list is ', peer_list
        if err:
            raise Exception(err)
        '''
    #Need to add the localhost because it is never returned as part of the peer list
    localhost = socket.getfqdn().strip()
    tmpd = {}
    tmpd["hostname"] = localhost
    tmpd["status"] = 1
    tmpd["status_str"] = "Peer in Cluster"
    peer_list.append(tmpd)
    '''

        # Get the list of basic info about the volumes. Need this to updates
        # the volumes residing on each node.
        vil, err = gluster_volumes.get_basic_volume_info_all()
        if err:
            raise Exception(err)

        for hostname in return_dict.keys():

            if hostname not in status_nodes:
                # That node is not there in the status so what do we do?? This
                # should never happen..
                continue

            # Default it to not being in the gluster trusted pool
            return_dict[hostname]['cluster_status_str'] = 'Peer not in cluster'
            return_dict[hostname]["in_cluster"] = False

            # Populate the list of volumes on this node.
            return_dict[hostname][
                "volume_list"], err = gluster_volumes.get_volumes_on_node(
                    hostname, vil)
            if err:
                raise Exception(err)

            # Now start updating it with the status info.
            status_node = status_nodes[hostname]

            for status_node_key in status_node.keys():

                if status_node_key not in return_dict[hostname]:
                    # It is a new piece of info from the status dict so add
                    # it..
                    return_dict[hostname][status_node_key] = status_node[
                        status_node_key]

                elif status_node_key == "disks":
                    for disk in status_node["disks"].keys():
                        if disk in return_dict[hostname]["disks"]:
                            # Disk exists so just update the dict from status..
                            return_dict[hostname]["disks"][disk].update(
                                status_node["disks"][disk])
                        else:
                            # Unknown disk in status. for now pass..
                            pass

                    # In case we have more than one pool per node which is not
                    # the case now, scan through them and determine which pool
                    # each disk is part of. This will be used for disk
                    # replacement.
                    pool_list = status_node['pools']
                    if pool_list:
                        for serial_num, disk in return_dict[hostname][
                                'disks'].items():
                            id = disk['id']
                            # print id
                            found = False
                            for pool in pool_list:
                                devices_list, err = zfs.get_disks_in_component(
                                    pool['config']['pool']['root'])
                                # print devices_list
                                if err:
                                    raise Exception(err)
                                if devices_list and id in devices_list:
                                    disk['pool'] = pool['pool_name']
                elif status_node_key == "interfaces":
                    for interface in status_node["interfaces"].keys():
                        if interface in return_dict[hostname]["interfaces"]:
                            return_dict[hostname]["interfaces"][
                                interface].update(
                                    status_node["interfaces"][interface])
                elif status_node_key == "memory":
                    # Pull in new memory keys that are not part of the manifest
                    # like free, used, etc.
                    for mem_key in status_node["memory"].keys():
                        if mem_key not in return_dict[hostname]["memory"]:
                            return_dict[hostname]["memory"][
                                mem_key] = status_node["memory"][mem_key]

            # Now update the trusted pool status.
            return_dict[hostname]["in_cluster"] = False
            if peer_list:
                for peer in peer_list:
                    # print 'peer is ', peer
                    # print 'hostname is ', hostname
                    # peer hostname could be hostname or IP so need to check
                    # both
                    if (hostname == peer["hostname"]) or (
                            'inet'
                            in return_dict[hostname]['interfaces']['bond0']
                            and return_dict[hostname]['interfaces']['bond0']
                        ['inet'][0]['address'] == peer['hostname']) or (
                            hostname
                            == '%s.integralstor.lan' % peer['hostname']):
                        # print 'updating ', hostname
                        return_dict[hostname]["in_cluster"] = True
                        return_dict[hostname]["cluster_status"] = int(
                            peer["status"])
                        return_dict[hostname]["cluster_status_str"] = peer[
                            "status_str"]
                        if 'status' in peer:
                            if peer['status'] == '1':
                                return_dict[hostname][
                                    "cluster_status_str"] += ' (Connected)'
                            else:
                                return_dict[hostname][
                                    "cluster_status_str"] += ' (Disconnected)'
                        break

            # Store the bond0 IP as a key just for easy reference since we need
            # it a lot.
            if 'interfaces' in return_dict[hostname] and return_dict[hostname][
                    'interfaces'] and 'bond0' in return_dict[hostname][
                        'interfaces'] and return_dict[hostname]['interfaces'][
                            'bond0'] and 'inet' in return_dict[hostname][
                                'interfaces']['bond0'] and return_dict[hostname][
                                    'interfaces']['bond0']['inet'] and return_dict[
                                        hostname]['interfaces']['bond0']['inet'][
                                            0] and 'address' in return_dict[
                                                hostname]['interfaces']['bond0'][
                                                    'inet'][0] and return_dict[
                                                        hostname]['interfaces'][
                                                            'bond0']['inet'][
                                                                0]['address']:
                return_dict[hostname]['bond0_ip'] = return_dict[hostname][
                    'interfaces']['bond0']['inet'][0]['address']
        '''
    #Commenting out as we wont use CTDB for this build
      if ctdb_status:
        for n, v in ctdb_status.items():
          if 'bond0_ip' in return_dict[hostname] and return_dict[hostname]['bond0_ip'] == n:
            return_dict[hostname]['ctdb_status'] = v
            break
    '''

    except Exception, e:
        return None, 'Error loading system configuration : %s' % str(e)
コード例 #7
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))
コード例 #8
0
def remove_bond():
    try:
        os.system('clear')
        interfaces, err = networking.get_interfaces()
        if err:
            raise Exception('Error retrieving interface information : %s' %
                            err)
        if not interfaces:
            raise Exception('No interfaces detected')

        print
        print
        print 'IntegralSTOR NIC Bonding'
        print '---------------------------------'
        print
        print
        print 'Active bond(s): \n'

        bm, err = networking.get_bonding_masters()
        if err:
            raise Exception(err)
        bid, err = networking.get_bonding_info_all()
        if err:
            raise Exception(err)

        avail_if = []
        for if_name, iface in interfaces.items():
            if if_name in bm:
                print '\t- %s' % if_name
                avail_if.append(if_name)
        print "\n"
        if not avail_if:
            raise Exception('There is nothing to remove!')

        bond_name = None
        is_name = False
        while is_name is False:
            bond_name = raw_input('To remove a bond, provide its name: ')
            if bond_name not in avail_if:
                print "\t- Can't remove %s, no such bond exists. Please provide another one.\n" % bond_name
            else:
                is_name = True

        ret, err = networking.delete_bond(bond_name)
        if not ret:
            if err:
                raise Exception('Error removing bond: %s' % err)
            else:
                raise Exception("Couldn't remove bond")
        if ret:
            print "\n\tBond removed!\n"

        print
        print 'Regenerating manifest and status.'
        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)
        print 'Regenerating manifest and status... Done'
        print
    except Exception, e:
        print "Error: %s" % e
        print
        return -1
コード例 #9
0
def load_system_config(first_time=False):
    """Returns a dictionary with the configuration and status of all the nodes and their components. This is done by comparing the originally generated master.manifest with a master.status that is generated every minute and combining them into one large dict.

    first_time - This indicates whether it is being called during the initial setup. If so, there is no admin volume that has been created and so no admin volume mountpoint. So we need to pick up the files from a tmp directory.
    """

    return_dict = {}
    try:
        ctdb_status = None
        if first_time:
            system_status_path, err = config.get_tmp_path()
            if err:
                raise Exception(err)
        else:
            system_status_path, err = config.get_system_status_path()
            if err:
                raise Exception(err)

        status_filename = "%s/master.status" % system_status_path
        manifest_filename = "%s/master.manifest" % system_status_path

        with open(status_filename, "r") as f:
            status_nodes = json.load(f)
        with open(manifest_filename, "r") as f:
            manifest_nodes = json.load(f)

        # First initialize it with the master nodes
        return_dict = manifest_nodes

        '''
    #Commenting out as we wont use CTDB for this build
    #Get the CTDB status so we can populate it into each node's dict
    if not first_time:
      ctdb_status, err = ctdb.get_status()
    #print ctdb_status, err
    if err:
      raise Exception(err)
    '''

        # Generate the gluster trusted pool peer list and add the localhost
        # onto it. Need this info to update the cluster status.
        peer_list, err = gluster_trusted_pools.get_peer_list()
        # print 'peer list is ', peer_list
        if err:
            raise Exception(err)
        '''
    #Need to add the localhost because it is never returned as part of the peer list
    localhost = socket.getfqdn().strip()
    tmpd = {}
    tmpd["hostname"] = localhost
    tmpd["status"] = 1
    tmpd["status_str"] = "Peer in Cluster"
    peer_list.append(tmpd)
    '''

        # Get the list of basic info about the volumes. Need this to updates
        # the volumes residing on each node.
        vil, err = gluster_volumes.get_basic_volume_info_all()
        if err:
            raise Exception(err)

        for hostname in return_dict.keys():

            if hostname not in status_nodes:
                # That node is not there in the status so what do we do?? This
                # should never happen..
                continue

            # Default it to not being in the gluster trusted pool
            return_dict[hostname]['cluster_status_str'] = 'Peer not in cluster'
            return_dict[hostname]["in_cluster"] = False

            # Populate the list of volumes on this node.
            return_dict[hostname]["volume_list"], err = gluster_volumes.get_volumes_on_node(
                hostname, vil)
            if err:
                raise Exception(err)

            # Now start updating it with the status info.
            status_node = status_nodes[hostname]

            for status_node_key in status_node.keys():

                if status_node_key not in return_dict[hostname]:
                    # It is a new piece of info from the status dict so add
                    # it..
                    return_dict[hostname][status_node_key] = status_node[status_node_key]

                elif status_node_key == "disks":
                    for disk in status_node["disks"].keys():
                        if disk in return_dict[hostname]["disks"]:
                            # Disk exists so just update the dict from status..
                            return_dict[hostname]["disks"][disk].update(
                                status_node["disks"][disk])
                        else:
                            # Unknown disk in status. for now pass..
                            pass

                    # In case we have more than one pool per node which is not
                    # the case now, scan through them and determine which pool
                    # each disk is part of. This will be used for disk
                    # replacement.
                    pool_list = status_node['pools']
                    if pool_list:
                        for serial_num, disk in return_dict[hostname]['disks'].items():
                            id = disk['id']
                            # print id
                            found = False
                            for pool in pool_list:
                                devices_list, err = zfs.get_disks_in_component(
                                    pool['config']['pool']['root'])
                                # print devices_list
                                if err:
                                    raise Exception(err)
                                if devices_list and id in devices_list:
                                    disk['pool'] = pool['pool_name']
                elif status_node_key == "interfaces":
                    for interface in status_node["interfaces"].keys():
                        if interface in return_dict[hostname]["interfaces"]:
                            return_dict[hostname]["interfaces"][interface].update(
                                status_node["interfaces"][interface])
                elif status_node_key == "memory":
                    # Pull in new memory keys that are not part of the manifest
                    # like free, used, etc.
                    for mem_key in status_node["memory"].keys():
                        if mem_key not in return_dict[hostname]["memory"]:
                            return_dict[hostname]["memory"][mem_key] = status_node["memory"][mem_key]

            # Now update the trusted pool status.
            return_dict[hostname]["in_cluster"] = False
            if peer_list:
                for peer in peer_list:
                    # print 'peer is ', peer
                    # print 'hostname is ', hostname
                    # peer hostname could be hostname or IP so need to check
                    # both
                    if (hostname == peer["hostname"]) or ('inet' in return_dict[hostname]['interfaces']['bond0'] and return_dict[hostname]['interfaces']['bond0']['inet'][0]['address'] == peer['hostname']) or (hostname == '%s.integralstor.lan' % peer['hostname']):
                        # print 'updating ', hostname
                        return_dict[hostname]["in_cluster"] = True
                        return_dict[hostname]["cluster_status"] = int(
                            peer["status"])
                        return_dict[hostname]["cluster_status_str"] = peer["status_str"]
                        if 'status' in peer:
                            if peer['status'] == '1':
                                return_dict[hostname]["cluster_status_str"] += ' (Connected)'
                            else:
                                return_dict[hostname]["cluster_status_str"] += ' (Disconnected)'
                        break

            # Store the bond0 IP as a key just for easy reference since we need
            # it a lot.
            if 'interfaces' in return_dict[hostname] and return_dict[hostname]['interfaces'] and 'bond0' in return_dict[hostname]['interfaces'] and return_dict[hostname]['interfaces']['bond0'] and 'inet' in return_dict[hostname]['interfaces']['bond0'] and return_dict[hostname]['interfaces']['bond0']['inet'] and return_dict[hostname]['interfaces']['bond0']['inet'][0] and 'address' in return_dict[hostname]['interfaces']['bond0']['inet'][0] and return_dict[hostname]['interfaces']['bond0']['inet'][0]['address']:
                return_dict[hostname]['bond0_ip'] = return_dict[hostname]['interfaces']['bond0']['inet'][0]['address']

        '''
    #Commenting out as we wont use CTDB for this build
      if ctdb_status:
        for n, v in ctdb_status.items():
          if 'bond0_ip' in return_dict[hostname] and return_dict[hostname]['bond0_ip'] == n:
            return_dict[hostname]['ctdb_status'] = v
            break
    '''

    except Exception, e:
        return None, 'Error loading system configuration : %s' % str(e)
コード例 #10
0
def update_hostname(request):
    return_dict = {}
    try:

        hostname = socket.gethostname()
        if request.method == "GET":
            hostname, err = networking.get_hostname()
            if err:
                raise Exception(err)
            domain_name, err = networking.get_domain_name()
            if err:
                raise Exception(err)

            initial = {}
            initial['hostname'] = hostname
            initial['domain_name'] = domain_name

            form = networking_forms.EditHostnameForm(initial=initial)
            return_dict['form'] = form
            return django.shortcuts.render_to_response(
                "update_hostname.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            form = networking_forms.EditHostnameForm(request.POST)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response(
                    "update_hostname.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
            cd = form.cleaned_data
            result_str = ""
            domain_name = None
            if 'domain_name' in cd:
                domain_name = cd['domain_name']
            result, err = networking.update_hostname(cd['hostname'],
                                                     domain_name)
            if not result:
                if err:
                    raise Exception(err)
                else:
                    raise Exception('Error setting hostname')
            result, err = networking.update_domain_name(domain_name)
            if not result:
                if err:
                    raise Exception(err)
                else:
                    raise Exception('Error setting domain name')
            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)
            ss_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, ss_path))
            if err:
                raise Exception(err)

            ret, err = command.get_command_output(
                "python %s/generate_status.py %s" %
                (common_python_scripts_path, ss_path))

            audit_str = "Hostname set to %s." % cd['hostname']
            if 'domain_name' in cd:
                audit_str += 'Domain name set to %s' % cd['domain_name']
            ret, err = audit.audit("edit_hostname", audit_str, request)
            if err:
                raise Exception(err)

            return django.http.HttpResponseRedirect(
                '/view_hostname?result=saved')
    except Exception, e:
        return_dict['base_template'] = "networking_base.html"
        return_dict["page_title"] = 'Modify system hostname'
        return_dict['tab'] = 'view_hostname_tab'
        return_dict["error"] = 'Error modifying system hostname'
        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))
コード例 #11
0
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))
コード例 #12
0
def create_bond(request):
    return_dict = {}
    try:

        interfaces, err = networking.get_interfaces()
        if err:
            raise Exception(err)
        if not interfaces:
            raise Exception(
                "Error loading network interface information : No interfaces found"
            )

        bm, err = networking.get_bonding_masters()
        if err:
            raise Exception(err)
        bid, err = networking.get_bonding_info_all()
        if err:
            raise Exception(err)

        return_dict['interfaces'] = interfaces
        iface_list = []
        existing_bonds = []
        for if_name, iface in interfaces.items():
            if if_name.startswith('lo') or if_name in bid['by_slave']:
                continue
            if if_name in bm:
                existing_bonds.append(if_name)
                continue
            iface_list.append(if_name)

        return_dict['is_iface_avail'] = False
        if iface_list:
            return_dict['is_iface_avail'] = True

        if request.method == "GET":
            form = networking_forms.CreateBondForm(
                interfaces=iface_list, existing_bonds=existing_bonds)
            return_dict['form'] = form
            return django.shortcuts.render_to_response(
                "create_bond.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            form = networking_forms.CreateBondForm(
                request.POST,
                interfaces=iface_list,
                existing_bonds=existing_bonds)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response(
                    "create_bond.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
            cd = form.cleaned_data
            print cd
            result, err = networking.create_bond(cd['name'], cd['slaves'],
                                                 int(cd['mode']))
            if not result:
                if err:
                    raise Exception(err)
                else:
                    raise Exception('Bond creation failed!')
            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 = "Created a network bond named %s with slaves %s" % (
                cd['name'], ','.join(cd['slaves']))
            audit.audit("create_bond", audit_str, request)
            return django.http.HttpResponseRedirect(
                '/view_interfaces?ack=created_bond')
    except Exception, e:
        return_dict['base_template'] = "networking_base.html"
        return_dict["page_title"] = 'Create a network interface bond'
        return_dict['tab'] = 'view_interfaces_tab'
        return_dict["error"] = 'Error creating 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))
コード例 #13
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))
コード例 #14
0
def establish_default_configuration(client, si, admin_gridcells):
    try:

        platform_root, err = config.get_platform_root()
        if err:
            raise Exception(err)

        defaults_dir, err = config.get_defaults_dir()
        if err:
            raise Exception(err)
        config_dir, err = config.get_config_dir()
        if err:
            raise Exception(err)
        ss_path, err = config.get_system_status_path()
        if err:
            raise Exception(err)
        tmp_path, err = config.get_tmp_path()
        if err:
            raise Exception(err)

        print "\nCopying the default configuration onto the IntegralStor administration volume."
        shutil.copytree("%s/db" % defaults_dir, "%s/db" % config_dir)

        # Create integral view DB
        ret, err = command.get_command_output('rm -rf %s/db/integral_view_config.db' % config_dir, shell=True)
        if err:
            pass
        ret, err = command.get_command_output('sqlite3 %s/db/integral_view_config.db < %s/db/integral_view_config.schema' % (config_dir,config_dir), shell=True)
        if err:
            raise Exception('Could not create DB: %s' % err)

        shutil.copytree("%s/ntp" % defaults_dir, "%s/ntp" % config_dir)
        shutil.copytree("%s/logs" % defaults_dir, "%s/logs" % config_dir)

        # Delete any existing NTP file
        r2 = client.cmd('roles:master', 'cmd.run_all', [
                        'rm /etc/ntp.conf'], expr_form='grain')

        # Link the new NTP conf file on the primary onto the admin vol
        ip_info, err = networking.get_ip_info('bond0')
        if err:
            raise Exception(err)
        ip_l = struct.unpack('!L', socket.inet_aton(ip_info['ipaddr']))[0]
        netmask_l = struct.unpack(
            '!L', socket.inet_aton(ip_info['netmask']))[0]
        network_l = ip_l & netmask_l
        network = socket.inet_ntoa(struct.pack('!L', network_l))
        r2 = client.cmd('roles:master', 'integralstor.configure_ntp_master', admin_gridcells, kwarg={
                        'network': network, 'netmask': ip_info['netmask']}, expr_form='grain')
        if r2:
            errors = ''
            for node, ret in r2.items():
                if not ret[0]:
                    print r2
                    errors += "Error configuring NTP on %s : %s" % (
                        node, ret[1])
            if errors:
                raise Exception(errors)

        # Create a home for the manifest and status files and move the
        # previously generated files here..
        os.mkdir("%s/status" % config_dir)
        shutil.move("%s/master.manifest" % tmp_path, ss_path)
        shutil.move("%s/master.status" % tmp_path, ss_path)

        print "Copying the default configuration onto the IntegralStor administration volume... Done."
        print

        print "Setting up CIFS access.."

        os.mkdir("%s/lock" % config_dir)
        os.mkdir("%s/samba" % config_dir)

        os.mkdir("%s/logs/task_logs" % config_dir, 0777)

        print "Creating assert_admin_vol_mount file"
        with open('%s/lock/assert_admin_vol_mount' % config_dir, 'w') as f:
            f.close()
        print "Creating assert_admin_vol_mount file... Done"
        print

        print "Creating CTDB config file"
        rc, errors = ctdb.create_config_file()
        if not rc:
            if errors:
                raise Exception(errors)
            else:
                raise Exception(
                    "Error creating the CTDB configuration file : Reason unknown")
        print "Creating CTDB config file... Done"
        print

        print "Creating CTDB nodes file"

        ip_list = []
        for node_name, node_info in si.items():
            if "interfaces" in node_info and "bond0" in node_info["interfaces"] and "inet" in node_info["interfaces"]["bond0"] and len(node_info["interfaces"]["bond0"]["inet"]) == 1:
                ip_list.append(
                    "%s" % node_info["interfaces"]["bond0"]["inet"][0]["address"])

        rc, errors = ctdb.add_to_nodes_file(ip_list)
        if not rc:
            if errors:
                raise Exception(errors)
            else:
                raise Exception(
                    "Error creating the CTDB nodes file : Reason unknown")
        print "Creating CTDB nodes file... Done"
        print

        # Create an empty public_addresses file. Entries to the file will be
        # added later from the menus.
        print "Creating CTDB public_addresses file(blank)"
        rc, err = ctdb.mod_public_addresses(None, action='create')
        if err:
            raise Exception(err)
        print "Creating CTDB public_addresses file(blank)... Done"

        print "Placing CTDB files"
        shutil.copyfile('/etc/sysconfig/ctdb', '%s/lock/ctdb' % config_dir)
        r2 = client.cmd('*', 'cmd.run_all', ['rm /etc/sysconfig/ctdb'])
        r2 = client.cmd('*', 'cmd.run_all',
                        ['cp %s/lock/ctdb /etc/sysconfig/ctdb' % config_dir])
        if r2:
            for node, ret in r2.items():
                if ret["retcode"] != 0:
                    print r2
                    errors = "Error placing the CTDB config file on %s" % node
                    raise Exception(errors)
        print "Placing CTDB files... Done"
        print

        # The initial add_to_nodes_file created the initial nodes file in admin
        # vol. So pull it to corresponding /etc/ctdb/ path on all nodes

        print "Placing CTDB nodes files"
        # next line is redundant?
        shutil.copyfile('%s/lock/nodes' % config_dir, '/etc/ctdb/nodes')
        r2 = client.cmd('*', 'cmd.run_all', ['rm -f /etc/ctdb/nodes'])
        r2 = client.cmd('*', 'cmd.run_all',
                        ['cp %s/lock/nodes /etc/ctdb/nodes' % config_dir])
        if r2:
            for node, ret in r2.items():
                if ret["retcode"] != 0:
                    print r2
                    errors = "Error linking to the CTDB nodes file on %s" % node
                    raise Exception(errors)
        print "Placing CTDB nodes files... Done"
        print

        print "Placing CTDB public_addresses files"
        # next line is redundant?
        shutil.copyfile('%s/lock/public_addresses' %
                        config_dir, '/etc/ctdb/public_addresses')
        r2 = client.cmd('*', 'cmd.run_all',
                        ['rm -f /etc/ctdb/public_addresses'])
        r2 = client.cmd(
            '*', 'cmd.run_all', ['cp %s/lock/public_addresses /etc/ctdb/public_addresses' % config_dir])
        if r2:
            for node, ret in r2.items():
                if ret["retcode"] != 0:
                    print r2
                    errors = "Error linking to the CTDB nodes file on %s" % node
                    raise Exception(errors)
        print "Placing CTDB public_addresses files... Done"
        print

        print "Linking smb.conf files"
        shutil.copyfile('%s/samba/smb.conf' % defaults_dir,
                        '%s/lock/smb.conf' % config_dir)
        r2 = client.cmd('*', 'cmd.run_all', ['rm -f /etc/samba/smb.conf'])
        r2 = client.cmd(
            '*', 'cmd.run_all', ['ln -s %s/lock/smb.conf /etc/samba/smb.conf' % config_dir])
        if r2:
            for node, ret in r2.items():
                if ret["retcode"] != 0:
                    print r2
                    errors = "Error linking to the smb.conf file on %s" % node
                    raise Exception(errors)
        print "Linking smb.conf files... Done"
        print

        print "Linking NFS exports file"
        shutil.copyfile('%s/nfs/exports' % defaults_dir,
                        '%s/lock/exports' % config_dir)
        r2 = client.cmd('*', 'cmd.run_all', ['rm -f /etc/exports'])
        r2 = client.cmd(
            '*', 'cmd.run_all', ['ln -s %s/lock/exports /etc/exports' % config_dir])
        if r2:
            for node, ret in r2.items():
                if ret["retcode"] != 0:
                    print r2
                    errors = "Error linking to the NFS exports file on %s" % node
                    raise Exception(errors)
        print "Linking NFS exports file... Done"
        print

        print "Linking Kerberos config file"
        r2 = client.cmd('*', 'cmd.run_all', ['rm /etc/krb5.conf'])
        with open('%s/lock/krb5.conf' % config_dir, 'w') as f:
            f.close()
        r2 = client.cmd('*', 'cmd.run_all',
                        ['ln -s %s/lock/krb5.conf /etc/krb5.conf' % config_dir])
        if r2:
            for node, ret in r2.items():
                if ret["retcode"] != 0:
                    print r2
                    errors = "Error linking to the krb5.conf file on %s" % node
                    raise Exception(errors)
        print "Linking Kerberos config file... Done"
        print

        print "Setting appropriate boot time init files."
        r2 = client.cmd('*', 'cmd.run_all', ['rm /etc/rc.local'])
        r2 = client.cmd('*', 'cmd.run_all', ['rm /etc/rc.d/rc.local'])
        r2 = client.cmd(
            '*', 'cmd.run_all', ['cp %s/rc_local/rc.local /etc/rc.local' % defaults_dir])
        r2 = client.cmd('*', 'cmd.run_all', ['chmod 755 /etc/rc.local'])
        if r2:
            for node, ret in r2.items():
                if ret["retcode"] != 0:
                    print r2
                    errors = "Error setting the appropriate rc.local file on %s" % node
                    raise Exception(errors)
        print "Setting appropriate boot time init files... Done"
        print

    except Exception, e:
        return False, 'Error establishing default configuration : %s' % str(e)
コード例 #15
0
ファイル: system_info.py プロジェクト: naveenmh/integralstor
def load_system_config(first_time=False):

    d = None
    try:
        if first_time:
            system_status_path, err = config.get_tmp_path()
            if err:
                raise Exception(err)
        else:
            system_status_path, err = config.get_system_status_path()
            if err:
                raise Exception(err)

        msfn = "%s/master.status" % system_status_path
        mmfn = "%s/master.manifest" % system_status_path

        try:
            with open(msfn, "r") as f:
                ms_nodes = json.load(f)
            with open(mmfn, "r") as f:
                mm_nodes = json.load(f)
        except IOError:
            raise Exception("file-not-found")

        d = {}
        # First load it with the master node keys
        for k in mm_nodes.keys():
            d[k] = mm_nodes[k]

        for k in d.keys():
            if k not in ms_nodes:
                continue
            status_node = ms_nodes[k]
            for sk in status_node.keys():
                if sk not in d[k]:
                    d[k][sk] = status_node[sk]
                elif sk == "disks":
                    for disk in status_node["disks"].keys():
                        if disk in d[k]["disks"]:
                            d[k]["disks"][disk].update(
                                status_node["disks"][disk])
                    pool_list, err = zfs.get_pools()
                    if pool_list:
                        for sn, disk in d[k]['disks'].items():
                            id = disk['id']
                            found = False
                            for pool in pool_list:
                                devices_list, err = zfs.get_disks_in_component(
                                    pool['config']['pool']['root'])
                                if err:
                                    raise Exception(err)
                                if devices_list and id in devices_list:
                                    disk['pool'] = pool['pool_name']
                        '''
            else:
              d[k]["disks"][disk] = status_node["disks"][disk]
            '''
                elif sk == "interfaces":
                    for interface in status_node["interfaces"].keys():
                        if interface in d[k]["interfaces"]:
                            d[k]["interfaces"][interface].update(
                                status_node["interfaces"][interface])
                        '''
            else:
              d[k]["interfaces"][interface] = status_node["interfaces"][interface]
            '''
                elif sk == "memory":
                    for mem_key in status_node["memory"].keys():
                        if mem_key not in d[k]["memory"]:
                            d[k]["memory"][mem_key] = status_node["memory"][mem_key]

    except Exception, e:
        if str(e) is "file-not-found":
            return None, '<a href="/update_manifest"> <h4>System configuartion not loaded, click here to regenerate.</h4></a>'
        else:
            return None, 'Error loading system configuration : %s' % str(e)