Changed Rspec --> RSpec throughout.
[sfa.git] / sfa / rspecs / aggregates / vini / rspec.py
1 from sfa.util.rspec import RSpec
2 from sfa.rspecs.aggregates.vini.utils import *
3 import sys
4
5 SFA_VINI_DEFAULT_RSPEC = '/etc/sfa/vini.rspec'
6
7 class ViniRSpec(RSpec):
8     def __init__(self, xml = None, xsd = None, NSURL = None):
9         RSpec.__init__(self, xml, xsd, NSURL)
10         if not xml:
11             self.parseFile(SFA_VINI_DEFAULT_RSPEC)
12         
13     def updateCapacity(self, topo):
14         d = self.toDict()
15         sitespecs = []
16         sitelinkspecs = []
17         for site in topo.getSites():
18             if not site.public:
19                 continue
20             sdict = {}
21             nodespecs = []
22             for node in site.get_sitenodes(topo.nodes):
23                 if not node.tag:
24                     continue
25                 ndict = {}
26                 ndict['hostname'] = [node.hostname]
27                 ndict['name'] = node.tag
28                 ndict['bw'] = [format_tc_rate(node.bps)] 
29                 nodespecs.append(ndict)
30             sdict['NodeSpec'] = nodespecs
31             sdict['name'] = site.name
32             sitespecs.append(sdict)
33             
34             for sl in site.links:
35                 if sl.end1 == site:
36                     sldict = {}
37                     sldict['endpoint'] = [sl.end1.name, sl.end2.name]
38                     sldict['bw'] = [format_tc_rate(sl.bps)]
39                     sitelinkspecs.append(sldict)
40                     
41         d['RSpec']['Capacity'][0]['NetSpec'][0]['SiteSpec'] = sitespecs
42         d['RSpec']['Capacity'][0]['NetSpec'][0]['SiteLinkSpec'] = sitelinkspecs
43         self.parseDict(d)
44
45
46     def updateRequest(self, slice, topo):
47         linkspecs = []
48         for link in topo.nodelinks:
49             edict = {}
50             edict['endpoint'] = [link.end1.tag, link.end2.tag]
51             edict['bw'] = [format_tc_rate(link.bps)]
52             linkspecs.append(edict)
53
54         d = self.toDict()
55         d['RSpec']['Request'][0]['NetSpec'][0]['LinkSpec'] = linkspecs
56         d['RSpec']['Request'][0]['NetSpec'][0]['name'] = slice.hrn
57         self.parseDict(d)