def get_pool_status():
    """Get status of all zfs pools."""
    pl = None
    try:
        pl, err = zfs.get_pools()
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error retrieving pool status : %s' % str(e)
def get_pool_status():
    """Get status of all zfs pools."""
    pl = None
    try:
        pl, err = zfs.get_pools()
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error retrieving pool status : %s' % str(e)
def get_disk_info_and_status():

    all_disks = None
    try:
        all_disks, err = disks.get_disk_info_all()
        if err:
            raise Exception(err)

        if all_disks:
            pool_list, err = zfs.get_pools()
            if pool_list:
                for sn, disk in all_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']
    except Exception, e:
        return None, 'Error retrieving disk information and status : %s' % str(e)
def get_disk_info_and_status():

    all_disks = None
    try:
        all_disks, err = disks.get_disk_info_all()
        if err:
            raise Exception(err)

        if all_disks:
            pool_list, err = zfs.get_pools()
            if pool_list:
                for sn, disk in all_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']
    except Exception, e:
        return None, 'Error retrieving disk information and status : %s' % str(
            e)
def get_status():
    """Overall status info about the system combining all of the above into one big dict."""
    d = {}
    try:
        zfs_ver, err = get_zfs_version()
        if err:
            raise Exception(err)
        d["zfs_version"] = zfs_ver

        os_ver = '%s %s' % (platform.system(), platform.release())
        d["os_version"] = os_ver

        dis, err = get_disk_info_and_status()
        if err:
            raise Exception(err)
        d["disks"] = dis

        services_stat, err = get_services_status()
        if err:
            raise Exception(err)
        d["services"] = services_stat

        iface_status, err = get_interface_status()
        if err:
            raise Exception(err)
        d["interfaces"] = iface_status

        pl, err = zfs.get_pools()
        if err:
            raise Exception(err)
        d["pools"] = pl

        lavg, err = get_load_avg()
        if err:
            raise Exception(err)
        d["load_avg"] = lavg

        meminfo, err = get_mem_info()
        if err:
            raise Exception(err)
        d["memory"] = meminfo

        ipmi, err = get_ipmi_status()
        if ipmi:
            d["ipmi_status"] = ipmi

        cm, err = get_cpu_model()
        if err:
            raise Exception(err)
        d["cpu_model"] = cm

        fqdn = socket.getfqdn()
        d["fqdn"] = fqdn

        hardware_dict, err = get_hardware_specific_info()
        if err:
            raise Exception(err)
        d["hardware_specific_dict"] = hardware_dict

    except Exception, e:
        return None, 'Error retrieving system status: %s' % str(e)
