Ejemplo n.º 1
0
def view_interfaces(request):
    return_dict = {}
    try:
        template = 'logged_in_error.html'
        nics, err = networking.get_interfaces()
        if err:
            raise Exception(err)
        bonds, err = networking.get_bonding_info_all()
        if err:
            raise Exception(err)

        if "ack" in request.GET:
            if request.GET["ack"] == "reset":
                return_dict[
                    'ack_message'] = "Successfully reset the address configuration of the network interface"
            if request.GET["ack"] == "saved":
                return_dict[
                    'ack_message'] = "Network interface information successfully updated"
            if request.GET["ack"] == "removed_bond":
                return_dict[
                    'ack_message'] = "Network bond successfully removed"
            if request.GET["ack"] == "removed_vlan":
                return_dict['ack_message'] = "VLAN successfully removed"
            if request.GET["ack"] == "created_vlan":
                return_dict['ack_message'] = "VLAN successfully created"
            if request.GET["ack"] == "state_down":
                return_dict[
                    'ack_message'] = "Network interface successfully disabled. The state change may take a couple of seconds to reflect on this page so please refresh it to check the updated status."
            if request.GET["ack"] == "state_up":
                return_dict[
                    'ack_message'] = "Network interface successfully enabled. The state change may take a couple of seconds to reflect on this page so please refresh it to check the updated status."
            if request.GET["ack"] == "created_bond":
                return_dict[
                    'ack_message'] = "Network bond successfully created. Please edit the address information for the bond in order to use it."
        return_dict["nics"] = nics
        return_dict["bonds"] = bonds
        template = "view_interfaces.html"
        return django.shortcuts.render_to_response(
            template,
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "networking_base.html"
        return_dict["page_title"] = 'View network interfaces'
        return_dict['tab'] = 'view_interfaces_tab'
        return_dict["error"] = 'Error loading interfaces'
        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.º 2
0
def create_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 '\n\nIntegralSTOR NIC Bonding'
        print '---------------------------------\n\n'
        print 'Available interfaces: \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.startswith('lo') or if_name in bm or if_name in bid['by_slave']:
                continue
            print '\t- %s' % if_name
            avail_if.append(if_name)
        print "\n"

        bond_name = None
        is_name = False
        while is_name is False:
            bond_name = raw_input('Provide bond name: ')
            if bond_name in interfaces or bond_name.startswith('lo'):
                print "\t- Can't assign %s, it's been taken already. Please provide another one.\n" % bond_name
            else:
                is_name = True

        print "\n"
        slaves = []
        is_ok = False
        while is_ok is False:
            s = raw_input(
                "\nEnter slaves from the shown interface list, separated by comma. - ").split(",")
            slaves = [inner.strip() for inner in s]
            for slave in slaves:
                if slave not in avail_if:
                    break

            else:
                is_ok = True
                print ("\nSelecetd slaves: %s") % slaves
                confirm = raw_input("\t- Confirm selected slaves (y/n)? ")
                if confirm.lower() in ["n"]:
                    is_ok = False

        print "\n"
        is_ok = False
        while is_ok is False:
            mode = raw_input(
                "Available modes [4]802.3ad, [6]balance-alb] - 4 or 6?: ")
            if mode in ["4", "6"]:
                is_ok = True

        ret, err = networking.create_bond(bond_name, slaves, int(mode))
        if not ret:
            if err:
                raise Exception('Error creating bond: %s' % err)
            else:
                raise Exception("Couldn't create bond")
        if ret:
            print "\nBond created! Configure IP to activate.\n"

    except Exception, e:
        print "Error: %s" % e
        return -1
Ejemplo n.º 3
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)
        python_scripts_path, err = config.get_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" % (python_scripts_path, status_path))
        if err:
            raise Exception(err)
        ret, err = command.get_command_output(
            "python %s/generate_status.py %s" % (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
Ejemplo n.º 4
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)
            python_scripts_path, err = config.get_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" %
                (python_scripts_path, status_path))
            if err:
                raise Exception(err)

            ret, err = command.get_command_output(
                "python %s/generate_status.py %s" %
                (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))