Ejemplo n.º 1
0
Archivo: create.py Proyecto: emjemj/ni
def new_switch(request, **kwargs):
    if request.POST:
        form = forms.NewSwitchForm(request.POST)
        if form.is_valid():
            try:
                nh = helpers.form_to_unique_node_handle(
                    request, form, 'switch', 'Physical')
            except UniqueNodeError:
                form = forms.NewSwitchForm(request.POST)
                form.add_error('name',
                               'A Switch with that name already exists.')
                return render(request, 'noclook/create/create_switch.html',
                              {'form': form})
            helpers.form_update_node(request.user, nh.handle_id, form)
            node = nh.get_node()
            if form.cleaned_data['relationship_provider']:
                provider_nh = NodeHandle.objects.get(
                    pk=form.cleaned_data['relationship_provider'])
                helpers.set_provider(request.user, node, provider_nh.handle_id)
            if form.cleaned_data['switch_type']:
                switch_type = SwitchType.objects.get(
                    pk=form.cleaned_data['switch_type'])
                helpers.dict_update_node(request.user, nh.handle_id,
                                         {"model": switch_type.name})
                if switch_type.ports:
                    for port in switch_type.ports.split(","):
                        helpers.create_port(node, port.strip(), request.user)

            return redirect(nh.get_absolute_url())
    else:
        name = kwargs.get('name', None)
        initial = {'name': name}
        form = forms.NewSwitchForm(initial=initial)
    return render(request, 'noclook/create/create_switch.html', {'form': form})
Ejemplo n.º 2
0
    def two_nodes(self, slug, num_ports, start_port=1):
        panel1 = self.create_node('node1', slug)
        panel_node1 = panel1.get_node()

        panel2 = self.create_node('node2', slug)
        panel_node2 = panel2.get_node()

        for i in range(start_port, start_port + num_ports):
            helpers.create_port(panel_node1, str(i), self.user)
            helpers.create_port(panel_node2, str(i), self.user)

        return panel1, panel2
Ejemplo n.º 3
0
    def test_decommissioned_equipment(self):
        self.skipTest('Not working as expected yet.')
        # Setup test data
        site = helpers.create_unique_node_handle(self.user, "Test site",
                                                 "site", "Location")
        site_node = site.get_node()
        rack = helpers.get_generic_node_handle(self.user, "A.01", "rack",
                                               "Location")
        helpers.set_has(self.user, site_node, rack.handle_id)
        odf = helpers.create_unique_node_handle(self.user, "NI-TEST-ODF-01",
                                                "odf", "Physical")
        odf_node = odf.get_node()
        helpers.dict_update_node(self.user, odf.handle_id, {"max_ports": 24})
        helpers.set_location(self.user, odf_node, rack.handle_id)

        decom_on = helpers.create_unique_node_handle(self.user,
                                                     "NI-TEST-ON-01",
                                                     "optical-node",
                                                     "Physical")
        decom_on_node = decom_on.get_node()
        helpers.dict_update_node(self.user, decom_on.handle_id,
                                 {"operational_state": "Decommissioned"})
        helpers.set_location(self.user, decom_on_node, rack.handle_id)

        helpers.create_port(decom_on_node, "1", self.user)
        helpers.create_port(decom_on_node, "2", self.user)
        # End test data

        resp = self.client.get(self.get_full_url(site) + "export")
        self.assertEquals('application/json', resp['Content-Type'])
        result = resp.json()

        # verify data
        self.assertEquals(1, len(result))
        rack_result = result[0]
        self.assertDictContainsSubset({
            'name': 'A.01',
            'node_type': 'Rack'
        }, rack_result)
        rack_equip = rack_result['children']
        # Decommissioned equipment should be gone
        self.assertEquals(1, len(rack_equip))
        self.assertDictContainsSubset(
            {
                'node_type': 'ODF',
                'name': 'NI-TEST-ODF-01'
            }, rack_equip[0])
        self.assertEquals(2, len(rack_equip[0]['children']))
Ejemplo n.º 4
0
 def get_port(self, bundle, device_name, device_type, port_name):
     node_type = helpers.slug_to_node_type(slugify(device_type),
                                           create=True)
     parent_node = nc.get_unique_node_by_name(nc.graphdb.manager,
                                              device_name,
                                              node_type.get_label())
     if not parent_node:
         raise_not_acceptable_error("End point {0} {1} not found.".format(
             device_type, device_name))
     result = parent_node.get_port(port_name).get('Has', [])
     if len(result) > 1:
         raise_not_acceptable_error(
             'Multiple port objects returned for a unique port name.')
     if result:
         port_node = result[0]['node']
     else:
         port_node = helpers.create_port(parent_node, port_name,
                                         bundle.request.user)
     return port_node
