示例#1
0
    def update_host(self, context, segment_uuid, id, host_data):
        """Update the host"""

        host = objects.Host.get_by_uuid(context, id, segment_uuid=segment_uuid)

        if is_failover_segment_under_recovery(host.failover_segment):
            msg = _("Host %s can't be updated as "
                    "it is in-use to process notifications.") % host.uuid
            LOG.error(msg)
            raise exception.HostInUse(msg)

        if 'name' in host_data:
            self._is_valid_host_name(context, host_data.get('name'))

        if 'on_maintenance' in host_data:
            host_data['on_maintenance'] = strutils.bool_from_string(
                host_data['on_maintenance'], strict=True)
        if 'reserved' in host_data:
            host_data['reserved'] = strutils.bool_from_string(
                host_data['reserved'], strict=True)

        try:
            host.update(host_data)
            host.save()
        except Exception as e:
            with excutils.save_and_reraise_exception():
                tb = traceback.format_exc()
                api_utils.notify_about_host_api(
                    context,
                    host,
                    action=fields.EventNotificationAction.HOST_UPDATE,
                    phase=fields.EventNotificationPhase.ERROR,
                    exception=e,
                    tb=tb)
        return host
示例#2
0
    def delete_host(self, context, segment_uuid, id):
        """Delete the host"""
        segment = objects.FailoverSegment.get_by_uuid(context, segment_uuid)

        host = objects.Host.get_by_uuid(context, id, segment_uuid=segment_uuid)
        if is_failover_segment_under_recovery(segment):
            msg = _("Host %s can't be deleted as "
                    "it is in-use to process notifications.") % host.uuid
            LOG.error(msg)
            raise exception.HostInUse(msg)

        host.destroy()
示例#3
0
    def delete_host(self, context, segment_uuid, id):
        """Delete the host"""

        segment = objects.FailoverSegment.get_by_uuid(context, segment_uuid)
        host = objects.Host.get_by_uuid(context, id, segment_uuid=segment_uuid)
        if is_failover_segment_under_recovery(segment):
            msg = _("Host %s can't be deleted as "
                    "it is in-use to process notifications.") % host.uuid
            LOG.error(msg)
            raise exception.HostInUse(msg)

        try:
            host.destroy()
        except Exception as e:
            with excutils.save_and_reraise_exception():
                tb = traceback.format_exc()
                api_utils.notify_about_host_api(context, host,
                    action=fields.EventNotificationAction.HOST_DELETE,
                    phase=fields.EventNotificationPhase.ERROR, exception=e,
                    tb=tb)
示例#4
0
 def setUp(self):
     super(HostAPITestCase, self).setUp()
     self.host_api = ha_api.HostAPI()
     self.req = fakes.HTTPRequest.blank('/v1/segments/%s/hosts' %
                                        uuidsentinel.fake_segment,
                                        use_admin_context=True)
     self.context = self.req.environ['masakari.context']
     self.failover_segment = fakes_data.create_fake_failover_segment(
         name="segment1",
         id=1,
         description="something",
         service_type="COMPUTE",
         recovery_method="auto",
         uuid=uuidsentinel.fake_segment)
     self.host = fakes_data.create_fake_host(
         name="host_1",
         id=1,
         reserved=False,
         on_maintenance=False,
         type="fake",
         control_attributes="fake-control_attributes",
         uuid=uuidsentinel.fake_host_1)
     self.exception_in_use = exception.HostInUse(uuid=self.host.uuid)
示例#5
0
    def update_host(self, context, segment_uuid, id, host_data):
        """Update the host"""
        segment = objects.FailoverSegment.get_by_uuid(context, segment_uuid)

        host = objects.Host.get_by_uuid(context, id)

        if is_failover_segment_under_recovery(segment):
            msg = _("Host %s can't be updated as "
                    "it is in-use to process notifications.") % host.uuid
            LOG.error(msg)
            raise exception.HostInUse(msg)

        if 'on_maintenance' in host_data:
            host_data['on_maintenance'] = strutils.bool_from_string(
                host_data['on_maintenance'], strict=True)
        if 'reserved' in host_data:
            host_data['reserved'] = strutils.bool_from_string(
                host_data['reserved'], strict=True)

        host.update(host_data)

        host.save()

        return host