30
30
from nova.compute import vm_states
31
31
from nova import db
32
32
from nova import exception
33
from nova import flags
34
33
from nova import notifications
35
34
from nova.openstack.common import cfg
36
35
from nova.openstack.common import importutils
52
51
help='Maximum number of attempts to schedule an instance'),
56
FLAGS.register_opts(scheduler_driver_opts)
58
flags.DECLARE('instances_path', 'nova.compute.manager')
59
flags.DECLARE('libvirt_type', 'nova.virt.libvirt.driver')
55
CONF.register_opts(scheduler_driver_opts)
56
CONF.import_opt('compute_topic', 'nova.config')
57
CONF.import_opt('instances_path', 'nova.compute.manager')
58
CONF.import_opt('libvirt_type', 'nova.virt.libvirt.driver')
62
61
def handle_schedule_error(context, ex, instance_uuid, request_spec):
87
86
'scheduler.run_instance', notifier.ERROR, payload)
90
def cast_to_volume_host(context, host, method, **kwargs):
91
"""Cast request to a volume host queue"""
93
volume_id = kwargs.get('volume_id', None)
94
if volume_id is not None:
95
now = timeutils.utcnow()
96
db.volume_update(context, volume_id,
97
{'host': host, 'scheduled_at': now})
99
rpc.queue_get_for(context, 'volume', host),
100
{"method": method, "args": kwargs})
101
LOG.debug(_("Casted '%(method)s' to volume '%(host)s'") % locals())
104
def instance_update_db(context, instance_uuid, host):
105
'''Set the host and scheduled_at fields of an Instance.
89
def instance_update_db(context, instance_uuid):
90
'''Clear the host and set the scheduled_at field of an Instance.
107
92
:returns: An Instance with the updated fields set properly.
109
94
now = timeutils.utcnow()
110
values = {'host': host, 'scheduled_at': now}
95
values = {'host': None, 'scheduled_at': now}
96
return db.instance_update(context, instance_uuid, values)
99
def db_instance_node_set(context, instance_uuid, node):
100
'''Set the node field of an Instance.
102
:returns: An Instance with the updated fields set properly.
104
values = {'node': node}
111
105
return db.instance_update(context, instance_uuid, values)
117
111
instance_uuid = kwargs.get('instance_uuid', None)
118
112
if instance_uuid:
119
instance_update_db(context, instance_uuid, host)
113
instance_update_db(context, instance_uuid)
121
115
rpc.cast(context,
122
rpc.queue_get_for(context, 'compute', host),
116
rpc.queue_get_for(context, CONF.compute_topic, host),
123
117
{"method": method, "args": kwargs})
124
118
LOG.debug(_("Casted '%(method)s' to compute '%(host)s'") % locals())
127
def cast_to_network_host(context, host, method, **kwargs):
128
"""Cast request to a network host queue"""
131
rpc.queue_get_for(context, 'network', host),
132
{"method": method, "args": kwargs})
133
LOG.debug(_("Casted '%(method)s' to network '%(host)s'") % locals())
136
121
def cast_to_host(context, topic, host, method, **kwargs):
137
122
"""Generic cast to host"""
140
"compute": cast_to_compute_host,
141
"volume": cast_to_volume_host,
142
'network': cast_to_network_host}
124
topic_mapping = {CONF.compute_topic: cast_to_compute_host}
144
126
func = topic_mapping.get(topic)
146
func(context, host, method, **kwargs)
128
cast_to_compute_host(context, host, method, **kwargs)
148
130
rpc.cast(context,
149
131
rpc.queue_get_for(context, topic, host),
176
158
def __init__(self):
177
159
self.host_manager = importutils.import_object(
178
FLAGS.scheduler_host_manager)
160
CONF.scheduler_host_manager)
179
161
self.compute_api = compute_api.API()
180
162
self.compute_rpcapi = compute_rpcapi.ComputeAPI()
207
189
msg = _("Driver must implement schedule_run_instance")
208
190
raise NotImplementedError(msg)
210
def schedule_create_volume(self, context, volume_id, snapshot_id,
212
msg = _("Driver must implement schedule_create_volune")
213
raise NotImplementedError(msg)
215
192
def schedule_live_migration(self, context, instance, dest,
216
193
block_migration, disk_over_commit):
217
194
"""Live migration scheduling method.
340
317
mem_inst = instance_ref['memory_mb']
341
318
avail = avail - used
342
if avail <= mem_inst:
319
if not mem_inst or avail <= mem_inst:
343
320
instance_uuid = instance_ref['uuid']
344
321
reason = _("Unable to migrate %(instance_uuid)s to %(dest)s: "
345
322
"Lack of memory(host:%(avail)s <= "