Skip to content

Commit 1169434

Browse files
ankur-odlamotoki
authored andcommitted
Auto allocated topology for OSC
Implementation of Auto-allocated topology into OSC. Dependency merged and released in SDK v. 0.9.11 Partially Implements: blueprint network-auto-allocated-topology Change-Id: I16120910893b0b26b0f7f77a184b0378448458c5
1 parent 3746fd2 commit 1169434

7 files changed

Lines changed: 507 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
===============================
2+
network auto allocated topology
3+
===============================
4+
5+
An **auto allocated topology** allows admins to quickly set up external
6+
connectivity for end-users. Only one auto allocated topology is allowed per
7+
project. For more information on how to set up the resources required
8+
for auto allocated topology review the documentation at:
9+
http://docs.openstack.org/newton/networking-guide/config-auto-allocation.html
10+
11+
Network v2
12+
13+
network auto allocated topology create
14+
--------------------------------------
15+
16+
Create the auto allocated topology for project
17+
18+
.. program:: network auto allocated topology create
19+
.. code:: bash
20+
21+
openstack network auto allocated topology create
22+
[--or-show]
23+
[--check-resources]
24+
[--project <project> [--project-domain <project-domain>]]
25+
26+
.. option:: --or-show
27+
28+
If topology exists returns the topologies information (Default).
29+
30+
.. option:: --check-resources
31+
32+
Validate the requirements for auto allocated topology.
33+
Does not return a topology.
34+
35+
.. option:: --project <project>
36+
37+
Return the auto allocated topology for a given project.
38+
Default is current project.
39+
40+
.. option:: --project-domain <project-domain>
41+
42+
Domain the project belongs to (name or ID).
43+
This can be used in case collisions between project names exist.
44+
45+
.. _network_auto_allocated_topology_create:
46+
47+
48+
network auto allocated topology delete
49+
--------------------------------------
50+
51+
Delete auto allocated topology for project
52+
53+
.. program:: network auto allocated topology delete
54+
.. code:: bash
55+
56+
openstack network auto allocated topology delete
57+
[--project <project> [--project-domain <project-domain>]]
58+
59+
.. option:: --project <project>
60+
61+
Delete auto allocated topology for a given project.
62+
Default is the current project.
63+
64+
.. option:: --project-domain <project-domain>
65+
66+
Domain the project belongs to (name or ID).
67+
This can be used in case collisions between project names exist.
68+
69+
.. _network_auto_allocated_topology_delete:

