Пример #1
0
    def resize_volume(self, new_size):
        LOG.debug(_("begin resize_volume for id: %s") % self.id)
        old_volume_size = self.volume_size
        new_size = int(new_size)
        LOG.debug(
            _("%(gt)s: Resizing instance %(instance_id)s volume for "
              "server %(server_id)s from %(old_volume_size)s to "
              "%(new_size)r GB") % {
                  'gt': greenthread.getcurrent(),
                  'instance_id': self.id,
                  'server_id': self.server.id,
                  'old_volume_size': old_volume_size,
                  'new_size': new_size
              })

        if self.server.status == 'active':
            self._resize_active_volume(new_size)
        else:
            self._do_resize(new_size)

        self.send_usage_event('modify_volume',
                              old_volume_size=old_volume_size,
                              launched_at=timeutils.isotime(self.updated),
                              modify_at=timeutils.isotime(self.updated),
                              volume_size=new_size)
        LOG.debug(_("end resize_volume for id: %s") % self.id)
Пример #2
0
 def resize_volume(self, new_size):
     old_volume_size = self.volume_size
     new_size = int(new_size)
     LOG.debug("%s: Resizing volume for instance: %s from %s to %r GB"
               % (greenthread.getcurrent(), self.server.id,
                  old_volume_size, new_size))
     self.volume_client.volumes.resize(self.volume_id, new_size)
     try:
         utils.poll_until(
             lambda: self.volume_client.volumes.get(self.volume_id),
             lambda volume: volume.status == 'in-use',
             sleep_time=2,
             time_out=CONF.volume_time_out)
         volume = self.volume_client.volumes.get(self.volume_id)
         self.update_db(volume_size=volume.size)
         self.nova_client.volumes.rescan_server_volume(self.server,
                                                       self.volume_id)
         self.send_usage_event('modify_volume',
                               old_volume_size=old_volume_size,
                               launched_at=timeutils.isotime(),
                               modify_at=timeutils.isotime(),
                               volume_size=new_size)
     except PollTimeOut as pto:
         LOG.error("Timeout trying to rescan or resize the attached volume "
                   "filesystem for volume: %s" % self.volume_id)
     except Exception as e:
         LOG.error(e)
         LOG.error("Error encountered trying to rescan or resize the "
                   "attached volume filesystem for volume: %s"
                   % self.volume_id)
     finally:
         self.update_db(task_status=inst_models.InstanceTasks.NONE)
Пример #3
0
 def _record_action_success(self):
     LOG.debug("Updating instance %s to flavor_id %s."
               % (self.instance.id, self.new_flavor_id))
     self.instance.update_db(flavor_id=self.new_flavor_id)
     self.instance.send_usage_event('modify_flavor',
                                    old_instance_size=self.old_memory_size,
                                    instance_size=self.new_memory_size,
                                    launched_at=timeutils.isotime(),
                                    modify_at=timeutils.isotime())
Пример #4
0
 def _record_action_success(self):
     LOG.debug("Updating instance %s to flavor_id %s." %
               (self.instance.id, self.new_flavor_id))
     self.instance.update_db(flavor_id=self.new_flavor_id)
     self.instance.send_usage_event(
         'modify_flavor',
         old_instance_size=self.old_flavor['ram'],
         instance_size=self.new_flavor['ram'],
         launched_at=timeutils.isotime(),
         modify_at=timeutils.isotime())
Пример #5
0
 def _record_action_success(self):
     LOG.debug(_("Updating instance %(id)s to flavor_id %(flavor_id)s.")
               % {'id': self.instance.id, 'flavor_id': self.new_flavor_id})
     self.instance.update_db(flavor_id=self.new_flavor_id)
     self.instance.send_usage_event(
         'modify_flavor',
         old_instance_size=self.old_flavor['ram'],
         instance_size=self.new_flavor['ram'],
         launched_at=timeutils.isotime(self.instance.updated),
         modify_at=timeutils.isotime(self.instance.updated))
Пример #6
0
    def resize_volume(self, new_size):
        old_volume_size = self.volume_size
        new_size = int(new_size)
        LOG.debug("%s: Resizing volume for instance: %s from %s to %r GB"
                  % (greenthread.getcurrent(), self.server.id,
                     old_volume_size, new_size))

        if self.server.status == 'active':
            self._resize_active_volume(new_size)
        else:
            self._do_resize(new_size)

        self.send_usage_event('modify_volume', old_volume_size=old_volume_size,
                              launched_at=timeutils.isotime(),
                              modify_at=timeutils.isotime(),
                              volume_size=new_size)
