Пример #1
0
 def listUserURNs (self):
   try:
     u = ConfigDB.getUser(request.environ["USER"])
     return jsonify(list(ConfigDB.getConfigItemByKey("geni.approval.user-urns").getValue(u)))
   except Exception, e:
     self._log.exception("Exception")
     return jsonify(None, code = 2, msg = traceback.format_exc())
Пример #2
0
 def createAttribute(self, attr):
     try:
         return ConfigDB.getAttributeByName(attr.name)
     except UnknownAttributeName, e:
         self._log.info("Creating attribute: %s" % (attr.name))
         ConfigDB.createAttribute(attr)
         self._log.debug("Created attribute [%s] with ID %d" % (attr.name, attr.id))
         return attr
Пример #3
0
 def createAttribute(self, attr):
     try:
         return ConfigDB.getAttributeByName(attr.name)
     except UnknownAttributeName, e:
         self._log.info("Creating attribute: %s" % (attr.name))
         ConfigDB.createAttribute(attr)
         self._log.debug("Created attribute [%s] with ID %d" %
                         (attr.name, attr.id))
         return attr
Пример #4
0
 def listUserURNs(self):
     try:
         u = ConfigDB.getUser(request.environ["USER"])
         return jsonify(
             list(
                 ConfigDB.getConfigItemByKey(
                     "geni.approval.user-urns").getValue(u)))
     except Exception, e:
         self._log.exception("Exception")
         return jsonify(None, code=2, msg=traceback.format_exc())
Пример #5
0
 def setConfig (self):
   if not request.json:
     return
   try:
     objs = self.validate(request.json, [("key", (unicode,str)), ("value", (dict, int, unicode, str))])
     u = ConfigDB.getUser(request.environ["USER"])
     key = request.json["key"]
     ConfigDB.getConfigItemByKey(request.json["key"]).write(request.json["value"], u)
     return jsonify({"status" : "success"})
   except JSONValidationError, e:
     jd = e.__json__()
     return jsonify(jd, code = 1, msg = jd["exception"])
Пример #6
0
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))
Пример #7
0
  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
Пример #8
0
  def __initDB (self):
    htp = HtpasswdFile(HTPASSWDFILE, create=True)
    htp.update("foamadmin", "admin")
    htp.save()

    metadata.drop_all()
    metadata.create_all()

    try:
      veritem = ConfigDB.getConfigItemByKey("geni.db-version")
      veritem.setValue(CURRENT_VERSION)
    except UnknownConfigKey, e:
      veritem = ConfigItem().setKey('geni.db-version').setValue(CURRENT_VERSION) \
                  .setDesc("GENI Database schema version")  \
                  .setUpdateFuncName("foam.geni.db.updateVersion") 
      ConfigDB.createConfigItem(veritem)
Пример #9
0
 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		
Пример #10
0
    def __initDB(self):
        htp = HtpasswdFile(HTPASSWDFILE, create=True)
        htp.update("foamadmin", "admin")
        htp.save()

        metadata.drop_all()
        metadata.create_all()

        try:
            veritem = ConfigDB.getConfigItemByKey("geni.db-version")
            veritem.setValue(CURRENT_VERSION)
        except UnknownConfigKey, e:
            veritem = ConfigItem().setKey('geni.db-version').setValue(CURRENT_VERSION) \
                        .setDesc("GENI Database schema version")  \
                        .setUpdateFuncName("foam.geni.db.updateVersion")
            ConfigDB.createConfigItem(veritem)
Пример #11
0
 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
Пример #12
0
  def getConfig (self):
    if not request.json:
      return

    try:
      objs = self.validate(request.json, [("key", (unicode,str))])
      u = ConfigDB.getUser(request.environ["USER"])
      # Don't look here - stupidity to get around the fact that we don't
      # have output processors
      if objs["key"] == "geni.max-lease":
        val = ConfigDB.getConfigItemByKey("geni.max-lease").getValue(u)
        return jsonify({"value" : str(val)})
      else:
        return jsonify({"value" : ConfigDB.getConfigItemByKey(request.json["key"]).getValue(u)})
    except JSONValidationError, e:
      jd = e.__json__()
      return jsonify(jd, code = 1, msg = jd["exception"])
