diff options
| author | Salvatore Orlando <salvatore.orlando@eu.citrix.com> | 2011-02-08 16:39:46 +0000 |
|---|---|---|
| committer | Salvatore Orlando <salvatore.orlando@eu.citrix.com> | 2011-02-08 16:39:46 +0000 |
| commit | 653ff11692fa5cd5ec5f9ea75cddc03df1b3dcd5 (patch) | |
| tree | bfb9c9e3f89b9b6af414afb68276ff5c03699871 /nova/virt | |
| parent | 035136525ef7944d3da4dcf8a4b0d28840bdfae3 (diff) | |
| download | nova-653ff11692fa5cd5ec5f9ea75cddc03df1b3dcd5.tar.gz nova-653ff11692fa5cd5ec5f9ea75cddc03df1b3dcd5.tar.xz nova-653ff11692fa5cd5ec5f9ea75cddc03df1b3dcd5.zip | |
avoiding HOST_UNAVAILABLE exception: if there is not enough free memory does not spawn the VM at all.
instance state is set to "SHUTDOWN"
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/xenapi/vm_utils.py | 11 | ||||
| -rw-r--r-- | nova/virt/xenapi/vmops.py | 9 |
2 files changed, 19 insertions, 1 deletions
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 4bbd522c1..3a0f0a149 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -139,6 +139,17 @@ class VMHelper(HelperBase): return vm_ref @classmethod + def ensure_free_mem(cls, session, instance): + instance_type = instance_types.INSTANCE_TYPES[instance.instance_type] + mem = str(long(instance_type['memory_mb']) * 1024 * 1024) + #get free memory from host + host = session.get_xenapi_host() + host_free_mem = session.get_xenapi().host.compute_free_memory(host) + if (host_free_mem < mem ): + return False + return True + + @classmethod def create_vbd(cls, session, vm_ref, vdi_ref, userdevice, bootable): """Create a VBD record. Returns a Deferred that gives the new VBD reference.""" diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index e84ce20c4..2d4e53083 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -66,7 +66,14 @@ class VMOps(object): if vm is not None: raise exception.Duplicate(_('Attempted to create' ' non-unique name %s') % instance.name) - + #ensure enough free memory, otherwise don't bother + if not VMHelper.ensure_free_mem(self._session,instance): + LOG.exception(_('instance %s: not enough free memory'), + instance['name']) + db.instance_set_state(context.get_admin_context(), + instance['id'], + power_state.SHUTDOWN) + return bridge = db.network_get_by_instance(context.get_admin_context(), instance['id'])['bridge'] network_ref = \ |
