From a66ae006e0a6103ee6db49ad2b8dc4506969178e Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Wed, 8 Jun 2011 15:45:23 +0000 Subject: Look for vm_mode property on images and use that if it exists to determine if image should be run in PV or HVM mode. If it doesn't exist, fall back to existing logic --- nova/compute/api.py | 6 ++- .../versions/022_add_vm_mode_to_instances.py | 43 ++++++++++++++++++++++ nova/db/sqlalchemy/models.py | 1 + nova/virt/xenapi/vmops.py | 11 ++++-- 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 nova/db/sqlalchemy/migrate_repo/versions/022_add_vm_mode_to_instances.py diff --git a/nova/compute/api.py b/nova/compute/api.py index 4f327fab1..5ea086088 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -166,6 +166,9 @@ class API(base.Base): os_type = None if 'properties' in image and 'os_type' in image['properties']: os_type = image['properties']['os_type'] + vm_mode = None + if 'properties' in image and 'vm_mode' in image['properties']: + vm_mode = image['properties']['vm_mode'] if kernel_id is None: kernel_id = image['properties'].get('kernel_id', None) @@ -224,7 +227,8 @@ class API(base.Base): 'locked': False, 'metadata': metadata, 'availability_zone': availability_zone, - 'os_type': os_type} + 'os_type': os_type, + 'vm_mode': vm_mode} elevated = context.elevated() instances = [] LOG.debug(_("Going to run %s instances..."), num_instances) diff --git a/nova/db/sqlalchemy/migrate_repo/versions/022_add_vm_mode_to_instances.py b/nova/db/sqlalchemy/migrate_repo/versions/022_add_vm_mode_to_instances.py new file mode 100644 index 000000000..5b6a25e41 --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/022_add_vm_mode_to_instances.py @@ -0,0 +1,43 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 OpenStack LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from sqlalchemy import Column, Integer, MetaData, String, Table + +meta = MetaData() + +instances = Table('instances', meta, + Column('id', Integer(), primary_key=True, nullable=False), + ) + +instances_vm_mode = Column('vm_mode', + String(length=255, convert_unicode=False, + assert_unicode=None, unicode_error=None, + _warn_on_bytestring=False), + nullable=True) + + +def upgrade(migrate_engine): + # Upgrade operations go here. Don't create your own engine; + # bind migrate_engine to your metadata + meta.bind = migrate_engine + + instances.create_column(instances_vm_mode) + + +def downgrade(migrate_engine): + meta.bind = migrate_engine + + instances.drop_column('vm_mode') diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 239f6e96a..612ccc93f 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -232,6 +232,7 @@ class Instance(BASE, NovaBase): locked = Column(Boolean) os_type = Column(String(255)) + vm_mode = Column(String(255)) # TODO(vish): see Ewan's email about state improvements, probably # should be in a driver base class or some such diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 32dae97c2..3b793113f 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -160,9 +160,14 @@ class VMOps(object): # Create the VM ref and attach the first disk first_vdi_ref = self._session.call_xenapi('VDI.get_by_uuid', vdis[0]['vdi_uuid']) - use_pv_kernel = VMHelper.determine_is_pv(self._session, - instance.id, first_vdi_ref, disk_image_type, - instance.os_type) + if instance.vm_mode in ('pv', 'PV'): + use_pv_kernel = True + elif instance.vm_mode in ('hv', 'HV', 'hvm', 'HVM'): + use_pv_kernel = False + else: + use_pv_kernel = VMHelper.determine_is_pv(self._session, + instance.id, first_vdi_ref, disk_image_type, + instance.os_type) vm_ref = VMHelper.create_vm(self._session, instance, kernel, ramdisk, use_pv_kernel) VMHelper.create_vbd(session=self._session, vm_ref=vm_ref, -- cgit From f20c73bbe395a93c087562966b10ade3c9f32afc Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Wed, 8 Jun 2011 22:28:28 +0000 Subject: Normalize and update database with used vm_mode --- nova/virt/xenapi/vmops.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 3b793113f..99d2dc758 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -160,14 +160,24 @@ class VMOps(object): # Create the VM ref and attach the first disk first_vdi_ref = self._session.call_xenapi('VDI.get_by_uuid', vdis[0]['vdi_uuid']) - if instance.vm_mode in ('pv', 'PV'): + + vm_mode = instance.vm_mode and instance.vm_mode.lower() + if vm_mode == 'pv': use_pv_kernel = True - elif instance.vm_mode in ('hv', 'HV', 'hvm', 'HVM'): + elif vm_mode in ('hv', 'hvm'): use_pv_kernel = False + vm_mode = 'hvm' # Normalize else: use_pv_kernel = VMHelper.determine_is_pv(self._session, instance.id, first_vdi_ref, disk_image_type, instance.os_type) + vm_mode = use_pv_kernel and 'pv' or 'hvm' + + if instance.vm_mode != vm_mode: + # Update database with normalized (or determined) value + db.instance_update(context.get_admin_context(), + instance['id'], {'vm_mode': vm_mode}) + vm_ref = VMHelper.create_vm(self._session, instance, kernel, ramdisk, use_pv_kernel) VMHelper.create_vbd(session=self._session, vm_ref=vm_ref, -- cgit From 467bda72a05a0fd9fa4d7d417da422eea04de220 Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Thu, 9 Jun 2011 18:51:21 +0000 Subject: 022 migration has already been added, so make ours 023 now --- .../versions/022_add_vm_mode_to_instances.py | 43 ---------------------- .../versions/023_add_vm_mode_to_instances.py | 43 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 43 deletions(-) delete mode 100644 nova/db/sqlalchemy/migrate_repo/versions/022_add_vm_mode_to_instances.py create mode 100644 nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py diff --git a/nova/db/sqlalchemy/migrate_repo/versions/022_add_vm_mode_to_instances.py b/nova/db/sqlalchemy/migrate_repo/versions/022_add_vm_mode_to_instances.py deleted file mode 100644 index 5b6a25e41..000000000 --- a/nova/db/sqlalchemy/migrate_repo/versions/022_add_vm_mode_to_instances.py +++ /dev/null @@ -1,43 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010 OpenStack LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from sqlalchemy import Column, Integer, MetaData, String, Table - -meta = MetaData() - -instances = Table('instances', meta, - Column('id', Integer(), primary_key=True, nullable=False), - ) - -instances_vm_mode = Column('vm_mode', - String(length=255, convert_unicode=False, - assert_unicode=None, unicode_error=None, - _warn_on_bytestring=False), - nullable=True) - - -def upgrade(migrate_engine): - # Upgrade operations go here. Don't create your own engine; - # bind migrate_engine to your metadata - meta.bind = migrate_engine - - instances.create_column(instances_vm_mode) - - -def downgrade(migrate_engine): - meta.bind = migrate_engine - - instances.drop_column('vm_mode') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py b/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py new file mode 100644 index 000000000..5b6a25e41 --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py @@ -0,0 +1,43 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 OpenStack LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from sqlalchemy import Column, Integer, MetaData, String, Table + +meta = MetaData() + +instances = Table('instances', meta, + Column('id', Integer(), primary_key=True, nullable=False), + ) + +instances_vm_mode = Column('vm_mode', + String(length=255, convert_unicode=False, + assert_unicode=None, unicode_error=None, + _warn_on_bytestring=False), + nullable=True) + + +def upgrade(migrate_engine): + # Upgrade operations go here. Don't create your own engine; + # bind migrate_engine to your metadata + meta.bind = migrate_engine + + instances.create_column(instances_vm_mode) + + +def downgrade(migrate_engine): + meta.bind = migrate_engine + + instances.drop_column('vm_mode') -- cgit From a86523d5ae17b4e5507b14fade0a87c5434f2cac Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Fri, 10 Jun 2011 17:26:25 +0000 Subject: Fix copyright year --- .../db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py b/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py index 5b6a25e41..16b9826d9 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py @@ -1,6 +1,6 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2010 OpenStack LLC. +# Copyright 2011 OpenStack LLC. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain -- cgit From d9c2a7112ba239fb64ecc76ce844caed9146a5dc Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Mon, 13 Jun 2011 20:46:25 +0000 Subject: Load table schema automatically instead of stubbing out --- .../sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py b/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py index 16b9826d9..2f7bfddcb 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py @@ -18,9 +18,7 @@ from sqlalchemy import Column, Integer, MetaData, String, Table meta = MetaData() -instances = Table('instances', meta, - Column('id', Integer(), primary_key=True, nullable=False), - ) +instances = Table('instances', meta, autoload=True) instances_vm_mode = Column('vm_mode', String(length=255, convert_unicode=False, -- cgit From 70bb9494639ec26f12b71dc22052d3e5b343890f Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Tue, 14 Jun 2011 15:36:07 +0000 Subject: autoload with the appropriate engine during upgrade/downgrade --- .../migrate_repo/versions/023_add_vm_mode_to_instances.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py b/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py index 2f7bfddcb..0c587f569 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/023_add_vm_mode_to_instances.py @@ -18,8 +18,6 @@ from sqlalchemy import Column, Integer, MetaData, String, Table meta = MetaData() -instances = Table('instances', meta, autoload=True) - instances_vm_mode = Column('vm_mode', String(length=255, convert_unicode=False, assert_unicode=None, unicode_error=None, @@ -32,10 +30,16 @@ def upgrade(migrate_engine): # bind migrate_engine to your metadata meta.bind = migrate_engine + instances = Table('instances', meta, autoload=True, + autoload_with=migrate_engine) + instances.create_column(instances_vm_mode) def downgrade(migrate_engine): meta.bind = migrate_engine + instances = Table('instances', meta, autoload=True, + autoload_with=migrate_engine) + instances.drop_column('vm_mode') -- cgit From e89aad7ca0ba7ab5e9b83fa6fd9cde7fb22924bf Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Tue, 14 Jun 2011 17:22:33 +0000 Subject: Really PEP8? A tab is inferior to 2 spaces? --- nova/virt/xenapi/vmops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 624588b6b..d105cf300 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -166,7 +166,7 @@ class VMOps(object): use_pv_kernel = True elif vm_mode in ('hv', 'hvm'): use_pv_kernel = False - vm_mode = 'hvm' # Normalize + vm_mode = 'hvm' # Normalize else: use_pv_kernel = VMHelper.determine_is_pv(self._session, instance.id, first_vdi_ref, disk_image_type, -- cgit