def create_cifs_share(request):

    return_dict = {}
    try:

        pools, err = zfs.get_pools()
        if err:
            raise Exception(
                'No ZFS pools available. Please create a pool and dataset before creating shares.'
            )

        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(
                        (ds['properties']['mountpoint']['value'], ds["name"]))

        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before creating shares.'
            )

        dataset = path = None
        ret, err = django_utils.get_request_parameter_values(
            request, ['dataset', 'path'])
        if err:
            raise Exception(err)
        if 'dataset' not in ret:
            dataset = ds_list[0][0]
        elif 'dataset' in ret:
            dataset = ret['dataset']
        if 'path' not in ret:
            path = dataset
        elif 'path' in ret:
            path = ret['path']

        return_dict['path'] = path
        return_dict["dataset"] = ds_list

        initial = {}
        initial['path'] = path
        initial['dataset'] = dataset
        if request.method == "GET":
            # Return the form
            initial['guest_ok'] = True
            if 'name' in request.GET:
                initial['name'] = request.GET['name']

            form = samba_shares_forms.CreateShareForm(dataset_list=ds_list,
                                                      initial=initial)
            return_dict["form"] = form

            return django.shortcuts.render_to_response(
                "create_cifs_share.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            # Form submission so create
            form = samba_shares_forms.CreateShareForm(request.POST,
                                                      initial=initial,
                                                      dataset_list=ds_list)
            return_dict["form"] = form
            if form.is_valid():
                cd = form.cleaned_data
                # print cd
                name = cd["name"]
                path = cd["path"]
                if not path:
                    return_dict["path_error"] = "Please select a dataset."
                    return django.shortcuts.render_to_response(
                        "create_cifs_share.html",
                        return_dict,
                        context_instance=django.template.context.
                        RequestContext(request))
                if 'new_folder' in cd and cd['new_folder']:
                    try:
                        path = '%s/%s' % (cd['path'], cd['new_folder'])
                        # print path
                        os.mkdir(path)
                        audit_str = 'Created new directory "%s" in "%s"' % (
                            cd['new_folder'], cd['path'])
                        audit.audit("create_dir", audit_str, request)
                    except Exception, e:
                        raise Exception('Error creating subfolder %s : %s' %
                                        (cd['new_folder'], str(e)))

                owner_dict, err = config.get_default_file_dir_owner()
                if err:
                    raise Exception(err)
                owner_uid, err = config.get_system_uid_gid(
                    owner_dict['user'], 'user')
                if err:
                    raise Exception(err)
                owner_gid, err = config.get_system_uid_gid(
                    owner_dict['group'], 'group')
                if err:
                    raise Exception(err)

                os.chown(path, owner_uid, owner_gid)

                if "comment" in cd:
                    comment = cd["comment"]
                else:
                    comment = None
                if "read_only" in cd:
                    read_only = cd["read_only"]
                else:
                    read_only = None
                if "browseable" in cd:
                    browseable = cd["browseable"]
                else:
                    browseable = None

                if 'hosts_allow_choice' in cd and cd[
                        'hosts_allow_choice'] == 'restricted':
                    if 'hosts_allow' not in cd or not cd['hosts_allow']:
                        raise Exception(
                            'Please enter a valid list of allowed hosts')
                    hosts_allow = cd['hosts_allow']
                else:
                    hosts_allow = None
                # print hosts_allow

                if 'hosts_deny_choice' in cd and cd[
                        'hosts_deny_choice'] == 'restricted':
                    if 'hosts_deny' not in cd or not cd['hosts_deny']:
                        raise Exception(
                            'Please enter a valid list of denied hosts')
                    hosts_deny = cd['hosts_deny']
                else:
                    hosts_deny = None
                # print hosts_deny

                guest_ok = True
                ret, err = cifs_common.create_share(name,
                                                    comment,
                                                    True,
                                                    read_only,
                                                    path,
                                                    path,
                                                    browseable,
                                                    None,
                                                    None,
                                                    "integralstor_novol",
                                                    hosts_allow=hosts_allow,
                                                    hosts_deny=hosts_deny)
                if err:
                    raise Exception(err)
                ret, err = cifs_integralstor.generate_smb_conf()
                if err:
                    raise Exception(err)

                audit_str = "Created Samba share %s" % name
                audit.audit("create_cifs_share", audit_str, request)
                return django.http.HttpResponseRedirect(
                    '/view_cifs_shares?ack=created')
            else:
예제 #7
0
def create_nfs_share(request):
    return_dict = {}
    try:
        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)

        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(
                        {'name': ds["name"], 'mountpoint': ds["mountpoint"]})
        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before creating shares.')

        req_ret, err = django_utils.get_request_parameter_values(
            request, ['dataset', 'path'])
        if err:
            raise Exception(err)

        if 'dataset' in req_ret:
            dataset = req_ret['dataset']
        else:
            dataset = ds_list[0]['mountpoint']
        if 'path' in req_ret:
            path = req_ret['path']
        else:
            path = dataset

        return_dict['path'] = path
        return_dict["dataset"] = ds_list

        if request.method == "GET":
            # Return the conf page
            initial = {}
            initial['path'] = path
            initial['dataset'] = dataset
            form = nfs_shares_forms.CreateShareForm(
                initial=initial, dataset_list=ds_list)
            return_dict['form'] = form
            return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = nfs_shares_forms.CreateShareForm(
                request.POST, dataset_list=ds_list)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
            cd = form.cleaned_data
            if 'new_folder' in cd and cd['new_folder']:
                try:
                    os.mkdir('%s/%s' % (cd['path'], cd['new_folder']))
                    audit_str = 'Created new directory "%s" in "%s"' % (
                        cd['new_folder'], cd['path'])
                    audit.audit("create_dir", audit_str, request)
                    cd['path'] = '%s/%s' % (cd['path'], cd['new_folder'])
                except Exception, e:
                    raise Exception('Error creating subfolder %s : %s' % (
                        cd['new_folder'], str(e)))
            result, err = nfs.save_share(cd, True)
            if err:
                raise Exception(err)

            audit_str = "Created NFS share %s" % cd['path']
            audit.audit("create_nfs_share", audit_str, request)
            return django.http.HttpResponseRedirect('/view_nfs_shares?ack=created')
    except Exception, e:
        return_dict['base_template'] = "shares_base.html"
        return_dict["page_title"] = 'Create a NFS share '
        return_dict['tab'] = 'view_nfs_shares_tab'
        return_dict["error"] = 'Error creating a NFS share'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_rsync_share(request):
    return_dict = {}
    try:
        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)

        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append({
                        'name': ds["name"],
                        'mountpoint': ds["mountpoint"]
                    })
        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before creating shares.'
            )

        if request.method == "GET":
            form = rsync_forms.CreateShareForm(dataset_list=ds_list)
            return_dict['form'] = form
            return django.shortcuts.render_to_response(
                "create_rsync_share.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            form = rsync_forms.CreateShareForm(request.POST,
                                               dataset_list=ds_list)
            path = request.POST.get("path")
            if not os.path.exists(path):
                os.mkdir(path)
            owner_dict, err = config.get_default_file_dir_owner()
            if err:
                raise Exception(err)
            owner_uid, err = config.get_system_uid_gid(owner_dict['user'],
                                                       'user')
            if err:
                raise Exception(err)
            owner_gid, err = config.get_system_uid_gid(owner_dict['group'],
                                                       'group')
            if err:
                raise Exception(err)

            os.chown(path, owner_uid, owner_gid)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response(
                    "create_rsync_share.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
            cd = form.cleaned_data
            result, err = rsync.create_rsync_share(
                cd["name"], cd["path"], cd["comment"], cd["browsable"],
                cd["readonly"], "integralstor", "integralstor")
            if err:
                raise Exception(err)
            audit_str = "Created RSYNC share with name '%s'. The share is set to be %s and %s" % (
                cd["name"],
                "Browsable" if cd["browsable"] else "Not Browsable",
                "Readonly" if cd["readonly"] else "Read/Write")
            audit.audit("create_rsync_share", audit_str, request)
            return django.http.HttpResponseRedirect(
                '/view_rsync_shares/?ack=created')
    except Exception, e:
        return_dict['base_template'] = "shares_base.html"
        return_dict["page_title"] = 'RSync shares'
        return_dict['tab'] = 'view_rsync_shares_tab'
        return_dict["error"] = 'Error creating RSync shares'
        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))
