本文整理汇总了Python中foam.geni.db.GeniDB类的典型用法代码示例。如果您正苦于以下问题:Python GeniDB类的具体用法?Python GeniDB怎么用?Python GeniDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GeniDB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gapi_CreateSliver
def gapi_CreateSliver(self, slice_urn, credentials, rspec, users, force_approval=False, options=None):
#GENI API imports
from foam.geni.db import GeniDB, UnknownSlice, UnknownNode
import foam.geni.approval
import foam.geni.ofeliaapproval
import sfa
user_info = users
try:
if True:
#self.recordAction("createsliver", credentials, slice_urn)
try:
self._log.debug("Parsed user cert with URN (%(urn)s) and email (%(email)s)" % users)
except Exception, e:
self._log.exception("UNFILTERED EXCEPTION")
user_info["urn"] = None
user_info["email"] = None
sliver = foam.geni.lib.createSliver(slice_urn, credentials, rspec, user_info)
style = ConfigDB.getConfigItemByKey("geni.approval.approve-on-creation").getValue()
if style == foam.geni.approval.NEVER:
approve = False
elif style == foam.geni.approval.ALWAYS:
approve = True
else:
approve = foam.geni.ofeliaapproval.of_analyzeForApproval(sliver)
if approve or force_approval:
pid = foam.task.approveSliver(sliver.getURN(), AUTO_SLIVER_PRIORITY)
self._log.debug("task.py launched for approve-sliver (PID: %d)" % pid)
data = GeniDB.getSliverData(sliver.getURN(), True)
foam.task.emailCreateSliver(data)
return self.successResult(GeniDB.getManifest(sliver.getURN()))
return
示例2: priv_CreateSliver
def priv_CreateSliver(self, slice_urn, credentials, rspec, users, force_approval=False, options=None):
#user_info = {}
user_info = users
try:
#if CredVerifier.checkValid(credentials, "createsliver"):
if True:
self.recordAction("createsliver", credentials, slice_urn)
try:
#cert = Certificate(request.environ['CLIENT_RAW_CERT'])
#user_info["urn"] = cert.getURN()
#user_info["email"] = cert.getEmailAddress()
self._log.debug("Parsed user cert with URN (%(urn)s) and email (%(email)s)" % users)
except Exception, e:
self._log.exception("UNFILTERED EXCEPTION")
user_info["urn"] = None
user_info["email"] = None
from foam.app import admin_apih
if not admin_apih.vlan_automation_on:
sliver = foam.geni.lib.createSliver(slice_urn, credentials, rspec, user_info)
style = ConfigDB.getConfigItemByKey("geni.approval.approve-on-creation").getValue()
if style == foam.geni.approval.NEVER:
approve = False
elif style == foam.geni.approval.ALWAYS:
approve = True
else:
approve = foam.geni.ofeliaapproval.of_analyzeForApproval(sliver)
if approve or force_approval:
pid = foam.task.approveSliver(sliver.getURN(), AUTO_SLIVER_PRIORITY)
self._log.debug("task.py launched for approve-sliver (PID: %d)" % pid)
else:
free_vlan_list = self.pub_get_offered_vlans(1)
free_vlan = free_vlan_list[0]
slice_id = slice_urn.split("+slice+")[1].split(":")[0].split("id_")[1].split("name_")[0]
#filedir = './opt/ofelia/ofam/local/db'
#filename = os.path.join(filedir, 'expedient_slices_info.json')
#f = open(filename, 'r')
#self.slice_info_dict = json.load(f)
#f.close()
if (slice_id == "") or (slice_id not in self.slice_info_dict):
self._log.exception("The slice id you specified is non-existent")
raise Exception
updated_slice_info_dict = self.slice_info_dict.copy()
for sliv_pos, sliver in enumerate(self.slice_info_dict[slice_id]['switch_slivers']):
for sfs_pos, sfs in enumerate(sliver['flowspace']):
updated_slice_info_dict[slice_id]['switch_slivers'][sliv_pos]['flowspace'][sfs_pos]['vlan_id_start'] = free_vlan
updated_slice_info_dict[slice_id]['switch_slivers'][sliv_pos]['flowspace'][sfs_pos]['vlan_id_end'] = free_vlan
all_efs = self.create_slice_fs(updated_slice_info_dict[slice_id]['switch_slivers'])
new_slice_of_rspec = create_ofv3_rspec(slice_id, updated_slice_info_dict[slice_id]['project_name'], updated_slice_info_dict[slice_id]['project_desc'], \
updated_slice_info_dict[slice_id]['slice_name'], updated_slice_info_dict[slice_id]['slice_desc'], \
updated_slice_info_dict[slice_id]['controller_url'], updated_slice_info_dict[slice_id]['owner_email'], \
updated_slice_info_dict[slice_id]['owner_password'], \
updated_slice_info_dict[slice_id]['switch_slivers'], all_efs)
self.slice_info_dict = updated_slice_info_dict.copy()
sliver = foam.geni.lib.createSliver(slice_urn, credentials, new_slice_of_rspec, user_info)
pid = foam.task.approveSliver(sliver.getURN(), AUTO_SLIVER_PRIORITY)
self._log.debug("task.py launched for approve-sliver (PID: %d)" % pid)
data = GeniDB.getSliverData(sliver.getURN(), True)
foam.task.emailCreateSliver(data)
return self.successResult(GeniDB.getManifest(sliver.getURN()))
return
示例3: renewSliver
def renewSliver (slice_urn, creds, exptime):
from foam.geni.db import GeniDB
sliver_urn = GeniDB.getSliverURN(slice_urn)
reqexp = dateutil.parser.parse(str(exptime))
reqexp = _asUTC(reqexp)
max_expiration = _asUTC(datetime.datetime.utcnow()) + ConfigDB.getConfigItemByKey("geni.max-lease").getValue()
if reqexp > max_expiration:
raise BadSliverExpiration(
"The requested expiration date (%s) is past the allowed maximum expiration (%s)." %
(reqexp, max_expiration))
for cred in creds:
credexp = _asUTC(cred.expiration)
if reqexp > credexp:
continue
else:
GeniDB.updateSliverExpiration(sliver_urn, reqexp)
sobj = GeniDB.getSliverObj(sliver_urn)
sobj.resetExpireEmail()
sobj.store()
return sliver_urn
raise BadSliverExpiration(
"No credential found whose expiration is greater than or equal to the requested sliver expiration (%s)" %
(reqexp))
示例4: pub_CreateSliver
def pub_CreateSliver (self, slice_urn, credentials, rspec, users):
user_info = {}
try:
if CredVerifier.checkValid(credentials, "createsliver"):
self.recordAction("createsliver", credentials, slice_urn)
try:
cert = Certificate(request.environ['CLIENT_RAW_CERT'])
user_info["urn"] = cert.getURN()
user_info["email"] = cert.getEmailAddress()
self._log.debug("Parsed user cert with URN (%(urn)s) and email (%(email)s)" % user_info)
except Exception, e:
self._log.exception("UNFILTERED EXCEPTION")
user_info["urn"] = None
user_info["email"] = None
sliver = foam.geni.lib.createSliver(slice_urn, credentials, rspec, user_info)
approve = foam.geni.approval.analyzeForApproval(sliver)
style = ConfigDB.getConfigItemByKey("geni.approval.approve-on-creation").getValue()
if style == foam.geni.approval.NEVER:
approve = False
elif style == foam.geni.approval.ALWAYS:
approve = True
if approve:
pid = foam.task.approveSliver(sliver.getURN(), AUTO_SLIVER_PRIORITY)
self._log.debug("task.py launched for approve-sliver (PID: %d)" % pid)
data = GeniDB.getSliverData(sliver.getURN(), True)
foam.task.emailCreateSliver(data)
return GeniDB.getManifest(sliver.getURN())
return
示例5: showSliver
def showSliver (self):
# from foam.core.tracer import Tracer
# Tracer.enable()
if not request.json:
return
try:
return_obj = {}
self.validate(request.json, [("sliver_urn", (unicode,str))])
sobj = GeniDB.getSliverObj(request.json["sliver_urn"])
return_obj["sliver"] = sobj
if request.json.has_key("flowspace") and request.json["flowspace"]:
return_obj["flowspace"] = sobj.generateFlowEntries()
if request.json.has_key("flowspec") and request.json["flowspec"]:
return_obj["flowspec"] = sobj.json_flowspec()
if request.json.has_key("rspec") and request.json["rspec"]:
return_obj["rspec"] = GeniDB.getRspec(request.json["sliver_urn"])
# path = Tracer.disable()
# self._log.debug("Tracer path: %s" % (path))
return jsonify(return_obj)
except JSONValidationError, e:
jd = e.__json__()
return jsonify(jd, code = 1, msg = jd["exception"])
示例6: pub_DeleteSliver
def pub_DeleteSliver (self, slice_urn, credentials, options):
"""Delete a sliver
Stop all the slice's resources and remove the reservation.
Returns True or False indicating whether it did this successfully.
"""
try:
if CredVerifier.checkValid(credentials, "deletesliver", slice_urn):
self.recordAction("deletesliver", credentials, slice_urn)
if GeniDB.getSliverURN(slice_urn) is None:
raise UnkownSlice(slice_urn)
sliver_urn = GeniDB.getSliverURN(slice_urn)
data = GeniDB.getSliverData(sliver_urn, True)
foam.geni.lib.deleteSliver(sliver_urn = sliver_urn)
foam.task.emailGAPIDeleteSliver(data)
propertyList = self.buildPropertyList(GENI_ERROR_CODE.SUCCESS, value=True)
except UnknownSlice as e:
msg = "Attempt to delete unknown sliver for slice URN %s" % (slice_urn)
propertyList = self.buildPropertyList(GENI_ERROR_CODE.SEARCHFAILED, output=msg)
e.log(self._log, msg, logging.INFO)
except Exception as e:
msg = "Exception: %s" % str(e)
propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
self._log.exception("Exception")
finally:
return propertyList
示例7: pub_ListResources
def pub_ListResources (self, credentials, options):
try:
CredVerifier.checkValid(credentials, [])
compressed = options.get("geni_compressed", False)
urn = options.get("geni_slice_urn", None)
if urn:
CredVerifier.checkValid(credentials, "getsliceresources", urn)
self.recordAction("listresources", credentials, urn)
sliver_urn = GeniDB.getSliverURN(urn)
if sliver_urn is None:
raise Fault("ListResources", "Sliver for slice URN (%s) does not exist" % (urn))
rspec = GeniDB.getManifest(sliver_urn)
else:
self.recordAction("listresources", credentials)
rspec = foam.geni.lib.getAdvertisement()
if compressed:
zrspec = zlib.compress(rspec)
rspec = base64.b64encode(zrspec)
return rspec
except ExpatError, e:
self._log.error("Error parsing credential strings")
e._foam_logged = True
raise e
示例8: pub_SliverStatus
def pub_SliverStatus (self, slice_urn, credentials, options):
"""Returns the status of the reservation for this slice at this aggregate"""
try:
if CredVerifier.checkValid(credentials, "sliverstatus", slice_urn):
self.recordAction("sliverstatus", credentials, slice_urn)
result = {}
sliver_urn = GeniDB.getSliverURN(slice_urn)
if not sliver_urn:
raise Exception("Sliver for slice URN (%s) does not exist" % (slice_urn))
sdata = GeniDB.getSliverData(sliver_urn, True)
status = foam.geni.lib.getSliverStatus(sliver_urn)
result["geni_urn"] = sliver_urn
result["geni_status"] = status
result["geni_resources"] = [{"geni_urn" : sliver_urn, "geni_status": status, "geni_error" : ""}]
result["foam_status"] = sdata["status"]
result["foam_expires"] = sdata["expiration"]
result["foam_pend_reason"] = sdata["pend_reason"]
propertyList = self.buildPropertyList(GENI_ERROR_CODE.SUCCESS, value=result)
except UnknownSlice as e:
msg = "Attempt to get status on unknown sliver for slice %s" % (slice_urn)
propertyList = self.buildPropertyList(GENI_ERROR_CODE.SEARCHFAILED, output=msg)
e.log(self._log, msg, logging.INFO)
except Exception as e:
msg = "Exception: %s" % str(e)
propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
self._log.exception(msg)
finally:
return propertyList
示例9: pub_DeleteSliver
def pub_DeleteSliver(self, xrn, creds, options={}):
"""Delete a sliver
Stop all the slice's resources and remove the reservation.
Returns True or False indicating whether it did this successfully.
"""
try:
self.pm.check_permissions("DeleteSliver", locals())
except Exception as e:
return self.buildPropertyList(GENI_ERROR_CODE.CREDENTIAL_INVALID, output=e)
self._log.info("Is HERE:")
try:
slivers = GeniDB.getSliverList()
self._log.info("Is HERE:")
sliver = get_slice_details_from_slivers(slivers, xrn)
self._log.info("Deleteing Sliver")
self._log.info(sliver["slice_urn"])
data = GeniDB.getSliverData(sliver["sliver_urn"], True)
foam.geni.lib.deleteSliver(sliver_urn=sliver["sliver_urn"])
# foam.task.emailGAPIDeleteSliver(data)
propertyList = self.buildPropertyList(GENI_ERROR_CODE.SUCCESS, value=True)
except UnknownSlice as e:
propertyList = self.buildPropertyList(GENI_ERROR_CODE.SEARCHFAILED, output=msg)
except Exception as e:
msg = "Exception: %s" % str(e)
propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
finally:
return propertyList
示例10: importSliver
def importSliver (opts):
# Quick dirty way to find out if a sliver exists
try:
GeniDB.getSliverPriority(opts["sliver_urn"])
return
except UnknownSliver, e:
pass
示例11: getAdvertisement
def getAdvertisement ():
NSMAP = {None: "%s" % (PGNS),
"xs" : "%s" % (XSNS),
"openflow" : "%s" % (OFNSv3)}
rspec = ET.Element("rspec", nsmap = NSMAP)
rspec.attrib["{%s}schemaLocation" % (XSNS)] = PGNS + " " \
"http://www.geni.net/resources/rspec/3/ad.xsd " + \
OFNSv3 + " " \
"http://www.geni.net/resources/rspec/ext/openflow/3/of-ad.xsd"
rspec.attrib["type"] = "advertisement"
links = FV.getLinkList()
devices = FV.getDeviceList()
fvversion = FV.getFVVersion()
db_devices = GeniDB.getDeviceSet()
GeniDB.refreshDevices(devices)
for dpid in devices:
db_devices.discard(dpid)
addAdDevice(rspec, dpid)
for dpid in db_devices:
addAdDevice(rspec, dpid, False)
#getLinks START
for link in links:
addAdLink(rspec, link)
#getLinks END
xml = StringIO()
ET.ElementTree(rspec).write(xml)
return xml.getvalue()
示例12: deleteSliver
def deleteSliver (slice_urn = None, sliver_urn = None):
slice_name = GeniDB.getFlowvisorSliceName(slice_urn=slice_urn, sliver_urn = sliver_urn)
if FV.sliceExists(slice_name):
# stats = FV.getCombinedStats(slice_name)
# GeniDB.insertFinalStats(slice_urn, stats)
FV.deleteSlice(slice_name)
GeniDB.deleteSliver(slice_urn=slice_urn, sliver_urn=sliver_urn)
foam.geni.approval.rebuildDB()
示例13: pub_CreateSliver
def pub_CreateSliver(self, slice_xrn, creds, rspec, users, options):
"""Allocate resources to a slice
Reserve the resources described in the given RSpec for the given slice, returning a manifest RSpec of what has been reserved.
"""
try:
self.pm.check_permissions("CreateSliver", locals())
except Exception as e:
return self.buildPropertyList(GENI_ERROR_CODE.CREDENTIAL_INVALID, output=e)
self.recordAction("createsliver", creds, slice_xrn)
user_info = {}
user_info["urn"] = None
user_info["email"] = None
request.environ.pop("CLIENT_RAW_CERT", None)
sliver = foam.geni.lib.createSliver(slice_xrn, creds, rspec, user_info)
try:
approve = foam.geni.approval.analyzeForApproval(sliver)
style = ConfigDB.getConfigItemByKey("geni.approval.approve-on-creation").getValue()
if style == foam.geni.approval.NEVER:
approve = False
elif style == foam.geni.approval.ALWAYS:
approve = True
if approve:
pid = foam.task.approveSliver(sliver.getURN(), self._auto_priority)
data = GeniDB.getSliverData(sliver.getURN(), True)
# foam.task.emailCreateSliver(data)
propertyList = self.buildPropertyList(GENI_ERROR_CODE.SUCCESS, value=GeniDB.getManifest(sliver.getURN()))
except foam.geni.lib.RspecParseError as e:
msg = str(e)
self._log.info(e)
return msg
propertyList = self.buildPropertyList(GENI_ERROR_CODE.BADARGS, output=msg)
except foam.geni.lib.RspecValidationError as e:
self._log.info(e)
msg = str(e)
return msg
propertyList = self.buildPropertyList(GENI_ERROR_CODE.BADARGS, output=msg)
except foam.geni.lib.DuplicateSliver as ds:
msg = "Attempt to create multiple slivers for slice [%s]" % (ds.slice_urn)
self._log.info(msg)
propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
except foam.geni.lib.UnknownComponentManagerID as ucm:
msg = "Component Manager ID specified in %s does not match this aggregate." % (ucm.cid)
self._log.info(msg)
propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
except (foam.geni.lib.UnmanagedComponent, UnknownNode) as uc:
msg = "DPID in component %s is unknown to this aggregate." % (uc.cid)
self._log.info(msg)
propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
except Exception as e:
msg = "Exception %s" % str(e)
self._log.info(e)
propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
finally:
return propertyList
示例14: adminSetSliverExpiration
def adminSetSliverExpiration (self):
if not request.json:
return
try:
objs = self.validate(request.json, [("datetime", types.DateTime), ("urn", types.SliverURN)])
GeniDB.updateSliverExpiration(objs["urn"], objs["datetime"])
return jsonify({"status" : "success"})
except JSONValidationError, e:
jd = e.__json__()
return jsonify(jd, code = 1, msg = jd["exception"])
示例15: setLocation
def setLocation (self):
if not request.json:
return
try:
self.validate(request.json, [("lat", float), ("long", float), ("dpid", (unicode,str)), ("country", (unicode,str))])
GeniDB.setLocation(request.json["dpid"], request.json["country"], request.json["lat"], request.json["long"])
return jsonify({"status" : "success"})
except JSONValidationError, e:
jd = e.__json__()
return jsonify(jd, code = 1, msg = jd["exception"])