コード例 #1
0
def init_catalog(logger, db_uri):
    # create configuration tables
    try:
        from gibbonbeehive.module.catalog.model import CatalogDbManager 
        
        # create api manager
        params = {'api_name':'catalog',
                  'api_id':'auth',
                  'database_uri':db_uri,
                  'api_module':['gibbonbeehive.module.catalog.mod.CatalogModule'],
                  'api_plugin':[],
                  'api_subsystem':'catalog'}
        manager = ApiManager(params)
        manager.configure()
        manager.register_modules()

        # remove and create scchema
        CatalogDbManager.remove_table(db_uri)
        CatalogDbManager.create_table(db_uri)
        
        # create module
        catalog_module = manager.modules['CatalogModule']
        controller = catalog_module.get_controller()

        # create session
        operation.session = manager.get_session()
        operation.perms = perms
        operation.user = authuser

        # init module
        catalog_module.init_object()
        
        cat1 = controller.add_catalog(catalog1['name'],
                                      catalog1['desc'], 
                                      catalog1['use'])
        cat = controller.get_catalogs(oid=cat1)[0]
        for s in services1:
            cat.add_service(s['name'], s['type'], s['desc'], s['uri'])
        
        cat2 = controller.add_catalog(catalog2['name'],
                                      catalog2['desc'], 
                                      catalog2['use'])
        cat = controller.get_catalogs(oid=cat2)[0]
        for s in services2:
            cat.add_service(s['name'], s['type'], s['desc'], s['uri'])        
    except:
        msg = traceback.format_exc()
        logger.error(msg)
    finally:
        # release session
        manager.release_session(operation.session)
        operation.session = None
コード例 #2
0
def init_auth(logger, db_uri):
    # create configuration tables
    try:
        from gibbonbeehive.common import ConfigDbManager 
        
        # create api manager
        params = {'api_name':'auth',
                  'api_id':'process',
                  'database_uri':db_uri,
                  'api_module':['gibbonbeehive.module.process.mod.ConfigModule'],
                  'api_plugin':[],
                  'api_subsystem':'process'}
        manager = ApiManager(params)        

        # remove and create scchema
        ConfigDbManager.remove_table(db_uri)
        ConfigDbManager.create_table(db_uri)

        # create session
        operation.session = manager.get_session()
        operation.perms = perms
        operation.user = authuser
        
        # create db manager
        config = ConfigDbManager()
        
        # set configurations
        #
        # populate table for beehive
        #
        app = 'beehive'
        
        # - redis
        #res = config.add(app, 'redis', 'redis_01', '10.102.47.208;6379;0')
        res = config.add(app, 'redis', 'redis_01', redis_uri)
        logger.info('Add redis configuration: %s' % res)

        # - mail server
        #res = config.add(app, 'redis', 'redis_01', '10.102.47.208;6379;0')
        res = config.add(app, 'mail', 'server1', mail_server)
        logger.info('Add mail server configuration: %s' % res)
        res = config.add(app, 'mail', 'sender1', mail_sender)
        logger.info('Add mail sender configuration: %s' % res)        
        
        # - authentication domains
        for auth in auths:          
            res = config.add(app, 'auth', auth['domain'], json.dumps(auth)) 
            logger.debug('Add auth domain: %s' % res)
        
        # - beehive queue        
        for queue in queues:
            res = config.add('beehive', 'queue', queue['name'], json.dumps(queue))
            logger.debug('Add queue: %s' % res)        
        
        # - tcp proxy
        #res = config.add('beehive', 'tcpproxy', 'proxy01', '10.102.47.208')
        #logger.debug('Add tcp proxy: %s' % res)    
    
        # - http proxy
        #res = config.add('beehive', 'httpproxy', 'proxy02', 'http://10.102.162.5:3128')
        #logger.debug('Add http proxy: %s' % res)
    except:
        msg = traceback.format_exc()
        logger.error(msg)
    finally:
        # release session
        manager.release_session(operation.session)
        operation.session = None
    
    try:
        from gibbonbeehive.module.auth.model import AuthDbManager        
        
        # create api manager
        params = {'api_name':'auth',
                  'api_id':'process',
                  'database_uri':db_uri,
                  'api_module':['gibbonbeehive.module.auth.mod.AuthModule'],
                  'api_plugin':[],
                  'api_subsystem':'process'}
        manager = ApiManager(params)
        manager.configure()
        manager.register_modules()
    
        # remove and create scchema
        AuthDbManager.remove_table(db_uri)
        AuthDbManager.create_table(db_uri)
    
        # create module
        auth_module = manager.modules['AuthModule']
        controller = auth_module.get_controller()
        
        # create session
        operation.session = auth_module.get_session()
        operation.perms = perms
        operation.user = authuser
        
        # init module
        auth_module.init_object()

        # add superadmin role
        perms_to_assign = auth_module.get_controller().get_superadmin_permissions()
        controller.add_superadmin_role(perms_to_assign)
    
        # add guest role
        controller.add_guest_role()
    
        # add superadmin role
        name = 'admin@local'
        storetype = 'DBUSER'
        systype = 'USER'
        profile = 'system'
        active = True
        password = '******'
        description = 'Super Administrator'
        attribute = ''
        user = controller.add_user(name, storetype, systype, active=active, 
                                   password=password, description=description)
        #user = controller.get_users(name)[0]
        user.append_role('ApiSuperadmin')
    
        # create users
        user = controller.add_generic_user('test1@local', 'DBUSER', 'testlab')
        #user = controller.get_users('test1@local')[0]
        #user.append_role('clsk44_209Admin')
    
        user = controller.add_generic_user('test2@local', 'DBUSER', 'testlab')
        #user = controller.get_users('test2@local')[0]
        #user.append_role('clsk44_209Admin')
        
        controller.add_system_user(api_user['name'], password=api_user['pwd'], 
                                   description='api user all modules')
          
    except:
        msg = traceback.format_exc()
        logger.error(msg)
    finally:
        # release session
        auth_module.release_session(operation.session)
        operation.session = None
