Beispiel #1
0
def deploy_vm_system_view():
    error = None
    if request.method == 'GET':
        #        socketio.start_background_task(cct_swx, '/dev/ttyUSB0', 'sw1usbsignal', 'sw1portsignal')
        #        socketio.start_background_task(cct_swx, '/dev/ttyUSB1', 'sw2usbsignal', 'sw2portsignal')
        #        deploy_sw_1_baseconfig = get_deploy_device_last_build_log('deploy_sw_1_baseconfig')
        #        deploy_sw_1_baseconfig_job_info = get_deploy_device_get_job_info('deploy_sw_1_baseconfig')
        #        deploy_sw_1_portconfig = get_deploy_device_last_build_log('deploy_sw_1_portconfig')
        #        deploy_sw_1_portconfig_job_info = get_deploy_device_get_job_info('deploy_sw_1_portconfig')
        #        deploy_sw_1_singleport = get_deploy_device_last_build_log('deploy_sw_1_singleport')
        #        deploy_sw_1_singleport_job_info = get_deploy_device_get_job_info('deploy_sw_1_singleport')
        return render_template(
            'deploy-vm-system.html',
            deploy_vm_systems=System_vm_profiles.query.all(),
            salt_pxe_nodes=Saltstack_pxe_nodes.query.all())
    elif request.method == 'POST':
        if 'deploy_vm_system' in request.form:
            if not request.form['id']:
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                deploy_vm_system = request.form.getlist('id')
                for deploy in deploy_vm_system:
                    reboot_vm_system = Saltstack_pxe_nodes.query.filter_by(
                        pxemac=deploy).one()
                    reboot_vm_system_ip = reboot_vm_system.pxeipaddr
                    reboot_vm_system_send_cmd = local.cmd(
                        reboot_vm_system_ip, 'cmd.run', ['shutdown -r now'])
                    #		    reboot_vm_system.pxeinstalled = True
                    db.session.delete(reboot_vm_system)
                    db.session.commit()
                    wheel.cmd_async({
                        'fun': 'key.delete',
                        'match': reboot_vm_system_ip
                    })
                return "<div class='alert alert-success' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>System Rebooted for PXE Installation.</div>"
        else:
            flash('Malformed form submitted !', 'danger')
            return redirect(request.url)
Beispiel #2
0
def switches_view():
    error = None
    if request.method == 'GET':
        file_switch1 = open("output/customer-sw-1-baseconfig.deploy", "r")
        lines_switch1 = file_switch1.readlines()
        file_switch2 = open("output/customer-sw-2-baseconfig.deploy", "r")
        lines_switch2 = file_switch2.readlines()
        return render_template('switches.html',
                               sws=Switches.query.all(),
                               vlans=Vlans.query.all(),
                               customer_sws=Customer_sw.query.all(),
                               lines_switch1=lines_switch1,
                               lines_switch2=lines_switch2)
    elif request.method == 'POST':
        if 'sw_add' in request.form:
            if not request.form['sw_hostname'] or not request.form[
                    'sw_ipaddress'] or not request.form[
                        'sw_subnet'] or not request.form[
                            'sw_gateway'] or not request.form[
                                'sw_mgmtvlan'] or not request.form[
                                    'sw_portnr'] or not request.form[
                                        'sw_porttype']:
                return "<div class='alert alert-danger' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>ERROR</div>"
            else:
                sw = Switches(
                    request.form['sw_hostname'], request.form['sw_ipaddress'],
                    request.form['sw_subnet'], request.form['sw_gateway'],
                    request.form['sw_mgmtvlan'], request.form['sw_portnr'],
                    request.form['sw_porttype'])
                db.session.add(sw)
                db.session.commit()
                #		sw_hostname = request.form['sw_hostname']
                #		sw = Switches.query.filter_by(hostname=sw_hostname).one()
                customer_sw_id = request.form['sw_customer_sw_map']
                if customer_sw_id == 'None':
                    pass
                else:
                    sw_hostname = request.form['sw_hostname']
                    sw = Switches.query.filter_by(hostname=sw_hostname).one()
                    customer_sw = Customer_sw.query.filter_by(
                        id=customer_sw_id).one()
                    customer_sw.customerswbackref = sw
                    db.session.add(customer_sw)
                    db.session.commit()
                return "<div class='alert alert-success' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Switch Added</div>"
        elif 'sw_edit' in request.form:
            if not request.form['sw_hostname'] or not request.form[
                    'sw_ipaddress'] or not request.form[
                        'sw_subnet'] or not request.form[
                            'sw_gateway'] or not request.form[
                                'sw_mgmtvlan'] or not request.form[
                                    'sw_portnr'] or not request.form[
                                        'sw_porttype']:
                return "<div class='alert alert-danger' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>ERROR</div>"
            else:
                sw_id = request.form.get('id')
                sw = Switches.query.filter_by(id=sw_id).one()
                sw.hostname = request.form['sw_hostname']
                sw.ipaddress = request.form['sw_ipaddress']
                sw.subnet = request.form['sw_subnet']
                sw.gateway = request.form['sw_gateway']
                sw.mgmtvlan = request.form['sw_mgmtvlan']
                sw.portnr = request.form['sw_portnr']
                sw.porttype = request.form['sw_porttype']
                #                db.session.add(sw)
                #                db.session.commit()
                customer_sw_id = request.form['sw_customer_sw_map']
                if customer_sw_id == 'None':
                    sw.customer_sw = ''
                    db.session.add(sw)
                    db.session.commit()
                else:
                    customer_sw = Customer_sw.query.filter_by(
                        id=customer_sw_id).one()
                    customer_sw.customerswbackref = sw
                    db.session.add(sw)
                    db.session.add(customer_sw)
                    db.session.commit()
                return "<div class='alert alert-success' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Switch Edited</div>"
        elif 'sw_delete' in request.form:
            if not request.form['sw_delete']:
                return "<div class='alert alert-danger' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>ERROR</div>"
            else:
                sw_id = request.form.getlist('id')
                for u in sw_id:
                    sw = Switches.query.filter_by(id=u).one()
                    db.session.delete(sw)
                    db.session.commit()
                return "<div class='alert alert-success' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Switch Deleted</div>"
        elif 'base_config_switch1_generate' in request.form:
            if not request.form[
                    'base_config_switch1_generate'] or not request.form[
                        'switch1_profile']:
                flash('Please fill all fields before sending a request !',
                      'danger')
                return redirect(request.url)
            else:
                switch1_profile = request.form.get('switch1_profile')
                switch1 = Switches.query.filter_by(id=switch1_profile).one()
                template_file = 'switch_templates/customer-sw-1-base-config.j2'
                template_output = "output/customer-sw-1-baseconfig.deploy"
                env = Environment(loader=FileSystemLoader(TEMPLATE_CONFIG))
                template = env.get_template(template_file)
                generate_template = template.render(
                    customer_sw_1=switch1.hostname,
                    customer_sw_1_mgmt_ipadress=switch1.ipaddress,
                    customer_sw_1_mgmt_subnet=switch1.subnet,
                    customer_sw_1_mgmt_gateway=switch1.gateway,
                    mgmt_vlan_id=switch1.mgmtvlan)
                with open(template_output, "wb") as f:
                    f.write(generate_template)
                flash('Template generated successfully !', 'success')
                return redirect(request.url)
        elif 'base_config_switch2_generate' in request.form:
            if not request.form[
                    'base_config_switch2_generate'] or not request.form[
                        'switch2_profile']:
                flash('Please fill all fields before sending a request !',
                      'danger')
                return redirect(request.url)
            else:
                switch2_profile = request.form.get('switch2_profile')
                switch2 = Switches.query.filter_by(id=switch2_profile).one()
                template_file = 'switch_templates/customer-sw-2-base-config.j2'
                template_output = "output/customer-sw-2-baseconfig.deploy"
                env = Environment(loader=FileSystemLoader(TEMPLATE_CONFIG))
                template = env.get_template(template_file)
                generate_template = template.render(
                    customer_sw_2=switch2.hostname,
                    customer_sw_2_mgmt_ipadress=switch2.ipaddress,
                    customer_sw_2_mgmt_subnet=switch2.subnet,
                    customer_sw_2_mgmt_gateway=switch2.gateway,
                    mgmt_vlan_id=switch2.mgmtvlan)
                with open(template_output, "wb") as f:
                    f.write(generate_template)
                flash('Template generated successfully !', 'success')
                return redirect(request.url)
    return render_template('switches.html')
