Example #1
0
    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.')
Example #2
0
    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 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.')