コード例 #1
0
    def test_verify_index(self):
        req = webob.Request.blank(
                    '/v2/faketenant_0/os-simple-tenant-usage?start=%s&end=%s' %
                    (START.isoformat(), STOP.isoformat()))
        req.method = "GET"
        req.headers["content-type"] = "application/json"

        res = req.get_response(fakes.wsgi_app(
                               fake_auth_context=self.admin_context))

        self.assertEqual(res.status_int, 200)
        res_dict = json.loads(res.body)
        usages = res_dict['tenant_usages']
        from nova import log as logging
        logging.warn(usages)
        for i in xrange(TENANTS):
            self.assertEqual(int(usages[i]['total_hours']),
                             SERVERS * HOURS)
            self.assertEqual(int(usages[i]['total_local_gb_usage']),
                             SERVERS * (ROOT_GB + EPHEMERAL_GB) * HOURS)
            self.assertEqual(int(usages[i]['total_memory_mb_usage']),
                             SERVERS * MEMORY_MB * HOURS)
            self.assertEqual(int(usages[i]['total_vcpus_usage']),
                             SERVERS * VCPUS * HOURS)
            self.assertFalse(usages[i].get('server_usages'))
コード例 #2
0
ファイル: service.py プロジェクト: CorCornelisse/nova
 def kill(self):
     """Destroy the service object in the datastore."""
     self.stop()
     try:
         db.service_destroy(context.get_admin_context(), self.service_id)
     except exception.NotFound:
         logging.warn(_('Service killed that has no database entry'))
コード例 #3
0
def upgrade(migrate_engine):
    meta.bind = migrate_engine
    instances = Table('instances', meta, autoload=True,
                      autoload_with=migrate_engine)

    types = {}
    for instance in migrate_engine.execute(instances.select()):
        if instance.instance_type_id is None:
            types[instance.id] = None
            continue
        try:
            types[instance.id] = int(instance.instance_type_id)
        except ValueError:
            logging.warn("Instance %s did not have instance_type_id "
                         "converted to an integer because its value is %s" %
                          (instance.id, instance.instance_type_id))
            types[instance.id] = None

    integer_column = Column('instance_type_id_int', Integer(), nullable=True)
    string_column = instances.c.instance_type_id

    integer_column.create(instances)
    for instance_id, instance_type_id in types.iteritems():
        update = instances.update().\
                where(instances.c.id == instance_id).\
                values(instance_type_id_int=instance_type_id)
        migrate_engine.execute(update)

    string_column.alter(name='instance_type_id_str')
    integer_column.alter(name='instance_type_id')
    string_column.drop()
コード例 #4
0
ファイル: service.py プロジェクト: cp16net/reddwarf
 def kill(self):
     """Destroy the service object in the datastore."""
     self.stop()
     try:
         db.service_destroy(context.get_admin_context(), self.service_id)
     except exception.NotFound:
         logging.warn(_('Service killed that has no database entry'))
コード例 #5
0
ファイル: zone_manager.py プロジェクト: yamahata/nova
    def get_all_host_data(self, context):
        """Returns a dict of all the hosts the ZoneManager
        knows about. Also, each of the consumable resources in HostInfo
        are pre-populated and adjusted based on data in the db.

        For example:
        {'192.168.1.100': HostInfo(), ...}

        Note: this can be very slow with a lot of instances.
        InstanceType table isn't required since a copy is stored
        with the instance (in case the InstanceType changed since the
        instance was created)."""

        # Make a compute node dict with the bare essential metrics.
        compute_nodes = self._compute_node_get_all(context)
        host_info_map = {}
        for compute in compute_nodes:
            all_disk = compute['local_gb']
            all_ram = compute['memory_mb']
            service = compute['service']
            if not service:
                logging.warn(_("No service for compute ID %s") % compute['id'])
                continue

            host = service['host']
            caps = self.service_states.get(host, None)
            host_info = HostInfo(host,
                                 caps=caps,
                                 free_disk_gb=all_disk,
                                 free_ram_mb=all_ram)
            # Reserve resources for host/dom0
            host_info.consume_resources(FLAGS.reserved_host_disk_mb * 1024,
                                        FLAGS.reserved_host_memory_mb)
            host_info_map[host] = host_info

        # "Consume" resources from the host the instance resides on.
        instances = self._instance_get_all(context)
        for instance in instances:
            host = instance['host']
            if not host:
                continue
            host_info = host_info_map.get(host, None)
            if not host_info:
                continue
            disk = instance['local_gb']
            ram = instance['memory_mb']
            host_info.consume_resources(disk, ram)

        return host_info_map
