Ejemplo n.º 1
0
    def __setitem__(self, key, value):
        key = normalize_to_unicode(key)
        value = normalize_to_unicode(value)
        try:
            self.logger.info("Setting key '%s' to '%s' in stanza '%s' "
                             "in %s.conf." %
                             (key, value, self.name, self.conf_name))
            # Update takes positional arguments and we send a dictionary so
            # if written update(key=value) field 'key' in stanza will get value
            self.raw_rest_stanza.update(**{key: value})
            self.raw_rest_stanza.refresh()

        except StanzaNotFound as s:
            self.logger.warn(s)
            raise
Ejemplo n.º 2
0
 def create_stanza(self, stanza_name, values=None):
     values = values or {}
     values = dict([normalize_to_unicode(k),
                    normalize_to_unicode(v)] for k, v in values.items())
     stanza_name = normalize_to_unicode(stanza_name)
     try:
         self.logger.info("Creating stanza '%s' in %s.conf with values:"
                          " %s." % (stanza_name, self.name, values))
         return RESTStanzaWrapper(
             self, self._create_stanza(stanza_name, **values))
     except HTTPError as h:
         self.logger.warn("Stanza '%s' already existed in %s.conf. "
                          "HTTPError message: %s" %
                          (stanza_name, self.name, h))
         return self[stanza_name]
     except Exception:
         raise
Ejemplo n.º 3
0
    def create(self, conf_name):
        conf_name = normalize_to_unicode(conf_name)
        if conf_name in self:
            self.logger.info("conf file '%s' already existed" % conf_name)
            return

        self.logger.info("Creating conf file %s" % conf_name)
        # create(conf_name)
        return RESTConfWrapper(self.connector, self._create(conf_name))
Ejemplo n.º 4
0
 def _create_index(self, index_name):
     index_name = normalize_to_str(index_name)
     url = PATH_PERFIX
     user_args = {"name": index_name}
     response, content = self.connector.make_request(
         "POST", url, user_args, {"output_mode": "json"}
     )
     assert response["status"] == "201"
     if normalize_to_unicode(index_name) in self:
         return RestIndex(self.connector, index_name)
Ejemplo n.º 5
0
 def delete_stanza(self, stanza_name):
     stanza_name = normalize_to_unicode(stanza_name)
     try:
         self.logger.info("Deleting stanza '%s' in %s.conf" %
                          (stanza_name, self.name))
         self._delete_stanza(stanza_name)
     except HTTPError as h:
         self.logger.warn("Error during deletion: %s" % h)
     except Exception:
         raise
Ejemplo n.º 6
0
 def create_index(self, index_name):
     index_name = normalize_to_unicode(index_name)
     try:
         self.logger.info("Creating index '%s'" % index_name)
         self._create_index(index_name)
     except HTTPError as err:
         # Index already exists
         if not err.status == 409:
             raise
         self.logger.warn(
             "Index '%s' already exists. HTTPError: %s" % (index_name, err)
         )
     return self[index_name]
Ejemplo n.º 7
0
 def _create_stanza(self, stanza_name, **values):
     if stanza_name in self:
         return RestStanza(self.connector, self._raw_rest_conf, stanza_name)
     values = dict(
         [normalize_to_str(k), normalize_to_str(v)]
         for k, v in values.items())
     stanza_name = normalize_to_str(stanza_name)
     url = PATH_PERFIX + self._raw_rest_conf.path
     user_args = {"name": stanza_name}
     user_args.update(values)
     response, content = self.connector.make_request(
         "POST", url, user_args, {"output_mode": "json"})
     assert response["status"] == "201"
     if normalize_to_unicode(stanza_name) in self:
         return RestStanza(self.connector, self._raw_rest_conf, stanza_name)
Ejemplo n.º 8
0
    def delete_value(self, key):
        key = normalize_to_unicode(key)
        try:
            self.logger.info("Deleting key %s in stanza '%s' in %s.conf." %
                             (key, self.name, self.conf_name))
            # Update takes positional arguments and we send a dictionary
            # If written update(key=value) field 'key' in stanza will get value
            self.raw_rest_stanza.update(**{key: ""})
            self.raw_rest_stanza.refresh()

            # If key has value '' or None when fetched return True
            if self[key] is None or self[key] == "":
                return True

            # Something is wrong since the key still contains _some_ value
            raise RuntimeError(
                "delete_value(%s, %s, %s) did not properly"
                " delete value. unexpected value in self[%s]: "
                "%s" % (key, self.name, self.conf_name, key, self[key]))
        except StanzaNotFound as s:
            self.logger.warn(s)
            raise
Ejemplo n.º 9
0
 def delete(self, **kwargs):
     kwargs = dict([normalize_to_unicode(k),
                    normalize_to_unicode(v)] for k, v in kwargs.items())
     self.logger.info("Deleting index %s with: %s" % (self.name, kwargs))
     self._raw_rest_index.delete(**kwargs)