diff options
author | Rick Harris <rconradharris@gmail.com> | 2013-04-02 17:48:31 +0000 |
---|---|---|
committer | Rick Harris <rconradharris@gmail.com> | 2013-05-02 15:38:44 +0000 |
commit | f3843dec216f400417637b145aa2982898f6c0c0 (patch) | |
tree | fab2b39362841c2b2f3ca86bc6fc543da2869bd6 /tools | |
parent | 6e3997322d306bda31e02b03bfbd8c73b3367b39 (diff) | |
download | nova-f3843dec216f400417637b145aa2982898f6c0c0.tar.gz nova-f3843dec216f400417637b145aa2982898f6c0c0.tar.xz nova-f3843dec216f400417637b145aa2982898f6c0c0.zip |
xenapi: Always set other_config for VDIs
The existing code only set `other_config` on a VDI when it was created using
`create_vdi`. This patch updates the code so that `other_config` is also set
when a VDI is created from a dom0 plugin or during a migration.
Also included is a one-time script to set the other_config for existing
VDIs that were affected by this bug.
Fixes bug 1162029
Change-Id: I4fa856754487f77ce9c8e39d45eee7ea5187123e
Diffstat (limited to 'tools')
-rw-r--r-- | tools/xenserver/populate_other_config.py | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/tools/xenserver/populate_other_config.py b/tools/xenserver/populate_other_config.py new file mode 100644 index 000000000..7151fee61 --- /dev/null +++ b/tools/xenserver/populate_other_config.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python + +# Copyright 2013 OpenStack Foundation +# +# 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. +""" +One-time script to populate VDI.other_config. + +We use metadata stored in VDI.other_config to associate a VDI with a given +instance so that we may safely cleanup orphaned VDIs. + +We had a bug in the code that meant that the vast majority of VDIs created +would not have the other_config populated. + +After deploying the fixed code, this script is intended to be run against all +compute-workers in a cluster so that existing VDIs can have their other_configs +populated. + +Run on compute-worker (not Dom0): + + python ./tools/xenserver/populate_other_config.py [--dry-run|--verbose] +""" +import gettext +gettext.install('nova', unicode=1) + +import os +import sys + +possible_topdir = os.getcwd() +if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")): + sys.path.insert(0, possible_topdir) + +from nova import config +from nova.openstack.common import uuidutils +from nova.virt import virtapi +from nova.virt.xenapi import driver as xenapi_driver +from nova.virt.xenapi import vm_utils +from oslo.config import cfg + +cli_opts = [ + cfg.BoolOpt('dry-run', + default=False, + help='Whether to actually update other_config.'), +] + +CONF = cfg.CONF +CONF.register_cli_opts(cli_opts) + + +def main(): + config.parse_args(sys.argv) + + xenapi = xenapi_driver.XenAPIDriver(virtapi.VirtAPI()) + session = xenapi._session + + vdi_refs = session.call_xenapi('VDI.get_all') + for vdi_ref in vdi_refs: + vdi_rec = session.call_xenapi('VDI.get_record', vdi_ref) + + other_config = vdi_rec['other_config'] + + # Already set... + if 'nova_instance_uuid' in other_config: + continue + + name_label = vdi_rec['name_label'] + + # We only want name-labels of form instance-<UUID>-[optional-suffix] + if not name_label.startswith('instance-'): + continue + + # Parse out UUID + instance_uuid = name_label.replace('instance-', '')[:36] + if not uuidutils.is_uuid_like(instance_uuid): + print "error: name label '%s' wasn't UUID-like" % name_label + continue + + vdi_type = vdi_rec['name_description'] + + # We don't need a full instance record, just the UUID + instance = {'uuid': instance_uuid} + + if not CONF.dry_run: + vm_utils._set_vdi_info(session, vdi_ref, vdi_type, name_label, + vdi_type, instance) + + if CONF.verbose: + print "Setting other_config for instance_uuid=%s vdi_uuid=%s" % ( + instance_uuid, vdi_rec['uuid']) + + if CONF.dry_run: + print "Dry run completed" + + +if __name__ == "__main__": + main() |