Skip to content

Commit

Permalink
Merge pull request #347 from bundlewrap/node-magic-number
Browse files Browse the repository at this point in the history
Node magic number
  • Loading branch information
trehn committed Jun 13, 2017
2 parents 2c1ad15 + 08cb67a commit a6e7c19
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bundlewrap/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from datetime import datetime, timedelta
from hashlib import md5
from os import environ
from sys import exit
from threading import Lock
Expand Down Expand Up @@ -526,6 +527,10 @@ def items(self):
for item in bundle.items:
yield item

@cached_property
def magic_number(self):
return int(md5(self.name.encode('UTF-8')).hexdigest(), 16)

@property
def _static_items(self):
for bundle in self.bundles:
Expand Down
10 changes: 10 additions & 0 deletions docs/content/repo/nodes.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ A string used as a DNS name when connecting to this node. May also be an IP addr
Cannot be set at group level.


### magic_number

A large number derived from the node's name. This number is very likely to be unique for your entire repository. You can, for example, use this number to easily "jitter" cronjobs:

'{} {} * * * root /my/script'.format(
node.magic_number % 60,
node.magic_number % 2 + 4,
)


### metadata

This can be a dictionary of arbitrary data (some type restrictions apply). You can access it from your templates as `node.metadata`. Use this to attach custom data (such as a list of IP addresses that should be configured on the target node) to the node. Note that you can also define metadata at the [group level](groups.py.md#metadata), but node metadata has higher priority.
Expand Down

0 comments on commit a6e7c19

Please sign in to comment.