コード例 #3
0
def configure_portal(logger, db_uri):
    try:
        from gibbonbeehive.common import ConfigDbManager 
        
        # create api manager
        params = {'api_name':'beehive',
                  'api_id':'process',
                  'database_uri':db_uri,
                  'api_module':['gibbonbeehive.module.process.mod.ConfigModule'],
                  'api_plugin':[],
                  'api_subsystem':'process'}
        manager = ApiManager(params)        

        # create session
        operation.session = manager.get_session()
        operation.perms = perms
        operation.user = authuser
        
        # create db manager
        config = ConfigDbManager()
        
        # set configurations
        #
        # populate table for portal
        #
        app = 'portal'
        
        '''
        # log
        logconf = {'gibbon.portal':('DEBUG', 'log/portal2.log'),
                   'gibbon.beehive':('DEBUG', 'log/portal2.log'),
                   'gibbon.cloud':('DEBUG', 'log/portal2.log'),
                   'gibbon.util':('DEBUG', 'log/portal2.log'),
                   'gibbon.util.watch':('DEBUG', 'log/portal2.watch.log', 
                                        '%(asctime)s - %(message)s')}
        num = 0
        for log_name, log_conf in logconf.iteritems():
            name = "logger_portal%s" % num
            res = config.add_log_config(app, name, log_name, log_conf)
            logger.debug('Add logger: %s' % res)
            num += 1
        '''
        
        # http_timeout
        res = config.add(app, 'http', 'http_timeout', 30)
        logger.debug('Add http timeout: %s' % res)
        
        # flask secret key
        #res = manager.set_config(app, 'flask', 'flask_secret_key', urandom(80))
        #logger.debug('Add flask secret key: %s' % res)    
        
        # flask babel
        res = config.add(app, 'flask-babel', 'default_locale', 'it')
        logger.debug('Add flask babel default locale: %s' % res)
        res = config.add(app, 'flask-babel', 'default_timezone', 'utc')
        logger.debug('Add flask babel default timezone: %s' % res)
        langs = {
            'en': 'English',
            'it': 'Italian',
        }
        res = config.add(app, 'flask-babel', 'languages', json.dumps(langs))
        logger.debug('Add flask babel languges: %s' % res)            
    except:
        msg = traceback.format_exc()
        logger.error(msg)
    finally:
        # release session
        manager.release_session(operation.session)
        operation.session = None
コード例 #4
0
def configure(logger, db_uri):
    try:
        from gibbonbeehive.common import ConfigDbManager 
        
        # create api manager
        params = {'api_name':'beehive',
                  'api_id':'process',
                  'database_uri':db_uri,
                  'api_module':['gibbonbeehive.module.process.mod.ConfigModule'],
                  'api_plugin':[],
                  'api_subsystem':'process'}
        manager = ApiManager(params)        

        # remove and create scchema
        ConfigDbManager.remove_table(db_uri)
        ConfigDbManager.create_table(db_uri)

        # create session
        operation.session = manager.get_session()
        operation.perms = perms
        operation.user = authuser
        
        # create db manager
        config = ConfigDbManager()
        
        # set configurations
        #
        # populate table for beehive
        #
        app = 'beehive'
        
        # - api user
        res = config.add(app, 'auth', 'api_user', json.dumps(api_user))
        logger.info('Add api user configuration: %s' % res)        
        
        # - redis
        #res = config.add(app, 'redis', 'redis_01', '10.102.47.208;6379;0')
        res = config.add(app, 'redis', 'redis_01', redis_uri)
        logger.info('Add redis configuration: %s' % res)
        
        # - task manager
        res = config.add(app, 'taskmanager', 'task_broker_url', task_broker_url)
        res = config.add(app, 'taskmanager', 'task_result_backend', task_result_backend)
        logger.info('Add task manager configuration: %s' % res)        
        
        # - scheduler
        res = config.add(app, 'scheduler', 'scheduler_broker_url', scheduler_broker_url)
        res = config.add(app, 'scheduler', 'scheduler_result_backend', scheduler_result_backend)
        logger.info('Add scheduler configuration: %s' % res)        
        
        # - tcp proxy
        res = config.add('beehive', 'tcpproxy', 'proxy01', '10.102.47.208')
        logger.debug('Add tcp proxy: %s' % res)    
    
        # - http proxy
        res = config.add('beehive', 'httpproxy', 'proxy02', 'http://10.102.162.5:3128')
        logger.debug('Add http proxy: %s' % res)
        
        # - endpoint
        for endpoint in endpoints:
            res = config.add('beehive', 'endpoint', endpoint['name'], 
                             json.dumps(endpoint))
            logger.debug('Add endpoint: %s' % res)
        
        # - gateway
        for gw in gateways:
            res = config.add('beehive', 'gateway', gw['name'], 
                             json.dumps(gw))
            logger.debug('Add gateway: %s' % res)        
        
        # - beehive queue        
        for queue in queues:
            res = config.add('beehive', 'queue', queue['name'], json.dumps(queue))
            logger.debug('Add queue: %s' % res)      
    except:
        msg = traceback.format_exc()
        logger.error(msg)
    finally:
        # release session
        manager.release_session(operation.session)
        operation.session = None