Beispiel #3
0
def system_phy_profiles_view():
    error = None
    if request.method == 'GET':
        napalm_switch1_macs = napalm_switch_mac_audit(1)
        list_of_profiles = cobbler_server.profiles()
        systems = cobbler_server.systems()
        return render_template('system-phy-profiles.html',
                               napalm_switch1_macs=napalm_switch1_macs,
                               list_of_profiles=list_of_profiles,
                               systems=systems,
                               servers=Servers.query.all(),
                               esxis=Esxis.query.all(),
                               salt_pxe_nodes=Saltstack_pxe_nodes.query.all())
    elif request.method == 'POST':
        if 'system_profiles_save' in request.form:
            if not request.form['system_name'] or not request.form[
                    'system_switch_port_mac'] or not request.form[
                        'system_salt_pxe_node'] or not request.form[
                            'system_profile']:
                flash('Please fill all fields before sending a request !',
                      'danger')
                return redirect(request.url)
            else:
                if re.sub(r"^.*=", "", request.form['system_switch_port_mac']
                          ).lower() != request.form['system_salt_pxe_node']:
                    flash(
                        'Switch Port MAC does not match PXE booted SALT agent !',
                        'danger')
                    return redirect(request.url)
                else:
                    system_name = request.form['system_name']
                    find_esxi = Esxis.query.filter_by(
                        hostname=system_name).first()
                    find_server = Servers.query.filter_by(
                        hostname=system_name).first()
                    if str(find_esxi) == str(system_name):
                        find_host = find_esxi
                        intname = "vmnic0"
                    elif str(find_server) == str(system_name):
                        find_host = find_server
                        intname = "ens192"
                    else:
                        find_host = 'NOT FOUND'
#		    request.form['system_switch_port_mac']
                    system_switch_port_mac = re.sub(
                        r"^.*=", "",
                        request.form['system_switch_port_mac']).lower()
                    system_salt_pxe_node = request.form['system_salt_pxe_node']
                    system_profile = request.form['system_profile']
                    #                   intname = "vmnic0"
                    system = cobbler_server.new_system()
                    system.name = system_name
                    system.profile = system_profile
                    system.set_hostname(find_host.hostname)
                    system.set_name_servers("8.8.8.8")
                    system.set_static(True, intname)
                    system.set_mac_address(system_switch_port_mac, intname)
                    system.set_ip_address(find_host.ipaddress, intname)
                    system.set_netmask(find_host.subnet, intname)
                    system.set_if_gateway(find_host.gateway, intname)
                    system.set_gateway(find_host.gateway)
                    cobbler_server.systems().add(system, with_copy=True)
                    cobbler_server.add_system(system, save=True)
                    os.system("service cobblerd restart")
                    time.sleep(2)
                    system_phy_profile_check = System_phy_profiles.query.filter_by(
                        name=system_name).first()
                    if str(system_phy_profile_check) == str(system_name):
                        salt_pxe_node = Saltstack_pxe_nodes.query.filter_by(
                            pxemac=system_salt_pxe_node).one()
                        salt_pxe_node.pxeinstalled = False
                        db.session.add(salt_pxe_node)
                        #                        db.session.commit()
                        system_phy_profile = System_phy_profiles.query.filter_by(
                            mac=system_switch_port_mac).one()
                        salt_pxe_node = Saltstack_pxe_nodes.query.filter_by(
                            pxemac=system_salt_pxe_node).one()
                        salt_pxe_node.saltvmbackref = system_phy_profile
                        db.session.commit()
                        flash(
                            'This System already exist. System OS updated and System Network Enabled !',
                            'success')
                        return redirect(request.url)
                    else:
                        system_phy_profiles = System_phy_profiles(
                            system_name, system_salt_pxe_node)
                        db.session.add(system_phy_profiles)
                        system_phy_profile = System_phy_profiles.query.filter_by(
                            mac=system_switch_port_mac).one()
                        salt_pxe_node = Saltstack_pxe_nodes.query.filter_by(
                            pxemac=system_salt_pxe_node).one()
                        salt_pxe_node.saltvmbackref = system_phy_profile
                        #                    db.session.add(system_vm_profile)
                        db.session.add(salt_pxe_node)
                        db.session.commit()
                        flash('System Profile ' + system_name + ' Saved',
                              'success')
                        return redirect(request.url)

#                    system_phy_profiles = System_phy_profiles(system_name, system_salt_pxe_node)
#                    db.session.add(system_phy_profiles)
#                    db.session.commit()
#                    flash('System PHY Profile ' + system_name + ' Saved','success')
#                    return redirect(request.url)
        if 'system_phy_edit' in request.form:
            if not request.form['id'] or not request.form[
                    'system_profile'] or not request.form[
                        'system_netboot_enabled']:
                flash('Please fill all fields before sending a request !',
                      'danger')
                return redirect(request.url)
            else:
                system_name = request.form.get('id')
                system_profile = request.form['system_profile']
                system_netboot_enabled = request.form['system_netboot_enabled']
                system = cobbler_server.find_system(system_name)
                system.name = system_name
                system.profile = system_profile
                system.netboot_enabled = system_netboot_enabled
                cobbler_server.systems().add(system, with_copy=True)
                cobbler_server.add_system(system, save=True)
                os.system("service cobblerd restart")
                time.sleep(2)
                return "<div class='alert alert-success' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Cobbler System Edited</div>"
        if 'system_phy_delete' in request.form:
            if not request.form['system_phy_delete']:
                return "<div class='alert alert-danger' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Form Error</div>"
            else:
                system_name = request.form.getlist('id')
                for system in system_name:
                    system_phy_profiles = System_phy_profiles.query.filter_by(
                        name=system).first()
                    system_vm_profiles = System_vm_profiles.query.filter_by(
                        name=system).first()
                    if str(system_phy_profiles) == str(system):
                        cobbler_server.remove_system(system)
                        system_vm_profiles = System_phy_profiles.query.filter_by(
                            name=system).first()
                        db.session.delete(system_phy_profiles)
                        db.session.commit()
                    elif str(system_vm_profiles) == str(system):
                        cobbler_server.remove_system(system)
                        system_vm_profiles = System_vm_profiles.query.filter_by(
                            name=system).first()
                        db.session.delete(system_vm_profiles)
                        db.session.commit()
                    else:
                        return "<div class='alert alert-danger' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Cobbler System ERROR</div>"
                os.system("service cobblerd restart")
                return "<div class='alert alert-success' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Cobbler System Deleted</div>"
        else:
            flash('Malformed form submitted !', 'danger')
            return redirect(request.url)
