3 """ DRL configurator. """
12 drl = """<?xml version="1.0" encoding="UTF-8"?>
15 <machine id="%d" limit="%d" commfabric="MESH" accounting="STANDARD" ewma="0.1" htb_node="100" htb_parent="10">
22 logger.log('drl plugin starting up...')
25 def DRLSetup(site_name, slice_name, site_id, bw_limit, peer):
26 DRL_file = '/vservers/%s/etc/drl.xml' % slice_name
27 DRL_config = drl % (site_name, site_id, bw_limit, peer)
29 # Check config changes
30 if os.path.exists(DRL_file):
32 new_digest = md5.new(DRL_config).digest()
33 old_digest = md5.new(open(DRL_file).read()).digest()
34 if old_digest == new_digest:
35 logger.log('drl: %s already exists...' % DRL_file)
36 DRLInstall(slice_name)
38 DRLConfig(DRL_file, DRL_config)
39 DRLInstall(slice_name)
42 def DRLConfig(DRL_file, DRL_config):
43 logger.log('drl: %s is out-dated...' % DRL_file)
44 logger.log('drl: generating %s' % DRL_file)
45 f = open( DRL_file, 'w')
50 def DRLInstall(slice_name):
51 if not os.path.exists('/vservers/%s/etc/yum.repos.d/myplc.repo' % slice_name):
52 shutil.copyfile('/etc/yum.myplc.d/myplc.repo', '/vservers/%s/etc/yum.repos.d/myplc.repo' % slice_name)
53 logger.log('drl: installing DistributedRateLimiting into %s slice' % slice_name)
54 logger.log_call(['vserver', '%s' % slice_name, 'suexec', '0', 'yum', 'install', '-y', '-q', 'DistributedRateLimiting'])
55 logger.log_call(['vserver', '%s' % slice_name, 'suexec', '0', 'chkconfig', '--add', 'ulogd'])
57 logger.log('drl: updating DistributedRateLimiting on %s slice' % slice_name)
58 logger.log_call(['vserver', '%s' % slice_name, 'suexec', '0', 'yum', 'update', '-y', '-q', 'DistributedRateLimiting'])
60 logger.log('drl: (re)starting DistributedRateLimiting service')
61 logger.log_call(['vserver', '%s' % slice_name, 'suexec', '0', 'service', 'ulogd', 'restart'])
64 def GetSlivers(data, conf = None, plc = None):
67 node_id = tools.node_id()
69 if 'slivers' not in data:
70 logger.log_missing_data("drl.GetSlivers",'slivers')
73 for sliver in data['slivers']:
74 for attribute in sliver['attributes']:
75 tag = attribute['tagname']
76 value = attribute['value']
77 if tag == 'drl' and value == '1':
79 DRL_SLICE_NAME = sliver['name']
82 site_id = plc.GetNodes({'node_id': int(node_id) }, ['site_id'])
83 site_id = site_id[0]['site_id']
85 q = plc.GetSites({'site_id': site_id, 'enabled': True, 'peer_site_id': None}, ['name', 'node_ids'])
87 if i['node_ids'] != [] and len(i['node_ids']) > 1:
88 z = plc.GetInterfaces({'node_id': i['node_ids'], 'is_primary': True, '~bwlimit': None}, ['node_id', 'ip', 'bwlimit'])
92 for j in range(len(z)):
93 total_bwlimit += z[j]['bwlimit']
94 if z[j]['node_id'] != int(node_id):
95 peer += '\t<peer>%s</peer>\n' % z[j]['ip']
99 DRLSetup(i['name'], DRL_SLICE_NAME, site_id, total_bwlimit/1000, peer)
101 logger.log('drl: This node has no bwlimit')
104 logger.log('drl: This site has only %s node' % len(i['node_ids']))
106 logger.log('drl: This node has no drl slice!...')