Пример #7
0
    def resize_volume(self, new_size):
        old_volume_size = self.volume_size
        new_size = int(new_size)
        LOG.debug("%s: Resizing volume for instance: %s from %s to %r GB" %
                  (greenthread.getcurrent(), self.server.id, old_volume_size,
                   new_size))

        if self.server.status == 'active':
            self._resize_active_volume(new_size)
        else:
            self._do_resize(new_size)

        self.send_usage_event('modify_volume',
                              old_volume_size=old_volume_size,
                              launched_at=timeutils.isotime(self.updated),
                              modify_at=timeutils.isotime(self.updated),
                              volume_size=new_size)
Пример #8
0
    def _delete_resources(self, deleted_at):
        LOG.debug(_("begin _delete_resources for id: %s") % self.id)
        server_id = self.db_info.compute_instance_id
        old_server = self.nova_client.servers.get(server_id)
        try:
            if use_heat:
                # Delete the server via heat
                heatclient = create_heat_client(self.context)
                name = 'trove-%s' % self.id
                heatclient.stacks.delete(name)
            else:
                self.server.delete()
        except Exception as ex:
            LOG.exception(
                _("Error during delete compute server %s") % self.server.id)
        try:
            dns_support = CONF.trove_dns_support
            LOG.debug(_("trove dns support = %s") % dns_support)
            if dns_support:
                dns_api = create_dns_client(self.context)
                dns_api.delete_instance_entry(instance_id=self.db_info.id)
        except Exception as ex:
            LOG.exception(
                _("Error during dns entry of instance %(id)s: %(ex)") % {
                    'id': self.db_info.id,
                    'ex': ex
                })

            # Poll until the server is gone.
        def server_is_finished():
            try:
                server = self.nova_client.servers.get(server_id)
                if server.status not in ['SHUTDOWN', 'ACTIVE']:
                    LOG.error(
                        _("Server %(server_id)s got into ERROR status "
                          "during delete of instance %(instance_id)s!") % {
                              'server_id': server.id,
                              'instance_id': self.id
                          })
                return False
            except nova_exceptions.NotFound:
                return True

        try:
            utils.poll_until(server_is_finished,
                             sleep_time=2,
                             time_out=CONF.server_delete_time_out)
        except PollTimeOut:
            LOG.exception(
                _("Timout during nova server delete of server: %s") %
                server_id)
        self.send_usage_event('delete',
                              deleted_at=timeutils.isotime(deleted_at),
                              server=old_server)
        LOG.debug(_("end _delete_resources for id: %s") % self.id)
Пример #9
0
    def resize_volume(self, new_size):
        old_volume_size = self.volume_size
        new_size = int(new_size)
        LOG.debug("%s: Resizing volume for instance: %s from %s to %r GB" %
                  (greenthread.getcurrent(), self.server.id, old_volume_size,
                   new_size))
        try:
            self.volume_client.volumes.extend(self.volume_id, new_size)
        except cinder_exceptions.ClientException:
            self.update_db(task_status=inst_models.InstanceTasks.NONE)
            LOG.exception("Error encountered trying to rescan or resize the "
                          "attached volume filesystem for volume: "
                          "%s" % self.volume_id)
            raise

        try:
            utils.poll_until(
                lambda: self.volume_client.volumes.get(self.volume_id),
                lambda volume: volume.status == 'in-use',
                sleep_time=2,
                time_out=CONF.volume_time_out)
            volume = self.volume_client.volumes.get(self.volume_id)
            self.update_db(volume_size=volume.size)
            self.nova_client.volumes.rescan_server_volume(
                self.server, self.volume_id)
            self.send_usage_event('modify_volume',
                                  old_volume_size=old_volume_size,
                                  launched_at=timeutils.isotime(),
                                  modify_at=timeutils.isotime(),
                                  volume_size=new_size)
        except PollTimeOut as pto:
            LOG.error("Timeout trying to rescan or resize the attached volume "
                      "filesystem for volume: %s" % self.volume_id)
        except Exception as e:
            LOG.error(e)
            LOG.error("Error encountered trying to rescan or resize the "
                      "attached volume filesystem for volume: %s" %
                      self.volume_id)
        finally:
            self.update_db(task_status=inst_models.InstanceTasks.NONE)