예제 #9
0
def view_dashboard(request, page):
    return_dict = {}
    try:
        return_dict["page_title"] = 'Overall system health'
        return_dict['tab'] = 'system_health_tab'
        return_dict["error"] = 'Error loading system health data'

        if request.method != 'GET':
            raise Exception('Invalid access method. Please use the menus')

        si, err = system_info.load_system_config()
        if err:
            raise Exception(err)
        if not si:
            raise Exception('Error loading system configuration')

        node_name = si.keys()[0]
        node = si[node_name]
        return_dict['node'] = node
        # print node.keys()

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

        # Chart specific declarations
        # will return 02, instead of 2.
        todays_date = (datetime.date.today()).strftime('%02d')
        start_hour = '%02d' % (datetime.datetime.today().hour - 3)
        end_hour = '%02d' % (datetime.datetime.today().hour)
        minute = '%02d' % (datetime.datetime.today().minute)
        start = str(start_hour) + ":" + str(minute) + str(":10")
        end = str(end_hour) + ":" + str(minute) + str(":40")

        value_list = []
        time_list = []

        num_bad_disks = 0
        num_hw_raid_bad_disks = 0
        num_hw_raid_ctrl_disks = 0
        num_smart_ctrl_disks = 0
        num_disks = len(node['disks'])
        disks_ok = True
        for sn, disk in node['disks'].items():
            if 'status' in disk:
                if 'hw_raid' in disk:
                    if not disk['hw_raid']:
                        num_smart_ctrl_disks += 1
                        if (disk['status'] is not None
                                and disk['status'].upper()
                                not in ['PASSED', 'OK']):
                            num_bad_disks += 1
                            disks_ok = False
                    else:
                        num_hw_raid_ctrl_disks += 1
                        if (disk['status'] is not None
                                and disk['status'].upper() != 'OK'):
                            num_hw_raid_bad_disks += 1
                            disks_ok = False
                else:
                    # Assume its a non raid disk
                    num_smart_ctrl_disks += 1
                    if (disk['status'] is not None and disk['status'].upper()
                            not in ['PASSED', 'OK']):
                        num_bad_disks += 1
                        disks_ok = False

        return_dict['num_disks'] = num_disks
        return_dict['num_bad_disks'] = num_bad_disks
        return_dict['disks_ok'] = disks_ok
        return_dict['num_hw_raid_bad_disks'] = num_hw_raid_bad_disks
        return_dict['num_hw_raid_ctrl_disks'] = num_hw_raid_ctrl_disks
        return_dict['num_smart_ctrl_disks'] = num_smart_ctrl_disks

        if 'ipmi_status' in node:
            num_sensors = len(node['ipmi_status'])
            num_bad_sensors = 0
            ipmi_ok = True
            for sensor in node['ipmi_status']:
                if sensor['status'] in ['ok', 'nr', 'na']:
                    continue
                else:
                    num_bad_sensors += 1
                    ipmi_ok = False
            return_dict['num_sensors'] = num_sensors
            return_dict['num_bad_sensors'] = num_bad_sensors
            return_dict['ipmi_ok'] = ipmi_ok

        services_dict, err = services_management.get_sysd_services_status()
        if err:
            raise Exception(err)

        num_services = len(services_dict)
        num_failed_services = 0
        num_active_services = 0
        num_inactive_services = 0
        services_ok = True

        if services_dict:
            for service, service_d in services_dict.items():
                if service_d["info"]["status"]["status_str"] == "Active":
                    num_active_services += 1
                elif service_d["info"]["status"]["status_str"] == "Inactive":
                    num_inactive_services += 1
                elif service_d["info"]["status"]["status_str"] == "Failed":
                    num_failed_services += 1
                    services_ok = False
                elif service_d["info"]["status"][
                        "status_str"] == "Unknown State":
                    num_failed_services += 1
                    services_ok = False
            return_dict['num_services'] = num_services
            return_dict['num_active_services'] = num_active_services
            return_dict['num_inactive_services'] = num_inactive_services
            return_dict['num_failed_services'] = num_failed_services
            return_dict['services_ok'] = services_ok
        else:
            raise Exception('Error retrieving services status')

        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)

        num_pools = len(pools)
        num_bad_pools = 0
        num_degraded_pools = 0
        num_high_usage_pools = 0
        for pool in pools:
            if pool['usage']['capacity']['value'] > 75:
                num_high_usage_pools += 1
            if pool['config']['pool']['root']['status']['state'] == 'ONLINE':
                pass
            elif pool['config']['pool']['root']['status'][
                    'state'] == 'DEGRADED':
                num_degraded_pools += 1
            else:
                num_bad_pools += 1
        return_dict['num_pools'] = num_pools
        return_dict['num_bad_pools'] = num_bad_pools
        return_dict['num_degraded_pools'] = num_degraded_pools
        return_dict['num_high_usage_pools'] = num_high_usage_pools

        load_avg_ok = True
        if (node["load_avg"]["5_min"] > node["load_avg"]["cpu_cores"]) or (
                node["load_avg"]["15_min"] > node["load_avg"]["cpu_cores"]):
            load_avg_ok = False
        return_dict['load_avg_ok'] = load_avg_ok

        shares_list, err = cifs_common.get_shares_list()
        if err:
            raise Exception(err)
        return_dict['num_cifs_shares'] = len(shares_list)

        exports_list, err = nfs.load_exports_list()
        if err:
            raise Exception(err)
        return_dict['num_nfs_exports'] = len(exports_list)

        target_list, err = iscsi_stgt.get_targets()
        if err:
            raise Exception(err)
        return_dict['num_iscsi_targets'] = len(target_list)

        with open('/proc/uptime', 'r') as f:
            uptime_seconds = float(f.readline().split()[0])
            uptime_str = '%s hours' % (':'.join(
                str(timedelta(seconds=uptime_seconds)).split(':')[:2]))
            return_dict['uptime_str'] = uptime_str

        # CPU status
        if page == "cpu":
            return_dict["page_title"] = 'CPU statistics'
            return_dict['tab'] = 'cpu_tab'
            return_dict["error"] = 'Error loading CPU statistics'
            cpu, err = stats.get_system_stats(todays_date, start, end, "cpu")
            if err:
                raise Exception(err)
            value_dict = {}
            if cpu:
                for key in cpu.keys():
                    value_list = []
                    time_list = []
                    if key == "date":
                        pass
                    else:
                        if cpu[key]:
                            for a in cpu[key]:
                                time_list.append(a[0])
                                value_list.append(a[1])
                        value_dict[key] = value_list
            return_dict["data_dict"] = value_dict
            queue, err = stats.get_system_stats(todays_date, start, end,
                                                "queue")
            if err:
                raise Exception(err)
            value_dict = {}
            if queue:
                for key in queue.keys():
                    value_list = []
                    time_list = []
                    if key == "date":
                        pass
                    else:
                        for a in queue[key]:
                            time_list.append(a[0])
                            value_list.append(a[1])
                        value_dict[key] = value_list
            return_dict["data_dict_queue"] = value_dict
            return_dict['node_name'] = node_name
            return_dict['node'] = si[node_name]
            d = {}
            template = "view_cpu_stats.html"
        elif page == "sys_health":
            return_dict["page_title"] = 'Overall system health'
            return_dict['tab'] = 'system_health_tab'
            return_dict["error"] = 'Error loading system health data'
            template = "view_dashboard.html"
            hw_platform, err = config.get_hardware_platform()
            if hw_platform:
                return_dict['hw_platform'] = hw_platform
                if hw_platform == 'dell':
                    from integralstor_utils.platforms import dell
                    idrac_url, err = dell.get_idrac_addr()
                    if idrac_url:
                        return_dict['idrac_url'] = idrac_url
        # Memory
        elif page == "memory":
            return_dict["page_title"] = 'Memory statistics'
            return_dict['tab'] = 'memory_tab'
            return_dict["error"] = 'Error loading memory statistics'
            mem, err = stats.get_system_stats(todays_date, start, end,
                                              "memory")
            if err:
                raise Exception(err)
            if mem:
                for a in mem["memused"]:
                    time_list.append(a[0])
                    value_list.append((a[1] / (1024 * 1024)))
            return_dict['memory_status'] = si[node_name]['memory']
            template = "view_memory_stats.html"
        # Network
        elif page == "network":
            return_dict["page_title"] = 'Network statistics'
            return_dict['tab'] = 'network_tab'
            return_dict["error"] = 'Error loading Network statistics'
            network, err = stats.get_system_stats(todays_date, start, end,
                                                  "network")
            if err:
                raise Exception(err)
            value_dict = {}
            if network:
                for key in network.keys():
                    value_list = []
                    time_list = []
                    if key == "date" or key == "lo":
                        pass
                    else:
                        for a in network[key]["ifutil-percent"]:
                            time_list.append(a[0])
                            value_list.append(a[1])
                        value_dict[key] = value_list

            return_dict["data_dict"] = value_dict
            return_dict["network_status"] = si[node_name]['interfaces']
            template = "view_network_stats.html"
        return_dict["labels"] = time_list
        return_dict["data"] = value_list
        return django.shortcuts.render_to_response(
            template,
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "dashboard_base.html"
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
def get_status():
    """Overall status info about the system combining all of the above into one big dict."""
    d = {}
    try:
        zfs_ver, err = get_zfs_version()
        if err:
            raise Exception(err)
        d["zfs_version"] = zfs_ver

        os_ver = '%s %s' % (platform.system(), platform.release())
        d["os_version"] = os_ver

        dis, err = get_disk_info_and_status()
        if err:
            raise Exception(err)
        d["disks"] = dis

        services_stat, err = get_services_status()
        if err:
            raise Exception(err)
        d["services"] = services_stat

        iface_status, err = get_interface_status()
        if err:
            raise Exception(err)
        d["interfaces"] = iface_status

        pl, err = zfs.get_pools()
        if err:
            raise Exception(err)
        d["pools"] = pl

        lavg, err = get_load_avg()
        if err:
            raise Exception(err)
        d["load_avg"] = lavg

        meminfo, err = get_mem_info()
        if err:
            raise Exception(err)
        d["memory"] = meminfo

        ipmi, err = get_ipmi_status()
        if ipmi:
            d["ipmi_status"] = ipmi

        cm, err = get_cpu_model()
        if err:
            raise Exception(err)
        d["cpu_model"] = cm

        fqdn = socket.getfqdn()
        d["fqdn"] = fqdn

        hardware_dict, err = get_hardware_specific_info()
        if err:
            raise Exception(err)
        d["hardware_specific_dict"] = hardware_dict

    except Exception, e:
        return None, 'Error retrieving system status: %s' % str(e)
예제 #11
0
def update_ftp_configuration(request):
    return_dict = {}
    try:
        config, err = vsftp.get_ftp_config()
        if err:
            raise Exception(err)
        pools, err = zfs.get_pools()
        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(ds["name"])
        cert_list, err = certificates.get_certificates()
        if err:
            raise Exception(err)
        cert_name_list = []
        for cert in cert_list:
            cert_name_list.append(cert['name'])
        # print ds_list
        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before configuring the FTP service.'
            )

        if request.method == 'GET':
            initial = {}
            if config:
                for key in config.keys():
                    initial[key] = config[key]
            form = ftp_management_forms.ConfigureFTPForm(
                datasets=ds_list, cert_names=cert_name_list, initial=initial)
            return_dict['form'] = form
            return django.shortcuts.render_to_response(
                'update_ftp_configuration.html',
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            form = ftp_management_forms.ConfigureFTPForm(
                request.POST, cert_names=cert_name_list, datasets=ds_list)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response(
                    "update_ftp_configuration.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
            cd = form.cleaned_data
            ret, err = vsftp.update_ftp_config(cd)
            if err:
                raise Exception(err)
            users, err = local_users.get_local_users()
            if err:
                raise Exception(err)
            ret, err = vsftp.create_ftp_user_dirs(cd['dataset'], users)
            if err:
                raise Exception(err)
            audit_str = 'Updated FTP configuration.'
            if cd['ssl_enabled']:
                audit_str = audit_str + \
                    ' SSL enabled with certificate %s' % cd['cert_name']
            else:
                audit_str = audit_str + ' SSL disabled.'
            ret, err = audit.audit("update_ftp_config", audit_str, request)
            return django.http.HttpResponseRedirect(
                '/view_ftp_configuration?ack=saved')
    except Exception, e:
        return_dict['base_template'] = "services_base.html"
        return_dict["page_title"] = 'Configure FTP service'
        return_dict['tab'] = 'ftp_service_settings'
        return_dict["error"] = 'Error configuring the FTP service '
        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 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)