def _show_segment(masakari_client, segment_uuid): try: segment = masakari_client.get_segment(segment_uuid) except sdk_exc.ResourceNotFound: raise exceptions.CommandError( _('Segment is not found: %s') % segment_uuid) formatters = {} columns = [ 'created_at', 'updated_at', 'uuid', 'name', 'description', 'id', '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)
def take_action(self, parsed_args): masakari_client = self.app.client_manager.ha attrs = { 'name': parsed_args.name, 'description': parsed_args.description, '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) try: segment = masakari_client.create_segment(**attrs) except Exception as ex: LOG.debug(_("Failed to create segment: %s"), parsed_args) raise ex return _show_segment(masakari_client, segment.uuid)
def take_action(self, parsed_args): masakari_client = self.app.client_manager.ha uuid = masakariclient_utils.get_uuid_by_name(masakari_client, parsed_args.segment) attrs = { 'name': parsed_args.name, 'description': parsed_args.description, '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) try: masakari_client.update_segment(segment=uuid, **attrs) # Reraise. To unify exceptions with other functions. except sdk_exc.NotFoundException: LOG.debug(_("Segment is not found: %s"), parsed_args) raise sdk_exc.ResourceNotFound(_('No Segment found for %s') % uuid) except Exception as ex: LOG.debug(_("Failed to update segment: %s"), parsed_args) raise ex return _show_segment(masakari_client, uuid)
def _show_notification(masakari_client, notification_uuid): try: notification = masakari_client.get_notification(notification_uuid) except sdk_exc.ResourceNotFound: raise exceptions.CommandError(_('Notification not found: %s' ) % notification_uuid) formatters = {} columns = [ 'created_at', 'updated_at', 'notification_uuid', 'type', 'status', 'source_host_uuid', 'generated_time', 'payload' ] if masakari_client.default_microversion: api_version = api_versions.APIVersion( masakari_client.default_microversion) if api_version >= api_versions.APIVersion("1.1"): columns.append('recovery_workflow_details') return columns, utils.get_dict_properties(notification.to_dict(), columns, formatters=formatters)
def take_action(self, parsed_args): masakari_client = self.app.client_manager.ha 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 = {} return (columns, (utils.get_item_properties(p, columns, formatters=formatters) for p in segments))