-Add UUIDv5 generation with URL to the UUID generation function (for use in libvirt storage pool creation)

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6782 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2010-07-16 20:49:38 +00:00
parent 8e2c4a6d2d
commit c08e59bef6

View File

@ -105,6 +105,21 @@ sub genUUID
$mac = lc($mac);
$uuid .= $mac;
return $uuid;
} elsif ($args{url}) { #generate a UUIDv5 from URL
#6ba7b810-9dad-11d1-80b4-00c04fd430c8 is the uuid for URL namespace
my $sum = sha1('6ba7b810-9dad-11d1-80b4-00c04fd430c8'.$args{url});
my @data = unpack("C*",$sum);
splice @data,16;
$data[6] = $data[6] & 0xf;
$data[6] = $data[6] | (5<<4);
$data[8] = $data[8] & 127;
$data[8] = $data[8] | 64;
my $uuid = unpack("H*",pack("C*",splice @data,0,4));
$uuid .= "-". unpack("H*",pack("C*",splice @data,0,2));
$uuid .= "-". unpack("H*",pack("C*",splice @data,0,2));
$uuid .= "-". unpack("H*",pack("C*",splice @data,0,2));
$uuid .= "-". unpack("H*",pack("C*",@data));
return $uuid;
}
srand(); #Many note this as bad practice, however, forks are going on..
my $uuid;