def get_ssh_state(): """Getting the state of the remote queue from a text file""" try: filename = os.path.expanduser('~/glidein_state') return json_decode(open(filename).read()) except Exception: logger.warn('error getting ssh state', exc_info=True)
def request(self, methodname, kwargs): """Send request to RPC Server""" # check method name for bad characters if methodname[0] == '_': logger.warning('cannot use RPC for private methods') raise Exception('Cannot use RPC for private methods') # translate request to json body = json_encode({ 'jsonrpc': '2.0', 'method': methodname, 'params': kwargs, 'id': Client.newid() }) if sys.version_info[0] > 2: body = body.encode() headers = {'Content-type': 'application/json'} request = Request(self._address, data=body, headers=headers) # make request to server try: response = urlopen(request, timeout=self._timeout) except Exception: logger.warn('error making jsonrpc request', exc_info=True) raise # translate response from json try: cb_data = response.read() data = json_decode(cb_data) except Exception: try: logger.info('json data: %r', cb_data) except Exception: pass raise if 'error' in data: try: raise Exception('Error %r: %r %r' % data['error']) except Exception: raise Exception('Error %r' % data['error']) if 'result' in data: return data['result'] else: return None
def request(self, methodname, kwargs): """Send request to RPC Server""" # check method name for bad characters if methodname[0] == '_': logger.warning('cannot use RPC for private methods') raise Exception('Cannot use RPC for private methods') # translate request to json body = json_encode({'jsonrpc': '2.0', 'method': methodname, 'params': kwargs, 'id': Client.newid()}) headers = {'Content-type':'application/json'} request = urllib2.Request(self._address, data=body, headers=headers) # make request to server try: response = urllib2.urlopen(request, timeout=self._timeout) except Exception: logger.warn('error making jsonrpc request', exc_info=True) raise # translate response from json try: cb_data = response.read() data = json_decode(cb_data) except Exception: try: logger.info('json data: %r', cb_data) except Exception: pass raise if 'error' in data: try: raise Exception('Error %r: %r %r'%data['error']) except Exception: raise Exception('Error %r'%data['error']) if 'result' in data: return data['result'] else: return None