Ejemplo n.º 1
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)
Ejemplo n.º 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)
Ejemplo n.º 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())
Ejemplo n.º 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_memory_size,
                                    instance_size=self.new_memory_size,
                                    launched_at=timeutils.isotime(),
                                    modify_at=timeutils.isotime())
Ejemplo n.º 5
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", "")
        }
        }
Ejemplo n.º 6
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", "")
        }
        }
Ejemplo n.º 7
0
    def send_usage_event(self, event_type, **kwargs):
        event_type = 'reddwarf.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,
            'display_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.reddwarf_volume_support:
            payload.update({
                'volume_size': self.volume_size,
                'nova_volume_id': self.volume_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)
Ejemplo n.º 8
0
    def send_usage_event(self, event_type, **kwargs):
        event_type = 'reddwarf.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,
            'display_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.reddwarf_volume_support:
            payload.update({
                'volume_size': self.volume_size,
                'nova_volume_id': self.volume_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)
Ejemplo n.º 9
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.reddwarf_dns_support
            LOG.debug(_("reddwarf 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)
Ejemplo n.º 10
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.reddwarf_dns_support
            LOG.debug(_("reddwarf 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)