Commit 3b683360 authored by Robert Ricci's avatar Robert Ricci

Convert examples to more modern geni-lib style

Use the new form that doesn't require addResource(), and use the new
style for the portal.context
parent e908b769
Pipeline #1759 passed with stage
in 2 minutes and 8 seconds
......@@ -11,34 +11,27 @@ communication only.)
"""
import geni.portal as portal
import geni.rspec.pg as pg
import geni.rspec.pg as rspec
pc = portal.Context()
rspec = pg.Request()
request = portal.context.makeRequestRSpec()
node1 = pg.XenVM("node1")
node1 = request.XenVM("node1")
iface1 = node1.addInterface("if1")
# Specify the component id and the IPv4 address
iface1.component_id = "eth1"
iface1.addAddress(pg.IPv4Address("192.168.1.1", "255.255.255.0"))
iface1.addAddress(rspec.IPv4Address("192.168.1.1", "255.255.255.0"))
rspec.addResource(node1)
node2 = pg.XenVM("node2")
node2 = request.XenVM("node2")
iface2 = node2.addInterface("if2")
# Specify the component id and the IPv4 address
iface2.component_id = "eth2"
iface2.addAddress(pg.IPv4Address("192.168.1.2", "255.255.255.0"))
rspec.addResource(node2)
iface2.addAddress(rspec.IPv4Address("192.168.1.2", "255.255.255.0"))
link = pg.LAN("lan")
link = request.LAN("lan")
link.addInterface(iface1)
link.addInterface(iface2)
rspec.addResource(link)
pc.printRequestRSpec(rspec)
portal.context.printRequestRSpec()
......@@ -9,20 +9,17 @@ required.
"""
import geni.portal as portal
import geni.rspec.pg as pg
import geni.rspec.pg as rspec
pc = portal.Context()
rspec = pg.Request()
request = portal.context.makeRequestRSpec()
node1 = pg.XenVM("node1")
node1 = request.XenVM("node1")
# Specify the URL for the disk image
node1.disk_image = "<URL to disk image>"
# Install and execute scripts on the VM
node1.addService(pg.Install(url="http://example.org/sample.tar.gz", path="/local"))
node1.addService(pg.Execute(shell="bash", command="/local/example.sh"))
node1.addService(rspec.Install(url="http://example.org/sample.tar.gz", path="/local"))
node1.addService(rspec.Execute(shell="bash", command="/local/example.sh"))
rspec.addResource(node1)
pc.printRequestRSpec(rspec)
pc.printRequestRSpec()
......@@ -9,28 +9,24 @@ the VMs via the ssh port(s) specified below.
# Import the Portal object.
import geni.portal as portal
# Import the ProtoGENI library.
import geni.rspec.pg as pg
# Create the Portal context.
pc = portal.Context()
import geni.rspec.pg as rspec
# Describe the parameter(s) this profile script can accept.
pc.defineParameter( "n", "Number of VMs", portal.ParameterType.INTEGER, 1 )
portal.context.defineParameter( "n", "Number of VMs", portal.ParameterType.INTEGER, 1 )
# Retrieve the values the user specifies during instantiation.
params = pc.bindParameters()
params = portal.context.bindParameters()
# Create a Request object to start building the RSpec.
rspec = pg.Request()
request = portal.context.makeRequestRSpec()
# Check parameter validity.
if params.n < 1 or params.n > 8:
pc.reportError( portal.ParameterError( "You must choose at least 1 and no more than 8 VMs." ) )
portal.context.reportError( portal.ParameterError( "You must choose at least 1 and no more than 8 VMs." ) )
for i in range( params.n ):
# Create a XenVM and add it to the RSpec.
node = pg.XenVM( "node" + str( i ) )
rspec.addResource( node )
node = request.XenVM( "node" + str( i ) )
# Print the RSpec to the enclosing page.
pc.printRequestRSpec(rspec)
portal.context.printRequestRSpec()
......@@ -5,20 +5,14 @@ Wait for the profile instance to start, and then log in to the host via the
ssh port specified below.
"""
# Import the Portal object.
import geni.portal as portal
# Import the ProtoGENI library.
import geni.rspec.pg as pg
import geni.rspec.pg as rspec
# Create the Portal context.
pc = portal.Context()
# Create a Request object to start building the RSpec.
rspec = pg.Request()
request = portal.context.makeRequestRSpec()
# Create a raw PC and add it to the RSpec.
node = pg.RawPC("node")
rspec.addResource(node)
# Create a raw PC
node = request.RawPC("node")
# Print the RSpec to the enclosing page.
pc.printRequestRSpec(rspec)
portal.context.printRequestRSpec()
......@@ -7,19 +7,14 @@ the VM through a high port on the physical host, since we have not requested
a public IP address for the VM itself.)
"""
# Import the Portal object.
import geni.portal as portal
# Import the ProtoGENI library.
import geni.rspec.pg as pg
import geni.rspec.pg as rspec
# Create the Portal context.
pc = portal.Context()
# Create a Request object to start building the RSpec.
rspec = pg.Request()
request = portal.context.makeRequestRSpec()
# Create a XenVM and add it to the RSpec.
node = pg.XenVM("node")
# Create a XenVM
node = request.XenVM("node")
# Ask for two cores
node.cores = 2
......@@ -28,8 +23,5 @@ node.ram = 2048
# Add an extra 8GB virtual disk.
node.disk = 8
# Add the node to the RSpec
rspec.addResource(node)
# Print the RSpec to the enclosing page.
pc.printRequestRSpec(rspec)
portal.context.printRequestRSpec()
......@@ -7,20 +7,14 @@ the VM through a high port on the physical host, since we have not requested
a public IP address for the VM itself.)
"""
# Import the Portal object.
import geni.portal as portal
# Import the ProtoGENI library.
import geni.rspec.pg as pg
import geni.rspec.pg as rspec
# Create the Portal context.
pc = portal.Context()
# Create a Request object to start building the RSpec.
rspec = pg.Request()
request = portal.context.makeRequestRSpec()
# Create a XenVM and add it to the RSpec.
node = pg.XenVM("node")
rspec.addResource(node)
# Create a XenVM
node = request.XenVM("node")
# Print the RSpec to the enclosing page.
pc.printRequestRSpec(rspec)
portal.context.printRequestRSpec()
......@@ -6,14 +6,13 @@ ssh ports specified below.
"""
import geni.portal as portal
import geni.rspec.pg as pg
import geni.rspec.pg as rspec
pc = portal.Context()
rspec = pg.Request()
request = portal.context.makeRequestRSpec()
# Create two raw "PC" nodes
node1 = pg.RawPC("node1")
node2 = pg.RawPC("node2")
node1 = request.RawPC("node1")
node2 = request.RawPC("node2")
# Set each of the two to specifically request "m400" nodes, which in CloudLab, are ARM
node1.hardware_type = "m400"
......@@ -23,17 +22,11 @@ node2.hardware_type = "m400"
iface1 = node1.addInterface("if1")
iface2 = node2.addInterface("if2")
rspec.addResource(node1)
rspec.addResource(node2)
# Create a link with the type of LAN.
link = pg.LAN("lan")
# Create a link with type LAN.
link = request.LAN("lan")
# Add both node interfaces to the link.
link.addInterface(iface1)
link.addInterface(iface2)
# Add the link to the RSpec.
rspec.addResource(link)
pc.printRequestRSpec(rspec)
portal.context.printRequestRSpec()
......@@ -10,35 +10,38 @@ refer to the OpenEPC documentation for instructions on how to
operate OpenEPC.
"""
import geni.portal
import geni.rspec.pg
import geni.rspec.emulab.pnext as PN
# Import the standard RSpec and portal modules
import geni.portal as portal
import geni.rspec.pg as rspec
pc = geni.portal.Context()
rspec = geni.rspec.pg.Request()
# Import phantoment-specific functionality
import geni.rspec.emulab.pnext as pn
# Create OpenEPC nodes:
epcen = PN.mkepcnode( "epc", PN.EPCROLES.ENABLERS )
rspec.addResource( epcen )
request = portal.context.makeRequestRSpec()
pgw = PN.mkepcnode( "pgw", PN.EPCROLES.PGW )
rspec.addResource( pgw )
# Create OpenEPC nodes; nodes made with this helper function must
# be explicitly added to request after creating them
epcen = pn.mkepcnode( "epc", pn.EPCROLES.ENABLERS )
request.addResource( epcen )
sgw = PN.mkepcnode( "sgw", PN.EPCROLES.SGW_MME_SGSN )
rspec.addResource( sgw )
pgw = pn.mkepcnode( "pgw", pn.EPCROLES.PGW )
request.addResource( pgw )
enodeb = PN.mkepcnode( "enodeb", PN.EPCROLES.ENODEB )
rspec.addResource( enodeb )
sgw = pn.mkepcnode( "sgw", pn.EPCROLES.SGW_MME_SGSN )
request.addResource( sgw )
ue = PN.mkepcnode( "ue", PN.EPCROLES.CLIENT )
rspec.addResource( ue )
enodeb = pn.mkepcnode( "enodeb", pn.EPCROLES.ENODEB )
request.addResource( enodeb )
ue = pn.mkepcnode( "ue", pn.EPCROLES.CLIENT )
request.addResource( ue )
# Create LANs:
mgmt = rspec.EPClan( PN.EPCLANS.MGMT )
net_a = rspec.EPClan( PN.EPCLANS.NET_A )
net_b = rspec.EPClan( PN.EPCLANS.NET_B )
net_d = rspec.EPClan( PN.EPCLANS.NET_D )
an_lte = rspec.EPClan( PN.EPCLANS.AN_LTE )
mgmt = request.EPClan( pn.EPCLANS.MGMT )
net_a = request.EPClan( pn.EPCLANS.NET_A )
net_b = request.EPClan( pn.EPCLANS.NET_B )
net_d = request.EPClan( pn.EPCLANS.NET_D )
an_lte = request.EPClan( pn.EPCLANS.AN_LTE )
# Add nodes to appropriate LANs:
mgmt.addMember( epcen )
......@@ -59,4 +62,4 @@ net_d.addMember( enodeb )
an_lte.addMember( enodeb )
an_lte.addMember( ue )
pc.printRequestRSpec( rspec )
portal.context.printRequestRSpec()
......@@ -8,23 +8,20 @@ This is an example profile to demonstrate the description of RF links.
It is not particularly useful to instantiate directly.
"""
import geni.portal
import geni.rspec.pg
import geni.rspec.emulab.pnext as PN
import geni.portal as portal
import geni.rspec.pg as rspec
import geni.rspec.emulab.pnext as pn
pc = geni.portal.Context()
rspec = geni.rspec.pg.Request()
request = portal.context.makeRequestRSpec()
node0 = geni.rspec.pg.RawPC( "node0" )
node0 = request.RawPC( "node0" )
iface0 = node0.addInterface( "rf0" )
rspec.addResource( node0 )
node1 = geni.rspec.pg.RawPC( "node1" )
node1 = request.RawPC( "node1" )
iface1 = node1.addInterface( "rf1" )
rspec.addResource( node1 )
rflink = rspec.RFLink( "rflink" )
rflink = request.RFLink( "rflink" )
rflink.addInterface( iface0 )
rflink.addInterface( iface1 )
pc.printRequestRSpec( rspec )
portal.context.printRequestRSpec()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment