Switch to using osc_lib.utils.tags
This patch updates the network modules to use the new osc_lib.utils.tags module and removes the in tree _tag.py version. A previous patch[1] moves the _tag.py code to osc-lib to allow other projects to leverage the code. [1] https://review.opendev.org/662859 Change-Id: Id0c34029e327de50c5fd2732bae5fbf45bbd16ee
This commit is contained in:
parent
4a2aa4acc1
commit
db29e28b7c
@ -54,7 +54,7 @@ openstacksdk==0.17.0
|
||||
os-client-config==1.28.0
|
||||
os-service-types==1.2.0
|
||||
os-testr==1.0.0
|
||||
osc-lib==1.14.0
|
||||
osc-lib==2.0.0
|
||||
osc-placement==1.7.0
|
||||
oslo.concurrency==3.26.0
|
||||
oslo.config==5.2.0
|
||||
|
@ -1,144 +0,0 @@
|
||||
# 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 argparse
|
||||
|
||||
from openstackclient.i18n import _
|
||||
|
||||
|
||||
class _CommaListAction(argparse.Action):
|
||||
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
setattr(namespace, self.dest, values.split(','))
|
||||
|
||||
|
||||
def add_tag_filtering_option_to_parser(parser, collection_name,
|
||||
enhance_help=lambda _h: _h):
|
||||
parser.add_argument(
|
||||
'--tags',
|
||||
metavar='<tag>[,<tag>,...]',
|
||||
action=_CommaListAction,
|
||||
help=enhance_help(
|
||||
_('List %s which have all given tag(s) (Comma-separated list of '
|
||||
'tags)') % collection_name)
|
||||
)
|
||||
parser.add_argument(
|
||||
'--any-tags',
|
||||
metavar='<tag>[,<tag>,...]',
|
||||
action=_CommaListAction,
|
||||
help=enhance_help(
|
||||
_('List %s which have any given tag(s) (Comma-separated list of '
|
||||
'tags)') % collection_name)
|
||||
)
|
||||
parser.add_argument(
|
||||
'--not-tags',
|
||||
metavar='<tag>[,<tag>,...]',
|
||||
action=_CommaListAction,
|
||||
help=enhance_help(
|
||||
_('Exclude %s which have all given tag(s) (Comma-separated list '
|
||||
'of tags)') % collection_name)
|
||||
)
|
||||
parser.add_argument(
|
||||
'--not-any-tags',
|
||||
metavar='<tag>[,<tag>,...]',
|
||||
action=_CommaListAction,
|
||||
help=enhance_help(
|
||||
_('Exclude %s which have any given tag(s) (Comma-separated list '
|
||||
'of tags)') % collection_name)
|
||||
)
|
||||
|
||||
|
||||
def get_tag_filtering_args(parsed_args, args):
|
||||
if parsed_args.tags:
|
||||
args['tags'] = ','.join(parsed_args.tags)
|
||||
if parsed_args.any_tags:
|
||||
args['any_tags'] = ','.join(parsed_args.any_tags)
|
||||
if parsed_args.not_tags:
|
||||
args['not_tags'] = ','.join(parsed_args.not_tags)
|
||||
if parsed_args.not_any_tags:
|
||||
args['not_any_tags'] = ','.join(parsed_args.not_any_tags)
|
||||
|
||||
|
||||
def add_tag_option_to_parser_for_create(parser, resource_name,
|
||||
enhance_help=lambda _h: _h):
|
||||
tag_group = parser.add_mutually_exclusive_group()
|
||||
tag_group.add_argument(
|
||||
'--tag',
|
||||
action='append',
|
||||
dest='tags',
|
||||
metavar='<tag>',
|
||||
help=enhance_help(
|
||||
_("Tag to be added to the %s "
|
||||
"(repeat option to set multiple tags)") % resource_name)
|
||||
)
|
||||
tag_group.add_argument(
|
||||
'--no-tag',
|
||||
action='store_true',
|
||||
help=enhance_help(_("No tags associated with the %s") % resource_name)
|
||||
)
|
||||
|
||||
|
||||
def add_tag_option_to_parser_for_set(parser, resource_name,
|
||||
enhance_help=lambda _h: _h):
|
||||
parser.add_argument(
|
||||
'--tag',
|
||||
action='append',
|
||||
dest='tags',
|
||||
metavar='<tag>',
|
||||
help=enhance_help(
|
||||
_("Tag to be added to the %s (repeat option to set multiple "
|
||||
"tags)") % resource_name)
|
||||
)
|
||||
parser.add_argument(
|
||||
'--no-tag',
|
||||
action='store_true',
|
||||
help=enhance_help(
|
||||
_("Clear tags associated with the %s. Specify both --tag and "
|
||||
"--no-tag to overwrite current tags") % resource_name)
|
||||
)
|
||||
|
||||
|
||||
def update_tags_for_set(client, obj, parsed_args):
|
||||
if parsed_args.no_tag:
|
||||
tags = set()
|
||||
else:
|
||||
tags = set(obj.tags or [])
|
||||
if parsed_args.tags:
|
||||
tags |= set(parsed_args.tags)
|
||||
if set(obj.tags or []) != tags:
|
||||
client.set_tags(obj, list(tags))
|
||||
|
||||
|
||||
def add_tag_option_to_parser_for_unset(parser, resource_name):
|
||||
tag_group = parser.add_mutually_exclusive_group()
|
||||
tag_group.add_argument(
|
||||
'--tag',
|
||||
action='append',
|
||||
dest='tags',
|
||||
metavar='<tag>',
|
||||
help=_("Tag to be removed from the %s "
|
||||
"(repeat option to remove multiple tags)") % resource_name)
|
||||
tag_group.add_argument(
|
||||
'--all-tag',
|
||||
action='store_true',
|
||||
help=_("Clear all tags associated with the %s") % resource_name)
|
||||
|
||||
|
||||
def update_tags_for_unset(client, obj, parsed_args):
|
||||
tags = set(obj.tags)
|
||||
if parsed_args.all_tag:
|
||||
tags = set()
|
||||
if parsed_args.tags:
|
||||
tags -= set(parsed_args.tags)
|
||||
if set(obj.tags) != tags:
|
||||
client.set_tags(obj, list(tags))
|
@ -16,12 +16,12 @@
|
||||
from osc_lib.cli import format_columns
|
||||
from osc_lib.command import command
|
||||
from osc_lib import utils
|
||||
from osc_lib.utils import tags as _tag
|
||||
|
||||
from openstackclient.i18n import _
|
||||
from openstackclient.identity import common as identity_common
|
||||
from openstackclient.network import common
|
||||
from openstackclient.network import sdk_utils
|
||||
from openstackclient.network.v2 import _tag
|
||||
|
||||
|
||||
_formatters = {
|
||||
|
@ -17,12 +17,12 @@ from cliff import columns as cliff_columns
|
||||
from osc_lib.cli import format_columns
|
||||
from osc_lib.command import command
|
||||
from osc_lib import utils
|
||||
from osc_lib.utils import tags as _tag
|
||||
|
||||
from openstackclient.i18n import _
|
||||
from openstackclient.identity import common as identity_common
|
||||
from openstackclient.network import common
|
||||
from openstackclient.network import sdk_utils
|
||||
from openstackclient.network.v2 import _tag
|
||||
|
||||
|
||||
class AdminStateColumn(cliff_columns.FormattableColumn):
|
||||
|
@ -24,12 +24,12 @@ from osc_lib.cli import parseractions
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
from osc_lib.utils import tags as _tag
|
||||
|
||||
from openstackclient.i18n import _
|
||||
from openstackclient.identity import common as identity_common
|
||||
from openstackclient.network import common
|
||||
from openstackclient.network import sdk_utils
|
||||
from openstackclient.network.v2 import _tag
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -23,11 +23,11 @@ from osc_lib.cli import parseractions
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
from osc_lib.utils import tags as _tag
|
||||
|
||||
from openstackclient.i18n import _
|
||||
from openstackclient.identity import common as identity_common
|
||||
from openstackclient.network import sdk_utils
|
||||
from openstackclient.network.v2 import _tag
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -19,13 +19,13 @@ from cliff import columns as cliff_columns
|
||||
from osc_lib.cli import format_columns
|
||||
from osc_lib.command import command
|
||||
from osc_lib import utils
|
||||
from osc_lib.utils import tags as _tag
|
||||
|
||||
from openstackclient.i18n import _
|
||||
from openstackclient.identity import common as identity_common
|
||||
from openstackclient.network import common
|
||||
from openstackclient.network import sdk_utils
|
||||
from openstackclient.network import utils as network_utils
|
||||
from openstackclient.network.v2 import _tag
|
||||
|
||||
|
||||
def _format_network_security_group_rules(sg_rules):
|
||||
|
@ -22,11 +22,11 @@ from osc_lib.cli import parseractions
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
from osc_lib.utils import tags as _tag
|
||||
|
||||
from openstackclient.i18n import _
|
||||
from openstackclient.identity import common as identity_common
|
||||
from openstackclient.network import sdk_utils
|
||||
from openstackclient.network.v2 import _tag
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -20,11 +20,11 @@ from osc_lib.cli import parseractions
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
from osc_lib.utils import tags as _tag
|
||||
|
||||
from openstackclient.i18n import _
|
||||
from openstackclient.identity import common as identity_common
|
||||
from openstackclient.network import sdk_utils
|
||||
from openstackclient.network.v2 import _tag
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -8,7 +8,7 @@ Babel!=2.4.0,>=2.3.4 # BSD
|
||||
cliff!=2.9.0,>=2.8.0 # Apache-2.0
|
||||
keystoneauth1>=3.6.2 # Apache-2.0
|
||||
openstacksdk>=0.17.0 # Apache-2.0
|
||||
osc-lib>=1.14.0 # Apache-2.0
|
||||
osc-lib>=2.0.0 # Apache-2.0
|
||||
oslo.i18n>=3.15.3 # Apache-2.0
|
||||
oslo.utils>=3.33.0 # Apache-2.0
|
||||
python-glanceclient>=2.8.0 # Apache-2.0
|
||||
|
Loading…
Reference in New Issue
Block a user