Commit f13a48ca authored by David Johnson's avatar David Johnson

Expose manager as an ApplicableClass, and a couple methods.

Expose the ensure_slice and ensure_sliver methods as managed_* aliases
to hopefully avoid confusion.
parent 69600158
......@@ -385,6 +385,7 @@ if __name__ == "__main__":
# Always create the manager. Do that after the helper,
createManager()
Applicable.register_object(manager)
if options.subcommand == 'interactive':
if config.automanage:
......
......@@ -7,6 +7,7 @@ import threading
from elasticslice.rpc.protogeni import ProtoGeniClientDefs, ProtoGeniServer, \
ProtoGeniResponse, ProtoGeniManifestWrapper, \
ProtoGeniClientServerEndpoint, ProtoGeniClientServer, SENDMAIL
from elasticslice.util.applicable import ApplicableClass,ApplicableMethod
import geni.rspec.pgad as RSpecAd
import geni.rspec.pg as RSpec
import geni.rspec.igext as IG
......@@ -687,6 +688,7 @@ class SimpleElasticSliceClientEndpoint(ElasticSliceClientEndpoint):
pass
@ApplicableClass()
class ElasticSliceManager(ElasticSliceHelper):
"""
A manager of a dynamic slice that creates a slice (and its sliver);
......@@ -706,6 +708,52 @@ class ElasticSliceManager(ElasticSliceHelper):
self.server = server
self.config = config
pass
@ApplicableMethod(alias='managed_ensure_slice')
def ensure_slice(self):
"""
Check to see if the slice exists; if not, create it.
"""
ret = self.server.resolve_slice()
if ret:
return ret
LOG.info("Slice does not exist, creating...")
ret = self.server.create_slice()
if ret:
return ret
LOG.error("Could not create slice!")
raise NonexistentSliceError()
@ApplicableMethod(alias='managed_ensure_sliver')
def ensure_sliver(self,cm=None):
"""
Check to see if the sliver exists; if not, create it using information
from the ElasticSliceHelper associated with this ElasticSliceManager.
"""
if not cm: cm = self.default_cm
ret = self.server.resolve_sliver(cm=cm)
if ret:
return ret
LOG.info("Sliver does not exist, creating...")
# Grab an rspec from the helper (us, via plugin helper)
# Save off old argv because geni-lib scripts process it :(
oldargv = sys.argv
sys.argv = [ sys.argv[0], ]
if not self.baseRspec:
self.baseRspec = self.create_rspec()
pass
sys.argv = oldargv
ret = self.server.create_sliver(self.baseRspec,gen_random_key=True)
if ret:
return ret
LOG.error("Could not create sliver!")
raise NonexistentSliverError()
def _add_nodes(self,nodes={},cm=None):
return self.server.add_nodes(nodes=nodes,cm=cm)
......@@ -1244,43 +1292,6 @@ class SimpleElasticSliceManager(ElasticSliceManager,
LOG.exception("could not get resources at CM %s!" % (cm,))
pass
pass
def ensure_slice(self):
ret = self.server.resolve_slice()
if ret:
return ret
LOG.info("Slice does not exist, creating...")
ret = self.server.create_slice()
if ret:
return ret
LOG.error("Could not create slice!")
raise NonexistentSliceError()
def ensure_sliver(self,cm=None):
if not cm: cm = self.default_cm
ret = self.server.resolve_sliver(cm=cm)
if ret:
return ret
LOG.info("Sliver does not exist, creating...")
# Grab an rspec from the helper (us, via plugin helper)
# Save off old argv because geni-lib scripts process it :(
oldargv = sys.argv
sys.argv = [ sys.argv[0], ]
if not self.baseRspec:
self.baseRspec = self.create_rspec()
pass
sys.argv = oldargv
ret = self.server.create_sliver(self.baseRspec,generateRandomKey=True)
if ret:
return ret
LOG.error("Could not create sliver!")
raise NonexistentSliverError()
def _handle_method_reset_triggers(self,method,cm=None):
if not cm: cm = self.default_cm
......
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