Пример #13
0
    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
0
def dispatchEmail (event, data):
  dispatch_admin = False
  dispatch_exp = False
  exp_email = None

  try:
    exp_email = getExperimenterEmail(data)
    dispatch_exp = ConfigDB.getConfigItemByKey("email.event.%s.exp" % (event)).getValue()
  except Exception, e:
    print traceback.format_exc()
Пример #15
0
 def expedientStampFSwithVlan(self):
   try:
     THIS_SITE_TAG = ConfigDB.getConfigItemByKey("geni.site-tag").getValue()
     filedir = './opt/ofelia/ofam/local/db'
     filename = os.path.join(filedir, 'expedient_slices_info.json')
     if os.path.isfile(filename):
       f = open(filename, 'r')
       slice_info_dict = json.load(f)
       f.close()
       self.validate(request.json, [("urn", (str)), ("vlan_stamp_start", (int)), ("vlan_stamp_end", (int))])
       slice_id = request.json["urn"].split("+slice+")[1].split(":")[0].split("id_")[1].split("name_")[0]      
       vlan_stamp_start = request.json["vlan_stamp_start"]
       vlan_stamp_end = request.json["vlan_stamp_end"]
       if (slice_id == "") or (slice_id not in slice_info_dict): 
         self._log.exception("The slice id you have specified is non-existent")
         raise Exception
       if vlan_stamp_start == 0:
         self._log.exception("You must provide a valid vlan stamp! Be careful with the provision, it is up to you")
         raise Exception
       updated_slice_info_dict = slice_info_dict.copy()
       for sliv_pos, sliver in enumerate(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'] = vlan_stamp_start
           updated_slice_info_dict[slice_id]['switch_slivers'][sliv_pos]['flowspace'][sfs_pos]['vlan_id_end'] = vlan_stamp_end
       all_efs = self.create_slice_fs(updated_slice_info_dict[slice_id]['switch_slivers'])
       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._log.info(slice_of_rspec) #print the new rspec in the log for debugging
       #form the slice URN according to http://groups.geni.net/geni/wiki/GeniApiIdentifiers
       slice_urn = "urn:publicid:IDN+openflow:foam:"+ str(THIS_SITE_TAG) +"+slice+" + "id_" + str(slice_id) + "name_" + str(updated_slice_info_dict[slice_id]['slice_name'])
       creds = [] #creds are not needed at least for now: to be fixed
       user_info = {}
       user_info["urn"] = "urn:publicid:IDN+openflow:foam"+ str(THIS_SITE_TAG) +"+ch+" + "user+" + str(updated_slice_info_dict[slice_id]['owner_email']) #temp hack
       user_info["email"] = str(updated_slice_info_dict[slice_id]['owner_email'])
       old_exp_shutdown_success = self.gapi_DeleteSliver(slice_urn, creds, [])
       creation_result = self.gapi_CreateSliver(slice_urn, creds, slice_of_rspec, user_info)
       #store updated dict as a json file in foam db folder
       filedir = './opt/ofelia/ofam/local/db'
       filename = os.path.join(filedir, 'expedient_slices_info.json')
       tempfilename = os.path.join(filedir, 'expedient_slices_info.json.temp.' + str(time.time()) + str(random.randint(1,10000)))
       f = open(tempfilename, 'w')
       json.dump(updated_slice_info_dict, f)
       f.close()
       os.rename(tempfilename, filename)
       return jsonify({"slice-stamped" : "yes"})
     else:
       self._log.exception("The expedient slice info dict file is non-existent!")
       raise Exception
   except JSONValidationError, e:
     jd = e.__json__()
     return jsonify(jd, code = 1, msg = jd["exception"])
Пример #16
0
 def removeUserURN (self):
   if not request.json:
     return
   try:
     objs = self.validate(request.json, [("urn", (unicode, str))])
     u = ConfigDB.getUser(request.environ["USER"])
     AppData.removeUserURN(objs["urn"], u)
     return jsonify(None)
   except JSONValidationError, e:
     jd = e.__json__()
     return jsonify(jd, code = 1, msg = jd["exception"])
Пример #17
0
def dispatchEmail(event, data):
    dispatch_admin = False
    dispatch_exp = False
    exp_email = None

    try:
        exp_email = getExperimenterEmail(data)
        dispatch_exp = ConfigDB.getConfigItemByKey("email.event.%s.exp" %
                                                   (event)).getValue()
    except Exception, e:
        print traceback.format_exc()
Пример #18
0
 def removeUserURN(self):
     if not request.json:
         return
     try:
         objs = self.validate(request.json, [("urn", (unicode, str))])
         u = ConfigDB.getUser(request.environ["USER"])
         AppData.removeUserURN(objs["urn"], u)
         return jsonify(None)
     except JSONValidationError, e:
         jd = e.__json__()
         return jsonify(jd, code=1, msg=jd["exception"])
Пример #19
0
 def createPortGroup(self):
     if not request.json:
         return
     try:
         objs = self.validate(request.json, [("name", (unicode, str)),
                                             ("desc", (unicode, str))])
         u = ConfigDB.getUser(request.environ["USER"])
         pg = AppData.createPortGroup(objs["name"], objs["desc"])
         return jsonify(str(pg.uuid))
     except JSONValidationError, e:
         jd = e.__json__()
         return jsonify(jd, code=1, msg=jd["exception"])
Пример #20
0
 def createPortGroup (self):
   if not request.json:
     return
   try:
     objs = self.validate(request.json, [("name", (unicode, str)),
                                         ("desc", (unicode, str))])
     u = ConfigDB.getUser(request.environ["USER"])
     pg = AppData.createPortGroup(objs["name"], objs["desc"])
     return jsonify(str(pg.uuid))
   except JSONValidationError, e:
     jd = e.__json__()
     return jsonify(jd, code = 1, msg = jd["exception"])
Пример #21
0
  def generateSiteInfo (self):
    dmap = [("site.admin.name", "admin-name"),
            ("site.admin.email", "admin-email"),
            ("site.admin.phone", "admin-phone"),
            ("site.location.address", "org-address"),
            ("site.location.organization", "org-name"),
            ("site.description", "description")]

    sinfo = {}
    for ckey, vkey in dmap:
      val = ConfigDB.getConfigItemByKey(ckey).getValue()
      if val is not None:
        sinfo[vkey] = val

    return sinfo
Пример #22
0
    def setAdminPasswd(self):
        if not request.json:
            return
        try:
            u = ConfigDB.getUser(request.environ["USER"])
            u.assertPrivilege(self.attrSetAdminPasswd)

            opts = self.validate(request.json, [("passwd", (unicode, str))])

            self._log.info("Updating foamadmin password")
            self._htp.update("foamadmin", opts["passwd"])
            self._htp.save()

            return jsonify(None)
        except JSONValidationError, e:
            jd = e.__json__()
            return jsonify(jd, code=1, msg=jd["exception"])
Пример #23
0
    def setAdminPasswd(self):
        if not request.json:
            return
        try:
            u = ConfigDB.getUser(request.environ["USER"])
            u.assertPrivilege(self.attrSetAdminPasswd)

            opts = self.validate(request.json, [("passwd", (unicode, str))])

            self._log.info("Updating foamadmin password")
            self._htp.update("foamadmin", opts["passwd"])
            self._htp.save()

            return jsonify(None)
        except JSONValidationError, e:
            jd = e.__json__()
            return jsonify(jd, code=1, msg=jd["exception"])
Пример #24
0
 def __init__ (self):
   self._cred_verifier = geni.CredentialVerifier(ConfigDB.getConfigItemByKey("geni.cert-dir").getValue())
Пример #25
0
    def pub_CreateSliver(self, slice_urn, credentials, 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.

    """

        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 as 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(),
                                                  self._auto_priority)
                    self._log.debug(
                        "task.py launched for approve-sliver (PID: %d)" % pid)

                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)
            propertyList = self.buildPropertyList(GENI_ERROR_CODE.BADARGS,
                                                  output=msg)
            e.log(self._log, msg, logging.INFO)
        except foam.geni.lib.RspecValidationError as e:
            msg = str(e)
            propertyList = self.buildPropertyList(GENI_ERROR_CODE.BADARGS,
                                                  output=msg)
            e.log(self._log, msg, logging.INFO)
        except foam.geni.lib.DuplicateSliver as ds:
            msg = "Attempt to create multiple slivers for slice [%s]" % (
                ds.slice_urn)
            propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR,
                                                  output=msg)
            ds.log(self._log, msg, logging.INFO)
        except foam.geni.lib.UnknownComponentManagerID as ucm:
            msg = "Component Manager ID specified in %s does not match this aggregate." % (
                ucm.cid)
            propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR,
                                                  output=msg)
            ucm.log(self._log, msg, logging.INFO)
        except (foam.geni.lib.UnmanagedComponent, UnknownNode) as uc:
            msg = "DPID in component %s is unknown to this aggregate." % (
                uc.cid)
            propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR,
                                                  output=msg)
            uc.log(self._log, msg, logging.INFO)
        except Exception:
            msg = "Exception"
            propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR,
                                                  output=msg)
            self._log.exception(msg)
        finally:
            return propertyList
Пример #26
0
def getManagerID ():
  tag = ConfigDB.getConfigItemByKey("geni.site-tag").getValue()
  return "urn:publicid:IDN+openflow:foam:%s+authority+am" % (tag)
Пример #27
0
def getManagerID():
    tag = ConfigDB.getConfigItemByKey("geni.site-tag").getValue()
    return "urn:publicid:IDN+openflow:foam:%s+authority+am" % (tag)
Пример #28
0
def generateSwitchComponentID (dpid, tag = None):
  if tag is None:
    tag = ConfigDB.getConfigItemByKey("geni.site-tag").getValue()
  return "urn:publicid:IDN+openflow:foam:%s+datapath+%s" % (tag, dpid)
Пример #29
0
    raise RspecParseError(slice_urn, str(exc))

  of3 = open("/opt/ofelia/ofam/local/schemas/of-resv-3.xsd", "r")
  xsdoc3 = etree.parse(of3)
  xs3 = etree.XMLSchema(xsdoc3)

  try:
    xs3.assertValid(rspec_dom)
  except etree.DocumentInvalid, e:
    flog.exception("XML rspec validation error")
    raise RspecValidationError()

  rspec_elem = rspec_dom.getroot()
  schemas = rspec_elem.get("{%s}schemaLocation" % (XSNS))

  expiration = _asUTC(datetime.datetime.utcnow()) + ConfigDB.getConfigItemByKey("geni.max-lease").getValue()
  for cred in creds:
    credexp = _asUTC(cred.expiration)
    if credexp < expiration:
      expiration = credexp

  GeniDB.refreshDevices()

  sliver = GENISliver(rspec_dom)

  sliver.setUserURN(user_info["urn"])
  sliver.setUserEmail(user_info["email"], overwrite=False)
  sliver.validate()

  GeniDB.insertSliver(slice_urn, sliver, rspec, expiration)
  return sliver
Пример #30
0
from foam.core.log import KeyAdapter

# GENI API imports
from foam.geni.db import GeniDB, UnknownSlice, UnknownNode
import foam.geni.approval
import foam.geni.ofeliaapproval
import foam.geni.lib
import sfa

# FV import
from foam.flowvisor import Connection as FV
from pprint import pprint
import json
import httplib, urllib, base64

THIS_SITE_TAG = ConfigDB.getConfigItemByKey("geni.site-tag").getValue()
from foam.geni.codes import GENI_ERROR_CODE
from foam.ethzlegacyoptinstuff.api_exp_to_rspecv3.expdatatogeniv3rspec import create_ofv3_rspec
from foam.sfa.drivers.OFSfaDriver import OFSfaDriver
from foam.sfa.sfa_config import config as CONFIG
from foam.sfa.methods.permission_manager import PermissionManager
from foam.sfa.lib import get_slice_details_from_slivers, getAdvertisement


def _same(val):
    return "%s" % val


class SfaApi(foam.api.xmlrpc.Dispatcher):
    def __init__(self, log):
        super(SfaApi, self).__init__("sfaapi", log)
Пример #31
0
  def pub_CreateSliver (self, slice_urn, credentials, 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.

    """
    
    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 as 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(), self._auto_priority)
          self._log.debug("task.py launched for approve-sliver (PID: %d)" % pid)

        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)
      propertyList = self.buildPropertyList(GENI_ERROR_CODE.BADARGS, output=msg)
      e.log(self._log, msg, logging.INFO)
    except foam.geni.lib.RspecValidationError as e:
      msg = str(e)
      propertyList = self.buildPropertyList(GENI_ERROR_CODE.BADARGS, output=msg)
      e.log(self._log, msg, logging.INFO)
    except foam.geni.lib.DuplicateSliver as ds:
      msg = "Attempt to create multiple slivers for slice [%s]" % (ds.slice_urn)
      propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
      ds.log(self._log, msg, logging.INFO)
    except foam.geni.lib.UnknownComponentManagerID as ucm:
      msg = "Component Manager ID specified in %s does not match this aggregate." % (ucm.cid)
      propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
      ucm.log(self._log, msg, logging.INFO)
    except (foam.geni.lib.UnmanagedComponent, UnknownNode) as uc:
      msg = "DPID in component %s is unknown to this aggregate." % (uc.cid)
      propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
      uc.log(self._log, msg, logging.INFO)
    except Exception:
      msg = "Exception"
      propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
      self._log.exception(msg)
    finally:
      return propertyList
