Movatterモバイル変換


[0]ホーム

URL:


CFEngine documentation homepage

hash_to_int

Suggest changes
Table of contents

Prototype:hash_to_int(lower, upper, string)

Return type:int

Description: Generates an integer betweenlower andupper range based on hash ofstring.

Notes:

This function is similar tosplayclass() but more widely usable. Anything thatinvolves orchestration of many hosts could use this function, either for evenlyspreading out the scheduling, or even for static load balancing. The resultwould may be coupled with anifelse() clause of some sort, or just useddirectly.

Arguments:

  • lower (inclusive):int - Lower inclusive bound - in the range:-99999999999,99999999999
  • upper (exclusive):int - Upper exclusive bound - in the range:-99999999999,99999999999
  • string:string - Input string to hash - in the range:.*

Example:

code
bodycommoncontrol{bundlesequence=>{"example"};}bundleagentexample{vars:"hello"int=>hash_to_int(0,1000,"hello");"world"int=>hash_to_int(0,1000,"world");# Hash can vary on hostkey or policy hub:"hour"int=>hash_to_int(0,24,"$(sys.key_digest)");"minute"int=>hash_to_int(0,60,"$(sys.policy_hub)");reports:"'hello' hashed to:$(hello)";"'world' hashed to:$(world)";}

Output:

code
R: 'hello' hashed to: 172R: 'world' hashed to: 760

History:

  • Introduced in 3.12.0.

See also:splayclass()

Still need help?

Chat Ask a question on Github Mailing list
Version 
master3.24 (LTS)3.21 (LTS)view all versions

[8]ページ先頭

©2009-2025 Movatter.jp