-
Notifications
You must be signed in to change notification settings - Fork 15
Omni Scripting Example With Options
Scripting was added to Omni in version 1.3. This script is an example of how to programmatically control Omni to do your own things.
This example script creates a variation on the Omni command line tool. This example shows how to inherit Omni options while also having options specific to this script.
However, you could also create a script which generates more complex results by making multiple calls to Omni. See OmniScriptingExpiration for an example.
The script can be found in the examples directory in the file myscript.py.
This script reads a supplied RSpec file, extracting the aggregate URL and slice name, if any, from a particular format XML comment at the top of the file. The comment is in the format that Omni adds when saving RSpecs.
This script has a command line option called '--myScriptPrivateOption' which prints a line of text.
Running with a script specific option.
$ ./myscript.py --myScriptPrivateOption getversion
Got myScriptOption
Call Omni with args ['getversion']:
INFO:omni:Loading config file /home/myuser/.gcf/omni_config
INFO:omni:Using control framework pgeni_gpo
INFO:omni:AM URN: http://myplc.gpolab.bbn.com:12346 (url: http://myplc.gpolab.bbn.com:12346) has version:
.....
Got Result from Omni:
{
"http://myplc.gpolab.bbn.com:12346": {
....
}
Got version for http://myplc.gpolab.bbn.com:12346
There were 1 item(s) returned.
In this basic usage of the script, the user saved off the manifest RSpec from a previous run of the same slice. Using this script, the experimenter does not need to specify the aggregate or the slice - both are read from the RSpec file itself.
$ python ./myscript.py createsliver ahtest-manifest-rspec-localhost-8001.xml
Looking for slice name and AM URL in RSpec file ahtest-manifest-rspec-localhost-8001.xml
Found AM unspecified_AM_URN (http://localhost:8001)
Found slice ahtest
Call Omni with args ['-a', 'http://localhost:8001', 'createsliver', 'ahtest', 'ahtest-manifest-rspec-localhost-8001.xml']:
INFO:omni:Loading config file ../my_oc
INFO:omni:Using control framework my_gcf
WARNING:omni:Slice urn:publicid:IDN+geni:gpo:gcf+slice+ahtest expires in <= 3 hours
INFO:omni:Slice urn:publicid:IDN+geni:gpo:gcf+slice+ahtest expires on 2012-09-14 19:15:58 UTC
INFO:omni:Creating sliver(s) from rspec file ahtest-manifest-rspec-localhost-8001.xml for slice urn:publicid:IDN+geni:gpo:gcf+slice+ahtest
INFO:omni:Got return from CreateSliver for slice ahtest at http://localhost:8001:
INFO:omni:<?xml version="1.0" ?>
INFO:omni: <!-- Reserved resources for:
Slice: ahtest
at AM:
URN: unspecified_AM_URN
URL: http://localhost:8001
-->
INFO:omni: <rspec type="manifest" xmlns="http://www.geni.net/resources/rspec/3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd"> <node client_id="foo"/></rspec>
Got Result from Omni:
'<?xml version="1.0" encoding="UTF-8"?>\n<rspec xmlns="http://www.geni.net/resources/rspec/3"\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n xsi:schemaLocation="http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd"\n type="manifest"><node client_id="foo"/></rspec>'
Got Reserved resources RSpec from localhost-8001
There were 1 item(s) returned.
The script also takes any Omni command and does the default behavior.
$ ./myscript.py listmyslices myuser
INFO:omni:Loading config file /home/myuser/.gcf/omni_config
INFO:omni:Using control framework pgeni_gpo
INFO:omni:User 'myuser' has slice(s):
urn:publicid:IDN+pgeni.gpolab.bbn.com+slice+testfortupty
Got Result from Omni:
['urn:publicid:IDN+pgeni.gpolab.bbn.com+slice+testfortupty']
Found 1 slice(s) for user 'myuser'.
There were 1 items returned.
Get usage.
Notice the default Omni options and the custom one for this script.
Notice the script specific "usage" message.
$ ./myscript.py -h
Usage:
GENI Omni Command Line Aggregate Manager Tool Version 2.5
Copyright (c) 2014 Raytheon BBN Technologies
myscript.py [options] [--project <proj_name>] <command and arguments>
Commands and their arguments are:
AM API functions:
getversion
listresources [In AM API V1 and V2 optional: slicename]
describe slicename [AM API V3 only]
createsliver <slicename> <rspec URL, filename, or nickname> [AM API V1&2 only]
allocate <slicename> <rspec URL, filename, or nickname> [AM API V3 only]
provision <slicename> [AM API V3 only]
performoperationalaction <slicename> <action> [AM API V3 only]
poa <slicename> <action>
[alias for 'performoperationalaction'; AM API V3 only]
sliverstatus <slicename> [AMAPI V1&2 only]
status <slicename> [AMAPI V3 only]
renewsliver <slicename> <new expiration time in UTC> [AM API V1&2 only]
renew <slicename> <new expiration time in UTC> [AM API V3 only]
deletesliver <slicename> [AM API V1&2 only]
delete <slicename> [AM API V3 only]
shutdown <slicename>
Non AM API aggregate functions (supported by some aggregates):
createimage <slicename> <imagename> [optional: false (keep image private)] -u <sliver urn> [ProtoGENI/InstaGENI only]
snapshotimage <slicename> <imagename> [optional: false (keep image private)] -u <sliver urn> [ProtoGENI/InstaGENI only]
[alias for 'createimage']
deleteimage <imageurn> [optional: creatorurn] [ProtoGENI/InstaGENI only]
listimages [optional: creatorurn] [ProtoGENI/InstaGENI only]
Clearinghouse / Slice Authority functions:
get_ch_version
listaggregates
createslice <slicename>
getslicecred <slicename>
renewslice <slicename> <new expiration time in UTC>
deleteslice <slicename>
listslices [optional: username] [Alias for listmyslices]
listmyslices [optional: username]
listmykeys [optional: username] [Alias for listkeys]
listkeys [optional: username]
getusercred
print_slice_expiration <slicename>
listslivers <slicename>
listslicemembers <slicename>
addslicemember <slicename> <username> [optional: role]
Other functions:
nicknames
See README-omni.txt for details.
And see the Omni website at http://trac.gpolab.bbn.com/gcf
myscript.py supports additional commands.
Commands and their arguments are:
[add stuff here]
Options:
--version show program's version number and exit
-h, --help show this help message and exit
--myScriptPrivateOption
A non-omni option added by examples/myscript.py
Basic and Most Used Options:
-a AGGREGATE_URL, --aggregate=AGGREGATE_URL
Communicate with a specific aggregate
--available Only return available resources
-c FILE, --configfile=FILE
Config file name (aka `omni_config`)
-f FRAMEWORK, --framework=FRAMEWORK
Control framework to use for creation/deletion of
slices
-r PROJECT, --project=PROJECT
Name of project. (For use with pgch framework.)
--alap Request slivers be renewed as close to the requested
time as possible, instead of failing if the requested
time is not possible. Default is False.
-t RSPEC-TYPE RSPEC-VERSION, --rspectype=RSPEC-TYPE RSPEC-VERSION
RSpec type and version to return, default 'GENI 3'
-V API_VERSION, --api-version=API_VERSION
Specify version of AM API to use (default 2)
--useSliceAggregates
Perform the slice action at all aggregates the given
slice is known to use according to clearinghouse
records. Default is False.
--useSliceMembers Create accounts and install slice members' SSH keys on
reserved resources in createsliver, provision or
performoperationalaction. Default is False. When true,
adds these users and keys to those read from your
omni_config (unless --ignoreConfigUsers).
--ignoreConfigUsers
Ignore users and SSH keys listed in your omni_config
when installing SSH keys on resources in createsliver
or provision or performoperationalaction. Default is
false - your omni_config users are read and used.
AM API v3+:
Options used in AM API v3 or later
--best-effort Should AMs attempt to complete the operation on only
some slivers, if others fail
--cred=CRED_FILENAME
Send credential in given filename with any call that
takes a list of credentials
--end-time=GENI_END_TIME
Requested end time for any newly allocated or
provisioned slivers - may be ignored by the AM
--optionsfile=JSON_OPTIONS_FILENAME
Send all options defined in named JSON format file to
methods that take options
--speaksfor=USER_URN
Supply given URN as user we are speaking for in Speaks
For option
-u SLIVERS, --sliver-urn=SLIVERS
Sliver URN (not name) on which to act. Supply this
option multiple times for multiple slivers, or not at
all to apply to the entire slice
Logging and Verboseness:
Control the amount of output to the screen and/or to a log
-q, --quiet Turn off verbose command summary for omni commandline
tool
-v, --verbose Turn on verbose command summary for omni commandline
tool
--debug Enable debugging output. If multiple loglevel are set
from commandline (e.g. --debug, --info) the more
verbose one will be preferred.
--info Set logging to INFO.If multiple loglevel are set from
commandline (e.g. --debug, --info) the more verbose
one will be preferred.
--warn Set log level to WARN. This won't print the command
outputs, e.g. manifest rspec, so use the -o or the
--outputfile options to save it to a file. If multiple
loglevel are set from commandline (e.g. --debug,
--info) the more verbose one will be preferred.
--error Set log level to ERROR. This won't print the command
outputs, e.g. manifest rspec, so use the -o or the
--outputfile options to save it to a file.If multiple
loglevel are set from commandline (e.g. --debug,
--info) the more verbose one will be preferred.
--verbosessl Turn on verbose SSL / XMLRPC logging
-l LOGCONFIG, --logconfig=LOGCONFIG
Python logging config file
--logoutput=LOGOUTPUT
Python logging output file [use %(logfilename)s in
logging config file]
--tostdout Print results like rspecs to STDOUT instead of to log
stream
File Output:
Control name of output file and whether to output to a file
-o, --output Write output of many functions (getversion,
listresources, allocate, status, getslicecred,...) ,
to a file (Omni picks the name)
-p FILENAME_PREFIX, --prefix=FILENAME_PREFIX
Filename prefix when saving results (used with -o, not
--usercredfile, --slicecredfile, or --outputfile)
--outputfile=OUTPUT_FILENAME
Name of file to write output to (instead of Omni
picked name). '%a' will be replaced by servername,
'%s' by slicename if any. Implies -o. Note that for
multiple aggregates, without a '%a' in the name, only
the last aggregate output will remain in the file.
Will ignore -p.
--usercredfile=USER_CRED_FILENAME
Name of user credential file to read from if it
exists, or save to when running like '--usercredfile
myUserCred.xml -o getusercred'. Defaults to value of
'GENI_USERCRED' environment variable if defined.
--slicecredfile=SLICE_CRED_FILENAME
Name of slice credential file to read from if it
exists, or save to when running like '--slicecredfile
mySliceCred.xml -o getslicecred mySliceName'. Defaults
to value of 'GENI_SLICECRED' environment variable if
defined.
GetVersion Cache:
Control GetVersion Cache
--NoGetVersionCache
Disable using cached GetVersion results (forces
refresh of cache)
--ForceUseGetVersionCache
Require using the GetVersion cache if possible
(default false)
--GetVersionCacheAge=GETVERSIONCACHEAGE
Age in days of GetVersion cache info before refreshing
(default is 7)
--GetVersionCacheName=GETVERSIONCACHENAME
File where GetVersion info will be cached, default is
~/.gcf/get_version_cache.json
Aggregate Nickname Cache:
Control Aggregate Nickname Cache
--NoAggNickCache Disable using cached AggNick results and force refresh
of cache (default is False)
--ForceUseAggNickCache
Require using the AggNick cache if possible (default
False)
--AggNickCacheAge=AGGNICKCACHEAGE
Age in days of AggNick cache info before refreshing
(default is 1)
--AggNickCacheName=AGGNICKCACHENAME
File where AggNick info will be cached, default is
~/.gcf/agg_nick_cache
--AggNickDefinitiveLocation=AGGNICKDEFINITIVELOCATION
Website with latest agg_nick_cache, default is
http://trac.gpolab.bbn.com/gcf/raw-
attachment/wiki/Omni/agg_nick_cache. To force Omni to
read this cache, delete your local AggNickCache or use
--NoAggNickCache.
For Developers:
Features only needed by developers
--abac Use ABAC authorization
--arbitrary-option Add an arbitrary option to ListResources (for testing
purposes)
--devmode Run in developer mode: more verbose, less error
checking of inputs
--no-compress Do not compress returned values
--no-ssl do not use ssl
--no-tz Do not send timezone on RenewSliver
--orca-slice-id=ORCA_SLICE_ID
Use the given Orca slice id
--raise-error-on-v2-amapi-error
In AM API v2, if an AM returns a non-0 (failure)
result code, raise an AMAPIError. Default is False.
For use by scripts.
--ssltimeout=SSLTIMEOUT
Seconds to wait before timing out AM and CH calls.
Default is 360 seconds.
--noExtraCHCalls Disable extra Clearinghouse calls like reporting
slivers. Default is False.
GENI is sponsored by the National Science Foundation.