예제 #1
0
  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
예제 #2
0
    def pub_RenewSliver(self, slice_urn, credentials, exptime, options):
        """Renew the reservation for resources in this slice"""
        try:
            if CredVerifier.checkValid(credentials, "renewsliver", slice_urn):
                self.recordAction("renewsliver", credentials, slice_urn)
                creds = CredVerifier.fromStrings(credentials, "renewsliver",
                                                 slice_urn)
                sliver_urn = foam.lib.renewSliver(slice_urn, creds, exptime)

                data = GeniDB.getSliverData(sliver_urn, True)
                foam.task.emailRenewSliver(data)

                propertyList = self.buildPropertyList(GENI_ERROR_CODE.SUCCESS,
                                                      value=True)
        except foam.lib.BadSliverExpiration as e:
            msg = "Bad expiration request: %s" % (e.msg)
            propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR,
                                                  output=msg)
            e.log(self._log, msg, logging.INFO)
        except Exception:
            msg = "Exception"
            propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR,
                                                  output=msg)
            self._log.exception("Exception")
        finally:
            return propertyList
예제 #3
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
예제 #4
0
파일: gapi2.py 프로젝트: HalasNet/felix
  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
예제 #5
0
파일: gapi2.py 프로젝트: HalasNet/felix
 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
예제 #6
0
  def pub_RenewSliver (self, slice_urn, credentials, exptime):
    try:
      if CredVerifier.checkValid(credentials, "renewsliver", slice_urn):
        self.recordAction("renewsliver", credentials, slice_urn)
        creds = CredVerifier.fromStrings(credentials, "renewsliver", slice_urn)
        sliver_urn = foam.lib.renewSliver(slice_urn, creds, exptime)

        data = GeniDB.getSliverData(sliver_urn, True)
        foam.task.emailRenewSliver(data)

        return True
      return False
    except foam.lib.BadSliverExpiration, e:
      self._log.info("Bad expiration request: %s" % (e.msg))
      e._foam_logged = True
      raise e
예제 #7
0
 def pub_Shutdown(self, slice_urn, credentials, options):
     """Perform an emergency shutdown of the resources in a slice at this aggregate"""
     if CredVerifier.checkValid(credentials, "shutdown", slice_urn):
         self.recordAction("shutdown", credentials, slice_urn)
         #foam.lib.shutdown(slice_urn)
         sliver_urn = GeniDB.getSliverURN(slice_urn)
         data = GeniDB.getSliverData(sliver_urn, True)
         foam.geni.lib.deleteSliver(sliver_urn=sliver_urn)
         return self.buildPropertyList(GENI_ERROR_CODE.SUCCESS, value=True)
     return self.buildPropertyList(GENI_ERROR_CODE.SUCCESS, value=False)
예제 #8
0
파일: gapi2.py 프로젝트: HalasNet/felix
 def pub_Shutdown (self, slice_urn, credentials, options):
   """Perform an emergency shutdown of the resources in a slice at this aggregate"""
   if CredVerifier.checkValid(credentials, "shutdown", slice_urn):
     self.recordAction("shutdown", credentials, slice_urn)
     #foam.lib.shutdown(slice_urn)
     sliver_urn = GeniDB.getSliverURN(slice_urn)
     data = GeniDB.getSliverData(sliver_urn, True)
     foam.geni.lib.deleteSliver(sliver_urn = sliver_urn)
     return self.buildPropertyList(GENI_ERROR_CODE.SUCCESS, value=True)
   return self.buildPropertyList(GENI_ERROR_CODE.SUCCESS, value=False)
