Alon Bar-Lev has uploaded a new change for review.
Change subject: vdsm-tool: vdsm-id: add force option to force generate id
......................................................................
vdsm-tool: vdsm-id: add force option to force generate id
this is handy to hide the existence and usage of /etc/vdsm/vdsm.id from
users (other components).
Change-Id: I89f1e29c9cdad0cadb32545fa27c1702ad2e116a
Signed-off-by: Alon Bar-Lev <alonbl(a)redhat.com>
---
M lib/vdsm/tool/vdsm-id.py
M lib/vdsm/utils.py
2 files changed, 35 insertions(+), 3 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/08/20808/1
diff --git a/lib/vdsm/tool/vdsm-id.py b/lib/vdsm/tool/vdsm-id.py
index 109c382..01f94a9 100644
--- a/lib/vdsm/tool/vdsm-id.py
+++ b/lib/vdsm/tool/vdsm-id.py
@@ -17,9 +17,13 @@
# Refer to the README and COPYING files for full details of the license
#
+
+import sys
+import argparse
+
+
from vdsm.utils import getHostUUID
from vdsm.tool import expose
-import sys
@expose("vdsm-id")
@@ -27,7 +31,19 @@
"""
Printing host uuid
"""
- hostUUID = getHostUUID(False)
+ parser = argparse.ArgumentParser('vdsm-tool configure')
+ parser.add_argument(
+ '--force',
+ dest='force',
+ default=False,
+ action='store_true',
+ help='Generate vdsmid if not available',
+ )
+ args = parser.parse_args(sys.argv[2:])
+ hostUUID = getHostUUID(
+ legacy=False,
+ force=args.force,
+ )
if hostUUID is None:
raise RuntimeError('Cannot retrieve host UUID')
sys.stdout.write(hostUUID)
diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index 78d055e..d38a273 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -48,6 +48,7 @@
import subprocess
import threading
import time
+import uuid
from cpopen import CPopen as BetterPopen
import constants
@@ -599,7 +600,7 @@
__hostUUID = None
-def getHostUUID(legacy=True):
+def getHostUUID(legacy=True, force=False):
global __hostUUID
if __hostUUID:
return __hostUUID
@@ -624,6 +625,14 @@
if p.returncode == 0 and 'Not' not in out:
#Avoid error string - 'Not Settable' or 'Not Present'
__hostUUID = out.strip()
+ elif force:
+ hostid = str(uuid.uuid4())
+ with open(constants.P_VDSM_NODE_ID, 'w') as f:
+ f.write("%s\n", hostid)
+ if isOvirtNode():
+ from ovirtnode import ovirtfunctions
+ ovirtfunctions.ovirt_store_config(constants.P_VDSM_NODE_ID)
+ __hostUUID = hostid
else:
logging.warning('Could not find host UUID.')
@@ -877,3 +886,10 @@
logging.error("Panic: %s", msg, exc_info=True)
os.killpg(0, 9)
sys.exit(-3)
+
+
+def isOvirtNode():
+ return (
+ os.path.exists('/etc/rhev-hypervisor-release') or
+ glob.glob('/etc/ovirt-node-*-release')
+ )
--
To view, visit
http://gerrit.ovirt.org/20808
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I89f1e29c9cdad0cadb32545fa27c1702ad2e116a
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <alonbl(a)redhat.com>