Beispiel #4
0
def design_switch2_24_port_view():
    error = None
    if request.method == 'GET':
        file = open("output/customer-sw-2-24-portconfig.deploy", "r")
        lines = file.readlines()
        return render_template('design-sw2-24.html', customer_sws=Customer_sw.query.all(), sws=Switches.query.all(), fws=Firewalls.query.all(), esxis=Esxis.query.all(), servers=Servers.query.all(), dedicatedsans=Dedicatedsan.query.all(), vlans=Vlans.query.all(), switch2_24_ports=Switch2_24_port.query.all(), lines=lines)
    elif request.method == 'POST':
        if 'port_config_switch2_24_port_save' in request.form:
            if not request.form['id'] or not request.form['port_device'] or not request.form['port_device_port'] or not request.form['port_mode'] or not request.form['port_vlan'] or not request.form['port_pxe_boot']:
                flash('Please fill all fields before sending a request !','danger')
                return redirect(request.url)
            else:
                if request.form['port_mode'] == 'None' and request.form['port_vlan'] == 'None':
                    port_id = request.form.get('id')
                    port = Switch2_24_port.query.filter_by(id=port_id).one()
                    port.devicename=request.form['port_device']
                    port.deviceport=request.form['port_device_port']
                    port.vlan_id = ''
                    port.portmode = 'None'
                    port.portvlan = 'None'
                    port.portpxeboot=(strtobool(request.form['port_pxe_boot']))
                    db.session.add(port)
                    db.session.commit()
                    flash('Port ' + port_id + ' Saved','success')
                    return redirect(request.url)
                if request.form['port_mode'] == 'trunk':
                    if request.form['port_vlan'] == 'trunk':
                        port_id = request.form.get('id')
                        port = Switch2_24_port.query.filter_by(id=port_id).one()
                        port.devicename=request.form['port_device']
                        port.deviceport=request.form['port_device_port']
                        port.portmode=request.form['port_mode']
                        port.portvlan = 'trunk'
                        port.portpxeboot=(strtobool(request.form['port_pxe_boot']))
                        db.session.add(port)
                        db.session.commit()
                        flash('Port ' + port_id + ' Saved','success')
                        return redirect(request.url)
                    if request.form['port_vlan'] == 'None':
                        flash('Trunk port cannot be "None" !','danger')
                        return redirect(request.url)
                    else:
                        flash('Trunk port cannot be "access" !','danger')
                        return redirect(request.url)
                elif request.form['port_mode'] == 'access':
                    if request.form['port_vlan'] == 'None' or request.form['port_vlan'] == '' or request.form['port_vlan'] == 'trunk':
                        flash('Access port cannot be "trunk" or "None" !','danger')
                        return redirect(request.url)
                    else:
                        port_id = request.form.get('id')
                        port = Switch2_24_port.query.filter_by(id=port_id).one()
                        port.devicename=request.form['port_device']
                        port.deviceport=request.form['port_device_port']
                        port.portmode=request.form['port_mode']
                        vlan_id =request.form['port_vlan']
                        vlan = Vlans.query.filter_by(id=vlan_id).one()
                        port.sw224vlansbackref = vlan
                        port.portvlan = request.form['port_vlan']
                        port.portpxeboot=(strtobool(request.form['port_pxe_boot']))
                        db.session.add(port)
                        db.session.commit()
                        flash('Port ' + port_id + ' Saved','success')
                        return redirect(request.url)
                else:
                    flash('Please fill all form fields! MODE and VLAN must be "None" to default interface.','danger')
                    return redirect(request.url)
        if 'port_config_switch2_24_port_generate' in request.form:
            if not request.form['port_config_switch2_24_port_generate'] or not request.form['switch2_24_port_version']:
                flash('Please fill all fields before sending a request !','danger')
                return redirect(request.url)
            else:
                customer_sw2 = Customer_sw.query.filter_by(id=2).one()
                if customer_sw2.customerswbackref.portnr == '8' or customer_sw2.customerswbackref.portnr == '48':
                    flash('Your switch has ' + customer_sw2.customerswbackref.portnr + ' ports and does match the template !','danger')
                    return redirect(request.url)
		else:
                    switch2_24_port_version = request.form.get('switch2_24_port_version')
                    vlans = Vlans.query.all()
                    ports = Switch2_24_port.query.all()
                    if switch2_24_port_version == 'sw-24-Fa':
                        template_file = 'switch_templates/customer-sw-2-24-Fa-port-config.j2'
                        template_output = "output/customer-sw-2-24-portconfig.deploy"
                    elif switch2_24_port_version == 'sw-24-Gi':
                        template_file = 'switch_templates/customer-sw-2-24-Gi-port-config.j2'
                        template_output = "output/customer-sw-2-24-portconfig.deploy"
                    env = Environment(loader=FileSystemLoader(TEMPLATE_CONFIG))
                    template = env.get_template(template_file)
                    generate_template = template.render(customer='HEXTRIM', ports=ports, vlans=vlans)
                    with open(template_output, "wb") as f:
                        f.write(generate_template)
                    flash('Template generated successfully !','success')
                    return redirect(request.url)
        else:
            flash('Malformed form submitted !','danger')
            return redirect(request.url)