Пример #10
0
    def data(self):
        get_utc = datetime.datetime.utcfromtimestamp
        next_avail = get_utc(self.rate_limit.get("resetTime", 0))

        return {"limit": {
            "nextAvailable": timeutils.isotime(at=next_avail),
            "remaining": self.rate_limit.get("remaining", 0),
            "unit": self.rate_limit.get("unit", ""),
            "value": self.rate_limit.get("value", ""),
            "verb": self.rate_limit.get("verb", ""),
            "uri": self.rate_limit.get("URI", ""),
            "regex": self.rate_limit.get("regex", "")
        }
        }
Пример #11
0
    def data(self):
        get_utc = datetime.datetime.utcfromtimestamp
        next_avail = get_utc(self.rate_limit.get("resetTime", 0))

        return {"limit": {
            "nextAvailable": timeutils.isotime(at=next_avail),
            "remaining": self.rate_limit.get("remaining", 0),
            "unit": self.rate_limit.get("unit", ""),
            "value": self.rate_limit.get("value", ""),
            "verb": self.rate_limit.get("verb", ""),
            "uri": self.rate_limit.get("URI", ""),
            "regex": self.rate_limit.get("regex", "")
        }
        }
Пример #12
0
    def send_usage_event(self, event_type, **kwargs):
        event_type = 'trove.instance.%s' % event_type
        publisher_id = CONF.host

        # Grab the instance size from the kwargs or from the nova client
        instance_size = kwargs.pop('instance_size', None)
        flavor = self.nova_client.flavors.get(self.flavor_id)
        server = kwargs.pop('server', None)
        if server is None:
            server = self.nova_client.servers.get(self.server_id)
        az = getattr(server, 'OS-EXT-AZ:availability_zone', None)

        # Default payload
        created_time = timeutils.isotime(self.db_info.created)
        payload = {
            'availability_zone': az,
            'created_at': created_time,
            'name': self.name,
            'instance_id': self.id,
            'instance_name': self.name,
            'instance_size': instance_size or flavor.ram,
            'instance_type': flavor.name,
            'instance_type_id': flavor.id,
            'launched_at': created_time,
            'nova_instance_id': self.server_id,
            'region': CONF.region,
            'state_description': self.status,
            'state': self.status,
            'tenant_id': self.tenant_id,
            'user_id': self.context.user,
        }

        if CONF.trove_volume_support:
            payload.update({
                'volume_size': self.volume_size,
                'nova_volume_id': self.volume_id
            })

        payload['service_id'] = self._get_service_id(
            self.datastore.manager, CONF.notification_service_id)

        # Update payload with all other kwargs
        payload.update(kwargs)
        LOG.debug(
            _('Sending event: %(event_type)s, %(payload)s') % {
                'event_type': event_type,
                'payload': payload
            })
        notifier.notify(self.context, publisher_id, event_type, 'INFO',
                        payload)
Пример #13
0
    def resize_volume(self, new_size):
        LOG.debug(_("begin resize_volume for id: %s") % self.id)
        old_volume_size = self.volume_size
        new_size = int(new_size)
        LOG.debug(_("%(gt)s: Resizing instance %(instance_id)s volume for "
                    "server %(server_id)s from %(old_volume_size)s to "
                    "%(new_size)r GB")
                  % {'gt': greenthread.getcurrent(),
                     'instance_id': self.id,
                     'server_id': self.server.id,
                     'old_volume_size': old_volume_size,
                     'new_size': new_size})

        if self.server.status == 'active':
            self._resize_active_volume(new_size)
        else:
            self._do_resize(new_size)

        self.send_usage_event('modify_volume', old_volume_size=old_volume_size,
                              launched_at=timeutils.isotime(self.updated),
                              modify_at=timeutils.isotime(self.updated),
                              volume_size=new_size)
        LOG.debug(_("end resize_volume for id: %s") % self.id)
