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

« back to all changes in this revision

Viewing changes to nova/scheduler/manager.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from nova import flags
30
30
from nova import manager
31
31
from nova import notifications
32
 
from nova.notifier import api as notifier
33
32
from nova.openstack.common import cfg
34
33
from nova.openstack.common import excutils
35
34
from nova.openstack.common import importutils
36
35
from nova.openstack.common import log as logging
 
36
from nova.openstack.common.notifier import api as notifier
 
37
from nova.openstack.common.rpc import common as rpc_common
37
38
from nova import quota
38
39
 
39
40
 
52
53
class SchedulerManager(manager.Manager):
53
54
    """Chooses a host to run instances on."""
54
55
 
55
 
    RPC_API_VERSION = '1.0'
 
56
    RPC_API_VERSION = '1.5'
56
57
 
57
58
    def __init__(self, scheduler_driver=None, *args, **kwargs):
58
59
        if not scheduler_driver:
68
69
        return functools.partial(self._schedule, key)
69
70
 
70
71
    def get_host_list(self, context):
71
 
        """Get a list of hosts from the HostManager."""
72
 
        return self.driver.get_host_list()
 
72
        """Get a list of hosts from the HostManager.
 
73
 
 
74
        Currently unused, but left for backwards compatibility.
 
75
        """
 
76
        raise rpc_common.RPCException(message=_('Deprecated in version 1.0'))
73
77
 
74
78
    def get_service_capabilities(self, context):
75
 
        """Get the normalized set of capabilities for this zone."""
76
 
        return self.driver.get_service_capabilities()
 
79
        """Get the normalized set of capabilities for this zone.
 
80
 
 
81
        Has been unused since pre-essex, but remains for rpc API 1.X
 
82
        completeness.
 
83
        """
 
84
        raise rpc_common.RPCException(message=_('Deprecated in version 1.0'))
77
85
 
78
86
    def update_service_capabilities(self, context, service_name=None,
79
87
            host=None, capabilities=None, **kwargs):
102
110
            return driver_method(*args, **kwargs)
103
111
        except Exception as ex:
104
112
            with excutils.save_and_reraise_exception():
 
113
                request_spec = kwargs.get('request_spec', {})
105
114
                self._set_vm_state_and_notify(method,
106
115
                                             {'vm_state': vm_states.ERROR},
107
 
                                             context, ex, *args, **kwargs)
 
116
                                             context, ex, request_spec)
108
117
 
109
 
    def run_instance(self, context, topic, *args, **kwargs):
 
118
    def run_instance(self, context, request_spec, admin_password,
 
119
            injected_files, requested_networks, is_first_time,
 
120
            filter_properties, reservations, topic=None):
110
121
        """Tries to call schedule_run_instance on the driver.
111
122
        Sets instance vm_state to ERROR on exceptions
112
123
        """
113
 
        args = (context,) + args
114
 
        reservations = kwargs.get('reservations', None)
115
124
        try:
116
 
            result = self.driver.schedule_run_instance(*args, **kwargs)
 
125
            result = self.driver.schedule_run_instance(context,
 
126
                    request_spec, admin_password, injected_files,
 
127
                    requested_networks, is_first_time, filter_properties,
 
128
                    reservations)
117
129
            return result
118
130
        except exception.NoValidHost as ex:
119
131
            # don't reraise
120
132
            self._set_vm_state_and_notify('run_instance',
121
133
                                         {'vm_state': vm_states.ERROR},
122
 
                                          context, ex, *args, **kwargs)
 
134
                                          context, ex, request_spec)
123
135
            if reservations:
124
136
                QUOTAS.rollback(context, reservations)
125
137
        except Exception as ex:
126
138
            with excutils.save_and_reraise_exception():
127
139
                self._set_vm_state_and_notify('run_instance',
128
140
                                             {'vm_state': vm_states.ERROR},
129
 
                                             context, ex, *args, **kwargs)
 
141
                                             context, ex, request_spec)
130
142
                if reservations:
131
143
                    QUOTAS.rollback(context, reservations)
132
144
 
133
 
    def prep_resize(self, context, topic, *args, **kwargs):
 
145
    # FIXME(comstud): Remove 'update_db' in a future version.  It's only
 
146
    # here for rpcapi backwards compatibility.
 
147
    def prep_resize(self, context, image, request_spec, filter_properties,
 
148
                    update_db=None, instance=None, instance_uuid=None,
 
149
                    instance_type=None, instance_type_id=None,
 
150
                    reservations=None, topic=None):
134
151
        """Tries to call schedule_prep_resize on the driver.
135
152
        Sets instance vm_state to ACTIVE on NoHostFound
136
153
        Sets vm_state to ERROR on other exceptions
137
154
        """
138
 
        args = (context,) + args
 
155
        if not instance:
 
156
            instance = db.instance_get_by_uuid(context, instance_uuid)
 
157
 
 
158
        if not instance_type:
 
159
            instance_type = db.instance_type_get(context, instance_type_id)
 
160
 
139
161
        try:
140
 
            return self.driver.schedule_prep_resize(*args, **kwargs)
 
162
            kwargs = {
 
163
                'context': context,
 
164
                'image': image,
 
165
                'request_spec': request_spec,
 
166
                'filter_properties': filter_properties,
 
167
                'instance': instance,
 
168
                'instance_type': instance_type,
 
169
                'reservations': reservations,
 
170
            }
 
171
            return self.driver.schedule_prep_resize(**kwargs)
141
172
        except exception.NoValidHost as ex:
142
173
            self._set_vm_state_and_notify('prep_resize',
143
174
                                         {'vm_state': vm_states.ACTIVE,
144
175
                                          'task_state': None},
145
 
                                         context, ex, *args, **kwargs)
 
176
                                         context, ex, request_spec)
 
177
            if reservations:
 
178
                QUOTAS.rollback(context, reservations)
146
179
        except Exception as ex:
147
180
            with excutils.save_and_reraise_exception():
148
181
                self._set_vm_state_and_notify('prep_resize',
149
182
                                             {'vm_state': vm_states.ERROR},
150
 
                                             context, ex, *args, **kwargs)
 
183
                                             context, ex, request_spec)
 
184
                if reservations:
 
185
                    QUOTAS.rollback(context, reservations)
151
186
 
152
187
    def _set_vm_state_and_notify(self, method, updates, context, ex,
153
 
                                *args, **kwargs):
 
188
                                 request_spec):
154
189
        """changes VM state and notifies"""
155
190
        # FIXME(comstud): Re-factor this somehow. Not sure this belongs in the
156
191
        # scheduler manager like this. We should make this easier.
166
201
        LOG.warning(_("Failed to schedule_%(method)s: %(ex)s") % locals())
167
202
 
168
203
        vm_state = updates['vm_state']
169
 
        request_spec = kwargs.get('request_spec', {})
170
204
        properties = request_spec.get('instance_properties', {})
171
205
        instance_uuid = properties.get('uuid', {})
172
206