Skip to content

Commit 3746fd2

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "OSC Network Flavor"
2 parents c828216 + edaeece commit 3746fd2

9 files changed

Lines changed: 1018 additions & 0 deletions

File tree

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
==============
2+
network flavor
3+
==============
4+
5+
A **network flavor** extension allows the user selection of operator-curated
6+
flavors during resource creations. It allows administrators to create network
7+
service flavors.
8+
9+
Network v2
10+
11+
.. _network_flavor_create:
12+
network flavor create
13+
---------------------
14+
15+
Create network flavor
16+
17+
.. program:: network flavor create
18+
.. code:: bash
19+
20+
openstack network flavor create
21+
--service-type <service-type>
22+
[--description <description>]
23+
[--enable | --disable]
24+
[--project <project> [--project-domain <project-domain>]]
25+
<name>
26+
27+
.. option:: --service-type <service-type>
28+
29+
Service type to which the flavor applies to: e.g. VPN.
30+
(See openstack :ref:'network_service_provider_list` (required)
31+
32+
.. option:: --description <description>
33+
34+
Description for the flavor
35+
36+
.. option:: --enable
37+
38+
Enable the flavor (default)
39+
40+
.. option:: --disable
41+
42+
Disable the flavor
43+
44+
.. option:: --project <project>
45+
46+
Owner's project (name or ID)
47+
48+
.. option:: --project-domain <project-domain>
49+
50+
Domain the project belongs to (name or ID). This can
51+
be used in case collisions between project names
52+
exist.
53+
54+
.. describe:: <name>
55+
56+
Name for the flavor
57+
58+
.. _network_flavor_delete:
59+
network flavor delete
60+
---------------------
61+
62+
Delete network flavor(s)
63+
64+
.. program:: network flavor delete
65+
.. code:: bash
66+
67+
openstack network flavor delete
68+
<flavor> [<flavor> ...]
69+
70+
.. describe:: <flavor>
71+
72+
Flavor(s) to delete (name or ID)
73+
74+
network flavor list
75+
-------------------
76+
77+
List network flavors
78+
79+
.. program:: network flavor list
80+
.. code:: bash
81+
82+
openstack network flavor list
83+
84+
.. _network_flavor_set:
85+
network flavor set
86+
------------------
87+
88+
Set network flavor properties
89+
90+
.. program:: network flavor set
91+
.. code:: bash
92+
93+
openstack network flavor set
94+
[--name <name>]
95+
[--description <description>]
96+
[--enable | --disable]
97+
<flavor>
98+
99+
.. option:: --name <name>
100+
101+
Set flavor name
102+
103+
.. option:: --description <description>
104+
105+
Set network flavor description
106+
107+
.. option:: --enable
108+
109+
Enable network flavor
110+
111+
.. option:: --disable
112+
113+
Disable network flavor
114+
115+
.. describe:: <flavor>
116+
117+
Flavor to update (name or ID)
118+
119+
.. _network_flavor_show:
120+
network flavor show
121+
-------------------
122+
123+
Show network flavor
124+
125+
.. program:: network flavor show
126+
.. code:: bash
127+
128+
openstack network flavor show
129+
<flavor>
130+
131+
.. describe:: <flavor>
132+
133+
Flavor to display (name or ID)

doc/source/command-objects/network-service-provider.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ networking service
77

88
Network v2
99

10+
.. _network_service_provider_list:
1011
network service provider list
1112
-----------------------------
1213

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 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
114115
* ``network meter``: (**Network**) - allow traffic metering in a network
115116
* ``network meter rule``: (**Network**) - rules for network traffic metering
116117
* ``network rbac``: (**Network**) - an RBAC policy for network resources
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
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+
"""Flavor action implementations"""
15+
16+
import logging
17+
18+
from osc_lib.command import command
19+
from osc_lib import exceptions
20+
from osc_lib import utils
21+
22+
from openstackclient.i18n import _
23+
from openstackclient.identity import common as identity_common
24+
from openstackclient.network import sdk_utils
25+
26+
27+
LOG = logging.getLogger(__name__)
28+
29+
30+
def _get_columns(item):
31+
column_map = {
32+
'is_enabled': 'enabled',
33+
'tenant_id': 'project_id',
34+
}
35+
36+
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
37+
38+
39+
def _get_attrs(client_manager, parsed_args):
40+
attrs = {}
41+
attrs['name'] = parsed_args.name
42+
attrs['service_type'] = parsed_args.service_type
43+
if parsed_args.description is not None:
44+
attrs['description'] = parsed_args.description
45+
if parsed_args.enable:
46+
attrs['enabled'] = True
47+
if parsed_args.disable:
48+
attrs['enabled'] = False
49+
if 'project' in parsed_args and parsed_args.project is not None:
50+
identity_client = client_manager.identity
51+
project_id = identity_common.find_project(
52+
identity_client,
53+
parsed_args.project,
54+
parsed_args.project_domain,
55+
).id
56+
attrs['tenant_id'] = project_id
57+
58+
return attrs
59+
60+
61+
# TODO(dasanind): Use the SDK resource mapped attribute names once the
62+
# OSC minimum requirements include SDK 1.0.
63+
class CreateNetworkFlavor(command.ShowOne):
64+
_description = _("Create new network flavor")
65+
66+
def get_parser(self, prog_name):
67+
parser = super(CreateNetworkFlavor, self).get_parser(prog_name)
68+
parser.add_argument(
69+
'name',
70+
metavar="<name>",
71+
help=_("Name for the flavor")
72+
)
73+
parser.add_argument(
74+
'--service-type',
75+
metavar="<service-type>",
76+
required=True,
77+
help=_('Service type to which the flavor applies to: e.g. VPN '
78+
'(See openstack network service provider list for loaded '
79+
'examples.)')
80+
)
81+
parser.add_argument(
82+
'--description',
83+
help=_('Description for the flavor')
84+
)
85+
parser.add_argument(
86+
'--project',
87+
metavar="<project>",
88+
help=_("Owner's project (name or ID)")
89+
)
90+
identity_common.add_project_domain_option_to_parser(parser)
91+
92+
enable_group = parser.add_mutually_exclusive_group()
93+
enable_group.add_argument(
94+
'--enable',
95+
action='store_true',
96+
help=_("Enable the flavor (default)")
97+
)
98+
enable_group.add_argument(
99+
'--disable',
100+
action='store_true',
101+
help=_("Disable the flavor")
102+
)
103+
104+
return parser
105+
106+
def take_action(self, parsed_args):
107+
client = self.app.client_manager.network
108+
attrs = _get_attrs(self.app.client_manager, parsed_args)
109+
obj = client.create_flavor(**attrs)
110+
display_columns, columns = _get_columns(obj)
111+
data = utils.get_item_properties(obj, columns, formatters={})
112+
113+
return (display_columns, data)
114+
115+
116+
class DeleteNetworkFlavor(command.Command):
117+
_description = _("Delete network flavors")
118+
119+
def get_parser(self, prog_name):
120+
parser = super(DeleteNetworkFlavor, self).get_parser(prog_name)
121+
122+
parser.add_argument(
123+
'flavor',
124+
metavar='<flavor>',
125+
nargs='+',
126+
help=_('Flavor(s) to delete (name or ID)')
127+
)
128+
return parser
129+
130+
def take_action(self, parsed_args):
131+
client = self.app.client_manager.network
132+
result = 0
133+
134+
for flavor in parsed_args.flavor:
135+
try:
136+
obj = client.find_flavor(flavor, ignore_missing=False)
137+
client.delete_flavor(obj)
138+
except Exception as e:
139+
result += 1
140+
LOG.error(_("Failed to delete flavor with "
141+
"name or ID '%(flavor)s': %(e)s"),
142+
{"flavor": flavor, "e": e})
143+
if result > 0:
144+
total = len(parsed_args.flavor)
145+
msg = (_("%(result)s of %(total)s flavors failed "
146+
"to delete.") % {"result": result, "total": total})
147+
raise exceptions.CommandError(msg)
148+
149+
150+
class ListNetworkFlavor(command.Lister):
151+
_description = _("List network flavors")
152+
153+
def take_action(self, parsed_args):
154+
client = self.app.client_manager.network
155+
156+
columns = (
157+
'id',
158+
'name',
159+
'is_enabled',
160+
'service_type',
161+
'description'
162+
)
163+
column_headers = (
164+
'ID',
165+
'Name',
166+
'Enabled',
167+
'Service Type',
168+
'Description'
169+
)
170+
171+
data = client.flavors()
172+
return (column_headers,
173+
(utils.get_item_properties(
174+
s, columns,
175+
) for s in data))
176+
177+
178+
# TODO(dasanind): Use only the SDK resource mapped attribute names once the
179+
# OSC minimum requirements include SDK 1.0.
180+
class SetNetworkFlavor(command.Command):
181+
_description = _("Set network flavor properties")
182+
183+
def get_parser(self, prog_name):
184+
parser = super(SetNetworkFlavor, self).get_parser(prog_name)
185+
parser.add_argument(
186+
'flavor',
187+
metavar="<flavor>",
188+
help=_("Flavor to update (name or ID)")
189+
)
190+
parser.add_argument(
191+
'--description',
192+
help=_('Set network flavor description')
193+
)
194+
enable_group = parser.add_mutually_exclusive_group()
195+
enable_group.add_argument(
196+
'--disable',
197+
action='store_true',
198+
help=_("Disable network flavor")
199+
)
200+
enable_group.add_argument(
201+
'--enable',
202+
action='store_true',
203+
help=_("Enable network flavor")
204+
)
205+
parser.add_argument(
206+
'--name',
207+
metavar="<name>",
208+
help=_('Set flavor name')
209+
)
210+
211+
return parser
212+
213+
def take_action(self, parsed_args):
214+
client = self.app.client_manager.network
215+
obj = client.find_flavor(
216+
parsed_args.flavor,
217+
ignore_missing=False)
218+
attrs = {}
219+
if parsed_args.name is not None:
220+
attrs['name'] = parsed_args.name
221+
if parsed_args.description is not None:
222+
attrs['description'] = parsed_args.description
223+
if parsed_args.enable:
224+
attrs['enabled'] = True
225+
if parsed_args.disable:
226+
attrs['enabled'] = False
227+
client.update_flavor(obj, **attrs)
228+
229+
230+
class ShowNetworkFlavor(command.ShowOne):
231+
_description = _("Display network flavor details")
232+
233+
def get_parser(self, prog_name):
234+
parser = super(ShowNetworkFlavor, self).get_parser(prog_name)
235+
parser.add_argument(
236+
'flavor',
237+
metavar='<flavor>',
238+
help=_('Flavor to display (name or ID)')
239+
)
240+
return parser
241+
242+
def take_action(self, parsed_args):
243+
client = self.app.client_manager.network
244+
obj = client.find_flavor(parsed_args.flavor, ignore_missing=False)
245+
display_columns, columns = _get_columns(obj)
246+
data = utils.get_item_properties(obj, columns)
247+
return display_columns, data

0 commit comments

Comments
 (0)