Пример #14
0
    def send_usage_event(self, event_type, **kwargs):
        event_type = 'trove.instance.%s' % event_type
        publisher_id = CONF.host

        # Grab the instance size from the kwargs or from the nova client
        instance_size = kwargs.pop('instance_size', None)
        flavor = self.nova_client.flavors.get(self.flavor_id)
        server = kwargs.pop('server', None)
        if server is None:
            server = self.nova_client.servers.get(self.server_id)
        az = getattr(server, 'OS-EXT-AZ:availability_zone', None)

        # Default payload
        created_time = timeutils.isotime(self.db_info.created)
        payload = {
            'availability_zone': az,
            'created_at': created_time,
            'name': self.name,
            'instance_id': self.id,
            'instance_name': self.name,
            'instance_size': instance_size or flavor.ram,
            'instance_type': flavor.name,
            'instance_type_id': flavor.id,
            'launched_at': created_time,
            'nova_instance_id': self.server_id,
            'region': CONF.region,
            'state_description': self.status,
            'state': self.status,
            'tenant_id': self.tenant_id,
            'user_id': self.context.user,
        }

        if CONF.trove_volume_support:
            payload.update({
                'volume_size': self.volume_size,
                'nova_volume_id': self.volume_id
            })

        if CONF.notification_service_id:
            payload.update({
                'service_id': CONF.notification_service_id
            })

        # Update payload with all other kwargs
        payload.update(kwargs)
        LOG.debug('Sending event: %s, %s' % (event_type, payload))
        notifier.notify(self.context, publisher_id, event_type, 'INFO',
                        payload)
Пример #15
0
    def _delete_resources(self, deleted_at):
        LOG.debug(_("begin _delete_resources for id: %s") % self.id)
        server_id = self.db_info.compute_instance_id
        old_server = self.nova_client.servers.get(server_id)
        try:
            if use_heat:
                # Delete the server via heat
                heatclient = create_heat_client(self.context)
                name = 'trove-%s' % self.id
                heatclient.stacks.delete(name)
            else:
                self.server.delete()
        except Exception as ex:
            LOG.exception(_("Error during delete compute server %s")
                          % self.server.id)
        try:
            dns_support = CONF.trove_dns_support
            LOG.debug(_("trove dns support = %s") % dns_support)
            if dns_support:
                dns_api = create_dns_client(self.context)
                dns_api.delete_instance_entry(instance_id=self.db_info.id)
        except Exception as ex:
            LOG.exception(_("Error during dns entry of instance %(id)s: %(ex)")
                          % {'id': self.db_info.id, 'ex': ex})

            # Poll until the server is gone.
        def server_is_finished():
            try:
                server = self.nova_client.servers.get(server_id)
                if server.status not in ['SHUTDOWN', 'ACTIVE']:
                    LOG.error(_("Server %(server_id)s got into ERROR status "
                                "during delete of instance %(instance_id)s!") %
                              {'server_id': server.id, 'instance_id': self.id})
                return False
            except nova_exceptions.NotFound:
                return True

        try:
            utils.poll_until(server_is_finished, sleep_time=2,
                             time_out=CONF.server_delete_time_out)
        except PollTimeOut:
            LOG.exception(_("Timout during nova server delete of server: %s") %
                          server_id)
        self.send_usage_event('delete',
                              deleted_at=timeutils.isotime(deleted_at),
                              server=old_server)
        LOG.debug(_("end _delete_resources for id: %s") % self.id)
Пример #16
0
    def _delete_resources(self, deleted_at):
        server_id = self.db_info.compute_instance_id
        old_server = self.nova_client.servers.get(server_id)
        try:
            if use_heat:
                # Delete the server via heat
                heatclient = create_heat_client(self.context)
                name = "trove-%s" % self.id
                heatclient.stacks.delete(name)
            else:
                self.server.delete()
        except Exception as ex:
            LOG.error("Error during delete compute server %s " % self.server.id)
            LOG.error(ex)
        try:
            dns_support = CONF.trove_dns_support
            LOG.debug(_("trove dns support = %s") % dns_support)
            if dns_support:
                dns_api = create_dns_client(self.context)
                dns_api.delete_instance_entry(instance_id=self.db_info.id)
        except Exception as ex:
            LOG.error("Error during dns entry for instance %s " % self.db_info.id)
            LOG.error(ex)
            # Poll until the server is gone.

        def server_is_finished():
            try:
                server = self.nova_client.servers.get(server_id)
                if server.status not in ["SHUTDOWN", "ACTIVE"]:
                    msg = "Server %s got into %s status during delete " "of instance %s!" % (
                        server.id,
                        server.status,
                        self.id,
                    )
                    LOG.error(msg)
                return False
            except nova_exceptions.NotFound:
                return True

        try:
            poll_until(server_is_finished, sleep_time=2, time_out=CONF.server_delete_time_out)
        except PollTimeOut as e:
            LOG.error("Timout during nova server delete", e)
        self.send_usage_event("delete", deleted_at=timeutils.isotime(deleted_at), server=old_server)