doc/source/commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ referring to both Compute and Volume quotas.
111111
* ``module``: (**Internal**) - installed Python modules in the OSC process
112112
* ``network``: (**Compute**, **Network**) - a virtual network for connecting servers and other resources
113113
* ``network agent``: (**Network**) - A network agent is an agent that handles various tasks used to implement virtual networks
114+
* ``network auto allocated topology``: (**Network**) - an auto-allocated topology for a project
114115
* ``network flavor``: (**Network**) - allows the user to choose the type of service by a set of advertised service capabilities (e.g., LOADBALANCER, FWAAS, L3, VPN, etc) rather than by a provider type or named vendor
115116
* ``network meter``: (**Network**) - allow traffic metering in a network
116117
* ``network meter rule``: (**Network**) - rules for network traffic metering
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
14+
"""Auto-allocated Topology Implementations"""
15+
16+
import logging
17+
18+
from osc_lib.command import command
19+
from osc_lib import utils
20+
21+
from openstackclient.i18n import _
22+
from openstackclient.identity import common as identity_common
23+
from openstackclient.network import sdk_utils
24+
25+
LOG = logging.getLogger(__name__)
26+
27+
28+
def _get_columns(item):
29+
column_map = {
30+
'tenant_id': 'project_id',
31+
}
32+
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
33+
34+
35+
def _format_check_resource_columns():
36+
return ('dry_run',)
37+
38+
39+
def _format_check_resource(item):
40+
item_id = getattr(item, 'id', False)
41+
if item_id == 'dry-run=pass':
42+
item.check_resource = 'pass'
43+
return item
44+
45+
46+
def _get_attrs(client_manager, parsed_args):
47+
attrs = {}
48+
if parsed_args.project:
49+
identity_client = client_manager.identity
50+
project_id = identity_common.find_project(
51+
identity_client,
52+
parsed_args.project,
53+
parsed_args.project_domain,
54+
).id
55+
attrs['tenant_id'] = project_id
56+
if parsed_args.check_resources:
57+
attrs['check_resources'] = True
58+
59+
return attrs
60+
61+
62+
# TODO(ankur-gupta-f): Use the SDK resource mapped attribute names once the
63+
# OSC minimum requirements include SDK 1.0.
64+
class CreateAutoAllocatedTopology(command.ShowOne):
65+
_description = _("Create the auto allocated topology for project")
66+
67+
def get_parser(self, prog_name):
68+
parser = super(CreateAutoAllocatedTopology, self).get_parser(prog_name)
69+
parser.add_argument(
70+
'--project',
71+
metavar='<project>',
72+
help=_("Return the auto allocated topology for a given project. "
73+
"Default is current project")
74+
)
75+
identity_common.add_project_domain_option_to_parser(parser)
76+
parser.add_argument(
77+
'--check-resources',
78+
action='store_true',
79+
help=_("Validate the requirements for auto allocated topology. "
80+
"Does not return a topology.")
81+
)
82+
parser.add_argument(
83+
'--or-show',
84+
action='store_true',
85+
default=True,
86+
help=_("If topology exists returns the topology's "
87+
"information (Default)")
88+
)
89+
90+
return parser
91+
92+
def check_resource_topology(self, client, parsed_args):
93+
obj = client.validate_auto_allocated_topology(parsed_args.project)
94+
95+
columns = _format_check_resource_columns()
96+
data = utils.get_item_properties(_format_check_resource(obj),
97+
columns,
98+
formatters={})
99+
100+
return (columns, data)
101+
102+
def get_topology(self, client, parsed_args):
103+
obj = client.get_auto_allocated_topology(parsed_args.project)
104+
display_columns, columns = _get_columns(obj)
105+
data = utils.get_item_properties(obj, columns, formatters={})
106+
return (display_columns, data)
107+
108+
def take_action(self, parsed_args):
109+
client = self.app.client_manager.network
110+
if parsed_args.check_resources:
111+
columns, data = self.check_resource_topology(client, parsed_args)
112+
else:
113+
columns, data = self.get_topology(client, parsed_args)
114+
return (columns, data)
115+
116+
117+
# TODO(ankur-gupta-f): Use the SDK resource mapped attribute names once the
118+
# OSC minimum requirements include SDK 1.0.
119+
class DeleteAutoAllocatedTopology(command.Command):
120+
_description = _("Delete auto allocated topology for project")
121+
122+
def get_parser(self, prog_name):
123+
parser = super(DeleteAutoAllocatedTopology, self).get_parser(prog_name)
124+
parser.add_argument(
125+
'--project',
126+
metavar='<project>',
127+
help=_('Delete auto allocated topology for a given project. '
128+
'Default is the current project')
129+
)
130+
identity_common.add_project_domain_option_to_parser(parser)
131+
132+
return parser
133+
134+
def take_action(self, parsed_args):
135+
client = self.app.client_manager.network
136+
client.delete_auto_allocated_topology(parsed_args.project)

openstackclient/tests/unit/network/v2/fakes.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,31 @@ def get_address_scopes(address_scopes=None, count=2):
157157
return mock.Mock(side_effect=address_scopes)
158158

159159

160+
class FakeAutoAllocatedTopology(object):
161+
"""Fake Auto Allocated Topology"""
162+
163+
@staticmethod
164+
def create_one_topology(attrs=None):
165+
attrs = attrs or {}
166+
167+
auto_allocated_topology_attrs = {
168+
'id': 'network-id-' + uuid.uuid4().hex,
169+
'tenant_id': 'project-id-' + uuid.uuid4().hex,
170+
}
171+
172+
auto_allocated_topology_attrs.update(attrs)
173+
174+
auto_allocated_topology = fakes.FakeResource(
175+
info=copy.deepcopy(auto_allocated_topology_attrs),
176+
loaded=True)
177+
178+
auto_allocated_topology.project_id = auto_allocated_topology_attrs[
179+
'tenant_id'
180+
]
181+
182+
return auto_allocated_topology
183+
184+
160185
class FakeAvailabilityZone(object):
161186
"""Fake one or more network availability zones (AZs)."""
162187

0 commit comments

Comments
 (0)