Beispiel #5
0
def deploy_switch_view():
    error = None
    if request.method == 'GET':
        socketio.start_background_task(cct_swx, '/dev/ttyUSB0', 'sw1usbsignal',
                                       'sw1portsignal')
        socketio.start_background_task(cct_swx, '/dev/ttyUSB1', 'sw2usbsignal',
                                       'sw2portsignal')
        deploy_sw_1_baseconfig = get_deploy_device_last_build_log(
            'deploy_sw_1_baseconfig')
        deploy_sw_1_baseconfig_job_info = get_deploy_device_get_job_info(
            'deploy_sw_1_baseconfig')
        deploy_sw_1_portconfig = get_deploy_device_last_build_log(
            'deploy_sw_1_portconfig')
        deploy_sw_1_portconfig_job_info = get_deploy_device_get_job_info(
            'deploy_sw_1_portconfig')
        deploy_sw_1_singleport = get_deploy_device_last_build_log(
            'deploy_sw_1_singleport')
        deploy_sw_1_singleport_job_info = get_deploy_device_get_job_info(
            'deploy_sw_1_singleport')
        return render_template(
            'deploy-switch.html',
            deploy_sw_1_baseconfig=deploy_sw_1_baseconfig,
            deploy_sw_1_baseconfig_job_info=deploy_sw_1_baseconfig_job_info,
            deploy_sw_1_portconfig=deploy_sw_1_portconfig,
            deploy_sw_1_portconfig_job_info=deploy_sw_1_portconfig_job_info,
            deploy_sw_1_singleport=deploy_sw_1_singleport,
            deploy_sw_1_singleport_job_info=deploy_sw_1_singleport_job_info,
            sws=Switches.query.all(),
            customer_sws=Customer_sw.query.all())
    elif request.method == 'POST':
        if 'deploy_switch1_config_deploy' in request.form:
            if not request.form['deploy_switch1_device'] or not request.form[
                    'deploy_switch1_config']:
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                sw1_device = request.form['deploy_switch1_device']
                sw1_config = request.form['deploy_switch1_config']
                sw1 = Switches.query.filter_by(id=sw1_device).one()
                if sw1_config == 'baseconfig':
                    srvjobs = srvjenkins.get_jobs()
                    config_xml = "output/deploy-sw-1-baseconfig.xml"
                    with codecs.open(config_xml, 'r', encoding='utf8') as f:
                        config_xml_file = f.read()
                    match = any(s['name'] == 'deploy_sw_1_baseconfig'
                                for s in srvjobs)
                    if match == True:
                        srvjenkins.reconfig_job('deploy_sw_1_baseconfig',
                                                config_xml_file)
                    else:
                        srvjenkins.create_job('deploy_sw_1_baseconfig',
                                              config_xml_file)
                    srvjenkins.build_job('deploy_sw_1_baseconfig')
                    flash(
                        'Deploy BASECONFIG task has been submitted and started.',
                        'success')
                    return redirect(request.url)
                elif sw1_config == 'portconfig' and sw1.portnr == '24':
                    srvjobs = srvjenkins.get_jobs()
                    config_xml = "output/deploy-sw-1-24-portconfig.xml"
                    with codecs.open(config_xml, 'r', encoding='utf8') as f:
                        config_xml_file = f.read()
                    match = any(s['name'] == 'deploy_sw_1_portconfig'
                                for s in srvjobs)
                    if match == True:
                        srvjenkins.reconfig_job('deploy_sw_1_portconfig',
                                                config_xml_file)
                    else:
                        srvjenkins.create_job('deploy_sw_1_portconfig',
                                              config_xml_file)
                    srvjenkins.build_job('deploy_sw_1_portconfig')
                    flash(
                        'Deploy PORTCONFIG task for 24 port switch has been submitted and started.',
                        'success')
                    return redirect(request.url)
                elif sw1_config == 'portconfig' and sw1.portnr == '48':
                    srvjobs = srvjenkins.get_jobs()
                    config_xml = "output/deploy-sw-1-48-portconfig.xml"
                    with codecs.open(config_xml, 'r', encoding='utf8') as f:
                        config_xml_file = f.read()
                    match = any(s['name'] == 'deploy_sw_1_portconfig'
                                for s in srvjobs)
                    if match == True:
                        srvjenkins.reconfig_job('deploy_sw_1_portconfig',
                                                config_xml_file)
                    else:
                        srvjenkins.create_job('deploy_sw_1_portconfig',
                                              config_xml_file)
                    srvjenkins.build_job('deploy_sw_1_portconfig')
                    flash(
                        'Deploy PORTCONFIG task for 48 port switch has been submitted and started.',
                        'success')
                    return redirect(request.url)
                elif int(sw1_config) in range(1, 48):
                    if sw1.portnr == '24' and sw1.porttype == 'Fa':
                        port = Switch1_24_port.query.filter_by(
                            id=sw1_config).one()
                        template_file = 'switch_templates/customer-sw-1-24-Fa-singleport-config.j2'
                        template_output = "output/customer-sw-1-singleport.deploy"
                        env = Environment(
                            loader=FileSystemLoader(TEMPLATE_CONFIG))
                        template = env.get_template(template_file)
                        generate_template = template.render(port=port)
                        with open(template_output, "wb") as f:
                            f.write(generate_template)
                        srvjobs = srvjenkins.get_jobs()
                        config_xml = "output/deploy-sw-1-singleport.xml"
                        with codecs.open(config_xml, 'r',
                                         encoding='utf8') as f:
                            config_xml_file = f.read()
                        match = any(s['name'] == 'deploy_sw_1_singleport'
                                    for s in srvjobs)
                        if match == True:
                            srvjenkins.reconfig_job('deploy_sw_1_singleport',
                                                    config_xml_file)
                        else:
                            srvjenkins.create_job('deploy_sw_1_singleport',
                                                  config_xml_file)
                        srvjenkins.build_job('deploy_sw_1_singleport')
                        flash(
                            'Deploy SINGLEPORT P' + sw1_config +
                            ' task has been submitted and started.', 'success')
                        return redirect(request.url)
                    elif sw1.portnr == '24' and sw1.porttype == 'Gi':
                        port = Switch1_24_port.query.filter_by(
                            id=sw1_config).one()
                        template_file = 'switch_templates/customer-sw-1-24-Gi-singleport-config.j2'
                        template_output = "output/customer-sw-1-singleport.deploy"
                        env = Environment(
                            loader=FileSystemLoader(TEMPLATE_CONFIG))
                        template = env.get_template(template_file)
                        generate_template = template.render(port=port)
                        with open(template_output, "wb") as f:
                            f.write(generate_template)
                        srvjobs = srvjenkins.get_jobs()
                        config_xml = "output/deploy-sw-1-singleport.xml"
                        with codecs.open(config_xml, 'r',
                                         encoding='utf8') as f:
                            config_xml_file = f.read()
                        match = any(s['name'] == 'deploy_sw_1_singleport'
                                    for s in srvjobs)
                        if match == True:
                            srvjenkins.reconfig_job('deploy_sw_1_singleport',
                                                    config_xml_file)
                        else:
                            srvjenkins.create_job('deploy_sw_1_singleport',
                                                  config_xml_file)
                        srvjenkins.build_job('deploy_sw_1_singleport')
                        flash(
                            'Deploy SINGLEPORT P' + sw1_config +
                            ' task has been submitted and started.', 'success')
                        return redirect(request.url)
                    elif sw1.portnr == '48' and sw1.porttype == 'Fa':
                        port = Switch1_48_port.query.filter_by(
                            id=sw1_config).one()
                    elif sw1.portnr == '48' and sw1.porttype == 'Gi':
                        port = Switch1_48_port.query.filter_by(
                            id=sw1_config).one()

                    flash(
                        'Deploy SINGLEPORT P' + sw1_config +
                        ' task has been submitted and started.', 'success')
                    return redirect(request.url)
                else:
                    flash('Oops something went wrong !', 'danger')
                    return redirect(request.url)

        elif 'deploy_switch2_config_deploy' in request.form:
            if not request.form['deploy_switch2_device'] or not request.form[
                    'deploy_switch2_config']:
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                sw2_device = request.form['deploy_switch2_device']
                sw2_config = request.form['deploy_switch2_config']
                sw2 = Switches.query.filter_by(id=sw2_device).one()
                if sw2_config == 'baseconfig':
                    srvjobs = srvjenkins.get_jobs()
                    config_xml = "output/deploy-sw-2-baseconfig.xml"
                    with codecs.open(config_xml, 'r', encoding='utf8') as f:
                        config_xml_file = f.read()
                    match = any(s['name'] == 'deploy_sw_2_baseconfig'
                                for s in srvjobs)
                    if match == True:
                        srvjenkins.reconfig_job('deploy_sw_2_baseconfig',
                                                config_xml_file)
                    else:
                        srvjenkins.create_job('deploy_sw_2_baseconfig',
                                              config_xml_file)
                    srvjenkins.build_job('deploy_sw_2_baseconfig')
                    flash(
                        'Deploy BASECONFIG task has been submitted and started.',
                        'success')
                    return redirect(request.url)
                elif sw2_config == 'portconfig' and sw2.portnr == '24':
                    srvjobs = srvjenkins.get_jobs()
                    config_xml = "output/deploy-sw-2-24-portconfig.xml"
                    with codecs.open(config_xml, 'r', encoding='utf8') as f:
                        config_xml_file = f.read()
                    match = any(s['name'] == 'deploy_sw_2_portconfig'
                                for s in srvjobs)
                    if match == True:
                        srvjenkins.reconfig_job('deploy_sw_2_portconfig',
                                                config_xml_file)
                    else:
                        srvjenkins.create_job('deploy_sw_2_portconfig',
                                              config_xml_file)
                    srvjenkins.build_job('deploy_sw_2_portconfig')
                    flash(
                        'Deploy PORTCONFIG task for 24 port switch has been submitted and started.',
                        'success')
                    return redirect(request.url)
                elif sw2_config == 'portconfig' and sw2.portnr == '48':
                    srvjobs = srvjenkins.get_jobs()
                    config_xml = "output/deploy-sw-2-48-portconfig.xml"
                    with codecs.open(config_xml, 'r', encoding='utf8') as f:
                        config_xml_file = f.read()
                    match = any(s['name'] == 'deploy_sw_2_portconfig'
                                for s in srvjobs)
                    if match == True:
                        srvjenkins.reconfig_job('deploy_sw_2_portconfig',
                                                config_xml_file)
                    else:
                        srvjenkins.create_job('deploy_sw_2_portconfig',
                                              config_xml_file)
                    srvjenkins.build_job('deploy_sw_2_portconfig')
                    flash(
                        'Deploy PORTCONFIG task for 48 port switch has been submitted and started.',
                        'success')
                    return redirect(request.url)
                elif int(sw2_config) in range(1, 48):
                    if sw2.portnr == '24' and sw2.porttype == 'Fa':
                        port = Switch2_24_port.query.filter_by(
                            id=sw2_config).one()
                        template_file = 'switch_templates/customer-sw-2-24-Fa-singleport-config.j2'
                        template_output = "output/customer-sw-2-singleport.deploy"
                        env = Environment(
                            loader=FileSystemLoader(TEMPLATE_CONFIG))
                        template = env.get_template(template_file)
                        generate_template = template.render(port=port)
                        with open(template_output, "wb") as f:
                            f.write(generate_template)
                        srvjobs = srvjenkins.get_jobs()
                        config_xml = "output/deploy-sw-2-singleport.xml"
                        with codecs.open(config_xml, 'r',
                                         encoding='utf8') as f:
                            config_xml_file = f.read()
                        match = any(s['name'] == 'deploy_sw_2_singleport'
                                    for s in srvjobs)
                        if match == True:
                            srvjenkins.reconfig_job('deploy_sw_2_singleport',
                                                    config_xml_file)
                        else:
                            srvjenkins.create_job('deploy_sw_2_singleport',
                                                  config_xml_file)
                        srvjenkins.build_job('deploy_sw_2_singleport')
                        flash(
                            'Deploy SINGLEPORT P' + sw2_config +
                            ' task has been submitted and started.', 'success')
                        return redirect(request.url)
                    elif sw2.portnr == '24' and sw2.porttype == 'Gi':
                        port = Switch2_24_port.query.filter_by(
                            id=sw2_config).one()
                        template_file = 'switch_templates/customer-sw-2-24-Gi-singleport-config.j2'
                        template_output = "output/customer-sw-2-singleport.deploy"
                        env = Environment(
                            loader=FileSystemLoader(TEMPLATE_CONFIG))
                        template = env.get_template(template_file)
                        generate_template = template.render(port=port)
                        with open(template_output, "wb") as f:
                            f.write(generate_template)
                        srvjobs = srvjenkins.get_jobs()
                        config_xml = "output/deploy-sw-2-singleport.xml"
                        with codecs.open(config_xml, 'r',
                                         encoding='utf8') as f:
                            config_xml_file = f.read()
                        match = any(s['name'] == 'deploy_sw_2_singleport'
                                    for s in srvjobs)
                        if match == True:
                            srvjenkins.reconfig_job('deploy_sw_2_singleport',
                                                    config_xml_file)
                        else:
                            srvjenkins.create_job('deploy_sw_2_singleport',
                                                  config_xml_file)
                        srvjenkins.build_job('deploy_sw_2_singleport')
                        flash(
                            'Deploy SINGLEPORT P' + sw2_config +
                            ' task has been submitted and started.', 'success')
                        return redirect(request.url)
                    elif sw2.portnr == '48' and sw2.porttype == 'Fa':
                        port = Switch2_48_port.query.filter_by(
                            id=sw2_config).one()
                    elif sw2.portnr == '48' and sw2.porttype == 'Gi':
                        port = Switch2_48_port.query.filter_by(
                            id=sw2_config).one()

                    flash(
                        'Deploy SINGLEPORT P' + sw2_config +
                        ' task has been submitted and started.', 'success')
                    return redirect(request.url)
                else:
                    flash('Oops something went wrong !', 'danger')
                    return redirect(request.url)

    return render_template('deploy-switch.html')
