Beispiel #1
0
 def check_version(self):
     if self.version < base.OLDEST_SUPPORTED_VERSION:
         raise exceptions.ClientError(
             "Version %s unsupported, must be %s or higher" %
             (utils.version_str(self.version),
              utils.version_str(base.OLDEST_SUPPORTED_VERSION)))
     return
Beispiel #2
0
    def inflate(self, url=None):
        """Load the resource from the server, if not already loaded."""
        if not self._is_inflated:
            if self._is_inflating:
                #  catch infinite recursion when attempting to inflate
                #  an object that doesn't have enough data to inflate
                msg = ("There is not enough data to inflate this object.  "
                       "Need either an href: {} or a {}: {}")
                msg = msg.format(self._href, self.primary_key,
                                 self._data.get(self.primary_key))
                LOG.error(msg)
                raise exceptions.ClientError(msg)

            self._is_inflating = True

            try:
                params = self.searchParameters if hasattr(
                    self, 'searchParameters') else {}
                # To keep the method same as the original request. The default is GET
                self.load(
                    self.client.request(self.method, url or self.url,
                                        **params))
            except Exception:
                self.load(self._data)

            self._is_inflated = True
            self._is_inflating = False
        return self
Beispiel #3
0
 def check_version(self):
     if (self.model_class.min_version > OLDEST_SUPPORTED_VERSION
             and self.client.version < self.model_class.min_version):
         min_version = utils.version_str(self.model_class.min_version)
         curr_version = utils.version_str(self.client.version)
         raise exceptions.ClientError(
             message="Cannot access %s in version %s, it was added in "
             "version %s" % (self.url, curr_version, min_version))
Beispiel #4
0
    def url(self):
        """Gets the url for the resource this model represents.

        It will just use the 'href' passed in to the constructor if that exists.
        Otherwise, it will generated it based on the collection's url and the
        model's identifier.
        """
        if self._href is not None:
            return self._href
        if self.identifier:
            #  for some reason atlas does not use classifications here in the path when considering one classification
            path = '/'.join([self.parent.url.replace('classifications/', 'classficiation/'), self.identifier])
            return path
        raise exceptions.ClientError("Not able to determine object URL")
Beispiel #5
0
    def inflate(self):
        """Load the resource from the server, if not already loaded."""
        if not self._is_inflated:
            if self._is_inflating:
                # catch infinite recursion when attempting to inflate
                # an object that doesn't have enough data to inflate
                msg = ("There is not enough data to inflate this object.  "
                       "Need either an href: {} or a {}: {}")
                msg = msg.format(self._href, self.primary_key, self._data.get(self.primary_key))
                raise exceptions.ClientError(msg)

            self._is_inflating = True
            self.load(self._data)
            self._is_inflated = True
            self._is_inflating = False
        return self