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
20 DEFAULT_ALLOCATION = {
24 'cpu_share': 32, # proportional share
25 # bandwidth parameters
26 'net_min': bwmin, # bps
27 'net_max': bwmax, # bps
28 'net_share': 1, # proportional share
29 # bandwidth parameters over routes exempt from node bandwidth limits
30 'net2_min': bwmin, # bps
31 'net2_max': bwmax, # bps
32 'net2_share': 1, # proportional share
33 'disk_max': 5000000 # bytes
36 start_requested = False # set to True in order to request that all slivers be started
39 @database.synchronized
40 def GetSlivers_callback(data, fullupdate=True):
41 """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."""
45 f = open('/etc/planetlab/node_id')
46 try: node_id = int(f.read())
48 except: logger.log_exc()
51 if d['node_id'] != node_id: continue
52 for sliver in d['slivers']:
54 rec.setdefault('timestamp', d['timestamp'])
56 # convert attributes field to a proper dict
58 for attr in rec.pop('attributes'): attr_dict[attr['name']] = attr['value']
61 keys = rec.pop('keys')
62 rec.setdefault('keys', '\n'.join([key_struct['key'] for key_struct in keys]))
64 rec.setdefault('type', attr_dict.get('type', 'sliver.VServer'))
65 rec.setdefault('vref', attr_dict.get('vref', 'default'))
66 rec.setdefault('initscript', attr_dict.get('initscript', ''))
67 rec.setdefault('delegations', []) # XXX - delegation not yet supported
69 # extract the implied rspec
72 for resname, default_amt in DEFAULT_ALLOCATION.iteritems():
73 try: amt = int(attr_dict[resname])
74 except (KeyError, ValueError): amt = default_amt
76 database.db.deliver_record(rec)
77 if fullupdate: database.db.set_min_timestamp(d['timestamp'])
80 # handle requested startup
81 global start_requested
83 start_requested = False
85 for name in database.db.iterkeys():
86 accounts.get(name).start(delay=cumulative_delay)
89 def deliver_ticket(data): return GetSlivers_callback(data, fullupdate=False)
93 accounts.register_class(sliver_vs.Sliver_VS)
94 accounts.register_class(delegate.Delegate)
95 global start_requested
96 start_requested = options.startup
98 api.deliver_ticket = deliver_ticket