コード例 #6
0
ファイル: zone_manager.py プロジェクト: BillTheBest/nova
    def get_all_host_data(self, context):
        """Returns a dict of all the hosts the ZoneManager
        knows about. Also, each of the consumable resources in HostInfo
        are pre-populated and adjusted based on data in the db.

        For example:
        {'192.168.1.100': HostInfo(), ...}

        Note: this can be very slow with a lot of instances.
        InstanceType table isn't required since a copy is stored
        with the instance (in case the InstanceType changed since the
        instance was created)."""

        # Make a compute node dict with the bare essential metrics.
        compute_nodes = self._compute_node_get_all(context)
        host_info_map = {}
        for compute in compute_nodes:
            all_disk = compute['local_gb']
            all_ram = compute['memory_mb']
            service = compute['service']
            if not service:
                logging.warn(_("No service for compute ID %s") % compute['id'])
                continue

            host = service['host']
            caps = self.service_states.get(host, None)
            host_info = HostInfo(host, caps=caps,
                    free_disk_gb=all_disk, free_ram_mb=all_ram)
            # Reserve resources for host/dom0
            host_info.consume_resources(FLAGS.reserved_host_disk_mb * 1024,
                    FLAGS.reserved_host_memory_mb)
            host_info_map[host] = host_info

        # "Consume" resources from the host the instance resides on.
        instances = self._instance_get_all(context)
        for instance in instances:
            host = instance['host']
            if not host:
                continue
            host_info = host_info_map.get(host, None)
            if not host_info:
                continue
            disk = instance['local_gb']
            ram = instance['memory_mb']
            host_info.consume_resources(disk, ram)

        return host_info_map
コード例 #7
0
ファイル: host_manager.py プロジェクト: xtoddx/nova
    def get_all_host_states(self, context, topic):
        """Returns a dict of all the hosts the HostManager
        knows about. Also, each of the consumable resources in HostState
        are pre-populated and adjusted based on data in the db.

        For example:
        {'192.168.1.100': HostState(), ...}

        Note: this can be very slow with a lot of instances.
        InstanceType table isn't required since a copy is stored
        with the instance (in case the InstanceType changed since the
        instance was created)."""

        if topic != 'compute':
            raise NotImplementedError(
                _("host_manager only implemented for 'compute'"))

        host_state_map = {}

        # Make a compute node dict with the bare essential metrics.
        compute_nodes = db.compute_node_get_all(context)
        for compute in compute_nodes:
            service = compute['service']
            if not service:
                logging.warn(_("No service for compute ID %s") % compute['id'])
                continue
            host = service['host']
            capabilities = self.service_states.get(host, None)
            host_state = self.host_state_cls(host,
                                             topic,
                                             capabilities=capabilities,
                                             service=dict(service.iteritems()))
            host_state.update_from_compute_node(compute)
            host_state_map[host] = host_state

        # "Consume" resources from the host the instance resides on.
        instances = db.instance_get_all(context)
        for instance in instances:
            host = instance['host']
            if not host:
                continue
            host_state = host_state_map.get(host, None)
            if not host_state:
                continue
            host_state.consume_from_instance(instance)
        return host_state_map
コード例 #8
0
ファイル: host_manager.py プロジェクト: littleidea/nova
    def get_all_host_states(self, context, topic):
        """Returns a dict of all the hosts the HostManager
        knows about. Also, each of the consumable resources in HostState
        are pre-populated and adjusted based on data in the db.

        For example:
        {'192.168.1.100': HostState(), ...}

        Note: this can be very slow with a lot of instances.
        InstanceType table isn't required since a copy is stored
        with the instance (in case the InstanceType changed since the
        instance was created)."""

        if topic != 'compute':
            raise NotImplementedError(_(
                "host_manager only implemented for 'compute'"))

        host_state_map = {}

        # Make a compute node dict with the bare essential metrics.
        compute_nodes = db.compute_node_get_all(context)
        for compute in compute_nodes:
            service = compute['service']
            if not service:
                logging.warn(_("No service for compute ID %s") % compute['id'])
                continue
            host = service['host']
            capabilities = self.service_states.get(host, None)
            host_state = self.host_state_cls(host, topic,
                    capabilities=capabilities,
                    service=dict(service.iteritems()))
            host_state.update_from_compute_node(compute)
            host_state_map[host] = host_state

        # "Consume" resources from the host the instance resides on.
        instances = db.instance_get_all(context)
        for instance in instances:
            host = instance['host']
            if not host:
                continue
            host_state = host_state_map.get(host, None)
            if not host_state:
                continue
            host_state.consume_from_instance(instance)
        return host_state_map
