def register_resource_plugin(logger, db_uri, plugin_class_name): try: # create api manager params = {'api_name':'beehive', 'api_id':'process', 'database_uri':db_uri, 'api_module':['gibbonbeehive.module.resource.mod.ResourceModule'], 'api_plugin':[], 'api_subsystem':'resource'} manager = ApiManager(params) manager.configure() manager.register_modules() # create module module = manager.modules['ResourceModule'] # import plugin operation.session = module.get_session() operation.perms = perms operation.user = authuser plugin_class = import_class(plugin_class_name) plugin = plugin_class(module) plugin.init() except: msg = traceback.format_exc() logger.error(msg) finally: # release session module.release_session(operation.session) operation.session = None
def init_config(logger, db_uri): try: #from gibbonbeehive.common.auth import AuthDbManager # create api manager params = {'api_name':'beehive', 'api_id':'process', 'database_uri':db_uri, 'api_module':['gibbonbeehive.module.config.mod.ConfigModule'], 'api_plugin':[], 'api_subsystem':'process'} manager = ApiManager(params) manager.configure() manager.register_modules() # create module conf_module = manager.modules['ConfigModule'] controller = conf_module.get_controller() # create session operation.session = conf_module.get_session() operation.perms = perms operation.user = authuser # init module conf_module.init_object() except: msg = traceback.format_exc() logger.error(msg) finally: # release session conf_module.release_session(operation.session) operation.session = None
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
def init_resource(logger, db_uri): try: from gibbonbeehive.module.resource.model import ResourceDbManager # create api manager params = {'api_name':'beehive', 'api_id':'process', 'database_uri':db_uri, 'api_module':['gibbonbeehive.module.resource.mod.ResourceModule'], 'api_plugin':[], 'api_subsystem':'resource'} manager = ApiManager(params) manager.configure() manager.register_modules() # remove and create scchema ResourceDbManager.remove_table(db_uri) ResourceDbManager.create_table(db_uri) # create module #from gibbonbeehive.module.resource.mod import ResourceModule #from gibbonbeehive.module.resource.plugins.cloudstack import CloudstackPlugin #resource_module = ResourceModule(manager) #CloudstackPlugin(resource_module).register() resource_module = manager.modules['ResourceModule'] controller = resource_module.get_controller() # create session operation.session = resource_module.get_session() operation.perms = perms operation.user = authuser # init module resource_module.init_object() controller = resource_module.get_controller() for item in containers: container_class = import_class(item['class']) container = container_class(controller, objid=id_gen(), name=item['name'], desc=item['desc'], active=True, connection=json.dumps(item['conn'])) controller.add_container(container) except: msg = traceback.format_exc() logger.error(msg) finally: # release session resource_module.release_session(operation.session) operation.session = None
def init_process(logger, db_uri): try: from gibbonbeehive.module.process.model import ProcessDbManager # create api manager params = {'api_name':'beehive', 'api_id':'process', 'database_uri':db_uri, 'api_module':['gibbonbeehive.module.process.mod.ProcessModule'], 'api_plugin':[], 'api_subsystem':'process'} manager = ApiManager(params) manager.configure() manager.register_modules() # remove and create scchema ProcessDbManager.remove_table(db_uri) ProcessDbManager.create_table(db_uri) # create module process_module = manager.modules['ProcessModule'] controller = process_module.get_controller() # create session operation.session = process_module.get_session() operation.perms = perms operation.user = authuser # init module process_module.init_object() # register main task type proc_manager = ProcessDbManager() proc_manager.add_task_type('start', 'gibbonbeehive.common.process.StartTask', type='SYS', desc='') proc_manager.add_task_type('stop', 'gibbonbeehive.common.process.StopTask', type='SYS', desc='') proc_manager.add_task_type('task1', 'gibbonbeehive.common.process.UserTask', type='USER', desc='') # create dummy process controller.create_dummy_process() except: msg = traceback.format_exc() logger.error(msg) finally: # release session process_module.release_session(operation.session) operation.session = None
def init_monitor(logger, db_uri, update=False): try: from gibbonbeehive.module.monitor.model import MonitorDbManager # create api manager params = {'api_name':'beehive', 'api_id':'monitor', 'database_uri':db_uri, 'api_module':['gibbonbeehive.module.monitor.mod.MonitorModule'], 'api_plugin':[], 'api_subsystem':'monitor'} manager = ApiManager(params) manager.configure() manager.register_modules() # remove and create scchema if update is False: MonitorDbManager.remove_table(db_uri) MonitorDbManager.create_table(db_uri) # create module module = manager.modules['MonitorModule'] controller = module.get_controller() # create session operation.session = module.get_session() operation.perms = perms operation.user = authuser # init module module.init_object() except: msg = traceback.format_exc() logger.error(msg) finally: # release session module.release_session(operation.session) operation.session = None
def init_service(logger, db_uri): try: from gibbonbeehive.module.service.model import ServiceDbManager # create api manager params = {'api_name':'beehive', 'api_id':'process', 'database_uri':db_uri, 'api_module':['gibbonbeehive.module.service.mod.ServiceModule'], 'api_plugin':['ServiceModule,gibbonbeehive.module.service.plugins.test.TestServicePlugin'], 'api_subsystem':'service'} manager = ApiManager(params) manager.configure() manager.register_modules() # remove and create scchema ServiceDbManager.remove_table(db_uri) ServiceDbManager.create_table(db_uri) # create module service_module = manager.modules['ServiceModule'] #controller = service_module.get_controller() # create session operation.session = service_module.get_session() operation.perms = perms operation.user = authuser # init module service_module.init_object() except: msg = traceback.format_exc() logger.error(msg) finally: # release session service_module.release_session(operation.session) operation.session = None
def init_platform(logger, db_uri): try: from gibbonbeehive.module.platform.model import PlatformDbManager # create api manager params = {'api_name':'beehive', 'api_id':'platform', 'database_uri':db_uri, 'api_module':['gibbonbeehive.module.platform.mod.PlatformModule'], 'api_plugin':[], 'api_subsystem':'platform'} manager = ApiManager(params) manager.configure() manager.register_modules() # remove and create scchema PlatformDbManager.remove_table(db_uri) PlatformDbManager.create_table(db_uri) # create module platorm_module = manager.modules['PlatformModule'] #controller = scheduler_module.get_controller() # create session operation.session = platorm_module.get_session() operation.perms = perms operation.user = authuser # init module platorm_module.init_object() except: msg = traceback.format_exc() logger.error(msg) finally: # release session platorm_module.release_session(operation.session) operation.session = None
def update_resource(logger, db_uri): try: from gibbonbeehive.module.resource.model import ResourceDbManager # create api manager params = {'api_name':'beehive', 'api_id':'resource', 'http-socket':None, 'database_uri':db_uri, 'api_module':['gibbonbeehive.module.resource.mod.ResourceModule'], 'api_plugin':[#'ResourceModule,gibbonbeehive.module.resource.plugins.vsphere.VspherePlugin', 'ResourceModule,gibbonbeehive.module.resource.plugins.openstack.OpenstackPlugin', #'ResourceModule,gibbonbeehive.module.resource.plugins.tenant.TenantPlugin', ], 'api_subsystem':'resource'} manager = ApiManager(params) manager.configure() manager.register_modules() # remove and create scchema #ResourceDbManager.remove_table(db_uri) ResourceDbManager.create_table(db_uri) # create module resource_module = manager.modules['ResourceModule'] #controller = service_module.get_controller() # create session operation.session = resource_module.get_session() operation.perms = perms operation.user = authuser # init module resource_module.init_object() #role = 'ApiSuperadmin' # add resource tag permission object ''' objdef = 'tag' class_name = 'gibbonbeehive.module.resource.container.ResourceTag' desc = 'All the resource tags' objaction = '*' objid = '*' manager.api_client.add_object_types(objtype, objdef, class_name) manager.api_client.add_object(objtype, objdef, objid, desc) manager.api_client.append_role_permissions(role, objtype, objdef, objid, objaction) objtype = 'event' manager.api_client.add_object_types(objtype, objdef, class_name) manager.api_client.add_object(objtype, objdef, objid, desc) manager.api_client.append_role_permissions(role, objtype, objdef, objid, objaction) ''' ''' objdefs = ['vsphere.nsx', 'vsphere.nsx.logical_switch', 'vsphere.nsx.security_group', 'vsphere.nsx.dlr', 'vsphere.nsx.edge', 'openstack.domain.project.security_group'] class_names = ['gibbonbeehive.module.resource.plugins.vsphere.container.NsxManager', 'gibbonbeehive.module.resource.plugins.vsphere.container.container.NsxLogicalSwitch', 'gibbonbeehive.module.resource.plugins.vsphere.container.container.NsxSecurityGroup', 'gibbonbeehive.module.resource.plugins.vsphere.container.container.NsxDlr', 'gibbonbeehive.module.resource.plugins.vsphere.container.container.NsxEdge', 'gibbonbeehive.module.resource.plugins.openstack.container.container.OpenstackSecurityGroup'] descs = ['All the nsx managers', 'All the nsx logical switches', 'All the nsx security groups', 'All the nsx dlrs', 'All the nsx edges', 'All the openstack security groups'] objaction = '*' objid = '*' n = 0 for objdef in objdefs: objtype = 'resource' manager.api_client.add_object_types(objtype, objdef, class_names[n]) manager.api_client.add_object(objtype, objdef, objid, descs[n]) manager.api_client.append_role_permissions(role, objtype, objdef, objid, objaction) objtype = 'event' manager.api_client.add_object_types(objtype, objdef, class_names[n]) manager.api_client.add_object(objtype, objdef, objid, descs[n]) manager.api_client.append_role_permissions(role, objtype, objdef, objid, objaction) n += 1 ''' except: msg = traceback.format_exc() logger.error(msg) finally: # release session resource_module.release_session(operation.session) operation.session = None
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