~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/scheduler/least_cost.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2011 OpenStack, LLC.
2
 
# All Rights Reserved.
3
 
#
4
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
 
#    not use this file except in compliance with the License. You may obtain
6
 
#    a copy of the License at
7
 
#
8
 
#         http://www.apache.org/licenses/LICENSE-2.0
9
 
#
10
 
#    Unless required by applicable law or agreed to in writing, software
11
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 
#    License for the specific language governing permissions and limitations
14
 
#    under the License.
15
 
"""
16
 
Least Cost is an algorithm for choosing which host machines to
17
 
provision a set of resources to. The input is a WeightedHost object which
18
 
is decided upon by a set of objective-functions, called the 'cost-functions'.
19
 
The WeightedHost contains a combined weight for each cost-function.
20
 
 
21
 
The cost-function and weights are tabulated, and the host with the least cost
22
 
is then selected for provisioning.
23
 
"""
24
 
 
25
 
from nova import flags
26
 
from nova.openstack.common import cfg
27
 
from nova.openstack.common import log as logging
28
 
 
29
 
 
30
 
LOG = logging.getLogger(__name__)
31
 
 
32
 
least_cost_opts = [
33
 
    cfg.ListOpt('least_cost_functions',
34
 
                default=[
35
 
                  'nova.scheduler.least_cost.compute_fill_first_cost_fn'
36
 
                  ],
37
 
                help='Which cost functions the LeastCostScheduler should use'),
38
 
    cfg.FloatOpt('noop_cost_fn_weight',
39
 
             default=1.0,
40
 
               help='How much weight to give the noop cost function'),
41
 
    cfg.FloatOpt('compute_fill_first_cost_fn_weight',
42
 
             default=-1.0,
43
 
               help='How much weight to give the fill-first cost function. '
44
 
                    'A negative value will reverse behavior: '
45
 
                    'e.g. spread-first'),
46
 
    ]
47
 
 
48
 
FLAGS = flags.FLAGS
49
 
FLAGS.register_opts(least_cost_opts)
50
 
 
51
 
# TODO(sirp): Once we have enough of these rules, we can break them out into a
52
 
# cost_functions.py file (perhaps in a least_cost_scheduler directory)
53
 
 
54
 
 
55
 
class WeightedHost(object):
56
 
    """Reduced set of information about a host that has been weighed.
57
 
    This is an attempt to remove some of the ad-hoc dict structures
58
 
    previously used."""
59
 
 
60
 
    def __init__(self, weight, host_state=None):
61
 
        self.weight = weight
62
 
        self.host_state = host_state
63
 
 
64
 
    def to_dict(self):
65
 
        x = dict(weight=self.weight)
66
 
        if self.host_state:
67
 
            x['host'] = self.host_state.host
68
 
        return x
69
 
 
70
 
    def __repr__(self):
71
 
        if self.host_state:
72
 
            return "WeightedHost host: %s" % self.host_state.host
73
 
        return "WeightedHost with no host_state"
74
 
 
75
 
 
76
 
def noop_cost_fn(host_state, weighing_properties):
77
 
    """Return a pre-weight cost of 1 for each host"""
78
 
    return 1
79
 
 
80
 
 
81
 
def compute_fill_first_cost_fn(host_state, weighing_properties):
82
 
    """More free ram = higher weight. So servers with less free
83
 
    ram will be preferred.
84
 
 
85
 
    Note: the weight for this function in default configuration
86
 
    is -1.0. With a -1.0 this function runs in reverse, so systems
87
 
    with the most free memory will be preferred.
88
 
    """
89
 
    return host_state.free_ram_mb
90
 
 
91
 
 
92
 
def weighted_sum(weighted_fns, host_states, weighing_properties):
93
 
    """Use the weighted-sum method to compute a score for an array of objects.
94
 
 
95
 
    Normalize the results of the objective-functions so that the weights are
96
 
    meaningful regardless of objective-function's range.
97
 
 
98
 
    :param host_list:    ``[(host, HostInfo()), ...]``
99
 
    :param weighted_fns: list of weights and functions like::
100
 
 
101
 
        [(weight, objective-functions), ...]
102
 
 
103
 
    :param weighing_properties: an arbitrary dict of values that can
104
 
        influence weights.
105
 
 
106
 
    :returns: a single WeightedHost object which represents the best
107
 
              candidate.
108
 
    """
109
 
 
110
 
    min_score, best_host = None, None
111
 
    for host_state in host_states:
112
 
        score = sum(weight * fn(host_state, weighing_properties)
113
 
                    for weight, fn in weighted_fns)
114
 
        if min_score is None or score < min_score:
115
 
            min_score, best_host = score, host_state
116
 
 
117
 
    return WeightedHost(min_score, host_state=best_host)