Ejemplo n.º 5
0
def _handle_ports(parent, clean_ports, user):
    if clean_ports and isinstance(clean_ports, list):
        for port_name in clean_ports:
            helpers.create_port(parent, port_name, user)
Ejemplo n.º 6
0
    def test_populated_site(self):
        # Setup test data
        site = helpers.create_unique_node_handle(self.user, "Test site",
                                                 "site", "Location")
        site_node = site.get_node()
        rack = helpers.get_generic_node_handle(self.user, "A.01", "rack",
                                               "Location")
        helpers.set_has(self.user, site_node, rack.handle_id)
        odf = helpers.create_unique_node_handle(self.user, "NI-TEST-ODF-01",
                                                "odf", "Physical")
        odf_node = odf.get_node()
        helpers.dict_update_node(self.user, odf.handle_id, {"max_ports": 24})
        helpers.set_location(self.user, odf_node, rack.handle_id)

        helpers.create_port(odf_node, "1", self.user)
        helpers.create_port(odf_node, "2", self.user)
        helpers.create_port(odf_node, "3", self.user)

        router = helpers.create_unique_node_handle(
            self.user, "ni-test.routers.nordu.net", "router", "Physical")
        router_node = router.get_node()
        helpers.dict_update_node(self.user, router.handle_id, {
            "operational_state": "Testing",
            "rack_units": 2
        })
        helpers.set_location(self.user, router_node, rack.handle_id)
        odf2 = helpers.get_generic_node_handle(self.user, "NI-TEST-ODF-02",
                                               "odf", "Physical")
        odf2_node = odf2.get_node()
        helpers.set_location(self.user, odf2_node, site.handle_id)
        # Done setting up testdata

        resp = self.client.get(self.get_full_url(site) + "export")
        self.assertEquals('application/json', resp['Content-Type'])
        result = resp.json()

        # verify data
        self.assertEquals(2, len(result))
        self.assertDictContainsSubset({
            'name': 'A.01',
            'node_type': 'Rack'
        }, result[0])
        self.assertDictContainsSubset(
            {
                'node_type': 'ODF',
                'name': 'NI-TEST-ODF-02'
            }, result[1])
        # Check racked equipment
        rack_equp = result[0]['children']
        self.assertEquals(2, len(rack_equp))
        odf1_result = rack_equp[0]
        self.assertDictContainsSubset(
            {
                'node_type': 'ODF',
                'name': 'NI-TEST-ODF-01',
                'max_ports': 24
            }, odf1_result)
        # Check ODF ports
        odf1_ports = odf1_result['children']
        self.assertEquals(3, len(odf1_ports))
        self.assertDictContainsSubset(
            {
                'node_type': 'Port',
                'name': '1',
                'port_type': ''
            }, odf1_ports[0])
        self.assertDictContainsSubset(
            {
                'node_type': 'Port',
                'name': '2',
                'description': ''
            }, odf1_ports[1])
        self.assertDictContainsSubset({
            'node_type': 'Port',
            'name': '3'
        }, odf1_ports[2])

        # Check router
        router = rack_equp[1]
        self.assertDictContainsSubset(
            {
                'node_type': 'Router',
                'name': 'ni-test.routers.nordu.net'
            }, router)
Ejemplo n.º 7
0
    def setUp(self):
        super(SearchTypeaheadPortsCase, self).setUp()
        self.typeahead_url = "/search/typeahead/ports"
        site = helpers.create_unique_node_handle(self.user, "UK-HEX", "site",
                                                 "Location")
        rack = helpers.get_generic_node_handle(self.user, "A.01", "rack",
                                               "Location")
        helpers.set_has(self.user, site.get_node(), rack.handle_id)

        odf1 = helpers.create_unique_node_handle(self.user, "test-odf1", "odf",
                                                 "Physical")
        odf1_node = odf1.get_node()
        helpers.set_location(self.user, odf1_node, rack.handle_id)
        helpers.create_port(odf1_node, "1+2", self.user)
        helpers.create_port(odf1_node, "3+4", self.user)

        odf2 = helpers.create_unique_node_handle(self.user, "other-odf2",
                                                 "odf", "Physical")
        odf2_node = odf2.get_node()
        helpers.set_location(self.user, odf2_node, site.handle_id)
        helpers.create_port(odf2_node, "11+12", self.user)
        helpers.create_port(odf2_node, "13+14", self.user)

        router = helpers.create_unique_node_handle(self.user,
                                                   "uk-hex.nordu.net",
                                                   "router", "Physical")
        router_node = router.get_node()
        helpers.set_location(self.user, router_node, site.handle_id)
        helpers.create_port(router_node, "ge-0/0/1", self.user)
        helpers.create_port(router_node, "ge-0/0/2", self.user)
        helpers.create_port(router_node, "ge-0/1/1", self.user)