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]
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]
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)
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
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 []
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
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
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
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]
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
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
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
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
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
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
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
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]
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
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]
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]
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]
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
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]
def refresh_list(self): _data = self._put_data(self.refresh_path) if _data.status == "ERROR": raise RinorError(_data.code, _data.description) return None
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]