Beispiel #1
0
 def test_create_cluster_with_invalid_ext_network(self):
     bdict = apiutils.cluster_post_data()
     self.mock_valid_os_res.side_effect = \
         exception.ExternalNetworkNotFound('test-net')
     response = self.post_json('/clusters', bdict, expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(self.mock_valid_os_res.called)
     self.assertEqual(400, response.status_int)
Beispiel #2
0
def get_network_id(context, network_name):
    nets = []
    n_client = clients.OpenStackClients(context).neutron()
    ext_filter = {'router:external': True}

    networks = n_client.list_networks(**ext_filter)
    for net in networks.get('networks'):
        if net.get('name') == network_name:
            nets.append(net)

    if len(nets) == 0:
        raise exception.ExternalNetworkNotFound(network=network_name)

    if len(nets) > 1:
        raise exception.Conflict(
            "Multiple networks exist with same name '%s'. Please use the "
            "network ID instead." % network_name)

    return nets[0]["id"]
Beispiel #3
0
def validate_external_network(cli, external_network):
    """Validate external network"""

    count = 0
    ext_filter = {'router:external': True}
    networks = cli.neutron().list_networks(**ext_filter)
    for net in networks.get('networks'):
        if (net.get('name') == external_network
                or net.get('id') == external_network):
            count = count + 1

    if count == 0:
        # Unable to find the external network.
        # Or the network is private.
        raise exception.ExternalNetworkNotFound(network=external_network)

    if count > 1:
        msg = _("Multiple external networks exist with same name '%s'. "
                "Please use the external network ID instead.")
        raise exception.Conflict(msg % external_network)
Beispiel #4
0
def get_network(context, network, source, target, external):
    nets = []
    n_client = clients.OpenStackClients(context).neutron()
    ext_filter = {'router:external': external}

    networks = n_client.list_networks(**ext_filter)
    for net in networks.get('networks'):
        if net.get(source) == network:
            nets.append(net)

    if len(nets) == 0:
        if external:
            raise exception.ExternalNetworkNotFound(network=network)
        else:
            raise exception.FixedNetworkNotFound(network=network)

    if len(nets) > 1:
        raise exception.Conflict(
            "Multiple networks exist with same name '%s'. Please use the "
            "network ID instead." % network)

    return nets[0][target]