~ubuntu-branches/ubuntu/saucy/nova/saucy-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-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from nova import manager
32
32
from nova.notifier import api as notifier
33
33
from nova.openstack.common import cfg
34
 
from nova import utils
 
34
from nova.openstack.common import excutils
 
35
from nova.openstack.common import importutils
 
36
from nova import quota
35
37
 
36
38
 
37
39
LOG = logging.getLogger(__name__)
43
45
FLAGS = flags.FLAGS
44
46
FLAGS.register_opt(scheduler_driver_opt)
45
47
 
 
48
QUOTAS = quota.QUOTAS
 
49
 
46
50
 
47
51
class SchedulerManager(manager.Manager):
48
52
    """Chooses a host to run instances on."""
49
53
 
 
54
    RPC_API_VERSION = '1.0'
 
55
 
50
56
    def __init__(self, scheduler_driver=None, *args, **kwargs):
51
57
        if not scheduler_driver:
52
58
            scheduler_driver = FLAGS.scheduler_driver
53
 
        self.driver = utils.import_object(scheduler_driver)
 
59
        self.driver = importutils.import_object(scheduler_driver)
54
60
        super(SchedulerManager, self).__init__(*args, **kwargs)
55
61
 
56
62
    def __getattr__(self, key):
57
63
        """Converts all method calls to use the schedule method"""
 
64
        # NOTE(russellb) Because of what this is doing, we must be careful
 
65
        # when changing the API of the scheduler drivers, as that changes
 
66
        # the rpc API as well, and the version should be updated accordingly.
58
67
        return functools.partial(self._schedule, key)
59
68
 
60
69
    def get_host_list(self, context):
91
100
        try:
92
101
            return driver_method(*args, **kwargs)
93
102
        except Exception as ex:
94
 
            with utils.save_and_reraise_exception():
 
103
            with excutils.save_and_reraise_exception():
95
104
                self._set_vm_state_and_notify(method,
96
105
                                             {'vm_state': vm_states.ERROR},
97
106
                                             context, ex, *args, **kwargs)
109
118
                                         {'vm_state': vm_states.ERROR},
110
119
                                          context, ex, *args, **kwargs)
111
120
        except Exception as ex:
112
 
            with utils.save_and_reraise_exception():
 
121
            with excutils.save_and_reraise_exception():
113
122
                self._set_vm_state_and_notify('run_instance',
114
123
                                             {'vm_state': vm_states.ERROR},
115
124
                                             context, ex, *args, **kwargs)
128
137
                                          'task_state': None},
129
138
                                         context, ex, *args, **kwargs)
130
139
        except Exception as ex:
131
 
            with utils.save_and_reraise_exception():
 
140
            with excutils.save_and_reraise_exception():
132
141
                self._set_vm_state_and_notify('prep_resize',
133
142
                                             {'vm_state': vm_states.ERROR},
134
143
                                             context, ex, *args, **kwargs)
156
165
 
157
166
        if instance_uuid:
158
167
            state = vm_state.upper()
159
 
            msg = _("Setting instance %(instance_uuid)s to %(state)s state.")
160
 
            LOG.warning(msg % locals())
 
168
            LOG.warning(_('Setting instance to %(state)s state.'), locals(),
 
169
                        instance_uuid=instance_uuid)
161
170
            db.instance_update(context, instance_uuid, updates)
162
171
 
163
172
        payload = dict(request_spec=request_spec,
167
176
                       method=method,
168
177
                       reason=ex)
169
178
 
170
 
        notifier.notify(notifier.publisher_id("scheduler"),
 
179
        notifier.notify(context, notifier.publisher_id("scheduler"),
171
180
                        'scheduler.' + method, notifier.ERROR, payload)
172
181
 
173
182
    # NOTE (masumotok) : This method should be moved to nova.api.ec2.admin.
227
236
                                 'ephemeral_gb': sum(ephemeral)}
228
237
 
229
238
        return {'resource': resource, 'usage': usage}
 
239
 
 
240
    @manager.periodic_task
 
241
    def _expire_reservations(self, context):
 
242
        QUOTAS.expire(context)