This repository was archived by the owner on Jan 22, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -606,19 +606,7 @@ def set_maxmemory(self, val):
606606 def get_uuid (self ):
607607 return self ._uuid
608608 def set_uuid (self , val ):
609- # need better validation
610- if type (val ) is not type ("string" ):
611- raise ValueError , _ ("UUID must be a string." )
612-
613- form = re .match ("[a-fA-F0-9]{8}[-]([a-fA-F0-9]{4}[-]){3}[a-fA-F0-9]{12}$" , val )
614- if form is None :
615- form = re .match ("[a-fA-F0-9]{32}$" , val )
616- if form is None :
617- raise ValueError , _ ("UUID must be a 32-digit hexadecimal number. It may take the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX or may omit hyphens altogether." )
618-
619- else : # UUID had no dashes, so add them in
620- val = val [0 :8 ] + "-" + val [8 :12 ] + "-" + val [12 :16 ] + \
621- "-" + val [16 :20 ] + "-" + val [20 :32 ]
609+ val = _util .validate_uuid (val )
622610 self ._uuid = val
623611 uuid = property (get_uuid , set_uuid )
624612
Original file line number Diff line number Diff line change @@ -305,18 +305,7 @@ def set_host(self, val):
305305 def get_uuid (self ):
306306 return self ._uuid
307307 def set_uuid (self , val ):
308- if type (val ) is not type ("string" ):
309- raise ValueError , _ ("UUID must be a string." )
310-
311- form = re .match ("[a-fA-F0-9]{8}[-]([a-fA-F0-9]{4}[-]){3}[a-fA-F0-9]{12}$" , val )
312- if form is None :
313- form = re .match ("[a-fA-F0-9]{32}$" , val )
314- if form is None :
315- raise ValueError , _ ("UUID must be a 32-digit hexadecimal number. It may take the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX or may omit hyphens altogether." )
316-
317- else : # UUID had no dashes, so add them in
318- val = val [0 :8 ] + "-" + val [8 :12 ] + "-" + val [12 :16 ] + \
319- "-" + val [16 :20 ] + "-" + val [20 :32 ]
308+ val = _util .validate_uuid (val )
320309 self ._uuid = val
321310 uuid = property (get_uuid , set_uuid )
322311
Original file line number Diff line number Diff line change 3131import libvirt
3232
3333from virtinst import util
34+ from virtinst import _virtinst as _
3435
3536def is_vdisk (path ):
3637 if not os .path .exists ("/usr/sbin/vdiskadm" ):
@@ -101,6 +102,25 @@ def vm_uuid_collision(conn, uuid):
101102 pass
102103 return check
103104
105+ def validate_uuid (val ):
106+ if type (val ) is not str :
107+ raise ValueError , _ ("UUID must be a string." )
108+
109+ form = re .match ("[a-fA-F0-9]{8}[-]([a-fA-F0-9]{4}[-]){3}[a-fA-F0-9]{12}$" ,
110+ val )
111+ if form is None :
112+ form = re .match ("[a-fA-F0-9]{32}$" , val )
113+ if form is None :
114+ raise ValueError , \
115+ _ ("UUID must be a 32-digit hexadecimal number. It may take "
116+ "the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX or may omit "
117+ "hyphens altogether." )
118+
119+ else : # UUID had no dashes, so add them in
120+ val = (val [0 :8 ] + "-" + val [8 :12 ] + "-" + val [12 :16 ] +
121+ "-" + val [16 :20 ] + "-" + val [20 :32 ])
122+ return val
123+
104124#
105125# These functions accidentally ended up in the API under virtinst.util
106126#
You can’t perform that action at this time.
0 commit comments