예제 #9
0
파일: gapi2.py 프로젝트: HalasNet/felix
  def pub_RenewSliver (self, slice_urn, credentials, exptime, options):
    """Renew the reservation for resources in this slice"""
    try:
      if CredVerifier.checkValid(credentials, "renewsliver", slice_urn):
        self.recordAction("renewsliver", credentials, slice_urn)
        creds = CredVerifier.fromStrings(credentials, "renewsliver", slice_urn)
        sliver_urn = foam.lib.renewSliver(slice_urn, creds, exptime)

        data = GeniDB.getSliverData(sliver_urn, True)
        foam.task.emailRenewSliver(data)

        propertyList = self.buildPropertyList(GENI_ERROR_CODE.SUCCESS, value=True)
    except foam.lib.BadSliverExpiration as e:
      msg = "Bad expiration request: %s" % (e.msg)
      propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
      e.log(self._log, msg, logging.INFO)
    except Exception:
      msg = "Exception"
      propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
      self._log.exception("Exception")
    finally:
      return propertyList
예제 #10
0
def createSliver(slice_urn, credentials, rspec, user_info):
    flog = logging.getLogger('foam')

    if GeniDB.sliceExists(slice_urn):
        raise DuplicateSliver(slice_urn)

    creds = CredVerifier.fromStrings(credentials, "createsliver", slice_urn)
    try:
        s = StringIO(rspec)
        rspec_dom = ET.parse(s)
    except Exception, exc:
        flog.exception("XML rspec parsing error")
        raise RspecParseError(slice_urn, str(exc))
예제 #11
0
파일: lib.py 프로젝트: HalasNet/felix
def createSliver (slice_urn, credentials, rspec, user_info):
  flog = logging.getLogger('foam')

  if GeniDB.sliceExists(slice_urn):
    raise DuplicateSliver(slice_urn)

  creds = CredVerifier.fromStrings(credentials, "createsliver", slice_urn)
  try:
    s = StringIO(rspec)
    rspec_dom = ET.parse(s)
  except Exception, exc:
    flog.exception("XML rspec parsing error")
    raise RspecParseError(slice_urn, str(exc))
예제 #12
0
  def pub_DeleteSliver (self, slice_urn, credentials):
    try:
      if CredVerifier.checkValid(credentials, "deletesliver", slice_urn):
        self.recordAction("deletesliver", credentials, slice_urn)
        if GeniDB.getSliverURN(slice_urn) is None:
          raise Fault("DeleteSliver", "Sliver for slice URN (%s) does not exist" % (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)

        return True
      return False
    except UnknownSlice, x:
      self._log.info("Attempt to delete unknown sliver for slice URN %s" % (slice_urn))
      x._foam_logged = True
      raise x
예제 #13
0
 def pub_SliverStatus (self, slice_urn, credentials):
   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 Fault("SliverStatus", "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"]
       return result
     return False
   except UnknownSlice, x:
     self._log.info("Attempt to get status on unknown sliver for slice %s" % (slice_urn))
     x._foam_logged = True
     raise x
예제 #14
0
 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
예제 #15
0
    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
예제 #16
0
파일: gapi2.py 프로젝트: HalasNet/felix
  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
예제 #17
0
파일: gapi2.py 프로젝트: HalasNet/felix
  def pub_ListResources (self, credentials, options):
    """Return information about available resources or resources allocated to a slice

    List the resources at this aggregate in an RSpec: may be all resources,
    only those available for reservation, or only those already reserved for the given slice.

    """
    try:
      CredVerifier.checkValid(credentials, [])

      # Parse options
      compressed = options.get("geni_compressed", False)
      urn = options.get("geni_slice_urn", None)
      spec_version = options.get("geni_rspec_version")
      supported_spec = {'version': '3', 'type': 'GENI'}
      if spec_version:
        if spec_version != supported_spec:
          msg = "RSpec type/version not supported"
          propertyList = self.buildPropertyList(GENI_ERROR_CODE.BADVERSION, output=msg)
          return propertyList
      else:
        msg = "Required option geni_rspec_version missing"
        propertyList = self.buildPropertyList(GENI_ERROR_CODE.BADARGS, output=msg)
        return propertyList

      if urn:
        CredVerifier.checkValid(credentials, "getsliceresources", urn)
        self.recordAction("listresources", credentials, urn)
        sliver_urn = GeniDB.getSliverURN(urn)
        if sliver_urn is None:
          raise Exception("Sliver for slice URN (%s) does not exist" % (urn))
        else:
          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)

      propertyList = self.buildPropertyList(GENI_ERROR_CODE.SUCCESS, value=rspec)

    except ExpatError:
      msg = "Error parsing credential strings"
      propertyList = self.buildPropertyList(GENI_ERROR_CODE.BADARGS, output=msg)
      self._log.error(msg)
    except UnknownSlice as x:
      # Raised by GeniDB.getSliverURN()
      msg = "Attempt to list resources on sliver for unknown slice %s" % (urn)
      propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
      x.log(self._log, msg, logging.INFO)
    except xmlrpclib.Fault as x:
      # Something thrown via GCF, we'll presume it was something related to credentials
      msg = "GCF credential check failure: <%s>" % (x)
      propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
      self._log.info(msg)
      self._log.debug(x, exc_info=True)
    except AttributeError as x:
      # New GCF problem with user creds that have no gid_caller, probably
      msg = "GCF credential check failure: <%s>" % (x)
      propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR, output=msg)
      self._log.info(msg)
      self._log.debug(x, exc_info=True)
    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
