def post(self): """Add a new buildout to database.""" try: data = self.request.params['data'] incoming = data.encode('utf-8') checksum = zlib.adler32(incoming) checksum_buildout = Buildout.get_by_checksum(checksum) if checksum_buildout: logging.info("Checksum matched") logging.info("Updating datetime..") checksum_buildout.datetime = datetime.now() DBSession.flush() raise Exception("No changes with existing data.") logging.info("New checksum") jsondata = JsonDataWrapper(data) except KeyError: return Response('No data. Nothing added.') except Exception as e: return Response(str(e)) host = Host.get_by_name(jsondata.hostname) if not host: host = Host.add(jsondata.hostname, jsondata.ipv4) self.add_buildout(jsondata, host, checksum) return Response('Added buildout information to Whiskers.')
def post(self): """Add a new buildout to database.""" try: data = self.request.json_body['data'] checksum = zlib.adler32(self.request.body) checksum_buildout = Buildout.get_by_checksum(checksum) if checksum_buildout: logging.info("Checksum matched") logging.info("Updating datetime..") checksum_buildout.datetime = datetime.now() DBSession.flush() raise Exception("No changes with existing data.") logging.info("New checksum") jsondata = JsonDataWrapper(data) except KeyError: return Response(u"No data. Nothing added.") except AttributeError as e: return Response(u"Not a valid request. Error was: {error}".format( error=str(e))) except Exception as e: return Response(u"Adding information failed. Error was: {error}". format(error=str(e))) host = Host.get_by_name(jsondata.hostname) if not host: host = Host.add(jsondata.hostname, jsondata.ipv4) self.add_buildout(jsondata, host, checksum) return Response(u'Added buildout information to Whiskers.')
def host_view(self): host_id = self.request.matchdict['host_id'] host = Host.get_by_id(int(host_id)) buildouts = self.get_buildouts(host_id) return {'host': host, 'main': self.main, 'buildouts': buildouts}
def host_view(self): host_id = self.request.matchdict['host_id'] try: host = Host.get_by_id(int(host_id)) buildouts = self.get_buildouts(host_id) except NoResultFound as e: host = None buildouts = [] return {'host': host, 'main': self.main, 'buildouts': buildouts}
def get(self): host_id = self.request.matchdict.get('host_id') host = Host.get_by_id(host_id) return host.get_as_dict()