- def prepare_sites(self, force=False):
- if not self.sites or force:
- for site in self.api.plshell.GetSites(self.api.plauth):
- self.sites[site['site_id']] = site
-
- 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}):
- self.nodes[node['node_id']] = node
-
- def prepare_interfaces(self, force=False):
- if not self.interfaces or force:
- for interface in self.api.plshell.GetInterfaces(self.api.plauth):
- self.interfaces[interface['interface_id']] = interface
-
- def prepare_links(self, force=False):
- if not self.links or force:
- pass
-
- def prepare_node_tags(self, force=False):
- if not self.node_tags or force:
- for node_tag in self.api.plshell.GetNodeTags(self.api.plauth):
- self.node_tags[node_tag['node_tag_id']] = node_tag
-
- def prepare_pl_initscripts(self, force=False):
- if not self.pl_initscripts or force:
- for initscript in self.api.plshell.GetInitScripts(self.api.plauth, {'enabled': True}):
- self.pl_initscripts[initscript['initscript_id']] = initscript
-
- 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_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):
- self.prepare()
- rspec = RSpec(version=version, user_options=self.user_options)
- #rspec_version = RSpecVersion(version)
- #if slice_xrn:
- # type = 'manifest'
- #else:
- # type = 'advertisement'
- #if rspec_version['type'].lower() == 'protogeni':
- # rspec = PGRSpec(type=type)
- #elif rspec_version['type'].lower() == 'sfa':
- # rspec = SfaRSpec(type=type, user_options=self.user_options)
- #else:
- # rspec = SfaRSpec(type=type, user_options=self.user_options)
-
- # get slice details if specified
+ def get_sites(self, filter={}):
+ sites = {}
+ for site in self.api.driver.GetSites(filter):
+ sites[site['site_id']] = site
+ return sites
+
+ def get_interfaces(self, filter={}):
+ interfaces = {}
+ for interface in self.api.driver.GetInterfaces(filter):
+ iface = Interface()
+ iface['interface_id'] = interface['interface_id']
+ iface['node_id'] = interface['node_id']
+ iface['ipv4'] = interface['ip']
+ if interface['bwlimit']:
+ iface['bwlimit'] = str(int(interface['bwlimit'])/1000)
+ interfaces[iface['interface_id']] = iface
+ return interfaces
+
+ def get_links(self, filter={}):
+
+ if not self.api.config.SFA_AGGREGATE_TYPE.lower() == 'vini':
+ return []
+
+ topology = Topology()
+ links = {}
+ for (site_id1, site_id2) in topology:
+ link = Link()
+ if not site_id1 in self.sites or site_id2 not in self.sites:
+ continue
+ site1 = self.sites[site_id1]
+ site2 = self.sites[site_id2]
+ # get hrns
+ site1_hrn = self.api.hrn + '.' + site1['login_base']
+ site2_hrn = self.api.hrn + '.' + site2['login_base']
+
+ for s1_node in self.nodes[site1['node_ids']]:
+ for s2_node in self.nodes[site2['node_ids']]:
+ # set interfaces
+ # just get first interface of the first node
+ if1_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (s1_node['node_id']))
+ if1_ipv4 = self.interfaces[node1['interface_ids'][0]]['ip']
+ if2_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (s2_node['node_id']))
+ if2_ipv4 = self.interfaces[node2['interface_ids'][0]]['ip']
+
+ if1 = Interface({'component_id': if1_xrn.urn, 'ipv4': if1_ipv4} )
+ if2 = Interface({'component_id': if2_xrn.urn, 'ipv4': if2_ipv4} )
+
+ # set link
+ link = Link({'capacity': '1000000', 'latency': '0', 'packet_loss': '0', 'type': 'ipv4'})
+ link['interface1'] = if1
+ link['interface2'] = if2
+ link['component_name'] = "%s:%s" % (site1['login_base'], site2['login_base'])
+ link['component_id'] = PlXrn(auth=self.api.hrn, interface=link['component_name']).get_urn()
+ link['component_manager_id'] = hrn_to_urn(self.api.hrn, 'authority+am')
+ links[link['component_name']] = link
+
+ return links
+
+ def get_node_tags(self, filter={}):
+ node_tags = {}
+ for node_tag in self.api.driver.GetNodeTags(filter):
+ node_tags[node_tag['node_tag_id']] = node_tag
+ return node_tags
+
+ def get_pl_initscripts(self, filter={}):
+ pl_initscripts = {}
+ filter.update({'enabled': True})
+ for initscript in self.api.driver.GetInitScripts(filter):
+ pl_initscripts[initscript['initscript_id']] = initscript
+ return pl_initscripts
+
+
+ def get_slice_and_slivers(self, slice_xrn):
+ """
+ Returns a dict of slivers keyed on the sliver's node_id
+ """
+ slivers = {}