Ejemplo n.º 1
0
 def put_detail(self, id, params):
     if (params):
         params = ['id', id] + list(
             reduce(lambda x, y: x + y, params.items()))
         _data = self._put_data(self.update_path, params)
         if _data.status == "ERROR":
             raise RinorError(_data.code, _data.description)
     else:
         raise RinorError('999', 'No command or value provided')
     return _data[self.index][0]
Ejemplo n.º 2
0
 def put_detail(self, id, firstname, lastname):
     _data = self._put_data(
         self.update_path,
         ['id', id, 'first_name', firstname, 'last_name', lastname])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     return _data[self.index][0]
Ejemplo n.º 3
0
def _get_json(path):
    try:
        ip = Parameter.objects.get(key='rinor_ip')
        port = Parameter.objects.get(key='rinor_port')
    except Parameter.DoesNotExist:
        raise RinorNotConfigured
    else:
        try:
            prefix = Parameter.objects.get(key='rinor_prefix')
        except Parameter.DoesNotExist:
            uri = "http://%s:%s%s" % (ip.value, port.value, path)
        else:
            uri = "http://%s:%s/%s%s" % (ip.value, port.value, prefix.value,
                                         path)

        retries = 0
        attempts = 0
        while True:
            try:
                attempts += 1
                respObj = urllib2.urlopen(uri)
                break
            except urllib2.HTTPError, e:
                raise RinorNotAvailable(code=e.code, resp=e.read())
            except urllib2.URLError, e:
                if attempts <= retries:
                    continue
                else:
                    raise RinorNotAvailable(reason=e.reason)
            except BadStatusLine:
                raise RinorError(reason="No response for '%s'" % uri)
Ejemplo n.º 4
0
 def get_mode(self):
     _data = self._get_data("/package/get-mode")
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     if len(_data['mode']) > 0:
         return _data['mode'][0]
     else:
         return None
Ejemplo n.º 5
0
 def get_list(self, hostname, id):
     _data = self._get_data(self.list_path, ['by-name', hostname, id])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     if len(_data[self.index]) > 0:
         return _data[self.index]
     else:
         return []
Ejemplo n.º 6
0
 def get_detail(self, hostname, id):
     _data = self._get_data(self.detail_path, [hostname, id])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     if len(_data[self.index]) > 0:
         return _data[self.index][0]
     else:
         return None
Ejemplo n.º 7
0
 def get_detail(self, id):
     _data = self._get_data("%s/%s" % (self.list_path, id))
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     if len(_data[self.index]) > 0:
         return _data[self.index][0]
     else:
         return None
Ejemplo n.º 8
0
 def get_info(self):
     _data = self._get_data(self.list_path)
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     if len(_data[self.index]) > 0:
         return _data[self.index][0]
     else:
         return None
Ejemplo n.º 9
0
 def post_list(self, login, password, is_admin, firstname, lastname):
     _data = self._post_data(self.add_path, [
         'login', login, 'password', password, 'is_admin', is_admin,
         'skin_used', '', 'first_name', firstname, 'last_name', lastname
     ])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     return _data[self.index][0]
Ejemplo n.º 10
0
 def get_auth(self, login, password):
     _data = self._get_data("/account/auth", [login, password])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     if len(_data[self.index]) > 0:
         return _data[self.index][0]
     else:
         return None
Ejemplo n.º 11
0
 def delete_list(self, hostname, id):
     _data = self._delete_data(self.delete_path, [hostname, id])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     if len(_data[self.index]) > 0:
         return _data[self.index]
     else:
         return None
Ejemplo n.º 12
0
 def delete_detail(self, hostname, id, key):
     _data = self._delete_data(self.delete_path,
                               [hostname, id, 'by-key', key])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     if len(_data[self.index]) > 0:
         return _data[self.index][0]
     else:
         return None
Ejemplo n.º 13
0
 def set_detail(self, hostname, id, key, value):
     _data = self._put_data(
         self.set_path,
         ['hostname', hostname, 'id', id, 'key', key, 'value', value])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     if len(_data[self.index]) > 0:
         return _data[self.index][0]
     else:
         return None
Ejemplo n.º 14
0
 def get_fromto(self, fromTime, toTime, interval, selector, feature):
     _data = self._get_data(self.list_path, [
         feature, 'from', fromTime, 'to', toTime, 'interval', interval,
         'selector', selector
     ])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     if len(_data[self.index]) > 0:
         return _data[self.index][0]
     else:
         return None
Ejemplo n.º 15
0
 def get_list(self, plugin):
     _data = self._get_data("%s/%s" % (self.list_path, plugin))
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     if len(_data[self.index]) > 0:
         listdata = []
         for obj in _data[self.index]:
             listdata.append(obj)
         return listdata
     else:
         return None
Ejemplo n.º 16
0
 def get_last(self, last, feature):
     if (last == 1):
         _data = self._get_data(self.list_path, [feature, 'lastest'])
     else:
         _data = self._get_data(self.list_path, [feature, 'last', last])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     if len(_data[self.index]) > 0:
         return _data[self.index]
     else:
         return None
Ejemplo n.º 17
0
 def put_detail_password(self, id, old, new):
     _data = self._put_data(self.password_path,
                            ['id', id, 'old', old, 'new', new])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     return _data[self.index][0]
Ejemplo n.º 18
0
 def command_detail(self, hostname, id, command):
     _data = self._put_data("/plugin", [command, hostname, id])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     return None
Ejemplo n.º 19
0
 def get_info(self, command):
     print command
     _data = self._get_data(self.list_path, command)
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     return _data[self.index]
Ejemplo n.º 20
0
 def post_list(self, firstname, lastname):
     _data = self._post_data(
         self.add_path, ['first_name', firstname, 'last_name', lastname])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     return _data[self.index][0]
Ejemplo n.º 21
0
 def get_list(self, host, id):
     _data = self._get_data("%s/%s/%s" % (self.list_path, host, id))
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     return _data[self.index]
Ejemplo n.º 22
0
 def put_uninstall(self, host, type, package):
     _data = self._put_data(self.uninstall_path, [host, type, package])
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     return None
Ejemplo n.º 23
0
 def get_available(self, host, type):
     _data = self._get_data("%s/%s/%s" % (self.available_path, host, type))
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     return _data[self.index]
Ejemplo n.º 24
0
 def refresh_list(self):
     _data = self._put_data(self.refresh_path)
     if _data.status == "ERROR":
         raise RinorError(_data.code, _data.description)
     return None
Ejemplo n.º 25
0
 def get_list(self):
     data = self._get_data(self.list_path)
     if data.status == "ERROR":
         raise RinorError(data.code, data.description)
     return data[self.index]