3 The sliver manager has several functions. It is responsible for
4 creating, resource limiting, starting, stopping, and destroying
5 slivers. It provides an API for users to access these functions and
6 also to make inter-sliver resource loans. The sliver manager is also
7 responsible for handling delegation accounts.
10 try: from bwlimit import bwmin, bwmax
11 except ImportError: bwmin, bwmax = 8, 1000*1000*1000
19 DEFAULT_ALLOCATION = {'enabled': 1, 'cpu_min': 0, 'cpu_share': 32, 'net_min': bwmin, 'net_max': bwmax, 'net2_min': bwmin, 'net2_max': bwmax, 'net_share': 1, 'disk_max': 5000000}
21 start_requested = False # set to True in order to request that all slivers be started
24 @database.synchronized
25 def GetSlivers_callback(data):
26 """This function has two purposes. One, convert GetSlivers() data into a more convenient format. Two, even if no updates are coming in, use the GetSlivers() heartbeat as a cue to scan for expired slivers."""
28 for sliver in d['slivers']:
30 rec.setdefault('timestamp', d['timestamp'])
31 rec.setdefault('type', 'sliver.VServer')
33 # convert attributes field to a proper dict
35 for attr in rec.pop('attributes'): attr_dict[attr['name']] = attr['value']
38 keys = rec.pop('keys')
39 rec.setdefault('keys', '\n'.join([key_struct['key'] for key_struct in keys]))
41 rec.setdefault('initscript', attr_dict.get('initscript', ''))
42 rec.setdefault('delegations', []) # XXX - delegation not yet supported
44 # extract the implied rspec
47 for resname, default_amt in DEFAULT_ALLOCATION.iteritems():
48 try: amt = int(attr_dict[resname])
49 except (KeyError, ValueError): amt = default_amt
51 database.db.deliver_record(rec)
52 database.db.set_min_timestamp(d['timestamp'])
55 # handle requested startup
56 global start_requested
58 start_requested = False
60 for name in database.db.iterkeys():
61 accounts.get(name).start(delay=cumulative_delay)
66 accounts.register_class(sliver_vs.Sliver_VS)
67 accounts.register_class(delegate.Delegate)
68 global start_requested
69 start_requested = options.startup