[et-mgmt-tools] [PATCH] check a UUID format
S.Sakamoto
fj0588di at aa.jp.fujitsu.com
Fri Mar 30 08:16:24 UTC 2007
Hi
When I install by virt-intall with invalid UUID(e.g."--uuid=4096 Characters"),
virt-install freeze.
So, here's the patch adds to check a UUID with following format:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ( xx should be in hexadecimal )
Signed-off-by: Shigeki Sakamoto <fj0588di at aa.jp.fujitsu.com>
Thanks,
Shigeki Sakamoto.
==========================================================
diff -r e63d9c7f0a89 virt-install
--- a/virt-install Thu Mar 29 15:56:42 2007 -0400
+++ b/virt-install Fri Mar 30 17:07:23 2007 +0900
@@ -88,6 +88,7 @@ def get_uuid(uuid, guest):
guest.uuid = uuid
except ValueError, e:
print "ERROR: ", e
+ sys.exit(1)
def get_vcpus(vcpus, check_cpu, guest, conn):
while 1:
@@ -305,7 +306,7 @@ def parse_args():
help="Memory to allocate for guest instance in megabytes")
parser.add_option("-u", "--uuid", type="string", dest="uuid",
action="callback", callback=check_before_store,
- help="UUID for the guest; if none is given a random UUID will be generated")
+ help="UUID for the guest; if none is given a random UUID will be generated. if specify UUID, you should use hexadecimal number with a form of XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.")
parser.add_option("", "--vcpus", type="int", dest="vcpus",
help="Number of vcpus to configure for your guest")
parser.add_option("", "--check-cpu", action="store_true", dest="check_cpu",
diff -r e63d9c7f0a89 virtinst/Guest.py
--- a/virtinst/Guest.py Thu Mar 29 15:56:42 2007 -0400
+++ b/virtinst/Guest.py Fri Mar 30 17:04:39 2007 +0900
@@ -417,12 +417,10 @@ class Guest(object):
return self._uuid
def set_uuid(self, val):
# need better validation
- if type(val) == type("str"):
- self._uuid = val
- elif type(val) == type(123):
- self._uuid = util.uuidToString(val)
- else:
- raise ValueError, "Invalid value for UUID"
+ form = re.match("[a-fA-F0-9]{8}[-]([a-fA-F0-9]{4}[-]){3}[a-fA-F0-9]{12}", val)
+ if form is None:
+ raise ValueError, "UUID must use hexadecimal number with a form of XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
+ self._uuid = val
uuid = property(get_uuid, set_uuid)
More information about the et-mgmt-tools
mailing list