~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/scheduler/host_manager.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman, Adam Gandelman, Chuck Short
  • Date: 2012-08-27 15:37:18 UTC
  • mfrom: (1.1.60)
  • Revision ID: package-import@ubuntu.com-20120827153718-lj8er44eqqz1gsrj
Tags: 2012.2~rc1~20120827.15815-0ubuntu1
[ Adam Gandelman ]
* New upstream release.

[ Chuck Short ]
* debian/patches/0001-Update-tools-hacking-for-pep8-1.2-and-
  beyond.patch: Dropped we dont run pep8 tests anymore.
* debian/control: Drop pep8 build depends
* debian/*.upstart.in: Make sure we transition correctly from runlevel
  1 to 2. (LP: #820694)

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
                  'AvailabilityZoneFilter',
48
48
                  'RamFilter',
49
49
                  'ComputeFilter',
50
 
                  'ComputeCapabilitiesFilter'
 
50
                  'ComputeCapabilitiesFilter',
 
51
                  'ImagePropertiesFilter'
51
52
                  ],
52
53
                help='Which filter class names to use for filtering hosts '
53
54
                      'when not specified in the request.'),
120
121
        """Update information about a host from its compute_node info."""
121
122
        all_disk_mb = compute['local_gb'] * 1024
122
123
        all_ram_mb = compute['memory_mb']
123
 
        vcpus_total = compute['vcpus']
 
124
 
 
125
        free_disk_mb = compute['free_disk_gb'] * 1024
 
126
        free_ram_mb = compute['free_ram_mb']
 
127
 
124
128
        if FLAGS.reserved_host_disk_mb > 0:
125
129
            all_disk_mb -= FLAGS.reserved_host_disk_mb
 
130
            free_disk_mb -= FLAGS.reserved_host_disk_mb
126
131
        if FLAGS.reserved_host_memory_mb > 0:
127
132
            all_ram_mb -= FLAGS.reserved_host_memory_mb
 
133
            free_ram_mb -= FLAGS.reserved_host_memory_mb
 
134
 
128
135
        #NOTE(jogo) free_ram_mb can be negative
129
 
        self.free_ram_mb = all_ram_mb
 
136
        self.free_ram_mb = free_ram_mb
130
137
        self.total_usable_ram_mb = all_ram_mb
131
 
        self.free_disk_mb = all_disk_mb
132
 
        self.vcpus_total = vcpus_total
 
138
        self.free_disk_mb = free_disk_mb
 
139
        self.vcpus_total = compute['vcpus']
 
140
        self.vcpus_used = compute['vcpus_used']
133
141
 
134
142
    def consume_from_instance(self, instance):
135
 
        """Update information about a host from instance info."""
 
143
        """Incrementally update host state from an instance"""
136
144
        disk_mb = (instance['root_gb'] + instance['ephemeral_gb']) * 1024
137
145
        ram_mb = instance['memory_mb']
138
146
        vcpus = instance['vcpus']
174
182
class HostManager(object):
175
183
    """Base HostManager class."""
176
184
 
177
 
    # Can be overriden in a subclass
 
185
    # Can be overridden in a subclass
178
186
    host_state_cls = HostState
179
187
 
180
188
    def __init__(self):
252
260
 
253
261
        host_state_map = {}
254
262
 
255
 
        # Make a compute node dict with the bare essential metrics.
 
263
        # Get resource usage across the available compute nodes:
256
264
        compute_nodes = db.compute_node_get_all(context)
257
265
        for compute in compute_nodes:
258
266
            service = compute['service']
267
275
            host_state.update_from_compute_node(compute)
268
276
            host_state_map[host] = host_state
269
277
 
270
 
        # "Consume" resources from the host the instance resides on.
271
 
        instances = db.instance_get_all(context,
272
 
                columns_to_join=['instance_type'])
273
 
        for instance in instances:
274
 
            host = instance['host']
275
 
            if not host:
276
 
                continue
277
 
            host_state = host_state_map.get(host, None)
278
 
            if not host_state:
279
 
                continue
280
 
            host_state.consume_from_instance(instance)
281
278
        return host_state_map