Пример #32
0
geni_apih = geni.setup(app) #Vasileios: get the returned api handlers

#here check maybe ofelia-geni api collaboration

from foam.api import gapi2
gapi2_apih = gapi2.setup(app) #Vasileios: get the returned api handlers

#modified by Vasileios, load afterwards
#from foam.api import legacyexpgapi2
#legexpgapi2_apih = legacyexpgapi2.setup(app) #Vasileios: get the returned api handlers

#modified by Vasileios, load afterwards
from foam.api import legacyexpedientapi #Vasileios: get the returned api handlers
legacyexpedientapi_apih = legacyexpedientapi.setup(app) #Vasileios: get the returned api handlers

from foam.api import sfaapi
sfaapi_apih = sfaapi.setup(app)

ConfigDB.commit()
GeniDB.commit()

def init (pm):
  pass
  #  for plugin in pm.getByInterface("foam.interface.rpc"):
  #  plugin.connect(app)

@request_started.connect_via(app)
def log_request (sender):
  app.logger.info("[REQUEST] [%s] <%s>" % (request.remote_addr, request.url))

Пример #33
0
from foam.core.log import KeyAdapter

#GENI API imports
from foam.geni.db import GeniDB, UnknownSlice, UnknownNode
import foam.geni.approval
import foam.geni.ofeliaapproval
import foam.geni.lib
import sfa

