Пример #1
0
 def __init__(self):
     super(CopyBot, self).__init__()
     self.wdir = mssapi.config.get('Pyami', 'working_dir')
     self.log_file = '%s.log' % self.instance_id
     self.log_path = os.path.join(self.wdir, self.log_file)
     mssapi.set_file_logger(self.name, self.log_path)
     self.src_name = mssapi.config.get(self.name, 'src_bucket')
     self.dst_name = mssapi.config.get(self.name, 'dst_bucket')
     self.replace = mssapi.config.getbool(self.name, 'replace_dst', True)
     s3 = mssapi.connect_s3()
     self.src = s3.lookup(self.src_name)
     if not self.src:
         mssapi.log.error('Source bucket does not exist: %s' % self.src_name)
     dest_access_key = mssapi.config.get(self.name, 'dest_aws_access_key_id', None)
     if dest_access_key:
         dest_secret_key = mssapi.config.get(self.name, 'dest_aws_secret_access_key', None)
         s3 = mssapi.connect(dest_access_key, dest_secret_key)
     self.dst = s3.lookup(self.dst_name)
     if not self.dst:
         self.dst = s3.create_bucket(self.dst_name)
Пример #2
0
    def run_scripts(self):
        scripts = config.get('Pyami', 'scripts')
        if scripts:
            for script in scripts.split(','):
                script = script.strip(" ")
                try:
                    pos = script.rfind('.')
                    if pos > 0:
                        mod_name = script[0:pos]
                        cls_name = script[pos + 1:]
                        cls = find_class(mod_name, cls_name)
                        mssapi.log.info('Running Script: %s' % script)
                        s = cls()
                        s.main()
                    else:
                        mssapi.log.warning('Trouble parsing script: %s' % script)
                except Exception as e:
                    mssapi.log.exception('Problem Running Script: %s. Startup process halting.' % script)
                    raise e

    def main(self):
        self.run_scripts()
        self.notify('Startup Completed for %s' % config.get('Instance', 'instance-id'))

if __name__ == "__main__":
    if not config.has_section('loggers'):
        mssapi.set_file_logger('startup', '/var/log/mssapi.log')
    sys.path.append(config.get('Pyami', 'working_dir'))
    su = Startup()
    su.main()
Пример #3
0
            mssapi.log.exception('Problem Retrieving file: %s' % s3_file)
            path = None
        return path

    def load_packages(self):
        package_str = mssapi.config.get('Pyami', 'packages')
        if package_str:
            packages = package_str.split(',')
            for package in packages:
                package = package.strip()
                if package.startswith('s3:'):
                    package = self.fetch_s3_file(package)
                if package:
                    # if the "package" is really a .py file, it doesn't have to
                    # be installed, just being in the working dir is enough
                    if not package.endswith('.py'):
                        self.run('easy_install -Z %s' % package, exit_on_error=False)

    def main(self):
        self.create_working_dir()
        self.load_mssapi()
        self.load_packages()
        self.notify('Bootstrap Completed for %s' % mssapi.config.get_instance('instance-id'))

if __name__ == "__main__":
    # because bootstrap starts before any logging configuration can be loaded from
    # the mssapi config files, we will manually enable logging to /var/log/mssapi.log
    mssapi.set_file_logger('bootstrap', '/var/log/mssapi.log')
    bs = Bootstrap()
    bs.main()
Пример #4
0
    def load_packages(self):
        package_str = mssapi.config.get('Pyami', 'packages')
        if package_str:
            packages = package_str.split(',')
            for package in packages:
                package = package.strip()
                if package.startswith('s3:'):
                    package = self.fetch_s3_file(package)
                if package:
                    # if the "package" is really a .py file, it doesn't have to
                    # be installed, just being in the working dir is enough
                    if not package.endswith('.py'):
                        self.run('easy_install -Z %s' % package,
                                 exit_on_error=False)

    def main(self):
        self.create_working_dir()
        self.load_mssapi()
        self.load_packages()
        self.notify('Bootstrap Completed for %s' %
                    mssapi.config.get_instance('instance-id'))


if __name__ == "__main__":
    # because bootstrap starts before any logging configuration can be loaded from
    # the mssapi config files, we will manually enable logging to /var/log/mssapi.log
    mssapi.set_file_logger('bootstrap', '/var/log/mssapi.log')
    bs = Bootstrap()
    bs.main()