Exemplo n.º 1
0
    def test_network_details(self):
        self.mox.StubOutWithMock(api, 'quantum_network_details')
        api.quantum_network_details(IsA(http.HttpRequest),
                                    'n1').AndReturn(self.network_details)

        self.mox.StubOutWithMock(api, 'quantum_list_ports')
        api.quantum_list_ports(IsA(http.HttpRequest),
                               'n1').AndReturn(self.ports)

        self.mox.StubOutWithMock(api, 'quantum_port_attachment')
        api.quantum_port_attachment(IsA(http.HttpRequest), 'n1',
                                    'p1').AndReturn(self.port_attachment)

        self.mox.StubOutWithMock(api, 'quantum_port_details')
        api.quantum_port_details(IsA(http.HttpRequest), 'n1',
                                 'p1').AndReturn(self.port_details)

        self.mox.StubOutWithMock(api, 'get_vif_ids')
        api.get_vif_ids(IsA(http.HttpRequest)).AndReturn(self.vifs)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('dash_networks_detail', args=['tenant', 'n1']))

        self.assertTemplateUsed(res,
                                'django_openstack/dash/networks/detail.html')
        self.assertIn('network', res.context)

        network = res.context['network']

        self.assertEqual(network['name'], 'test_network')
        self.assertEqual(network['id'], 'n1')

        self.mox.VerifyAll()
    def test_network_details(self):
        self.mox.StubOutWithMock(api, 'quantum_network_details')
        api.quantum_network_details(IsA(http.HttpRequest),
                                    'n1').AndReturn(self.network_details)

        self.mox.StubOutWithMock(api, 'quantum_list_ports')
        api.quantum_list_ports(IsA(http.HttpRequest),
                               'n1').AndReturn(self.ports)

        self.mox.StubOutWithMock(api, 'quantum_port_attachment')
        api.quantum_port_attachment(IsA(http.HttpRequest),
                                    'n1', 'p1').AndReturn(self.port_attachment)

        self.mox.StubOutWithMock(api, 'quantum_port_details')
        api.quantum_port_details(IsA(http.HttpRequest),
                                 'n1', 'p1').AndReturn(self.port_details)

        self.mox.StubOutWithMock(api, 'get_vif_ids')
        api.get_vif_ids(IsA(http.HttpRequest)).AndReturn(self.vifs)

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_networks_detail',
                              args=['tenant', 'n1']))

        self.assertTemplateUsed(res,
                'django_openstack/dash/networks/detail.html')
        self.assertIn('network', res.context)

        network = res.context['network']

        self.assertEqual(network['name'], 'test_network')
        self.assertEqual(network['id'], 'n1')

        self.mox.VerifyAll()
Exemplo n.º 3
0
def _get_port_states(request, tenant_id, network_id):
    """
    Helper method to find port states for a network
    """
    network_ports = []
    # Get all vifs for comparison with port attachments
    vifs = api.get_vif_ids(request)

    # Get all ports on this network
    ports = api.quantum_list_ports(request, network_id)
    for port in ports['ports']:
        port_details = api.quantum_port_details(request, network_id,
                                                port['id'])
        # Get port attachments
        port_attachment = api.quantum_port_attachment(request, network_id,
                                                      port['id'])
        # Find instance the attachment belongs to
        connected_instance = None
        if port_attachment['attachment']:
            for vif in vifs:
                if str(vif['id']) == str(port_attachment['attachment']['id']):
                    connected_instance = vif['instance_name']
                    break
        network_ports.append({
            'id': port_details['port']['id'],
            'state': port_details['port']['state'],
            'attachment': port_attachment['attachment'],
            'instance': connected_instance
        })
    return network_ports
Exemplo n.º 4
0
def _get_port_states(request, tenant_id, network_id):
    """
    Helper method to find port states for a network
    """
    network_ports = []
    # Get all vifs for comparison with port attachments
    vifs = api.get_vif_ids(request)

    # Get all ports on this network
    ports = api.quantum_list_ports(request, network_id)
    for port in ports['ports']:
        port_details = api.quantum_port_details(request,
                                                network_id, port['id'])
        # Get port attachments
        port_attachment = api.quantum_port_attachment(request,
                                                      network_id, port['id'])
        # Find instance the attachment belongs to
        connected_instance = None
        if port_attachment['attachment']:
            for vif in vifs:
                if str(vif['id']) == str(port_attachment['attachment']['id']):
                    connected_instance = vif['instance_name']
                    break
        network_ports.append({
            'id': port_details['port']['id'],
            'state': port_details['port']['state'],
            'attachment': port_attachment['attachment'],
            'instance': connected_instance
        })
    return network_ports
Exemplo n.º 5
0
def _get_available_vifs(request):
    """
    Method to get a list of available virtual interfaces
    """
    vif_choices = []
    vifs = api.get_vif_ids(request)

    for vif in vifs:
        if vif["available"]:
            name = "Instance %s VIF %s" % (str(vif["instance_name"]), str(vif["id"]))
            vif_choices.append({"name": str(name), "id": str(vif["id"])})

    return vif_choices
Exemplo n.º 6
0
def _get_available_vifs(request):
    """
    Method to get a list of available virtual interfaces
    """
    vif_choices = []
    vifs = api.get_vif_ids(request)

    for vif in vifs:
        if vif['available']:
            name = "Instance %s VIF %s" % \
                   (str(vif['instance_name']), str(vif['id']))
            vif_choices.append({'name': str(name), 'id': str(vif['id'])})

    return vif_choices
Exemplo n.º 7
0
def _get_available_vifs(request):
    """
    Method to get a list of available virtual interfaces
    """
    vif_choices = []
    vifs = api.get_vif_ids(request)

    for vif in vifs:
        if vif['available']:
            name = "Instance %s VIF %s" % \
                   (str(vif['instance_name']), str(vif['id']))
            vif_choices.append({
                'name': str(name),
                'id': str(vif['id'])
            })

    return vif_choices