adding PGv2 RSpec support to the vini aggregate manager
Tony Mack [Sat, 15 Oct 2011 00:38:02 +0000 (20:38 -0400)]
setup.py
sfa/client/client_helper.py
sfa/managers/aggregate_manager_vini.py
sfa/plc/aggregate.py
sfa/rspecs/elements/link.py

index 483c82f..49c6a93 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -43,6 +43,7 @@ package_dirs = [
     'sfa/trust',
     'sfa/util', 
     'sfa/managers',
+    'sfa/managers/vini',
     'sfa/rspecs',
     'sfa/rspecs/elements',
     'sfa/rspecs/versions',
index 64c8b43..32e21a1 100644 (file)
@@ -16,7 +16,7 @@ def sfa_users_arg(records, slice_record):
             continue
         user = {'urn': record['geni_urn'], #
                 'keys': record['keys'],
-                'email': record['email'], #  needed for MyPLC
+                'email': record['email'], # needed for MyPLC
                 'person_id': record['person_id'], # needed for MyPLC
                 'first_name': record['first_name'], # needed for MyPLC
                 'last_name': record['last_name'], # needed for MyPLC
index 66fb5cc..7f36419 100644 (file)
@@ -17,6 +17,8 @@ from sfa.server.registry import Registries
 from sfa.plc.slices import Slices
 import sfa.plc.peers as peers
 from sfa.managers.vini.vini_network import *
+from sfa.plc.vini_aggregate import ViniAggregate
+from sfa.rspecs.version_manager import VersionManager
 from sfa.plc.api import SfaAPI
 from sfa.plc.slices import *
 from sfa.managers.aggregate_manager_pl import __get_registry_objects, __get_hostnames
@@ -96,20 +98,22 @@ def ListResources(api, creds, options,call_id):
     # get slice's hrn from options
     xrn = options.get('geni_slice_urn', '')
     hrn, type = urn_to_hrn(xrn)
+
+    version_manager = VersionManager()
+    # get the rspec's return format from options
+    rspec_version = version_manager.get_version(options.get('rspec_version'))
+    version_string = "rspec_%s" % (rspec_version.to_string())
     
     # look in cache first
     if api.cache and not xrn:
-        rspec = api.cache.get('nodes')
+        rspec = api.cache.get(version_string)
         if rspec:
+            api.logger.info("aggregate.ListResources: returning cached value for hrn %s"%hrn)
             return rspec
 
-    network = ViniNetwork(api)
-    if (hrn):
-        if network.get_slice(api, hrn):
-            network.addSlice()
-
-    rspec =  network.toxml()
-
+    aggregate = ViniAggregate(api, options) 
+    rspec =  aggregate.get_rspec(slice_xrn=xrn, version=rspec_version)
+           
     # cache the result
     if api.cache and not xrn:
         api.cache.add('nodes', rspec)
index f39fd61..7603b5a 100644 (file)
@@ -6,6 +6,7 @@ from sfa.util.plxrn import *
 #from sfa.rspecs.rspec_version import RSpecVersion
 from sfa.rspecs.rspec import RSpec
 from sfa.rspecs.version_manager import VersionManager
+from sfa.util.bw_limit import get_tc_rate
 
 class Aggregate:
 
@@ -32,6 +33,18 @@ class Aggregate:
     def prepare_nodes(self, force=False):
         if not self.nodes or force:
             for node in self.api.plshell.GetNodes(self.api.plauth, {'peer_id': None}):
+                # add site/interface info to nodes.
+                # assumes that sites, interfaces and tags have already been prepared.
+                site = self.sites[node['site_id']]
+                interfaces = [self.interfaces[interface_id] for interface_id in node['interface_ids']]
+                tags = [self.node_tags[tag_id] for tag_id in node['node_tag_ids']]
+                node['network'] = self.api.hrn
+                node['network_urn'] = hrn_to_urn(self.api.hrn, 'authority+am')
+                node['urn'] = hostname_to_urn(self.api.hrn, site['login_base'], node['hostname'])
+                node['site_urn'] = hrn_to_urn(PlXrn.site_hrn(self.api.hrn, site['login_base']), 'authority+sa')
+                node['site'] = site
+                node['interfaces'] = interfaces
+                node['tags'] = tags
                 self.nodes[node['node_id']] = node
 
     def prepare_interfaces(self, force=False):
@@ -56,25 +69,11 @@ class Aggregate:
     def prepare(self, force=False):
         if not self.prepared or force:
             self.prepare_sites(force)
-            self.prepare_nodes(force)
             self.prepare_interfaces(force)
-            self.prepare_links(force)
             self.prepare_node_tags(force)
+            self.prepare_nodes(force)
+            self.prepare_links(force)
             self.prepare_pl_initscripts()
-            # add site/interface info to nodes
-            for node_id in self.nodes:
-                node = self.nodes[node_id]
-                site = self.sites[node['site_id']]
-                interfaces = [self.interfaces[interface_id] for interface_id in node['interface_ids']]
-                tags = [self.node_tags[tag_id] for tag_id in node['node_tag_ids']]
-                node['network'] = self.api.hrn
-                node['network_urn'] = hrn_to_urn(self.api.hrn, 'authority+am')
-                node['urn'] = hostname_to_urn(self.api.hrn, site['login_base'], node['hostname'])
-                node['site_urn'] = hrn_to_urn(PlXrn.site_hrn(self.api.hrn, site['login_base']), 'authority+sa') 
-                node['site'] = site
-                node['interfaces'] = interfaces
-                node['tags'] = tags
-
         self.prepared = True  
 
     def get_rspec(self, slice_xrn=None, version = None):
@@ -125,7 +124,24 @@ class Aggregate:
                 # and belongs in the <sliver_defaults> tag
                 if not tag['node_id']:
                     rspec.version.add_default_sliver_attribute(tag['tagname'], tag['value'], self.api.hrn)
-
+                if tag['tagname'] == 'topo_rspec' and tag['node_id']:
+                    node = self.nodes[tag['node_id']]
+                    value = eval(tag['value'])
+                    for (id, realip, bw, lvip, rvip, vnet) in value:
+                        bps = get_tc_rate(bw)
+                        remote = self.nodes[id]
+                        site1 = self.sites[node['site_id']]
+                        site2 = self.sites[remote['site_id']]
+                        link1_name = '%s:%s' % (site1['login_base'], site2['login_base']) 
+                        link2_name = '%s:%s' % (site2['login_base'], site1['login_base']) 
+                        p_link = None
+                        if link1_name in self.links:
+                            link = self.links[link1_name] 
+                        elif link2_name in self.links:
+                            link = self.links[link2_name]
+                        v_link = Link()
+                        
+                        link.capacity = bps 
             for node_id in slice['node_ids']:
                 try:
                     sliver = {}
index e69de29..682232e 100644 (file)
@@ -0,0 +1,14 @@
+from sfa.rspec.elements.interface import Interface
+
+class Link:
+    def __init__(self):
+        self.component_id = None
+        self.component_name = None
+        self.component_manager_id = None
+        self.type = None
+        self.endpoint1 = Interface()
+        self.endpoint2 = Interface()
+        self.capacity = None
+        self.latency = None
+        self.packet_loss = None
+        self.description = None