コード例 #9
0
ファイル: test_host_manager.py プロジェクト: KarimAllah/nova
    def test_get_all_host_states(self):
        self.flags(reserved_host_memory_mb=512,
                reserved_host_disk_mb=1024)

        context = 'fake_context'
        topic = 'compute'

        self.mox.StubOutWithMock(db, 'compute_node_get_all')
        self.mox.StubOutWithMock(logging, 'warn')
        self.mox.StubOutWithMock(db, 'instance_get_all')

        db.compute_node_get_all(context).AndReturn(fakes.COMPUTE_NODES)
        # Invalid service
        logging.warn("No service for compute ID 5")
        db.instance_get_all(context).AndReturn(fakes.INSTANCES)

        self.mox.ReplayAll()
        host_states = self.host_manager.get_all_host_states(context, topic)
        self.mox.VerifyAll()

        self.assertEqual(len(host_states), 4)
        # Check that .service is set properly
        for i in xrange(4):
            compute_node = fakes.COMPUTE_NODES[i]
            host = compute_node['service']['host']
            self.assertEqual(host_states[host].service,
                    compute_node['service'])
        self.assertEqual(host_states['host1'].free_ram_mb, 0)
        # 511GB
        self.assertEqual(host_states['host1'].free_disk_mb, 523264)
        self.assertEqual(host_states['host2'].free_ram_mb, 512)
        # 1023GB
        self.assertEqual(host_states['host2'].free_disk_mb, 1047552)
        self.assertEqual(host_states['host3'].free_ram_mb, 2560)
        # 3071GB
        self.assertEqual(host_states['host3'].free_disk_mb, 3144704)
        self.assertEqual(host_states['host4'].free_ram_mb, 7680)
        # 8191GB
        self.assertEqual(host_states['host4'].free_disk_mb, 8387584)
コード例 #10
0
    def test_get_all_host_states(self):
        self.flags(reserved_host_memory_mb=512, reserved_host_disk_mb=1024)

        context = 'fake_context'
        topic = 'compute'

        self.mox.StubOutWithMock(db, 'compute_node_get_all')
        self.mox.StubOutWithMock(logging, 'warn')
        self.mox.StubOutWithMock(db, 'instance_get_all')

        db.compute_node_get_all(context).AndReturn(fakes.COMPUTE_NODES)
        # Invalid service
        logging.warn("No service for compute ID 5")
        db.instance_get_all(context).AndReturn(fakes.INSTANCES)

        self.mox.ReplayAll()
        host_states = self.host_manager.get_all_host_states(context, topic)
        self.mox.VerifyAll()

        self.assertEqual(len(host_states), 4)
        # Check that .service is set properly
        for i in xrange(4):
            compute_node = fakes.COMPUTE_NODES[i]
            host = compute_node['service']['host']
            self.assertEqual(host_states[host].service,
                             compute_node['service'])
        self.assertEqual(host_states['host1'].free_ram_mb, 0)
        # 511GB
        self.assertEqual(host_states['host1'].free_disk_mb, 523264)
        self.assertEqual(host_states['host2'].free_ram_mb, 512)
        # 1023GB
        self.assertEqual(host_states['host2'].free_disk_mb, 1047552)
        self.assertEqual(host_states['host3'].free_ram_mb, 2560)
        # 3071GB
        self.assertEqual(host_states['host3'].free_disk_mb, 3144704)
        self.assertEqual(host_states['host4'].free_ram_mb, 7680)
        # 8191GB
        self.assertEqual(host_states['host4'].free_disk_mb, 8387584)
コード例 #11
0
    def test_verify_index(self):
        req = webob.Request.blank(
            '/v1.1/faketenant_0/os-simple-tenant-usage?start=%s&end=%s' %
            (START.isoformat(), STOP.isoformat()))
        req.method = "GET"
        req.headers["content-type"] = "application/json"

        res = req.get_response(
            fakes.wsgi_app(fake_auth_context=self.admin_context))

        self.assertEqual(res.status_int, 200)
        res_dict = json.loads(res.body)
        usages = res_dict['tenant_usages']
        from nova import log as logging
        logging.warn(usages)
        for i in xrange(TENANTS):
            self.assertEqual(int(usages[i]['total_hours']), SERVERS * HOURS)
            self.assertEqual(int(usages[i]['total_local_gb_usage']),
                             SERVERS * LOCAL_GB * HOURS)
            self.assertEqual(int(usages[i]['total_memory_mb_usage']),
                             SERVERS * MEMORY_MB * HOURS)
            self.assertEqual(int(usages[i]['total_vcpus_usage']),
                             SERVERS * VCPUS * HOURS)
            self.assertFalse(usages[i].get('server_usages'))