summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-05-06 16:03:06 +0000
committerGerrit Code Review <review@openstack.org>2013-05-06 16:03:06 +0000
commit6cbb3209264fc5af6cf8faedfcc66c7b485fb601 (patch)
treeacb68d92b36d0f7ebc3d9548f7aaa30ef5635c13 /tools
parentef0df189db0b4c18e2742bbd195a18afb535b908 (diff)
parentf3843dec216f400417637b145aa2982898f6c0c0 (diff)
downloadnova-6cbb3209264fc5af6cf8faedfcc66c7b485fb601.tar.gz
nova-6cbb3209264fc5af6cf8faedfcc66c7b485fb601.tar.xz
nova-6cbb3209264fc5af6cf8faedfcc66c7b485fb601.zip
Merge "xenapi: Always set other_config for VDIs"
Diffstat (limited to 'tools')
-rw-r--r--tools/xenserver/populate_other_config.py106
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()