#FV import
from foam.flowvisor import Connection as FV
from pprint import pprint
import json
import httplib, urllib, base64

THIS_SITE_TAG = ConfigDB.getConfigItemByKey("geni.site-tag").getValue()
from foam.geni.codes import GENI_ERROR_CODE
from foam.ethzlegacyoptinstuff.api_exp_to_rspecv3.expdatatogeniv3rspec import create_ofv3_rspec
from foam.sfa.drivers.OFSfaDriver import OFSfaDriver
from foam.sfa.sfa_config import config as CONFIG
from foam.sfa.methods.permission_manager import PermissionManager
from foam.sfa.lib import get_slice_details_from_slivers, getAdvertisement


def _same(val):
    return "%s" % val


class SfaApi(foam.api.xmlrpc.Dispatcher):
    def __init__(self, log):
        super(SfaApi, self).__init__("sfaapi", log)
Пример #34
0
    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
Пример #35
0
def generateSwitchComponentID(dpid, tag=None):
    if tag is None:
        tag = ConfigDB.getConfigItemByKey("geni.site-tag").getValue()
    return "urn:publicid:IDN+openflow:foam:%s+datapath+%s" % (tag, dpid)
Пример #36
0
        return None


def dispatchEmail(event, data):
    dispatch_admin = False
    dispatch_exp = False
    exp_email = None

    try:
        exp_email = getExperimenterEmail(data)
        dispatch_exp = ConfigDB.getConfigItemByKey("email.event.%s.exp" %
                                                   (event)).getValue()
    except Exception, e:
        print traceback.format_exc()

    admin_email = ConfigDB.getConfigItemByKey("email.admin-addr").getValue()
    dispatch_admin = ConfigDB.getConfigItemByKey("email.event.%s.admin" %
                                                 (event)).getValue()

    # Preserving for compatibility
    email_info = {
        "reply-to": ConfigDB.getConfigItemByKey("email.reply-to").getValue(),
        "from": ConfigDB.getConfigItemByKey("email.from").getValue(),
        "smtp_server":
        ConfigDB.getConfigItemByKey("email.smtp-server").getValue()
    }

    data["admin_email"] = admin_email
    data["site"] = ConfigDB.getConfigItemByKey("geni.site-tag").getValue()

    if dispatch_admin:
