Commit 5d7fe1c5 authored by Robert Ricci's avatar Robert Ricci

Add three new code samples

Asking for a raw PC, asking for ARM machines, and setting up a
parameterized profile. Also re-worked #:tags to be more meaningful
parent 780b409c
import geni.portal as portal
import geni.rspec.pg as RSpec
# The legal types of nodes - note that the first string in each pair is the
# string that will get put in the RSpec, and the second is the one that will
# get shown to the user. If there is no need to show the user a different string,
# each element of the array can be a simple string rather than a tuple.
hw_types = [("m400", "ARM64"), ("dl360", "x86-64")]
pc = portal.Context()
# Define parameters - see this page for API documentation for the
# defineParameter() call:
# http://geni-lib.readthedocs.org/en/latest/api/geniportal.html#geni.portal.Context.defineParameter
pc.defineParameter("N", "Number of nodes",
portal.ParameterType.INTEGER, 5)
pc.defineParameter("hwtype", "Hardware type",
portal.ParameterType.NODETYPE, "m400", hw_types)
pc.defineParameter("lan", "Put all nodes in a LAN",
portal.ParameterType.BOOLEAN, False)
# Get values for the parameters - since a default is required by defineParameter,
# the params object is guaranteed to contain a vale for every parameter
params = pc.bindParameters()
rspec = RSpec.Request()
# Create a LAN iff one was requested
if (params.lan):
lan = RSpec.LAN()
rspec.addResource(lan)
# Loop through the number of nodes requested, settting up each and adding it
# to the RSpec
for i in range(1, params.N+1):
node = RSpec.RawPC("node%d" % i)
node.hardware_type = params.hwtype
rspec.addResource(node)
# Only create an interface if we are putting all nodes into a LAN
if params.lan:
iface = node.addInterface("eth0")
lan.addInterface(iface)
pc.printRequestRSpec(rspec)
# 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()
# Create a Request object to start building the RSpec.
rspec = pg.Request()
# Create a raw PC and add it to the RSpec.
node = pg.RawPC("node")
rspec.addResource(node)
# Print the RSpec to the enclosing page.
pc.printRequestRSpec(rspec)
import geni.portal as portal
import geni.rspec.pg as pg
pc = portal.Context()
rspec = pg.Request()
# Create two raw "PC" nodes
node1 = pg.RawPC("node1")
node2 = pg.RawPC("node2")
# Set each of the two to specifically request "m400" nodes, which in CloudLab, are ARM
node1.hardware_type = "m400"
node2.hardware_type = "m400"
# Create interfaces for each node.
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")
# 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)
......@@ -246,22 +246,28 @@ The following examples demonstrate basic @tt{geni-lib} usage. More information
about @tt{geni-lib} and additional examples, can be found in the
@hyperlink["https://bitbucket.org/barnstorm/geni-lib/src"]{@tt{geni-lib} repository}.
@subsection[#:tag "geni-lib-example-1"]{A Single XEN VM node}
@subsection[#:tag "geni-lib-example-single-vm"]{A single XEN VM node}
@code-sample["geni-lib-single-vm.py"]
@subsection[#:tag "geni-lib-example-single-pc"]{A single physical host}
@subsection[#:tag "geni-lib-example-2"]{Two XenVM nodes with a LAN between them}
@code-sample["geni-lib-single-pc.py"]
@subsection[#:tag "geni-lib-example-two-vm-lan"]{Two XenVM nodes with a LAN between them}
@code-sample["geni-lib-two-vm-lan.py"]
@subsection[#:tag "geni-lib-example-two-arm-lan"]{Two ARM64 servers in a LAN}:w
@code-sample["geni-lib-two-arm-lan.py"]
@subsection[#:tag "geni-lib-example-3"]{Set a specific IP address on each node}
@subsection[#:tag "geni-lib-example-node-ips"]{Set a specific IP address on each node}
@code-sample["geni-lib-node-ips.py"]
@subsection[#:tag "geni-lib-example-4"]{Specify an operating system and set install and execute scripts}
@subsection[#:tag "geni-lib-example-os-install-scripts"]{Specify an operating system and set install and execute scripts}
@code-sample["geni-lib-os-install-scripts.py"]
......
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