예제 #1
0
    def create_dependencies(self, fw, state):
        state.eth_obj = None
        state.eth = testlib.get_available_interfaces(fw)[0]

        state.eth_obj = network.EthernetInterface(state.eth, 'layer3',
                                                  testlib.random_ip('/24'))
        fw.add(state.eth_obj)
        state.eth_obj.create()

        tag = random.randint(1, 4000)
        state.parent = network.Layer3Subinterface(
            '{0}.{1}'.format(state.eth, tag), tag, testlib.random_ip('/24'))
        state.eth_obj.add(state.parent)
        state.parent.create()
예제 #2
0
 def setup_state_obj(self, fw, state):
     tag = random.randint(1, 4000)
     name = '{0}.{1}'.format(state.eth, tag)
     state.obj = network.Layer3Subinterface(
         name,
         tag,
         testlib.random_ip('/24'),
         False,
         state.management_profile,
         random.randint(576, 1500),
         True,
         None,
         'This is my subeth',
         random.randint(40, 300),
         random.randint(60, 300),
     )
     state.parent.add(state.obj)
예제 #3
0
    obj = device.SystemSettings(hostname='example')
    _check(obj, vsys, with_pano)


@pytest.mark.parametrize('vsys', [None, 'vsys1', 'vsys3'])
@pytest.mark.parametrize('with_pano', [False, True])
def test_xpath_for_mgtconfig_root(vsys, with_pano):
    obj = device.Administrator('newadmin')
    _check(obj, vsys, with_pano)


@pytest.mark.parametrize('vsys', [None, 'vsys1', 'vsys3'])
@pytest.mark.parametrize('with_pano', [False, True])
@pytest.mark.parametrize('obj', [
    network.EthernetInterface('ethernet1/3', 'layer3'),
    network.Layer3Subinterface('ethernet1/4.42', 42),
    network.Layer2Subinterface('ethernet1/4.420', 420),
    network.VirtualRouter('someroute'),
    network.VirtualWire('tripwire'),
    network.Vlan('myvlan'),
])
def test_xpath_import(vsys, with_pano, obj):
    _check(obj, vsys, with_pano, True)


def test_vsys_xpath_unchanged():
    expected = "/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='vsys3']"
    c = firewall.Firewall('127.0.0.1', 'admin', 'admin')
    c.vsys = 'vsys3'

    assert expected == c.xpath_vsys()
예제 #4
0
파일: views.py 프로젝트: xod442/panix
def deploy():
    # Get the credentials from the user
    selected_fwip = request.form.get('firewall').encode('utf-8')
    interface = request.form.get('interface').encode('utf-8')
    router = request.form.get('router').encode('utf-8')

    if interface == 'none selected':
        error = "ERR2222-Go back you didn't select an interface"
        return render_template('main/gen_error.html', error=error)
    '''
    Handling HA

    # Don't assume either firewall is primary or active.
    # Just start by telling pandevice they are an HA pair
    # and how to connect to them.
    fw = Firewall('10.0.0.1', 'admin', 'password')
    fw.set_ha_peers(Firewall('10.0.0.2', 'admin', 'password'))
    fw.refresh_ha_active()
    # Now, verify the config is synced between the devices.
    # If it's not synced, force config synchronization from active to standby
    if not fw.config_synced():
        fw.synchronize_config()  # blocks until synced or error
    '''
    for i in Creds.objects:
        fwip = i.fwip.encode('utf-8')
        username = i.username.encode('utf-8')
        password = i.password.encode('utf-8')

        if fwip == None:
            error = 'ERR2222-No creds in the Creds DB. Log out and login again'
            return render_template('main/dberror.html')

    # First, let's create the firewall object that we want to modify.
    fw = firewall.Firewall(selected_fwip, username, password)
    # Get vsys
    vsys_list = device.Vsys.refreshall(fw, name_only=True)

    # This works...need to figure out a better way
    vsys = random.choice(vsys_list)

    # Let's make our base interface that we're going to make subinterfaces
    base = network.EthernetInterface(interface, "layer3")
    fw.add(base)
    base.create()
    # Now let's go ahead and make all of our subinterfaces.
    for i in Networks.objects:
        gateway = i.gateway.encode('utf-8')
        tag = i.tag.encode('utf-8')
        comment = i.comment.encode('utf-8')
        zone = i.zone.encode('utf-8')

        # Build subinterface
        name = "{0}.{1}".format(interface, tag)
        sub_intf = network.Layer3Subinterface(name, tag, gateway, comment)
        # Now add the subinterface to that randomly chosen vsys.
        vsys.add(sub_intf)
        vr = sub_intf.set_virtual_router(virtual_router_name=router)
        security_zone = sub_intf.set_zone(zone_name=zone)

    # Creat all subinterfaces at once
    sub_intf.create_similar()
    vsys.add(vr)
    vsys.add(security_zone)
    vr.create()
    security_zone.create()

    return render_template('main/deploy_success.html', fwip=selected_fwip)