def rspec_to_omnispec(urn, rspec): # URN is that of the AM ospec = OmniSpec("rspec_sfa", urn) doc = ET.fromstring(rspec) for network in doc.findall('network'): for site in network.findall('site'): for node in site.findall('node'): net_name = network.get('name') site_id = site.get('id') site_name = site.find('name').text hostname = node.find('hostname').text r = OmniResource(hostname, '%s %s %s' % (net_name, site_id, hostname), 'vm') urn = 'urn:publicid:IDN+%s:%s+node+%s' % (net_name.replace( '.', ":"), site_name, hostname.split('.')[0]) misc = r['misc'] misc['site_id'] = site_id misc['site_name'] = site_name misc['hostname'] = hostname misc['net_name'] = net_name misc['node_id'] = node.get('id') if not node.find('sliver') is None: r.set_allocated(True) ospec.add_resource(urn, r) return ospec
def rspec_to_omnispec(urn, rspec): # URN is that of the AM ospec = OmniSpec("rspec_sfa", urn) doc = ET.fromstring(rspec) for network in doc.findall('network'): for site in network.findall('site'): for node in site.findall('node'): net_name = network.get('name') site_id = site.get('id') site_name = site.find('name').text hostname = node.find('hostname').text r = OmniResource(hostname, '%s %s %s' % (net_name, site_id, hostname), 'vm') urn = 'urn:publicid:IDN+%s:%s+node+%s' % (net_name.replace('.', ":"), site_name, hostname.split('.')[0]) misc = r['misc'] misc['site_id'] = site_id misc['site_name'] = site_name misc['hostname'] = hostname misc['net_name'] = net_name misc['node_id'] = node.get('id') if not node.find('sliver') is None: r.set_allocated(True) ospec.add_resource(urn, r) return ospec
def add_nodes(ospec, root): for res in root.findall(pg_tag('node')): name = res.attrib['component_name'] description = 'ProtoGENI Node' type = 'node' omni_res = OmniResource(name, description, type) available = res.find(pg_tag('available')).text.lower() == 'true' omni_res.set_allocated(not (available)) omni_res['orig_xml'] = ET.tostring(res) id = res.attrib['component_uuid'] ospec.add_resource(id, omni_res)
def add_links(ospec, root): for res in root.findall(pg_tag('link')): name = res.attrib['component_name'] description = 'ProtoGENI Link' type = 'link' omni_res = OmniResource(name, description, type) # Links appear to be always available available = True omni_res.set_allocated(not (available)) omni_res['orig_xml'] = ET.tostring(res) id = res.attrib['component_uuid'] ospec.add_resource(id, omni_res)
def add_links(ospec, root): for res in root.findall(pg_tag('link')): name = res.attrib['component_name'] description = 'ProtoGENI Link' type = 'link' omni_res = OmniResource(name, description, type) # Links appear to be always available available = True omni_res.set_allocated(not(available)) omni_res['orig_xml'] = ET.tostring(res) id = res.attrib['component_uuid'] ospec.add_resource(id, omni_res)
def add_nodes(ospec, root): for res in root.findall(pg_tag('node')): name = res.attrib['component_name'] description = 'ProtoGENI Node' type = 'node' omni_res = OmniResource(name, description, type) available = res.find(pg_tag('available')).text.lower() == 'true' omni_res.set_allocated(not(available)) omni_res['orig_xml'] = ET.tostring(res) id = res.attrib['component_uuid'] ospec.add_resource(id, omni_res)
def rspec_to_omnispec(urn, rspec): # URN is that of the AM ospec = OmniSpec("rspec_gcf", urn) doc = ET.fromstring(rspec) for res in doc.findall('resource'): type = res.find('type').text id = res.find('id').text rurn = res.find('urn').text available = res.find('available').text available = available.lower() == 'true' r = OmniResource(id, 'node ' + id, type) r.set_allocated(not available) ospec.add_resource(rurn, r) return ospec
def rspec_to_omnispec(urn, rspec): ospec = OmniSpec("rspec_of", urn) ospec = make_skeleton_of_ospec(ospec) doc = ET.fromstring(rspec) #sys.stderr.write(rspec) for network in doc.findall('network'): net_name = network.get('name') switches = network.findall('switches')[0] swmap = {} for switch in switches.findall('switch'): # convert: # "<switch urn="urn:publicid:IDN+openflow:stanford+switch:0" />" urn = switch.get('urn') # switchname = "stanford_network:switch:00:00:00:23:01:35:a5:5d" switchname = net_name + ':' + urn.split('+')[1] s = OmniResource(switchname, "OpenFlow Switch" ,'switch') options=['dl_src', 'dl_dst', 'dl_type', 'vlan_id', 'nw_src',\ 'nw_dst', 'nw_proto', 'tp_src', 'tp_dst'] for opt in options: s['options'][opt] = 'from=*, to=*' swmap[urn] = s ospec.add_resource(urn, s) for port in switch.findall('port'): port_urn = port.get('urn') port = 'port:' + port_urn.split('port:')[-1] swmap[urn]['options'][port] = "switch:* port:*" links = network.findall('links')[0] for link in links.findall('link'): # convert: # <link # src_urn="urn:publicid:IDN+openflow:stanford+switch:0+port:0 # dst_urn="urn:publicid:IDN+openflow:stanford+switch:1+port:0 # /> _,domain,src_switch,src_port = link.get('src_urn').split('+') _,_,dst_switch,dst_port = link.get('dst_urn').split('+') switch_urn = "urn:publicid:IDN+" + domain + "+" + src_switch swmap[switch_urn]['options'][src_port] = dst_switch + " " + dst_port #sw_ports = swmap[switch_urn]['misc'].setdefault('ports', {}) #sw_ports[src_port] = dst_switch + " " + dst_port #swmap[switch_urn]['options'][src_port] = "from=%s, to=%s" % (src_port.split(":")[-1], src_port.split(":")[-1]) return ospec
def make_skeleton_of_ospec(ospec): ''' Add resources for the client to reserve. Hacking it in here because Expedient assumes the caller will add them themselves. ''' # setup a resource for fv_account user = OmniResource("sliceinfo","Slice information for FlowVisor Access",'user') # goes in <user> user['options']['firstname'] = 'John' user['options']['lastname'] = 'Doe' user['options']['email'] = '*****@*****.**' user['options']['fv_password'] = '******' # goes in <project> user['options']['project_name'] = 'Stanford Networking Group' user['options']['project_description'] = 'Internet performance research to ...' # goes in <slice> user['options']['slice_name'] = 'Crazy Load Balancing Experiment' user['options']['slice_description'] = 'Does crazy load balancing and plate spinning' user['options']['controller_url'] = 'tcp:unknown:6633' user_urn = 'urn:publicid:IDN+openflow:stanford+user+' + user.get_name() ospec.add_resource(user_urn, user) return ospec
def add_options(ospec, root): onode = OmniResource("RandomNode", "Let Protogeni select available nodes for you", "RandomPC") misc = onode['misc'] free = 0 used = 0 for res in root.findall(pg_tag('node')): if res.find(pg_tag('disk_image')) is None: continue if res.find(pg_tag('available')).text.lower() == 'false': used += 1 else: free += 1 misc['free nodes'] = free misc['used nodes'] = used options = onode['options'] options['startup command'] = '/bin/ls > /dev/null' options['virtual'] = True options['number'] = 1 options['os'] = 'FEDORA10-STD' ospec.add_resource('RandomNode', onode)