예제 #18
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
예제 #19
0
 def pub_Shutdown (self, slice_urn, credentials):
   if CredVerifier.checkValid(credentials, "shutdown", slice_urn):
     self.recordAction("shutdown", credentials, slice_urn)
     foam.lib.shutdown(slice_urn)
     return True
   return False
예제 #20
0
    def pub_ListResources(self, credentials, options):
        """Return information about available resources or resources allocated to a slice

    List the resources at this aggregate in an RSpec: may be all resources,
    only those available for reservation, or only those already reserved for the given slice.

    """
        try:
            CredVerifier.checkValid(credentials, [])

            # Parse options
            compressed = options.get("geni_compressed", False)
            urn = options.get("geni_slice_urn", None)
            spec_version = options.get("geni_rspec_version")
            supported_spec = {'version': '3', 'type': 'GENI'}
            if spec_version:
                if spec_version != supported_spec:
                    msg = "RSpec type/version not supported"
                    propertyList = self.buildPropertyList(
                        GENI_ERROR_CODE.BADVERSION, output=msg)
                    return propertyList
            else:
                msg = "Required option geni_rspec_version missing"
                propertyList = self.buildPropertyList(GENI_ERROR_CODE.BADARGS,
                                                      output=msg)
                return propertyList

            if urn:
                CredVerifier.checkValid(credentials, "getsliceresources", urn)
                self.recordAction("listresources", credentials, urn)
                sliver_urn = GeniDB.getSliverURN(urn)
                if sliver_urn is None:
                    raise Exception(
                        "Sliver for slice URN (%s) does not exist" % (urn))
                else:
                    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)

            propertyList = self.buildPropertyList(GENI_ERROR_CODE.SUCCESS,
                                                  value=rspec)

        except ExpatError:
            msg = "Error parsing credential strings"
            propertyList = self.buildPropertyList(GENI_ERROR_CODE.BADARGS,
                                                  output=msg)
            self._log.error(msg)
        except UnknownSlice as x:
            # Raised by GeniDB.getSliverURN()
            msg = "Attempt to list resources on sliver for unknown slice %s" % (
                urn)
            propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR,
                                                  output=msg)
            x.log(self._log, msg, logging.INFO)
        except xmlrpclib.Fault as x:
            # Something thrown via GCF, we'll presume it was something related to credentials
            msg = "GCF credential check failure: <%s>" % (x)
            propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR,
                                                  output=msg)
            self._log.info(msg)
            self._log.debug(x, exc_info=True)
        except AttributeError as x:
            # New GCF problem with user creds that have no gid_caller, probably
            msg = "GCF credential check failure: <%s>" % (x)
            propertyList = self.buildPropertyList(GENI_ERROR_CODE.ERROR,
                                                  output=msg)
            self._log.info(msg)
            self._log.debug(x, exc_info=True)
        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