1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

名前からuuidを生成する

Last updated at Posted at 2015-06-12

hearteatのha.cfでuuidfrom nodenameしてコピった時に重複して面倒なことになったり、
chefのレシピでcib.xmlのテンプレート作るときに差し込むとかしたいので、
ホスト名から生成された情報を事前に知りたいなーと思ったというのが経緯です。
実際設定してクラスタ立ち上げてからじゃないとuuidが分からないだとめんどかっただけです。

・uuidtoolsを入れる
# gem install uuidtools

・スクリプトを書いてみる

# vi uuid.rb 
---------------------
require 'uuidtools'

hostnames = ARGV

hostnames.each do |hostname|
puts "<<#{hostname}>>"
puts "md5  :"
puts UUIDTools::UUID.md5_create(UUIDTools::UUID_DNS_NAMESPACE, "#{hostname}")
puts "sha1 :"
puts UUIDTools::UUID.sha1_create(UUIDTools::UUID_DNS_NAMESPACE, "#{hostname}")
puts ""
end
---------------------

・実行結果

# ruby ./uuid.rb hoge1 hoge2
<<hoge1>>
md5  :
13950234-f550-3575-91d8-3fc8cbc47b0d
sha1 :
cdac4b6c-0856-515e-8318-799eb2afcdaf

<<hoge2>>
md5  :
c4c17ae2-6948-3902-87c5-53ff8d8cbf87
sha1 :
6833d38b-1531-598f-8cd8-2a1a1c03bf06

何回か実行して同じ値になることが確認できると思います。

・参考
http://99blues.dyndns.org/blog/2010/07/uuid_generate/
http://linux-ha.osdn.jp/wp/archives/891
http://www.drbd.jp/pacemaker.pdf
http://d.hatena.ne.jp/shunsuk/20110506/1304686954
http://www.python-izm.com/contents/application/uuid.shtml

名前から生成されたくない場合はSecureRandomを使うと良いようです。
http://qiita.com/tnoda_/items/ad98f8a5fa23696fbb7d

実際クラスタ組んでみたところ、全然違うuuidになったあげく、
別にdcuuidとか勝手に認識してcib.xmlも自動で書き変わってて、
template化する必要も特になかったというオチがつきましたorz。。

以上

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?