예제 #1
0
    def do_emit(self, tmpfile_path=None):
        if not tmpfile_path:
            return
        aws_access_key_id = config.get_access_key_id()
        aws_secret_access_key = config.get_secret_access_key()
        security_token = config.get_security_token()
        conn = boto.connect_s3(
            aws_access_key_id=aws_access_key_id,
            aws_secret_access_key=aws_secret_access_key,
            security_token=security_token,
            is_secure=False,
            port=config.get_webservice_port(),
            path='/services/objectstorage',
            host=config.get_objectstorage_service_host(),
            calling_format='boto.s3.connection.OrdinaryCallingFormat')
        if not conn:
            raise Exception('Could not connect to object storage (S3) service')

        key_name = self.generate_log_file_name()
        bucket = conn.get_bucket(self.bucket_name, validate=False)
        k = Key(bucket)
        k.key = key_name
        k.set_contents_from_filename(tmpfile_path,
                                     policy='bucket-owner-full-control')
        servo.log.debug(
            'Access logs were emitted successfully: s3://%s/%s' %
            (urllib2.quote(self.bucket_name), urllib2.quote(key_name)))
예제 #2
0
    def do_emit(self, tmpfile_path=None):
        if not tmpfile_path:
            return
        aws_access_key_id = config.get_access_key_id()
        aws_secret_access_key = config.get_secret_access_key()
        security_token = config.get_security_token()
        conn = boto.connect_s3(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, security_token=security_token, is_secure=False, port=config.get_webservice_port(), path='/services/objectstorage', host= config.get_objectstorage_service_host(), calling_format='boto.s3.connection.OrdinaryCallingFormat')
        if not conn:
            raise Exception('Could not connect to object storage (S3) service') 

        key_name = self.generate_log_file_name()
        bucket = conn.get_bucket(self.bucket_name, validate=False)
        k = Key(bucket)
        k.key = key_name
        k.set_contents_from_filename(tmpfile_path, policy='bucket-owner-full-control')
        servo.log.debug('Access logs were emitted successfully: s3://%s/%s'  % (urllib2.quote(self.bucket_name),urllib2.quote(key_name)))
예제 #3
0
    def do_emit(self):
        servo.log.debug('Trying to emit access log of %d entries' % len(self._logs))
        print 'Trying to emit access log of %d entries' % len(self._logs)
        aws_access_key_id = config.get_access_key_id()
        aws_secret_access_key = config.get_secret_access_key()
        security_token = config.get_security_token()
        conn = boto.connect_s3(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, security_token=security_token, is_secure=False, port=8773, path='/services/objectstorage', host= config.get_objectstorage_service_host(), calling_format='boto.s3.connection.OrdinaryCallingFormat')
        if not conn:
            raise Exception('Could not connect to object storage (S3) service') 

        key_name = self.generate_log_file_name()
        tmpfile = tempfile.mkstemp()
        fd = os.fdopen(tmpfile[0],'w')
        tmpfile_path = tmpfile[1]
	for line in self._logs:
            fd.write(line+'\n')
        fd.close()
        
        bucket = conn.get_bucket(self.bucket_name)
        k = Key(bucket)
        k.key = key_name
        k.set_contents_from_filename(tmpfile_path)
        k.add_user_grant('FULL_CONTROL', config.get_owner_account_id())

        os.unlink(tmpfile_path)
        servo.log.debug('Access logs were emitted successfully: s3://%s/%s'  % (self.bucket_name,key_name))