Ejemplo n.º 1
0
def reload_manifest(request):
  return_dict = {}
  try:
    if request.method == "GET":
      from integralstor_unicell 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("reload_manifest.html", return_dict, context_instance=django.template.context.RequestContext(request))
    elif request.method == "POST":
      common_python_scripts_path, err = common.get_common_python_scripts_path()
      if err:
        raise Exception(err)
      ss_path, err = common.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"%(common.get_python_scripts_path(), common.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("/show/node_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))
def edit_hostname(request):
  return_dict = {}
  try:

    hostname = socket.gethostname()
    if request.method == "GET":
      hostname = socket.gethostname()
      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("edit_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("edit_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.set_hostname(cd['hostname'], domain_name)
      if not result:
        if err:
          raise Exception(err)
        else:
          raise Exception('Error setting hostname')
      result, err = networking.set_domain_name(domain_name)
      if not result:
        if err:
          raise Exception(err)
        else:
          raise Exception('Error setting domain name')
      python_scripts_path, err = common.get_python_scripts_path()
      if err:
        raise Exception(err)
      common_python_scripts_path, err = common.get_common_python_scripts_path()
      if err:
        raise Exception(err)
      ss_path, err = common.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))
      if err:
        raise Exception(err)

      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.META["REMOTE_ADDR"])
      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))
Ejemplo n.º 3
0
def edit_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(
                "edit_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(
                    "edit_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.set_hostname(cd['hostname'], domain_name)
            if not result:
                if err:
                    raise Exception(err)
                else:
                    raise Exception('Error setting hostname')
            result, err = networking.set_domain_name(domain_name)
            if not result:
                if err:
                    raise Exception(err)
                else:
                    raise Exception('Error setting domain name')
            python_scripts_path, err = common.get_python_scripts_path()
            if err:
                raise Exception(err)
            common_python_scripts_path, err = common.get_common_python_scripts_path(
            )
            if err:
                raise Exception(err)
            ss_path, err = common.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.META)
            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))
Ejemplo n.º 4
0
def remove_bond(request):

    return_dict = {}
    try:
        if 'name' not in request.REQUEST:
            raise Exception("No bond name specified. Please use the menus")

        name = request.REQUEST["name"]
        return_dict["name"] = name

        if request.method == "GET":
            #Return the conf page
            return django.shortcuts.render_to_response(
                "remove_bond_conf.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            result, err = networking.remove_bond(name)
            if not result:
                if not err:
                    raise Exception("Error removing bond")
                else:
                    raise Exception(err)

            python_scripts_path, err = common.get_python_scripts_path()
            if err:
                raise Exception(err)
            common_python_scripts_path, err = common.get_common_python_scripts_path(
            )
            if err:
                raise Exception(err)
            status_path, err = common.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.META)
            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))
Ejemplo n.º 5
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
        if_list = []
        existing_bonds = []
        for if_name, iface in interfaces.items():
            ret, err = networking.get_ip_info(if_name)
            if ret:
                continue
            if if_name.startswith('lo') or if_name in bid['by_slave']:
                continue
            if if_name in bm:
                existing_bonds.append(if_name)
                continue
            if_list.append(if_name)

        if request.method == "GET":
            form = networking_forms.CreateBondForm(
                interfaces=if_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=if_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 = common.get_python_scripts_path()
            if err:
                raise Exception(err)
            common_python_scripts_path, err = common.get_common_python_scripts_path(
            )
            if err:
                raise Exception(err)
            status_path, err = common.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.META)
            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))