Merge "Improve logging"
This commit is contained in:
commit
d875c0206f
@ -12,14 +12,19 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
|
||||
from openstack import exceptions as sdk_exc
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
|
||||
from masakariclient.common.i18n import _
|
||||
import masakariclient.common.utils as masakariclient_utils
|
||||
|
||||
# Get the logger of this module
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ListHost(command.Lister):
|
||||
"""List Hosts."""
|
||||
@ -152,8 +157,13 @@ class CreateHost(command.ShowOne):
|
||||
# Remove not specified keys
|
||||
attrs = masakariclient_utils.remove_unspecified_items(attrs)
|
||||
|
||||
host = masakari_client.create_host(segment_id=parsed_args.segment_id,
|
||||
**attrs)
|
||||
try:
|
||||
host = masakari_client.create_host(
|
||||
segment_id=parsed_args.segment_id,
|
||||
**attrs)
|
||||
except Exception as ex:
|
||||
LOG.debug(_("Failed to create segment host: %s"), parsed_args)
|
||||
raise ex
|
||||
return _show_host(masakari_client,
|
||||
parsed_args.segment_id,
|
||||
host.uuid)
|
||||
@ -222,8 +232,12 @@ class UpdateHost(command.ShowOne):
|
||||
segment_id=parsed_args.segment_id, host=uuid, **attrs)
|
||||
except sdk_exc.NotFoundException:
|
||||
# Reraise. To unify exceptions with other functions.
|
||||
LOG.debug(_("Segment host is not found: %s"), parsed_args)
|
||||
raise sdk_exc.ResourceNotFound(
|
||||
_('No Host found for %s') % uuid)
|
||||
except Exception as ex:
|
||||
LOG.debug(_("Failed to update segment host: %s"), parsed_args)
|
||||
raise ex
|
||||
|
||||
return _show_host(masakari_client, parsed_args.segment_id, uuid)
|
||||
|
||||
@ -257,7 +271,11 @@ class DeleteHost(command.ShowOne):
|
||||
|
||||
|
||||
def _show_host(masakari_client, segment_id, uuid):
|
||||
host = masakari_client.get_host(segment_id, uuid)
|
||||
try:
|
||||
host = masakari_client.get_host(segment_id, uuid)
|
||||
except sdk_exc.ResourceNotFound:
|
||||
raise exceptions.CommandError(_('Segment host is not found: %s'
|
||||
) % uuid)
|
||||
|
||||
formatters = {}
|
||||
columns = [
|
||||
|
@ -12,7 +12,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
from openstack import exceptions as sdk_exc
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
|
@ -12,13 +12,19 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
|
||||
from openstack import exceptions as sdk_exc
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
|
||||
from masakariclient.common.i18n import _
|
||||
import masakariclient.common.utils as masakariclient_utils
|
||||
|
||||
# Get the logger of this module
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ListSegment(command.Lister):
|
||||
"""List segments."""
|
||||
@ -128,7 +134,11 @@ class CreateSegment(command.ShowOne):
|
||||
# Remove not specified keys
|
||||
attrs = masakariclient_utils.remove_unspecified_items(attrs)
|
||||
|
||||
segment = masakari_client.create_segment(**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)
|
||||
|
||||
@ -184,8 +194,12 @@ class UpdateSegment(command.ShowOne):
|
||||
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)
|
||||
|
||||
|
||||
@ -215,8 +229,11 @@ class DeleteSegment(command.Command):
|
||||
|
||||
|
||||
def _show_segment(masakari_client, segment_uuid):
|
||||
|
||||
segment = masakari_client.get_segment(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 = [
|
||||
|
@ -43,7 +43,7 @@ def make_client(instance):
|
||||
cert=instance.session.cert,
|
||||
profile=prof)
|
||||
LOG.debug('Connection: %s', conn)
|
||||
LOG.debug('masakari client initialized: %s', conn.ha)
|
||||
LOG.debug('masakari client initialized using OpenStack SDK: %s', conn.ha)
|
||||
return conn.ha
|
||||
|
||||
|
||||
|
@ -12,11 +12,15 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
|
||||
from openstack import connection
|
||||
from openstack import profile
|
||||
|
||||
from masakariclient.sdk.ha import ha_service
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def create_connection(prof=None, user_agent=None, **kwargs):
|
||||
"""Create connection to masakari_api."""
|
||||
@ -35,8 +39,11 @@ def create_connection(prof=None, user_agent=None, **kwargs):
|
||||
prof.set_api_version('ha', '1')
|
||||
|
||||
try:
|
||||
conn = connection.Connection(profile=prof, user_agent=user_agent,
|
||||
conn = connection.Connection(profile=prof,
|
||||
user_agent=user_agent,
|
||||
**kwargs)
|
||||
LOG.debug('Connection: %s', conn)
|
||||
LOG.debug('masakari client initialized: %s', conn.ha)
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user