def cluster(N_NODES, AM, SLICE_NAME, NODE_NAME, XML_NAME, SOFTWARE, PUBLIC_IP): rspec = PG.Request() IFACE = "if%d" INSTALL = "install-%s" for i in range(0, N_NODES): if i == 0: vm = IGX.XenVM("master") vm.disk_image = "urn:publicid:IDN+emulab.net+image+emulab-ops:UBUNTU14-64-STD" rspec.addResource(vm) vm.routable_control_ip = PUBLIC_IP if N_NODES > 1: vm_iface = vm.addInterface(IFACE % i) link = PG.LAN("lan0") link.addInterface(vm_iface) else: vm = IGX.XenVM(NODE_NAME % (i - 1)) vm.disk_image = "urn:publicid:IDN+emulab.net+image+emulab-ops:UBUNTU14-64-STD" rspec.addResource(vm) vm_iface = vm.addInterface(IFACE % i) link.addInterface(vm_iface) # Prepare nodes with corresponding software and install files # Create scripts for each software #for i in SOFTWARE: # /bin/bash # vm.addService(PG.Install(url=software(i), path="/tmp")) # vm.addService(PG.Execute(shell="/bin/bash", command="sudo sh /tmp/%s" % INSTALL % i + ".sh")) # Docker installation (for Trusty) vm.addService(PG.Install(url="", path="/tmp/docker")) vm.addService( PG.Execute(shell="/bin/bash", command="bash /tmp/docker/docker_inst_trusty.sh")) if N_NODES > 1: rspec.addResource(link) # Deploy resources at GENI manifest = AM.createsliver(context, SLICE_NAME, rspec) geni.util.printlogininfo(manifest=manifest) # Create manifest in XML file rspec.writeXML(XML_NAME)
def Node(name, public): if params.raw: newnode = RSpec.RawPC(name) else: newnode = IG.XenVM(name) newnode.ram = 2048 newnode.cores = 2 if public: newnode.routable_control_ip = True return newnode
def __init__(self): """Summary """ # Import optional libraries import geni.rspec.igext as IGX self.households = [] self.router = IGX.XenVM("router-%d" % self.server_count) self.links = [] self.house_count_local = 0 self.server_count += 1
def add_node_to_rspec(config_info, site_dict, link_ifaces, vn, rspec): ''' add node resource to RSpec ''' for site_id in site_dict: node_in_site = site_dict[site_id] for node_id in node_in_site: node = vn.node_dict[node_id] vm = ig.XenVM(node.hostname) # Nodes are bounded to particular InstaGENI Sites, add component_manager_id to RSpec if site_id != 'any': vm.component_manager_id = site_info.ig_site[int( site_id)].component_manager_id for iface in node.iface_list: vm_iface = vm.addInterface(iface.id) vm_iface.addAddress(pg.IPv4Address(iface.addr, iface.prefix)) link_ifaces[iface.link_id].append(vm_iface) if node.node_type == 'lan-sw': # invisible node for LAN topology, no need to add service, etc. pass else: # add node properties to non-"sw" type nodes vm.disk_image = node.disk_image service_list = config_info[ node.node_type]['install_script'].split('\n') cmd_list = config_info[node.node_type]['execute_cmd'].split( '\n') if "routable_control_ip" in config_info[node.node_type]: vm.routable_control_ip = config_info[ node.node_type]['routable_control_ip'] in YES for service in service_list: if service != '': service_url = service.split(',')[0].strip() service_path = service.split(',')[1].strip() vm.addService( pg.Install(url=service_url, path=service_path)) for cmd in cmd_list: if cmd != '': cmd_exe = cmd.split(',')[0].strip() cmd_shell = cmd.split(',')[1].strip() vm.addService( pg.Execute(shell=cmd_shell, command=cmd_exe)) rspec.addResource(vm) return rspec
def add_household(self, house): """Summary Args: house (TYPE): Description Returns: TYPE: Description """ # Import optional libraries import geni.rspec.pg as PG import geni.rspec.igext as IGX speed = max(house.rate_up_kbps, house.rate_down_kbps) self.links.insert(self.house_count_local, PG.LAN('lan%d' % self.house_count)) self.links[self.house_count_local].bandwidth = int(speed) igvm = IGX.XenVM("house-%d" % house.unit_id) ip_netem = "10.0.%d.0" % self.house_count netem_str = "$(ip route get %s | head -n 1 | cut -d \ -f4)" % ( ip_netem) user_netem = house.netem_template_up(netem_str) server_netem = house.netem_template_down(netem_str) self.router.addService( PG.Execute(shell="/bin/sh", command=server_netem)) igvm.addService(PG.Execute(shell="/bin/sh", command=user_netem)) self.households.insert(self.house_count_local, igvm) iface = igvm.addInterface("if-%d-1" % self.house_count) iface.addAddress( PG.IPv4Address("10.0.%d.1" % self.house_count, "255.255.255.0")) self.links[self.house_count_local].addInterface(iface) server_iface = self.router.addInterface("if-%d-2" % self.house_count) server_iface.addAddress( PG.IPv4Address("10.0.%d.2" % self.house_count, "255.255.255.0")) self.links[self.house_count_local].addInterface(server_iface) self.house_count_local += 1 self.house_count += 1
import geni.rspec.emulab as emulab from lxml import etree as ET pc = portal.Context() request = rspec.Request() pc.defineParameter("param1", "dsc1", portal.ParameterType.INTEGER, 1) pc.defineParameter("param2", "dsc2", portal.ParameterType.STRING, "value2") params = pc.bindParameters() ele2 = ET.Element("xmlstuff") ET.SubElement(ele2, "evenmorexml") node1 = IG.XenVM("node1") iface1 = node1.addInterface("if1") # Add user data to node1 in a single line node1.UserData(emulab.UserDataSet({"data1": ele2, "data2": "val2"})) link = rspec.Link("link") link.addInterface(iface1) # Add user data to link over several lines linkdata = emulab.UserDataSet() linkdata.addData("linkdata1", "val1") linkdata.addData("linkdata2", "val2") link.UserData(linkdata) request.addResource(node1)
for (k, v) in addrs.iteritems(): sa = k.split('-')[1:] (src, dst) = (sa[0], sa[1]) if len(sa) > 2: linkidx = int(sa[2]) postfix = "-" + sa[2] else: linkidx = None postfix = "" srcname = 'node-' + src dstname = 'node-' + dst for (name, num) in [(srcname, src), (dstname, dst)]: if name in nodes: continue vnode = nodes[name] = IG.XenVM(name) if disableTestbedRootKeys: vnode.installRootKeys(False, False) if name == params.controllerNode: vnode._ext_children.append(Label("controller", "1")) if name in snifferNodes: vnode._ext_children.append(Label("sniffer", "1")) if name in netflowNodes: vnode._ext_children.append(Label("netflow", "1")) vnode.addService(RSpec.Execute(shell="sh", command=CMD)) vnode.cores = params.coresPerVM vnode.ram = params.ramPerVM vnode.exclusive = True if params.vmImage: vnode.disk_image = params.vmImage if params.hostType != "any":
#import geni.aggregate.instageni as IG #import geni.aggregate.apis #import nbastin #context = nbastin.buildContext() #context.debug = True #try: # IG.GPO.deletesliver(context, "xen-test2") #except geni.aggregate.apis.AMError, e: # pass r = PG.Request() vm1 = IGX.XenVM("xen1") intf1 = vm1.addInterface("if0") r.addResource(vm1) vm2 = IGX.XenVM("xen2") intf2 = vm2.addInterface("if0") r.addResource(vm2) lnk = PG.Link() lnk.addInterface(intf1) lnk.addInterface(intf2) lnk.bandwidth = 1000000 lnk.disableMACLearning() r.addResource(lnk)