Add auto-allocated-topology to SDK

Added Neutron features for "Get me a network"

Partially Implements: blueprint network-auto-allocated-topology

Change-Id: I85bf6a1d7ae45f04b54430bbf738ea2886be6cb4
This commit is contained in:
Ankur Gupta 2016-10-05 14:01:53 -05:00 committed by Ankur
parent 8d583936c8
commit 5f70a4afa9
7 changed files with 238 additions and 0 deletions

View File

@ -6,6 +6,7 @@ Network Resources
v2/address_scope
v2/agent
v2/auto_allocated_topology
v2/availability_zone
v2/extension
v2/flavor

View File

@ -0,0 +1,12 @@
openstack.network.v2.auto_allocated_topology
============================================
.. automodule:: openstack.network.v2.auto_allocated_topology
The Auto Allocated Topology Class
---------------------------------
The ``Auto Allocated Toplogy`` class inherits from :class:`~openstack.resource.Resource`.
.. autoclass:: openstack.network.v2.auto_allocated_topology:AutoAllocatedTopology
:members:

View File

@ -12,6 +12,8 @@
from openstack.network.v2 import address_scope as _address_scope
from openstack.network.v2 import agent as _agent
from openstack.network.v2 import auto_allocated_topology as \
_auto_allocated_topology
from openstack.network.v2 import availability_zone
from openstack.network.v2 import extension
from openstack.network.v2 import flavor as _flavor
@ -194,6 +196,61 @@ class Proxy(proxy.BaseProxy):
"""
return self._update(_agent.Agent, agent, **attrs)
def get_auto_allocated_topology(self, project=None):
"""Get the auto-allocated topology of a given tenant
:param project:
The value is the ID or name of a project
:returns: The auto-allocated topology
:rtype: :class:`~openstack.network.v2.\
auto_allocated_topology.AutoAllocatedTopology`
"""
# If project option is not given, grab project id from session
if project is None:
project = self.session.get_project_id()
return self._get(_auto_allocated_topology.AutoAllocatedTopology,
project)
def delete_auto_allocated_topology(self, project=None,
ignore_missing=False):
"""Delete auto-allocated topology
:param project:
The value is the ID or name of a project
:param ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be
raised when the topology does not exist.
When set to ``True``, no exception will be raised when
attempting to delete nonexistant topology
:returns: ``None``
"""
# If project option is not given, grab project id from session
if project is None:
project = self.session.get_project_id()
self._delete(_auto_allocated_topology.AutoAllocatedTopology,
project, ignore_missing=ignore_missing)
def validate_auto_allocated_topology(self, project=None):
"""Validate the resources for auto allocation
:param project:
The value is the ID or name of a project
:returns: Whether all resources are correctly configured or not
:rtype: :class:`~openstack.network.v2.\
auto_allocated_topology.ValidateTopology`
"""
# If project option is not given, grab project id from session
if project is None:
project = self.session.get_project_id()
return self._get(_auto_allocated_topology.ValidateTopology,
path_args={'project': project})
def availability_zones(self):
"""Return a generator of availability zones

View File

@ -0,0 +1,46 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from openstack.network import network_service
from openstack import resource
class AutoAllocatedTopology(resource.Resource):
resource_name = 'auto_allocated_topology'
resource_key = 'auto_allocated_topology'
base_path = '/auto-allocated-topology'
service = network_service.NetworkService()
# Capabilities
allow_create = False
allow_retrieve = True
allow_update = False
allow_delete = True
allow_list = False
# Properties
#: Project ID
#: If project is not specified the topology will be created
#: for project user is authenticated against.
#: Will return in error if resources have not been configured correctly
#: To use this feature auto-allocated-topology, subnet_allocation,
#: external-net and router extensions must be enabled and set up.
project_id = resource.prop('tenant_id')
class ValidateTopology(AutoAllocatedTopology):
base_path = '/auto-allocated-topology/%(project)s?fields=dry-run'
#: Validate requirements before running (Does not return topology)
#: Will return "Deployment error:" if the resources required have not
#: been correctly set up.
dry_run = resource.prop('dry_run')