Beispiel #6
0
def system_profiles_view():
    error = None
    if request.method == 'GET':
	napalm_switch1_macs = napalm_switch_mac_audit(1)
        list_of_profiles = cobbler_server.profiles()
        systems = cobbler_server.systems()
        return render_template('system-profiles.html', napalm_switch1_macs=napalm_switch1_macs, list_of_profiles=list_of_profiles, systems=systems, servers=Servers.query.all(), esxis=Esxis.query.all(), virtualmachines=VirtualMachines.query.all(), salt_pxe_nodes=Saltstack_pxe_nodes.query.all())
    elif request.method == 'POST':
        if 'system_profiles_save' in request.form:
            if not request.form['system_name'] or not request.form['system_switch_port_mac'] or not request.form['system_salt_pxe_node'] or not request.form['system_profile']:
                flash('Please fill all fields before sending a request !','danger')
                return redirect(request.url)
            else:
                if re.sub(r"^.*=","", request.form['system_switch_port_mac']).lower() != request.form['system_salt_pxe_node']:
                    flash('Switch Port MAC does not match PXE booted SALT agent !','danger')
                    return redirect(request.url)
                else:
		    system_name = request.form['system_name']
                    find_esxi = Esxis.query.filter_by(hostname=system_name).first()
		    find_server = Servers.query.filter_by(hostname=system_name).first()
                    find_vm = VirtualMachines.query.filter_by(hostname=system_name).first()
		    if str(find_esxi) == str(system_name):
                        find_host = find_esxi
			intname = "vmnic0"
		    elif str(find_server) == str(system_name):
		        find_host = find_server
                        intname = "ens192"
		    elif str(find_vm) == str(system_name):
		        find_host = find_vm
                        intname = "ens160"
		    else:
			find_host = 'NOT FOUND'
#		    request.form['system_switch_port_mac']
		    system_switch_port_mac = re.sub(r"^.*=","", request.form['system_switch_port_mac']).lower()
		    system_salt_pxe_node = request.form['system_salt_pxe_node']
		    system_profile = request.form['system_profile']
#                   intname = "vmnic0"
                    system = cobbler_server.new_system()
                    system.name = system_name
	 	    system.profile = system_profile
                    system.set_hostname(find_host.hostname)
		    system.set_name_servers("8.8.8.8")
		    system.set_static(True, intname)
		    system.set_mac_address(system_switch_port_mac, intname)
		    system.set_ip_address(find_host.ipaddress, intname)
		    system.set_netmask(find_host.subnet, intname)
		    system.set_if_gateway(find_host.gateway, intname)
                    system.set_gateway(find_host.gateway)
		    cobbler_server.systems().add(system,with_copy=True)
                    cobbler_server.add_system(system, save=True)
		    os.system("service cobblerd restart") 
                    flash('System Profile ' + system_name + ' Saved','success')
                    return redirect(request.url)
        if 'cobbler_system_delete' in request.form:
            if not request.form['cobbler_system_delete']:
                return "<div class='alert alert-danger' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Form Error</div>"
            else:
                system_name = request.form.get('id')
	        print system_name
#                system_name = request.form['system_name']
                cobbler_server.remove_system(system_name)
                os.system("service cobblerd restart")
                return "<div class='alert alert-success' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Cobbler System Deleted</div>"
#                flash('Template generated successfully !','success')
#                return redirect(request.url)
        else:
            flash('Malformed form submitted !','danger')
            return redirect(request.url)
