Merge branch 'master' of ssh://git.f-lab.fr/git/sfa
[sfa.git] / sfa / plc / vini_aggregate.py
1 from sfa.plc.aggregate import Aggregate
2 from sfa.managers.vini.topology import PhysicalLinks
3 from sfa.rspecs.elements.link import Link
4 from sfa.util.xrn import hrn_to_urn
5 from sfa.util.plxrn import PlXrn
6
7 class ViniAggregate(Aggregate):
8
9     def prepare_links(self, force=False):
10         for (site_id1, site_id2) in PhysicalLinks:
11             link = Link()
12             if not site_id1 in self.sites or site_id2 not in self.sites:
13                 continue 
14             site1 = self.sites[site_id1]
15             site2 = self.sites[site_id2]
16             # get hrns
17             site1_hrn = self.api.hrn + '.' + site1['login_base']
18             site2_hrn = self.api.hrn + '.' + site2['login_base']
19             # get the first node
20             node1 = self.nodes[site1['node_id'][0]]
21             node2 = self.nodes[site2['node_id'][0]]
22         
23             # set interfaces
24             # just get first interface of the first node 
25             if1_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (node1['node_id']))   
26             if2_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (node2['node_id']))
27                
28             if1 = Interface({'component_id': if1_xrn.urn} )  
29             if2 = Interface({'component_id': if2_xrn.urn} )  
30             
31             # set link
32             link = Link({'capacity': '1000000', 'latency': '0', 'packet_loss': '0', 'type': 'ipv4'})
33             link['interface1'] = if1
34             link['interface2'] = if2
35             link['component_name'] = "%s:%s" % (site1['login_base'], site2['login_base'])
36             link['component_id'] = PlXrn(auth=self.api.hrn, link=link['component_name'])
37             link['component_manager_id'] =  hrn_to_urn(self.api.hrn, 'authority+am')
38             self.links[link['component_name']] = link
39         
40