View File

@ -0,0 +1,61 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from openstack.tests.functional import base
class TestAutoAllocatedTopology(base.BaseFunctionalTest):
NETWORK_NAME = 'auto_allocated_network'
NETWORK_ID = None
PROJECT_ID = None
@classmethod
def setUpClass(cls):
super(TestAutoAllocatedTopology, cls).setUpClass()
projects = [o.project_id for o in cls.conn.network.networks()]
cls.PROJECT_ID = projects[0]
@classmethod
def tearDownClass(cls):
res = cls.conn.network.delete_auto_allocated_topology(cls.PROJECT_ID)
cls.assertIs(None, res)
def test_dry_run_option_pass(self):
# Dry run will only pass if there is a public network
networks = self.conn.network.networks()
self._set_network_external(networks)
# Dry run option will return "dry-run=pass" in the 'id' resource
top = self.conn.network.validate_auto_allocated_topology(
self.PROJECT_ID)
self.assertEqual(self.PROJECT_ID, top.project)
self.assertEqual('dry-run=pass', top.id)
def test_show_no_project_option(self):
top = self.conn.network.get_auto_allocated_topology()
project = self.conn.session.get_project_id()
network = self.conn.network.get_network(top.id)
self.assertEqual(top.project_id, project)
self.assertEqual(top.id, network.id)
def test_show_project_option(self):
top = self.conn.network.get_auto_allocated_topology(self.PROJECT_ID)
network = self.conn.network.get_network(top.id)
self.assertEqual(top.project_id, network.project_id)
self.assertEqual(top.id, network.id)
self.assertEqual(network.name, 'auto_allocated_network')
def _set_network_external(self, networks):
for network in networks:
if network.name == 'public':
self.conn.network.update_network(network, is_default=True)

View File

@ -0,0 +1,37 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import testtools
from openstack.network.v2 import auto_allocated_topology
EXAMPLE = {
'project_id': '1',
'dry_run': False,
}
class TestAutoAllocatedTopology(testtools.TestCase):
def test_basic(self):
topo = auto_allocated_topology.AutoAllocatedTopology
self.assertEqual('auto_allocated_topology', topo.resource_key)
self.assertEqual('/auto-allocated-topology', topo.base_path)
self.assertFalse(topo.allow_create)
self.assertTrue(topo.allow_retrieve)
self.assertFalse(topo.allow_update)
self.assertTrue(topo.allow_delete)
self.assertFalse(topo.allow_list)
def test_make_it(self):
topo = auto_allocated_topology.AutoAllocatedTopology(EXAMPLE)
self.assertEqual(EXAMPLE['project_id'], topo.project_id)

View File

@ -16,6 +16,7 @@ import uuid
from openstack.network.v2 import _proxy
from openstack.network.v2 import address_scope
from openstack.network.v2 import agent
from openstack.network.v2 import auto_allocated_topology
from openstack.network.v2 import availability_zone
from openstack.network.v2 import extension
from openstack.network.v2 import flavor
@ -873,3 +874,26 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
self.verify_list(self.proxy.service_providers,
service_provider.ServiceProvider,
paginated=False)
def test_auto_allocated_topology_get(self):
self.verify_get(self.proxy.get_auto_allocated_topology,
auto_allocated_topology.AutoAllocatedTopology)
def test_auto_allocated_topology_delete(self):
self.verify_delete(self.proxy.delete_auto_allocated_topology,
auto_allocated_topology.AutoAllocatedTopology,
False)
def test_auto_allocated_topology_delete_ignore(self):
self.verify_delete(self.proxy.delete_auto_allocated_topology,
auto_allocated_topology.AutoAllocatedTopology,
True)
def test_validate_topology(self):
self.verify_get(self.proxy.validate_auto_allocated_topology,
auto_allocated_topology.ValidateTopology,
value=[mock.sentinel.project_id],
expected_args=[
auto_allocated_topology.ValidateTopology],
expected_kwargs={"path_args": {
"project": mock.sentinel.project_id}})