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

« back to all changes in this revision

Viewing changes to nova/scheduler/weights/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-2012 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
NOTE(comstud): This is deprecated. One should use the RAMWeigher and/or
 
25
create other weight modules.
 
26
"""
 
27
 
 
28
from nova import exception
 
29
from nova.openstack.common import cfg
 
30
from nova.openstack.common import importutils
 
31
from nova.openstack.common import log as logging
 
32
 
 
33
 
 
34
LOG = logging.getLogger(__name__)
 
35
 
 
36
least_cost_opts = [
 
37
    cfg.ListOpt('least_cost_functions',
 
38
                default=None,
 
39
                help='Which cost functions the LeastCostScheduler should use'),
 
40
    cfg.FloatOpt('noop_cost_fn_weight',
 
41
                 default=1.0,
 
42
                 help='How much weight to give the noop cost function'),
 
43
    cfg.FloatOpt('compute_fill_first_cost_fn_weight',
 
44
                 default=None,
 
45
                 help='How much weight to give the fill-first cost function. '
 
46
                      'A negative value will reverse behavior: '
 
47
                      'e.g. spread-first'),
 
48
    ]
 
49
 
 
50
CONF = cfg.CONF
 
51
CONF.register_opts(least_cost_opts)
 
52
 
 
53
 
 
54
def noop_cost_fn(host_state, weight_properties):
 
55
    """Return a pre-weight cost of 1 for each host"""
 
56
    return 1
 
57
 
 
58
 
 
59
def compute_fill_first_cost_fn(host_state, weight_properties):
 
60
    """Higher weights win, so we should return a lower weight
 
61
    when there's more free ram available.
 
62
 
 
63
    Note: the weight modifier for this function in default configuration
 
64
    is -1.0. With -1.0 this function runs in reverse, so systems
 
65
    with the most free memory will be preferred.
 
66
    """
 
67
    return -host_state.free_ram_mb
 
68
 
 
69
 
 
70
def _get_cost_functions():
 
71
    """Returns a list of tuples containing weights and cost functions to
 
72
    use for weighing hosts
 
73
    """
 
74
    cost_fns_conf = CONF.least_cost_functions
 
75
    if cost_fns_conf is None:
 
76
        # The old default.  This will get fixed up below.
 
77
        fn_str = 'nova.scheduler.least_cost.compute_fill_first_cost_fn'
 
78
        cost_fns_conf = [fn_str]
 
79
    cost_fns = []
 
80
    for cost_fn_str in cost_fns_conf:
 
81
        short_name = cost_fn_str.split('.')[-1]
 
82
        if not (short_name.startswith('compute_') or
 
83
                short_name.startswith('noop')):
 
84
            continue
 
85
        # Fix up any old paths to the new paths
 
86
        if cost_fn_str.startswith('nova.scheduler.least_cost.'):
 
87
            cost_fn_str = ('nova.scheduler.weights.least_cost' +
 
88
                       cost_fn_str[25:])
 
89
        try:
 
90
            # NOTE: import_class is somewhat misnamed since
 
91
            # the weighing function can be any non-class callable
 
92
            # (i.e., no 'self')
 
93
            cost_fn = importutils.import_class(cost_fn_str)
 
94
        except ImportError:
 
95
            raise exception.SchedulerCostFunctionNotFound(
 
96
                    cost_fn_str=cost_fn_str)
 
97
 
 
98
        try:
 
99
            flag_name = "%s_weight" % cost_fn.__name__
 
100
            weight = getattr(CONF, flag_name)
 
101
        except AttributeError:
 
102
            raise exception.SchedulerWeightFlagNotFound(
 
103
                    flag_name=flag_name)
 
104
        # Set the original default.
 
105
        if (flag_name == 'compute_fill_first_cost_fn_weight' and
 
106
                weight is None):
 
107
            weight = -1.0
 
108
        cost_fns.append((weight, cost_fn))
 
109
    return cost_fns
 
110
 
 
111
 
 
112
def get_least_cost_weighers():
 
113
    cost_functions = _get_cost_functions()
 
114
 
 
115
    # Unfortunately we need to import this late so we don't have an
 
116
    # import loop.
 
117
    from nova.scheduler import weights
 
118
 
 
119
    class _LeastCostWeigher(weights.BaseHostWeigher):
 
120
        def weigh_objects(self, weighted_hosts, weight_properties):
 
121
            for host in weighted_hosts:
 
122
                host.weight = sum(weight * fn(host.obj, weight_properties)
 
123
                            for weight, fn in cost_functions)
 
124
 
 
125
    return [_LeastCostWeigher]