Skip to content

Commit 09a0916

Browse files
hellochosenDean Troyer
authored andcommitted
Network: Add tag support for floating ip
Change-Id: I7a500a4ff6cec2442b4050df26c0b017d9f71903 Closes-Bug: #1750985
1 parent 7505831 commit 09a0916

5 files changed

Lines changed: 220 additions & 4 deletions

File tree

doc/source/cli/command-objects/floating-ip.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Create floating IP
2020
[--description <description>]
2121
[--qos-policy <qos-policy>]
2222
[--project <project> [--project-domain <project-domain>]]
23+
[--tag <tag> | --no-tag]
2324
<network>
2425
2526
.. option:: --subnet <subnet>
@@ -66,6 +67,18 @@ Create floating IP
6667
6768
*Network version 2 only*
6869
70+
.. option:: --tag <tag>
71+
72+
Tag to be added to the floating IP (repeat option to set multiple tags)
73+
74+
*Network version 2 only*
75+
76+
.. option:: --no-tag
77+
78+
No tags associated with the floating IP
79+
80+
*Network version 2 only*
81+
6982
.. describe:: <network>
7083
7184
Network to allocate floating IP from (name or ID)
@@ -100,6 +113,8 @@ List floating IP(s)
100113
[--status <status>]
101114
[--project <project> [--project-domain <project-domain>]]
102115
[--router <router>]
116+
[--tags <tag>[,<tag>,...]] [--any-tags <tag>[,<tag>,...]]
117+
[--not-tags <tag>[,<tag>,...]] [--not-any-tags <tag>[,<tag>,...]]
103118
104119
.. option:: --network <network>
105120
@@ -150,6 +165,30 @@ List floating IP(s)
150165
151166
*Network version 2 only*
152167
168+
.. option:: --tags <tag>[,<tag>,...]
169+
170+
List floating IP(s) which have all given tag(s)
171+
172+
*Network version 2 only*
173+
174+
.. option:: --any-tags <tag>[,<tag>,...]
175+
176+
List floating IP(s) which have any given tag(s)
177+
178+
*Network version 2 only*
179+
180+
.. option:: --not-tags <tag>[,<tag>,...]
181+
182+
Exclude floating IP(s) which have all given tag(s)
183+
184+
*Network version 2 only*
185+
186+
.. option:: --not-any-tags <tag>[,<tag>,...]
187+
188+
Exclude floating IP(s) which have any given tag(s)
189+
190+
*Network version 2 only*
191+
153192
floating ip set
154193
---------------
155194
@@ -162,6 +201,7 @@ Set floating IP properties
162201
--port <port>
163202
[--fixed-ip-address <ip-address>]
164203
[--qos-policy <qos-policy> | --no-qos-policy]
204+
[--tag <tag>] [--no-tag]
165205
<floating-ip>
166206
167207
.. option:: --port <port>
@@ -180,6 +220,15 @@ Set floating IP properties
180220
181221
Remove the QoS policy attached to the floating IP
182222
223+
.. option:: --tag <tag>
224+
225+
Tag to be added to the floating IP (repeat option to set multiple tags)
226+
227+
.. option:: --no-tag
228+
229+
Clear tags associated with the floating IP. Specify both --tag
230+
and --no-tag to overwrite current tags
231+
183232
.. _floating_ip_set-floating-ip:
184233
.. describe:: <floating-ip>
185234
@@ -210,6 +259,7 @@ Unset floating IP Properties
210259
openstack floating ip unset
211260
--port
212261
--qos-policy
262+
[--tag <tag> | --all-tag]
213263
<floating-ip>
214264
215265
.. option:: --port
@@ -220,6 +270,15 @@ Unset floating IP Properties
220270
221271
Remove the QoS policy attached to the floating IP
222272
273+
.. option:: --tag <tag>
274+
275+
Tag to be removed from the floating IP
276+
(repeat option to remove multiple tags)
277+
278+
.. option:: --all-tag
279+
280+
Clear all tags associated with the floating IP
281+
223282
.. _floating_ip_unset-floating-ip:
224283
.. describe:: <floating-ip>
225284

