Merge "Add 'is_enabled' attr to segment"
This commit is contained in:
commit
393960b3a6
@ -57,7 +57,7 @@ def format_parameters(params, parse_semicolon=True):
|
||||
def remove_unspecified_items(attrs):
|
||||
"""Remove the items that don't have any values."""
|
||||
for key, value in list(attrs.items()):
|
||||
if not value:
|
||||
if value is None:
|
||||
del attrs[key]
|
||||
return attrs
|
||||
|
||||
|
@ -18,7 +18,9 @@ from openstack import exceptions as sdk_exc
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
from oslo_utils import strutils
|
||||
|
||||
from masakariclient import api_versions
|
||||
from masakariclient.common.i18n import _
|
||||
import masakariclient.common.utils as masakariclient_utils
|
||||
|
||||
@ -67,6 +69,12 @@ class ListSegment(command.Lister):
|
||||
columns = ['uuid', 'name', 'description', 'service_type',
|
||||
'recovery_method']
|
||||
|
||||
if masakari_client.default_microversion:
|
||||
api_version = api_versions.APIVersion(
|
||||
masakari_client.default_microversion)
|
||||
if api_version >= api_versions.APIVersion("1.2"):
|
||||
columns.append('is_enabled')
|
||||
|
||||
queries = masakariclient_utils.format_sort_filter_params(parsed_args)
|
||||
segments = masakari_client.segments(**queries)
|
||||
formatters = {}
|
||||
@ -118,6 +126,12 @@ class CreateSegment(command.ShowOne):
|
||||
metavar='<service_type>',
|
||||
help=_('Service type of segment.')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--is_enabled',
|
||||
metavar='<boolean>',
|
||||
help=_('The enabled flag of this segment. '
|
||||
'Supported after microversion 1.2.')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
@ -133,6 +147,16 @@ class CreateSegment(command.ShowOne):
|
||||
'recovery_method': parsed_args.recovery_method,
|
||||
'service_type': parsed_args.service_type,
|
||||
}
|
||||
|
||||
if masakari_client.default_microversion:
|
||||
api_version = api_versions.APIVersion(
|
||||
masakari_client.default_microversion)
|
||||
if (api_version >= api_versions.APIVersion("1.2") and
|
||||
parsed_args.is_enabled is not None):
|
||||
attrs['is_enabled'] = strutils.bool_from_string(
|
||||
parsed_args.is_enabled,
|
||||
strict=True)
|
||||
|
||||
# Remove not specified keys
|
||||
attrs = masakariclient_utils.remove_unspecified_items(attrs)
|
||||
|
||||
@ -172,6 +196,12 @@ class UpdateSegment(command.ShowOne):
|
||||
metavar='<service_type>',
|
||||
help=_('Service type of segment.')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--is_enabled',
|
||||
metavar='<boolean>',
|
||||
help=_('The enabled flag of this segment. '
|
||||
'Supported after microversion 1.2.')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
@ -191,6 +221,16 @@ class UpdateSegment(command.ShowOne):
|
||||
'recovery_method': parsed_args.recovery_method,
|
||||
'service_type': parsed_args.service_type,
|
||||
}
|
||||
|
||||
if masakari_client.default_microversion:
|
||||
api_version = api_versions.APIVersion(
|
||||
masakari_client.default_microversion)
|
||||
if (api_version >= api_versions.APIVersion("1.2") and
|
||||
parsed_args.is_enabled is not None):
|
||||
attrs['is_enabled'] = strutils.bool_from_string(
|
||||
parsed_args.is_enabled,
|
||||
strict=True)
|
||||
|
||||
# Remove not specified keys
|
||||
attrs = masakariclient_utils.remove_unspecified_items(attrs)
|
||||
|
||||
@ -250,5 +290,12 @@ def _show_segment(masakari_client, segment_uuid):
|
||||
'service_type',
|
||||
'recovery_method',
|
||||
]
|
||||
|
||||
if masakari_client.default_microversion:
|
||||
api_version = api_versions.APIVersion(
|
||||
masakari_client.default_microversion)
|
||||
if api_version >= api_versions.APIVersion("1.2"):
|
||||
columns.append('is_enabled')
|
||||
|
||||
return columns, utils.get_dict_properties(segment.to_dict(), columns,
|
||||
formatters=formatters)
|
||||
|
@ -18,14 +18,15 @@ from osc_lib import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_HA_API_VERSION = '1.1'
|
||||
DEFAULT_HA_API_VERSION = '1.2'
|
||||
API_VERSION_OPTION = 'os_ha_api_version'
|
||||
API_NAME = 'ha'
|
||||
|
||||
SUPPORTED_VERSIONS = [
|
||||
'1',
|
||||
'1.0',
|
||||
'1.1'
|
||||
'1.1',
|
||||
'1.2',
|
||||
]
|
||||
|
||||
API_VERSIONS = {v: 'masakariclient.v1.client.Client'
|
||||
|
@ -86,6 +86,7 @@ class BaseV1Segment(base.TestCase):
|
||||
self.app = mock.Mock()
|
||||
self.app_args = mock.Mock()
|
||||
self.client_manager = mock.Mock()
|
||||
self.client_manager.default_microversion = '1.0'
|
||||
self.app.client_manager.ha = self.client_manager
|
||||
# segment data setup
|
||||
self.dummy_segment = FakeSegment()
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adds support for API microversion 1.2 with ``enabled`` flag for segments.
|
||||
`Blueprint enable-to-segment <https://blueprints.launchpad.net/masakari/+spec/enable-to-segment>`__
|
Loading…
x
Reference in New Issue
Block a user