Beispiel #7
0
def cobbler_view():
    error = None
    if request.method == 'GET':
        file_dhcp = open("/etc/cobbler/dhcp.template", "r")
        lines_dhcp = file_dhcp.readlines()
        lines_dhcp = lines_dhcp[20:25]
        file_pxe = open("/etc/cobbler/pxe/pxedefault.template", "r")
        lines_pxe = file_pxe.readlines()
        list_of_distros = cobbler_server.get_distros()
        list_of_profiles = cobbler_server.get_profiles()
        return render_template('cobbler.html',
                               lines_dhcp=lines_dhcp,
                               lines_pxe=lines_pxe,
                               list_of_distros=list_of_distros,
                               list_of_profiles=list_of_profiles,
                               isos=Isos.query.all())
    elif request.method == 'POST':
        if 'cobbler_change_dhcp_subnet_save' in request.form:
            if not request.form['cobbler_dhcp_subnet'] or request.form[
                    'cobbler_dhcp_subnet'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                cobbler_dhcp_subnet = request.form['cobbler_dhcp_subnet']
                #               cobbler_config_file = fileinput.FileInput("/etc/cobbler/dhcp.template", inplace=True)
                #                cobbler_dhcp_subnet_string = "subnet " + cobbler_dhcp_subnet + " "
                #                for line in cobbler_config_file:
                #                    line = re.sub(r"(subnet)+\s+\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}[^0-9]", cobbler_dhcp_subnet_string, line.rstrip())
                #                   print(line)
                # print(line) is required as without it, the whole file may go truncated - replaces with blank input - removed
                cobbler_config_replace("subnet", cobbler_dhcp_subnet)
                flash('Your Cobbler DHCP Subnet has been changed.', 'success')
                return redirect(request.url)
        elif 'cobbler_change_dhcp_subnet_mask_save' in request.form:
            if not request.form['cobbler_dhcp_subnet_mask'] or request.form[
                    'cobbler_dhcp_subnet_mask'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                cobbler_dhcp_subnet_mask = request.form[
                    'cobbler_dhcp_subnet_mask']
                cobbler_config_replace("netmask", cobbler_dhcp_subnet_mask)
                cobbler_config_replace("subnet-mask",
                                       cobbler_dhcp_subnet_mask + ";")
                flash(
                    'Your Cobbler DHCP Subnet Mask details have been changed.',
                    'success')
                return redirect(request.url)
        elif 'cobbler_change_router_save' in request.form:
            if not request.form['cobbler_router'] or request.form[
                    'cobbler_router'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                cobbler_router = request.form['cobbler_router']
                cobbler_config_replace("routers", cobbler_router + ";")
                flash('Your Cobbler Router details have been changed.',
                      'success')
                return redirect(request.url)
        elif 'cobbler_change_dhcp_dns_server_save' in request.form:
            if not request.form['cobbler_dhcp_dns_server'] or request.form[
                    'cobbler_dhcp_dns_server'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                cobbler_dhcp_dns_server = request.form[
                    'cobbler_dhcp_dns_server']
                cobbler_config_replace("domain-name-servers",
                                       cobbler_dhcp_dns_server + ";")
                flash(
                    'Your Cobbler DHCP DNS Server details have been changed.',
                    'success')
                return redirect(request.url)
        elif 'cobbler_change_dhcp_deployment_range_save' in request.form:
            if not request.form[
                    'cobbler_dhcp_deployment_range'] or request.form[
                        'cobbler_dhcp_deployment_range'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                cobbler_dhcp_deployment_range = request.form[
                    'cobbler_dhcp_deployment_range']
                cobbler_config_file = fileinput.FileInput(
                    "/etc/cobbler/dhcp.template", inplace=True)
                cobbler_dhcp_deployment_range_string = "dynamic-bootp " + cobbler_dhcp_deployment_range + ";"
                for line in cobbler_config_file:
                    line = re.sub(
                        r"\b(dynamic-bootp)+\s+\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}[^0-9]+\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}[^0-9]",
                        cobbler_dhcp_deployment_range_string, line.rstrip())
                    print(line)
                flash(
                    'Your Cobbler DHCP Deployment Range details have been changed.',
                    'success')
                return redirect(request.url)
        elif 'cobbler_change_pxe_default_boot_save' in request.form:
            if not request.form['cobbler_pxe_default_boot'] or request.form[
                    'cobbler_pxe_default_boot'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                cobbler_pxe_default_boot = request.form[
                    'cobbler_pxe_default_boot']
                cobbler_pxe_file = fileinput.FileInput(
                    "/etc/cobbler/pxe/pxedefault.template", inplace=True)
                cobbler_pxe_default_boot_string = "ONTIMEOUT " + cobbler_pxe_default_boot
                for line in cobbler_pxe_file:
                    line = re.sub(r"^.*\b(ONTIMEOUT).*",
                                  cobbler_pxe_default_boot_string,
                                  line.rstrip())
                    print(line)
                cobbler_server.sync(token)
                flash(
                    'Your Cobbler PXE Default Boot details have been changed.',
                    'success')
                return redirect(request.url)
        elif 'cobbleriso_import' in request.form:
            if not request.form['cobbleriso_import']:
                return "<div class='alert alert-danger' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Form Error</div>"
            else:
                iso_id = request.form.get('id')
                iso = Isos.query.filter_by(id=iso_id).one()
                iso_file_path = iso.filepath
                iso_mount_path = os.path.join(app.config['BASE_DIR'],
                                              iso_file_path)
                os.system("/usr/bin/mkdir /mnt/iso")
                os.system("/usr/bin/mount -o rw,loop %s /mnt/iso" %
                          iso_mount_path)
                iso_mount_dir = "/mnt/iso"
                iso_arch = "x86_64"
                iso_full_filename = iso.filename
                iso_name = iso_full_filename.rsplit('.', 1)
                cobbler_server.background_import(
                    {
                        "path": iso_mount_dir,
                        "arch": iso_arch,
                        "name": iso_name[0]
                    }, token)
                (year, month, day, hour, minute, second, weekday, julian,
                 dst) = time.localtime()
                iso_import_date = "%04d-%02d-%02d_%02d%02d" % (
                    year, month, day, hour, minute)
                iso.import_eventid = iso_import_date
                cobbler_task_status, cobbler_task_name = cobbler_import(
                    iso_import_date)
                cobbler_os_name = cobbler_os_name_find(cobbler_task_name)
                #               cobbler_import(iso_import_date)
                os.system("/usr/bin/umount /mnt/iso")
                #               if cobbler_import(iso_import_date) == 'complete':
                if cobbler_task_status == 'complete':
                    cobbler_server.sync(token)
                    iso.cobbler_status = 'imported'
                    iso.cobbler_name = cobbler_os_name
                    db.session.add(iso)
                    db.session.commit()
                    return "<div class='alert alert-success' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>ISO Import Succeeded</div>"
                elif cobbler_import(iso_import_date) == 'failed':
                    cobbler_server.sync(token)
                    iso.cobbler_status = 'failed'
                    db.session.add(iso)
                    db.session.commit()
                    return "<div class='alert alert-danger' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>ISO Import Failed</div>"
        elif 'cobblerdistro_delete' in request.form:
            if not request.form['cobblerdistro_delete']:
                return "<div class='alert alert-danger' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Form Error</div>"
            else:
                cobblerdistro_name = request.form.get('id')
                iso = Isos.query.filter_by(
                    cobbler_name=cobblerdistro_name).first()
                cobblerdistro_delete = cobbler_server.remove_distro(
                    cobblerdistro_name, token)
                cobbler_server.sync(token)
                iso.cobbler_status = 'removed'
                db.session.add(iso)
                db.session.commit()
                return "<div class='alert alert-success' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Cobbler Distro Deleted</div>"
        elif 'cobblerprofile_delete' in request.form:
            if not request.form['cobblerprofile_delete']:
                return "<div class='alert alert-danger' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Form Error</div>"
            else:
                cobblerprofile_name = request.form.get('id')
                iso = Isos.query.filter_by(
                    cobbler_name=cobblerprofile_name).first()
                cobblerprofile_delete = cobbler_server.remove_profile(
                    cobblerprofile_name, token)
                cobbler_server.sync(token)
                iso.cobbler_status = 'removed'
                db.session.add(iso)
                db.session.commit()
                return "<div class='alert alert-success' role='alert'><a href='#' class='close' data-dismiss='alert'>&times;</a>Cobbler Profile Deleted</div>"
    return render_template('cobbler.html')
Beispiel #8
0
def design_fw1_view():
    error = None
    if request.method == 'GET':
        file = open("output/customer-sw-1-24-portconfig.deploy", "r")
        lines = file.readlines()
#        return render_template('design-fw1.html', fws=Firewalls.query.all(), vlans=Vlans.query.all())
        return render_template('design-fw1.html', subnets=Subnets.query.all(), pochanns=Port_channels_fw1.query.all(), pos=Firewall1_interfaces.query.filter(Firewall1_interfaces.group).all(), fw_interfaces=Firewall1_interfaces.query.all(), customer_sws=Customer_sw.query.all(), vlans=Vlans.query.all(), lines=lines)
    elif request.method == 'POST':
        if 'design_fw1_port_channel_save' in request.form:
            if not request.form['design_fw1_port_channel_mode'] or not request.form.getlist['design_fw1_port_channel_interfaces']:
                flash('Please fill all fields before sending a request !','danger')
                return redirect(request.url)
            else:
                flash('Saved','success')
                return redirect(request.url)
        if 'design_fw1_port_channel_interfaces_delete' in request.form:
            if not request.form['design_fw1_port_channel_interfaces_id']:
                flash('Please fill all fields before sending a request !','danger')
                return redirect(request.url)
	    else:
                flash('Template generated successfully !','success')
                return redirect(request.url)
        if 'design_fw1_configure_interface_save' in request.form:
            if not request.form['design_fw1_configure_interface_id'] or not request.form['design_fw1_configure_interface_mode']:
                flash('Please fill all fields before sending a request !','danger')
                return redirect(request.url)
            else:
                flash('Template generated successfully !','success')
                return redirect(request.url)
        if 'design_fw1_configure_interface_delete' in request.form:
            if not request.form['design_fw1_configure_interface_id']:
                flash('Please fill all fields before sending a request !','danger')
                return redirect(request.url)
            else:
                flash('Template generated successfully !','success')
                return redirect(request.url)
        if 'design_fw1_configure_phy_interface_save' in request.form:
            if not request.form['design_fw1_configure_phy_interface_id'] or not request.form['design_fw1_configure_phy_interface_name'] or not request.form['design_fw1_configure_phy_interface_seclvl'] or not request.form['design_fw1_configure_phy_interface_subnet'] or not request.form['design_fw1_configure_phy_interface_enabled']:
                flash('Please fill all fields before sending a request !','danger')
                return redirect(request.url)
            else:
                flash('Template generated successfully !','success')
                return redirect(request.url)
        if 'design_fw1_configure_phy_interface_delete' in request.form:
            if not request.form['design_fw1_configure_phy_interface_id']:
                flash('Please fill all fields before sending a request !','danger')
                return redirect(request.url)
            else:
                flash('Template generated successfully !','success')
                return redirect(request.url)
        if 'design_fw1_configure_sub_interface_save' in request.form:
            if not request.form['design_fw1_configure_sub_interface_id'] or not request.form['design_fw1_configure_sub_interface_vlan'] or not request.form['design_fw1_configure_sub_interface_name'] or not request.form['design_fw1_configure_sub_interface_sec_lvl'] or not request.form['design_fw1_configure_sub_interface_subnet'] or not request.form['design_fw1_configure_sub_interface_enabled']:
                flash('Please fill all fields before sending a request !','danger')
                return redirect(request.url)
            else:
                flash('Template generated successfully !','success')
                return redirect(request.url)
        if 'design_fw1_configure_sub_interface_delete' in request.form:
            if not request.form['design_fw1_configure_sub_interface_id']:
                flash('Please fill all fields before sending a request !','danger')
                return redirect(request.url)
            else:
                flash('Template generated successfully !','success')
                return redirect(request.url)
        else:
            flash('Malformed form submitted !','danger')
            return redirect(request.url)
Beispiel #9
0
def profile_view():
    error = None
    if request.method == 'GET':
        page = request.args.get('page')
        return render_template('profile.html', page=page)
    elif request.method == 'POST':
        # check if the post request has the file part
        if 'profile_change_pic' in request.form:
            if 'file' not in request.files:
                flash(
                    'Please make sure you are submitting a file part request!',
                    'warning')
                return redirect(request.url)
            file = request.files['file']
            # if user does not select file, browser also
            # submit a empty part without filename
            if file.filename == '':
                flash('Please select a file for upload!', 'warning')
                return redirect(request.url)
            if file and allowed_file(file.filename):
                filename = secure_filename(file.filename)
                profile_pic = file.save(
                    os.path.join(app.config['UPLOAD_CONFIG'], filename))
                user_pic = User.query.filter_by(
                    email=current_user.email).first()
                user_pic.profile_pic = os.path.join(
                    app.config['PROFILE_PICS_DIR'], filename)
                db.session.add(user_pic)
                db.session.commit()
                return redirect(request.url)
        elif 'profile_change_username' in request.form:
            if not request.form['profile_change_username']:
                flash('Please fill all the fields before sending a request!',
                      'danger')
            else:
                user = User.query.filter_by(email=current_user.email).first()
                user.username = request.form['profile_username']
                db.session.add(user)
                db.session.commit()
                flash('Your username details have been changed.', 'success')
        elif 'profile_change_email' in request.form:
            if not request.form['profile_change_email'] or request.form[
                    'profile_email'] == '':
                flash('Email address field cannot be empty for this request!',
                      'danger')
            else:
                user = User.query.filter_by(email=current_user.email).first()
                user.email = request.form['profile_email']
                db.session.add(user)
                db.session.commit()
                flash('Your email details have been changed.', 'success')
        elif 'profile_change_password' in request.form:
            if not request.form['profile_old_password'] or not request.form[
                    'profile_new_password'] or not request.form[
                        'profile_new_password_repeat']:
                flash('Please fill all the fields before sending a request!',
                      'danger')
            else:
                if request.form['profile_new_password'] != request.form[
                        'profile_new_password_repeat']:
                    flash('Please ensure you type the new password correctly!',
                          'danger')
                else:
                    user = User.query.filter_by(
                        email=current_user.email).first()
                    profile_old_password = request.form['profile_old_password']
                    profile_old_password_hash = user.password
                    profile_password_verify = verify_password(
                        profile_old_password, profile_old_password_hash)
                    if profile_password_verify != True:
                        flash(
                            'Please provide your old password for this request!',
                            'danger')
                    else:
                        user.password = request.form['profile_new_password']
                        db.session.add(user)
                        db.session.commit()
                        flash('Your password has been changed.', 'success')
    page = request.args.get('page')
    return render_template('profile.html', page=page)
Beispiel #10
0
def saltstack_view():
    error = None
    if request.method == 'GET':
        salt_svc_check = salt_service_check()
        salt_keys_acc = salt_keys_accepted()
        salt_keys_unacc = salt_keys_unaccepted()
        salt_keys_den = salt_keys_denied()
        salt_keys_rej = salt_keys_rejected()
        return render_template('saltstack.html',
                               pxe_nodes=Saltstack_pxe_nodes.query.all(),
                               salt_svc_check=salt_svc_check,
                               salt_keys_acc=salt_keys_acc,
                               salt_keys_unacc=salt_keys_unacc,
                               salt_keys_den=salt_keys_den,
                               salt_keys_rej=salt_keys_rej)
    elif request.method == 'POST':
        if 'salt_keys_denied_delete' in request.form:
            if not request.form['salt_keys_denied_delete'] or request.form[
                    'key_ip'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                key_ip = request.form['key_ip']
                wheel.cmd_async({'fun': 'key.delete', 'match': key_ip})
                pxe_node = Saltstack_pxe_nodes.query.filter_by(
                    pxeipaddr=key_ip).first()
                if str(key_ip) == str(pxe_node):
                    db.session.delete(pxe_node)
                    db.session.commit()
                flash('Requested key ' + key_ip + ' has been removed!',
                      'success')
                return redirect(request.url)
        elif 'salt_keys_rejected_delete' in request.form:
            if not request.form['salt_keys_rejected_delete'] or request.form[
                    'key_ip'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                key_ip = request.form['key_ip']
                wheel.cmd_async({'fun': 'key.delete', 'match': key_ip})
                pxe_node = Saltstack_pxe_nodes.query.filter_by(
                    pxeipaddr=key_ip).first()
                if str(key_ip) == str(pxe_node):
                    db.session.delete(pxe_node)
                    db.session.commit()
                flash('Requested key ' + key_ip + ' has been removed!',
                      'success')
                return redirect(request.url)
        elif 'salt_keys_unaccepted_accept' in request.form:
            if not request.form['salt_keys_unaccepted_accept'] or request.form[
                    'key_ip'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                key_ip = request.form['key_ip']
                wheel.cmd('key.accept', [key_ip])
                flash('Requested key ' + key_ip + ' has been accepted!',
                      'success')
                return redirect(request.url)
        elif 'salt_keys_unaccepted_delete' in request.form:
            if not request.form['salt_keys_unaccepted_delete'] or request.form[
                    'key_ip'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                key_ip = request.form['key_ip']
                wheel.cmd_async({'fun': 'key.delete', 'match': key_ip})
                pxe_node = Saltstack_pxe_nodes.query.filter_by(
                    pxeipaddr=key_ip).first()
                if str(key_ip) == str(pxe_node):
                    db.session.delete(pxe_node)
                    db.session.commit()
                flash('Requested key ' + key_ip + ' has been removed!',
                      'success')
                return redirect(request.url)
        elif 'salt_keys_accepted_delete' in request.form:
            if not request.form['salt_keys_accepted_delete'] or request.form[
                    'key_ip'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                key_ip = request.form['key_ip']
                wheel.cmd_async({'fun': 'key.delete', 'match': key_ip})
                pxe_node = Saltstack_pxe_nodes.query.filter_by(
                    pxeipaddr=key_ip).first()
                if str(key_ip) == str(pxe_node):
                    db.session.delete(pxe_node)
                    db.session.commit()
                flash('Requested key ' + key_ip + ' has been removed!',
                      'success')
                return redirect(request.url)
        elif 'salt_keys_audit_save' in request.form:
            if not request.form['salt_keys_audit_save'] or request.form[
                    'key_ip'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                key_ip = request.form['key_ip']
                pxe_node_check = Saltstack_pxe_nodes.query.filter_by(
                    pxeipaddr=key_ip).first()
                if str(key_ip) == str(pxe_node_check):
                    flash(
                        'Candidate ' + key_ip + ' has already been audited !',
                        'danger')
                    return redirect(request.url)
                else:
                    pxe_int_name = local.cmd(key_ip, 'network.ifacestartswith',
                                             [key_ip])
                    pxe_mac_addr = local.cmd(key_ip, 'network.hwaddr',
                                             [pxe_int_name[key_ip][0]])
                    pxe_node = Saltstack_pxe_nodes(key_ip,
                                                   pxe_int_name[key_ip][0],
                                                   pxe_mac_addr[key_ip])
                    db.session.add(pxe_node)
                    db.session.commit()
                    #		print pxe_int_name[key_ip][0], pxe_mac_addr[key_ip]
                    flash(
                        'Requested key ' + key_ip +
                        ' has been audited! INT: ' + pxe_int_name[key_ip][0] +
                        ' MAC: ' + pxe_mac_addr[key_ip] + ' ', 'success')
                    return redirect(request.url)
        else:
            flash('Malformed form submitted !', 'danger')
            return redirect(request.url)
Beispiel #11
0
def livecd_view():
    error = None
    if request.method == 'GET':
        file = open("output/hextrimos.cfg", "r")
        lines = file.readlines()
        build_hextrimos_iso = get_deploy_device_last_build_log(
            'build_hextrimos_iso')
        build_hextrimos_iso_info = get_deploy_device_get_job_info(
            'build_hextrimos_iso')
        convert_hextrimos_to_pxeboot = get_deploy_device_last_build_log(
            'convert_hextrimos_to_pxeboot')
        convert_hextrimos_to_pxeboot_info = get_deploy_device_get_job_info(
            'convert_hextrimos_to_pxeboot')
        return render_template(
            'livecd.html',
            lines=lines,
            build_hextrimos_iso=build_hextrimos_iso,
            build_hextrimos_iso_info=build_hextrimos_iso_info,
            convert_hextrimos_to_pxeboot=convert_hextrimos_to_pxeboot,
            convert_hextrimos_to_pxeboot_info=convert_hextrimos_to_pxeboot_info
        )
    elif request.method == 'POST':
        if 'livecd_salt_master_ip_save' in request.form:
            if not request.form['livecd_salt_master_ip'] or request.form[
                    'livecd_salt_master_ip'] == '':
                flash('Please fill all the fields before sending a request!',
                      'danger')
                return redirect(request.url)
            else:
                salt_master_ip = request.form['livecd_salt_master_ip']
                template_file = 'hextrimos.j2'
                template_output = "output/hextrimos.cfg"
                env = Environment(
                    loader=FileSystemLoader(TEMPLATE_CONFIG_SALTSTACK))
                template = env.get_template(template_file)
                generate_template = template.render(
                    salt_master_ip=salt_master_ip)
                with open(template_output, "wb") as f:
                    f.write(generate_template)
                flash('HextrimOS configration file has been updated.',
                      'success')
                return redirect(request.url)
        elif 'build_hextrimos_iso_build' in request.form:
            if not request.form['build_hextrimos_iso_build']:
                flash('Incorrect request received!', 'danger')
                return redirect(request.url)
            else:
                #                srvjenkins = jenkins.Jenkins('http://localhost:8080', username='******', password='******')
                srvjobs = srvjenkins.get_jobs()
                config_xml = "output/build-hextrimos-iso.xml"
                with codecs.open(config_xml, 'r', encoding='utf8') as f:
                    config_xml_file = f.read()
                match = any(s['name'] == 'build_hextrimos_iso'
                            for s in srvjobs)
                if match == True:
                    srvjenkins.reconfig_job('build_hextrimos_iso',
                                            config_xml_file)
                else:
                    srvjenkins.create_job('build_hextrimos_iso',
                                          config_xml_file)
                srvjenkins.build_job('build_hextrimos_iso')
                flash('Build HextrimOS ISO: Build request received!',
                      'success')
                return redirect(request.url)
        elif 'convert_hextrimos_to_pxeboot_convert' in request.form:
            if not request.form['convert_hextrimos_to_pxeboot_convert']:
                flash('Incorrect request received!', 'danger')
                return redirect(request.url)
            else:
                #                srvjenkins = jenkins.Jenkins('http://localhost:8080', username='******', password='******')
                srvjobs = srvjenkins.get_jobs()
                config_xml = "output/convert-hextrimos-to-pxeboot.xml"
                with codecs.open(config_xml, 'r', encoding='utf8') as f:
                    config_xml_file = f.read()
                match = any(s['name'] == 'convert_hextrimos_to_pxeboot'
                            for s in srvjobs)
                if match == True:
                    srvjenkins.reconfig_job('convert_hextrimos_to_pxeboot',
                                            config_xml_file)
                else:
                    srvjenkins.create_job('convert_hextrimos_to_pxeboot',
                                          config_xml_file)
                srvjenkins.build_job('convert_hextrimos_to_pxeboot')
                flash('Convert HextrimOS To PXEboot: Build request received!',
                      'success')
                return redirect(request.url)
    return render_template('livecd.html')