Пример #17
0
    def send_usage_event(self, event_type, **kwargs):
        event_type = "trove.instance.%s" % event_type
        publisher_id = CONF.host

        # Grab the instance size from the kwargs or from the nova client
        instance_size = kwargs.pop("instance_size", None)
        flavor = self.nova_client.flavors.get(self.flavor_id)
        server = kwargs.pop("server", None)
        if server is None:
            server = self.nova_client.servers.get(self.server_id)
        az = getattr(server, "OS-EXT-AZ:availability_zone", None)

        # Default payload
        created_time = timeutils.isotime(self.db_info.created)
        payload = {
            "availability_zone": az,
            "created_at": created_time,
            "name": self.name,
            "instance_id": self.id,
            "instance_name": self.name,
            "instance_size": instance_size or flavor.ram,
            "instance_type": flavor.name,
            "instance_type_id": flavor.id,
            "launched_at": created_time,
            "nova_instance_id": self.server_id,
            "region": CONF.region,
            "state_description": self.status,
            "state": self.status,
            "tenant_id": self.tenant_id,
            "user_id": self.context.user,
        }

        if CONF.trove_volume_support:
            payload.update({"volume_size": self.volume_size, "nova_volume_id": self.volume_id})

        if CONF.notification_service_id:
            payload.update({"service_id": CONF.notification_service_id})

        # Update payload with all other kwargs
        payload.update(kwargs)
        LOG.debug("Sending event: %s, %s" % (event_type, payload))
        notifier.notify(self.context, publisher_id, event_type, "INFO", payload)
Пример #18
0
    def _delete_resources(self, deleted_at):
        server_id = self.db_info.compute_instance_id
        old_server = self.nova_client.servers.get(server_id)
        try:
            self.server.delete()
        except Exception as ex:
            LOG.error("Error during delete compute server %s " %
                      self.server.id)
            LOG.error(ex)
        try:
            dns_support = CONF.trove_dns_support
            LOG.debug(_("trove dns support = %s") % dns_support)
            if dns_support:
                dns_api = create_dns_client(self.context)
                dns_api.delete_instance_entry(instance_id=self.db_info.id)
        except Exception as ex:
            LOG.error("Error during dns entry for instance %s " %
                      self.db_info.id)
            LOG.error(ex)
            # Poll until the server is gone.

        def server_is_finished():
            try:
                server = self.nova_client.servers.get(server_id)
                if server.status not in ['SHUTDOWN', 'ACTIVE']:
                    msg = "Server %s got into ERROR status during delete " \
                          "of instance %s!" % (server.id, self.id)
                    LOG.error(msg)
                return False
            except nova_exceptions.NotFound:
                return True

        try:
            poll_until(server_is_finished,
                       sleep_time=2,
                       time_out=CONF.server_delete_time_out)
        except PollTimeOut as e:
            LOG.error("Timout during nova server delete", e)
        self.send_usage_event('delete',
                              deleted_at=timeutils.isotime(deleted_at),
                              server=old_server)
Пример #19
0
    def _delete_resources(self):
        server_id = self.db_info.compute_instance_id
        old_server = self.nova_client.servers.get(server_id)
        try:
            self.server.delete()
        except Exception as ex:
            LOG.error("Error during delete compute server %s "
                      % self.server.id)
            LOG.error(ex)
        try:
            dns_support = CONF.trove_dns_support
            LOG.debug(_("trove dns support = %s") % dns_support)
            if dns_support:
                dns_api = create_dns_client(self.context)
                dns_api.delete_instance_entry(instance_id=self.db_info.id)
        except Exception as ex:
            LOG.error("Error during dns entry for instance %s "
                      % self.db_info.id)
            LOG.error(ex)
        # Poll until the server is gone.

        def server_is_finished():
            try:
                server = self.nova_client.servers.get(server_id)
                if server.status not in ['SHUTDOWN', 'ACTIVE']:
                    msg = "Server %s got into ERROR status during delete " \
                          "of instance %s!" % (server.id, self.id)
                    LOG.error(msg)
                return False
            except nova_exceptions.NotFound:
                return True

        poll_until(server_is_finished, sleep_time=2,
                   time_out=CONF.server_delete_time_out)
        self.send_usage_event('delete', deleted_at=timeutils.isotime(),
                              server=old_server)
Пример #20
0
 def _send_usage_event(self,old_server,deleted_at):
     self.send_usage_event('delete',
                           deleted_at=timeutils.isotime(deleted_at),
                           server=old_server)