Пример #37
0
    of3 = open("/opt/ofelia/ofam/local/schemas/of-resv-3.xsd", "r")
    xsdoc3 = etree.parse(of3)
    xs3 = etree.XMLSchema(xsdoc3)

    try:
        xs3.assertValid(rspec_dom)
    except etree.DocumentInvalid, e:
        flog.exception("XML rspec validation error")
        raise RspecValidationError()

    rspec_elem = rspec_dom.getroot()
    schemas = rspec_elem.get("{%s}schemaLocation" % (XSNS))

    expiration = _asUTC(datetime.datetime.utcnow(
    )) + ConfigDB.getConfigItemByKey("geni.max-lease").getValue()
    for cred in creds:
        credexp = _asUTC(cred.expiration)
        if credexp < expiration:
            expiration = credexp

    GeniDB.refreshDevices()

    sliver = GENISliver(rspec_dom)

    sliver.setUserURN(user_info["urn"])
    sliver.setUserEmail(user_info["email"], overwrite=False)
    sliver.validate()

    GeniDB.insertSliver(slice_urn, sliver, rspec, expiration)
    return sliver
Пример #38
0
    return data["email"]
  else:
    return None

def dispatchEmail (event, data):
  dispatch_admin = False
  dispatch_exp = False
  exp_email = None

  try:
    exp_email = getExperimenterEmail(data)
    dispatch_exp = ConfigDB.getConfigItemByKey("email.event.%s.exp" % (event)).getValue()
  except Exception, e:
    print traceback.format_exc()
    
  admin_email = ConfigDB.getConfigItemByKey("email.admin-addr").getValue()
  dispatch_admin = ConfigDB.getConfigItemByKey("email.event.%s.admin" % (event)).getValue()

  # Preserving for compatibility
  email_info = {"reply-to" : ConfigDB.getConfigItemByKey("email.reply-to").getValue(),
                "from" : ConfigDB.getConfigItemByKey("email.from").getValue(),
                "smtp_server" : ConfigDB.getConfigItemByKey("email.smtp-server").getValue()}

  data["admin_email"] = admin_email
  data["site"] = ConfigDB.getConfigItemByKey("geni.site-tag").getValue()

  if dispatch_admin:
    sendEmail("email.event.%s.admin" % (event), data, email_info, admin_email)
  if dispatch_exp and exp_email:
    sendEmail("email.event.%s.exp" % (event), data, email_info, exp_email)
  
 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
Пример #40
0
#here check maybe ofelia-geni api collaboration

from foam.api import gapi2
gapi2_apih = gapi2.setup(app)  #Vasileios: get the returned api handlers

#modified by Vasileios, load afterwards
#from foam.api import legacyexpgapi2
#legexpgapi2_apih = legacyexpgapi2.setup(app) #Vasileios: get the returned api handlers

#modified by Vasileios, load afterwards
from foam.api import legacyexpedientapi  #Vasileios: get the returned api handlers
legacyexpedientapi_apih = legacyexpedientapi.setup(
    app)  #Vasileios: get the returned api handlers

from foam.api import sfaapi
sfaapi_apih = sfaapi.setup(app)

ConfigDB.commit()
GeniDB.commit()


def init(pm):
    pass
    #  for plugin in pm.getByInterface("foam.interface.rpc"):
    #  plugin.connect(app)


@request_started.connect_via(app)
def log_request(sender):
    app.logger.info("[REQUEST] [%s] <%s>" % (request.remote_addr, request.url))
Пример #41
0
 def __init__(self):
     self._cred_verifier = geni.CredentialVerifier(
         ConfigDB.getConfigItemByKey("geni.cert-dir").getValue())