X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Frspecs%2Fversions%2Fslabv1.py;h=39adddacefccc0ddae4bcb37ab7d1c5c79be48c5;hb=1cc8e9613cab8b5b22478de369f259e591c54e6d;hp=465eca55a7363ea2757911fd1eaf20527514b941;hpb=0f490c099f9ca3904906db97827eb3162fd7be6b;p=sfa.git diff --git a/sfa/rspecs/versions/slabv1.py b/sfa/rspecs/versions/slabv1.py index 465eca55..39adddac 100644 --- a/sfa/rspecs/versions/slabv1.py +++ b/sfa/rspecs/versions/slabv1.py @@ -1,15 +1,15 @@ from copy import deepcopy -#from StringIO import StringIO -#from sfa.util.xrn import urn_to_sliver_id -#from sfa.util.plxrn import hostname_to_urn, xrn_to_hostname from sfa.rspecs.version import RSpecVersion import sys - +from sfa.rspecs.elements.versions.slabv1Lease import Slabv1Lease from sfa.rspecs.elements.versions.slabv1Node import Slabv1Node from sfa.rspecs.elements.versions.slabv1Sliver import Slabv1Sliver -from sfa.rspecs.elements.versions.slabv1Timeslot import Slabv1Timeslot + + +from sfa.rspecs.elements.versions.sfav1Lease import SFAv1Lease + from sfa.util.sfalogging import logger class Slabv1(RSpecVersion): @@ -30,7 +30,10 @@ class Slabv1(RSpecVersion): # Network def get_networks(self): - network_elems = self.xml.xpath('//network') + #WARNING Added //default:network to the xpath + #otherwise network element not detected 16/07/12 SA + + network_elems = self.xml.xpath('//network | //default:network') networks = [network_elem.get_instance(fields=['name', 'slice']) for \ network_elem in network_elems] return networks @@ -55,9 +58,12 @@ class Slabv1(RSpecVersion): def get_slice_timeslot(self ): return Slabv1Timeslot.get_slice_timeslot(self.xml) - + + def add_connection_information(self, ldap_username, sites_set): + return Slabv1Node.add_connection_information(self.xml,ldap_username, sites_set) + def add_nodes(self, nodes, check_for_dupes=False): - return Slabv1Node.add_nodes(self.xml, nodes) + return Slabv1Node.add_nodes(self.xml,nodes ) def merge_node(self, source_node_tag, network, no_dupes = False): logger.debug("SLABV1 merge_node") @@ -91,18 +97,16 @@ class Slabv1(RSpecVersion): def get_slice_attributes(self, network=None): slice_attributes = [] - slot = self.get_slice_timeslot() + nodes_with_slivers = self.get_nodes_with_slivers() - slice_attributes.append({'timeslot':slot}) - #slice_attributes.append({'name': 'timeslot', 'value' : slot}) - print>>sys.stderr, "\r\n \r\n \r\n \t\t SLABV1.PY get_slice_attributes -----------------nodes_with_slivers %s "%(nodes_with_slivers) + # TODO: default sliver attributes in the PG rspec? default_ns_prefix = self.namespaces['default'] for node in nodes_with_slivers: sliver_attributes = self.get_sliver_attributes(node['component_id'],node, network) for sliver_attribute in sliver_attributes: - name=str(sliver_attribute[0]) - text =str(sliver_attribute[1]) + name = str(sliver_attribute[0]) + text = str(sliver_attribute[1]) attribs = sliver_attribute[2] # we currently only suppor the and attributes #if 'info' in name: @@ -117,8 +121,7 @@ class Slabv1(RSpecVersion): attribute = {'name': 'initscript', 'value': value, 'node_id': node} slice_attributes.append(attribute) - - print>>sys.stderr, "\r\n \r\n \r\n \t\t SLABV1.PY get_slice_attributes ----------------- slice_attributes %s "%(slice_attributes) + return slice_attributes def attributes_list(self, elem): @@ -145,6 +148,7 @@ class Slabv1(RSpecVersion): node_elem = node_elems[0] # determine sliver types for this node + #TODO : add_slivers valid type of sliver needs to be changed 13/07/12 SA valid_sliver_types = ['slab-node', 'emulab-openvz', 'raw-pc', 'plab-vserver', 'plab-vnode'] #valid_sliver_types = ['emulab-openvz', 'raw-pc', 'plab-vserver', 'plab-vnode'] requested_sliver_type = None @@ -193,35 +197,51 @@ class Slabv1(RSpecVersion): def remove_slivers(self, slivers, network=None, no_dupes=False): Slabv1Node.remove_slivers(self.xml, slivers) - - - + + # Utility - + def merge(self, in_rspec): """ Merge contents for specified rspec with current rspec """ - from sfa.rspecs.rspec import RSpec - # just copy over all the child elements under the root element - if isinstance(in_rspec, basestring): - in_rspec = RSpec(in_rspec) - - nodes = in_rspec.version.get_nodes() - # protogeni rspecs need to advertise the availabel sliver types - for node in nodes: - if not node.has_key('sliver') or not node['sliver']: - node['sliver'] = {'name': 'slab-node'} - - self.add_nodes(nodes) - #self.add_links(in_rspec.version.get_links()) - - # - #rspec = RSpec(in_rspec) - #for child in rspec.xml.iterchildren(): - # self.xml.root.append(child) + + if not in_rspec: + return + from sfa.rspecs.rspec import RSpec + + if isinstance(in_rspec, RSpec): + rspec = in_rspec + else: + rspec = RSpec(in_rspec) + if rspec.version.type.lower() == 'protogeni': + from sfa.rspecs.rspec_converter import RSpecConverter + in_rspec = RSpecConverter.to_sfa_rspec(rspec.toxml()) + rspec = RSpec(in_rspec) + # just copy over all networks + #Attention special get_networks using //default:network xpath + current_networks = self.get_networks() + networks = rspec.version.get_networks() + for network in networks: + current_network = network.get('name') + if current_network and current_network not in current_networks: + self.xml.append(network.element) + current_networks.append(current_network) + + + + + # Leases + + def get_leases(self, lease_filter=None): + return SFAv1Lease.get_leases(self.xml, lease_filter) + #return Slabv1Lease.get_leases(self.xml, lease_filter) + + def add_leases(self, leases, network = None, no_dupes=False): + SFAv1Lease.add_leases(self.xml, leases) + #Slabv1Lease.add_leases(self.xml, leases) def cleanup(self): # remove unncecessary elements, attributes