openstackclient/network/v2/floating_ip.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from openstackclient.identity import common as identity_common
2323
from openstackclient.network import common
2424
from openstackclient.network import sdk_utils
25+
from openstackclient.network.v2 import _tag
2526

2627

2728
def _get_network_columns(item):
@@ -139,11 +140,14 @@ def update_parser_network(self, parser):
139140
help=_("Owner's project (name or ID)")
140141
)
141142
identity_common.add_project_domain_option_to_parser(parser)
143+
_tag.add_tag_option_to_parser_for_create(parser, _('floating IP'))
142144
return parser
143145

144146
def take_action_network(self, client, parsed_args):
145147
attrs = _get_attrs(self.app.client_manager, parsed_args)
146148
obj = client.create_ip(**attrs)
149+
# tags cannot be set when created, so tags need to be set later.
150+
_tag.update_tags_for_set(client, obj, parsed_args)
147151
display_columns, columns = _get_network_columns(obj)
148152
data = utils.get_item_properties(obj, columns)
149153
return (display_columns, data)
@@ -280,6 +284,7 @@ def update_parser_network(self, parser):
280284
help=_("List floating IP(s) according to "
281285
"given router (name or ID)")
282286
)
287+
_tag.add_tag_filtering_option_to_parser(parser, _('floating IP'))
283288

284289
return parser
285290

@@ -308,11 +313,13 @@ def take_action_network(self, client, parsed_args):
308313
'router_id',
309314
'status',
310315
'description',
316+
'tags',
311317
)
312318
headers = headers + (
313319
'Router',
314320
'Status',
315321
'Description',
322+
'Tags',
316323
)
317324

318325
query = {}
@@ -342,6 +349,8 @@ def take_action_network(self, client, parsed_args):
342349
ignore_missing=False)
343350
query['router_id'] = router.id
344351

352+
_tag.get_tag_filtering_args(parsed_args, query)
353+
345354
data = client.ips(**query)
346355

347356
return (headers,
@@ -431,6 +440,9 @@ def get_parser(self, prog_name):
431440
action='store_true',
432441
help=_("Remove the QoS policy attached to the floating IP")
433442
)
443+
444+
_tag.add_tag_option_to_parser_for_set(parser, _('floating IP'))
445+
434446
return parser
435447

436448
def take_action(self, parsed_args):
@@ -453,7 +465,11 @@ def take_action(self, parsed_args):
453465
if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
454466
attrs['qos_policy_id'] = None
455467

456-
client.update_ip(obj, **attrs)
468+
if attrs:
469+
client.update_ip(obj, **attrs)
470+
471+
# tags is a subresource and it needs to be updated separately.
472+
_tag.update_tags_for_set(client, obj, parsed_args)
457473

458474

459475
class ShowFloatingIP(common.NetworkAndComputeShowOne):
@@ -528,6 +544,8 @@ def get_parser(self, prog_name):
528544
default=False,
529545
help=_("Remove the QoS policy attached to the floating IP")
530546
)
547+
_tag.add_tag_option_to_parser_for_unset(parser, _('floating IP'))
548+
531549
return parser
532550

533551
def take_action(self, parsed_args):
@@ -544,3 +562,6 @@ def take_action(self, parsed_args):
544562

545563
if attrs:
546564
client.update_ip(obj, **attrs)
565+
566+
# tags is a subresource and it needs to be updated separately.
567+
_tag.update_tags_for_unset(client, obj, parsed_args)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,7 @@ def create_one_floating_ip(attrs=None):
13791379
'tenant_id': 'project-id-' + uuid.uuid4().hex,
13801380
'description': 'floating-ip-description-' + uuid.uuid4().hex,
13811381
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
1382+
'tags': [],
13821383
}
13831384

13841385
# Overwrite default attributes.

0 commit comments

Comments
 (0)