Exemplo n.º 1
0
    def get_rspec(self,
                  version=None,
                  slice_leaf=None,
                  projectName=None,
                  created_vms=[],
                  new_nodes=[],
                  options={}):

        version_manager = VersionManager()
        version = version_manager.get_version(version)
        if slice_leaf:
            #Manifest RSpec will be used when somebody creates an sliver, returning the resources of this AM and the vm(s) requested by the user.
            rspec_version = version_manager._get_version(
                version.type, version.version, 'manifest')
            options['slice'] = slice_leaf
            nodes = self.get_nodes_in_geni(options, slice_leaf, projectName,
                                           created_vms, new_nodes)
            rspec = RSpec(version=rspec_version, user_options=options)
            rspec.version.add_nodes_geni(nodes)

        else:
            rspec_version = version_manager._get_version(
                version.type, version.version, 'ad')
            nodes = self.get_nodes(options, slice_leaf, projectName,
                                   created_vms, new_nodes)
            rspec = RSpec(version=rspec_version, user_options=options)
            #nodes = self.get_nodes(options,slice_leaf,projectName,created_vms,new_nodes)
            rspec.version.add_nodes(nodes)
        return rspec.toxml()
Exemplo n.º 2
0
	def list_resources (self,options):

		version_manager = VersionManager()
        	rspec_version = 'OcfVt'#version_manager.get_version(options.get('geni_rspec_version'))
        	version_string = "rspec_%s" % (rspec_version)
	        rspec =  self.aggregate.get_rspec(version=rspec_version,options=options)
       		return rspec
    def to_sfa_rspec(rspec, content_type=None):
        if not isinstance(rspec, RSpec):
            pg_rspec = RSpec(rspec)
        else:
            pg_rspec = rspec

        version_manager = VersionManager()
        sfa_version = version_manager._get_version('sfa', '1')
        sfa_rspec = RSpec(version=sfa_version)

        #nodes = pg_rspec.version.get_nodes()
        #sfa_rspec.version.add_nodes(nodes())
        #sfa_rspec.version.add_links(pg_rspec.version.get_links())
        #return sfa_rspec.toxml()

        # get network
        networks = pg_rspec.version.get_networks()
        network_hrn = networks[0]["name"]
        network_element = sfa_rspec.xml.add_element('network',
                                                    name=network_hrn,
                                                    id=network_hrn)

        # get nodes
        pg_nodes_elements = pg_rspec.version.get_nodes()
        nodes_with_slivers = pg_rspec.version.get_nodes_with_slivers()
        i = 1
        for pg_node in pg_nodes_elements:
            attribs = dict(pg_node.items())
            attribs['id'] = 'n' + str(i)

            node_element = network_element.add_element('node')
            for attrib in attribs:
                if type(attribs[attrib]) == str:
                    node_element.set(attrib, attribs[attrib])
            urn = pg_node["component_id"]
            if urn:
                if type(urn) == list:
                    # legacy code, not sure if urn is ever a list...
                    urn = urn[0]
                hostname = Xrn.urn_split(urn)[-1]
                hostname_element = node_element.add_element('hostname')
                hostname_element.set_text(hostname)
                if hostname in nodes_with_slivers:
                    node_element.add_element('sliver')

            for hardware_type in pg_node["hardware_types"]:
                if "name" in hardware_type:
                    node_element.add_element("hardware_type",
                                             name=hardware_type["name"])

            # just copy over remaining child elements
            #for child in pg_node_element.getchildren():
            #    node_element.append(transform(child).getroot())
            i = i + 1

        return sfa_rspec.toxml()
Exemplo n.º 4
0
 def list_resources(self, options):
     version_manager = VersionManager()
     rspec_version = 'OcfVt'  #version_manager.get_version(options.get('geni_rspec_version'))
     version_string = "rspec_%s" % (rspec_version)
     slice_leaf = None
     if options.get("slice"):
         slice_leaf = options['slice']
     rspec = self.aggregate.get_rspec(version=rspec_version,
                                      options=options,
                                      slice_leaf=slice_leaf)
     return rspec
 def to_sfa_rspec(in_rspec, content_type=None):
     rspec = RSpec(in_rspec)
     version_manager = VersionManager()
     sfa_version = version_manager._get_version('sfa', '1')
     pg_version = version_manager._get_version('protogeni', '2')
     if rspec.version.type.lower() == sfa_version.type.lower():
         return in_rspec
     elif rspec.version.type.lower() == pg_version.type.lower():
         return PGRSpecConverter.to_sfa_rspec(in_rspec, content_type)
     else:
         return in_rspec
Exemplo n.º 6
0
 def __init__(self, rspec="", version=None, user_options={}):
     self.header = '<?xml version="1.0"?>\n'
     self.template = """<RSpec></RSpec>"""
     self.version = None
     self.xml = XML()
     self.version_manager = VersionManager()
     self.user_options = user_options
     self.elements = {}
     if rspec:
         if version:
             self.version = self.version_manager.get_version(version)
             self.parse_xml(rspec, version)
         else:
             self.parse_xml(rspec)
     elif version:
         self.create(version)
     else:
         raise InvalidRSpec(
             "No RSpec or version specified. Must specify a valid rspec string or a valid version"
         )