def _makeObjectStore(self): import siptrackdlib from siptrackdlib.storage import stsqlite storage_file = os.path.join(self.tempdir, 'stsqlite.db') storage = stsqlite.Storage(storage_file) object_store = siptrackdlib.ObjectStore(storage) return object_store
def run(): print 'Creating object store, this might take a while.' object_store = siptrackdlib.ObjectStore(storage) yield object_store.init() um = object_store.view_tree.add(None, 'user manager local') u = um.add(None, 'user local', 'admin', 'admin', True) object_store.view_tree.setActiveUserManager(um) yield object_store.commit([object_store.view_tree, um, u]) print 'New user manager oid: %s' % (um.oid) reactor.stop()
def run(): print 'Creating object store, this might take a while.' object_store = siptrackdlib.ObjectStore(storage) yield object_store.init() for um in object_store.view_tree.listChildren(include = \ ['user manager local', 'user manager ldap']): active = False if um is object_store.view_tree.user_manager: active = True s = 'name: %s, oid: %s, active: %s' % (um.getAttributeValue( 'name', 'NONE'), um.oid, active) print s reactor.stop()
def run_siptrackd_twisted(listen_port, ssl_port, ssl_private_key, ssl_certificate, storage, reload_interval, searcher): log.msg('Creating object store') object_store = siptrackdlib.ObjectStore(storage, searcher=searcher) session_handler = sessions.SessionHandler() log.msg('Creating rpc interface') siptrackd_rpc = SiptrackdRPC(object_store, session_handler) xmlrpc.addIntrospection(siptrackd_rpc) view_rpc = view.ViewRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('view', view_rpc) view_tree_rpc = view.ViewTreeRPC(object_store, session_handler) view_rpc.putSubHandler('tree', view_tree_rpc) counter_rpc = counter.CounterRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('counter', counter_rpc) counter_loop_rpc = counter.CounterLoopRPC(object_store, session_handler) counter_rpc.putSubHandler('loop', counter_loop_rpc) user_rpc = user.UserRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('user', user_rpc) user_local_rpc = user.UserLocalRPC(object_store, session_handler) user_rpc.putSubHandler('local', user_local_rpc) user_ldap_rpc = user.UserLDAPRPC(object_store, session_handler) user_rpc.putSubHandler('ldap', user_ldap_rpc) user_active_directory_rpc = user.UserActiveDirectoryRPC( object_store, session_handler) user_rpc.putSubHandler('activedirectory', user_active_directory_rpc) user_rpc.putSubHandler('ad', user_active_directory_rpc) user_manager_rpc = user.UserManagerRPC(object_store, session_handler) user_rpc.putSubHandler('manager', user_manager_rpc) user_manager_local_rpc = user.UserManagerLocalRPC(object_store, session_handler) user_manager_rpc.putSubHandler('local', user_manager_local_rpc) user_manager_ldap_rpc = user.UserManagerLDAPRPC(object_store, session_handler) user_manager_rpc.putSubHandler('ldap', user_manager_ldap_rpc) user_manager_active_directory_rpc = user.UserManagerActiveDirectoryRPC( object_store, session_handler) user_manager_rpc.putSubHandler('activedirectory', user_manager_active_directory_rpc) user_manager_rpc.putSubHandler('ad', user_manager_active_directory_rpc) user_group_rpc = user.UserGroupRPC(object_store, session_handler) user_rpc.putSubHandler('group', user_group_rpc) user_group_ldap_rpc = user.UserGroupLDAPRPC(object_store, session_handler) user_group_rpc.putSubHandler('ldap', user_group_ldap_rpc) user_group_active_directory_rpc = user.UserGroupActiveDirectoryRPC( object_store, session_handler) user_group_rpc.putSubHandler('activedirectory', user_group_active_directory_rpc) user_group_rpc.putSubHandler('ad', user_group_active_directory_rpc) device_rpc = device.DeviceRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('device', device_rpc) device_tree_rpc = device.DeviceTreeRPC(object_store, session_handler) device_rpc.putSubHandler('tree', device_tree_rpc) device_category_rpc = device.DeviceCategoryRPC(object_store, session_handler) device_rpc.putSubHandler('category', device_category_rpc) device_config_rpc = deviceconfig.DeviceConfigRPC(object_store, session_handler) device_rpc.putSubHandler('config', device_config_rpc) device_config_template_rpc = deviceconfig.DeviceConfigTemplateRPC( object_store, session_handler) device_config_rpc.putSubHandler('template', device_config_template_rpc) password_rpc = password.PasswordRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('password', password_rpc) password_key_rpc = password.PasswordKeyRPC(object_store, session_handler) password_rpc.putSubHandler('key', password_key_rpc) password_tree_rpc = password.PasswordTreeRPC(object_store, session_handler) password_rpc.putSubHandler('tree', password_tree_rpc) password_category_rpc = password.PasswordCategoryRPC( object_store, session_handler) password_rpc.putSubHandler('category', password_category_rpc) sub_key_rpc = password.SubKeyRPC(object_store, session_handler) password_rpc.putSubHandler('subkey', sub_key_rpc) network_rpc = network.NetworkRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('network', network_rpc) network_tree_rpc = network.NetworkTreeRPC(object_store, session_handler) network_rpc.putSubHandler('tree', network_tree_rpc) network_ipv4_rpc = network.NetworkIPV4RPC(object_store, session_handler) network_rpc.putSubHandler('ipv4', network_ipv4_rpc) network_range_rpc = network.NetworkRangeRPC(object_store, session_handler) network_rpc.putSubHandler('range', network_range_rpc) network_range_ipv4_rpc = network.NetworkRangeIPV4RPC( object_store, session_handler) network_range_rpc.putSubHandler('ipv4', network_range_ipv4_rpc) network_ipv6_rpc = network.NetworkIPV6RPC(object_store, session_handler) network_rpc.putSubHandler('ipv6', network_ipv6_rpc) network_range_ipv6_rpc = network.NetworkRangeIPV6RPC( object_store, session_handler) network_range_rpc.putSubHandler('ipv6', network_range_ipv6_rpc) container_rpc = container.ContainerRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('container', container_rpc) container_tree_rpc = container.ContainerTreeRPC(object_store, session_handler) container_rpc.putSubHandler('tree', container_tree_rpc) attribute_rpc = attribute.AttributeRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('attribute', attribute_rpc) versioned_attribute_rpc = attribute.VersionedAttributeRPC( object_store, session_handler) attribute_rpc.putSubHandler('versioned', versioned_attribute_rpc) encrypted_attribute_rpc = attribute.EncryptedAttributeRPC( object_store, session_handler) attribute_rpc.putSubHandler('encrypted', encrypted_attribute_rpc) template_rpc = template.TemplateRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('template', template_rpc) device_template_rpc = template.DeviceTemplateRPC(object_store, session_handler) template_rpc.putSubHandler('device', device_template_rpc) network_template_rpc = template.NetworkTemplateRPC(object_store, session_handler) template_rpc.putSubHandler('network', network_template_rpc) template_rule_rpc = template.TemplateRuleRPC(object_store, session_handler) template_rpc.putSubHandler('rule', template_rule_rpc) template_rule_password_rpc = template.TemplateRulePasswordRPC( object_store, session_handler) template_rule_rpc.putSubHandler('password', template_rule_password_rpc) template_rule_assign_network_rpc = template.TemplateRuleAssignNetworkRPC( object_store, session_handler) template_rule_rpc.putSubHandler('assign_network', template_rule_assign_network_rpc) template_rule_subdevice_rpc = template.TemplateRuleSubdeviceRPC( object_store, session_handler) template_rule_rpc.putSubHandler('subdevice', template_rule_subdevice_rpc) template_rule_text_rpc = template.TemplateRuleTextRPC( object_store, session_handler) template_rule_rpc.putSubHandler('text', template_rule_text_rpc) template_rule_fixed_rpc = template.TemplateRuleFixedRPC( object_store, session_handler) template_rule_rpc.putSubHandler('fixed', template_rule_fixed_rpc) template_rule_regmatch_rpc = template.TemplateRuleRegmatchRPC( object_store, session_handler) template_rule_rpc.putSubHandler('regmatch', template_rule_regmatch_rpc) template_rule_bool_rpc = template.TemplateRuleBoolRPC( object_store, session_handler) template_rule_rpc.putSubHandler('bool', template_rule_bool_rpc) template_rule_int_rpc = template.TemplateRuleIntRPC( object_store, session_handler) template_rule_rpc.putSubHandler('int', template_rule_int_rpc) template_rule_delete_attribute_rpc = template.TemplateRuleDeleteAttributeRPC( object_store, session_handler) template_rule_rpc.putSubHandler('delete_attribute', template_rule_delete_attribute_rpc) template_rule_flush_nodes_rpc = template.TemplateRuleFlushNodesRPC( object_store, session_handler) template_rule_rpc.putSubHandler('flush_nodes', template_rule_flush_nodes_rpc) template_rule_flush_associations_rpc = template.TemplateRuleFlushAssociationsRPC( object_store, session_handler) template_rule_rpc.putSubHandler('flush_associations', template_rule_flush_associations_rpc) config_rpc = config.ConfigRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('config', config_rpc) config_network_autoassign_rpc = config.ConfigNetworkAutoassignRPC( object_store, session_handler) config_rpc.putSubHandler('network_autoassign', config_network_autoassign_rpc) config_value_rpc = config.ConfigValueRPC(object_store, session_handler) config_rpc.putSubHandler('value', config_value_rpc) simple_rpc = simple.SimpleRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('simple', simple_rpc) permission_rpc = permission.PermissionRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('permission', permission_rpc) command_rpc = event.CommandRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('command', command_rpc) command_queue_rpc = event.CommandQueueRPC(object_store, session_handler) command_rpc.putSubHandler('queue', command_queue_rpc) event_rpc = event.EventRPC(object_store, session_handler) siptrackd_rpc.putSubHandler('event', event_rpc) event_trigger_rpc = event.EventTriggerRPC(object_store, session_handler) event_rpc.putSubHandler('trigger', event_trigger_rpc) event_trigger_rule_rpc = event.EventTriggerRuleRPC(object_store, session_handler) event_trigger_rpc.putSubHandler('rule', event_trigger_rule_rpc) event_trigger_rule_python_rpc = event.EventTriggerRulePythonRPC( object_store, session_handler) event_trigger_rule_rpc.putSubHandler('python', event_trigger_rule_python_rpc) root_service = service.MultiService() if listen_port: siptrackd_xmlrpc_service = internet.TCPServer( listen_port, server.Site(siptrackd_rpc)) siptrackd_xmlrpc_service.setServiceParent(root_service) if ssl_port: ssl_context = SiptrackOpenSSLContextFactory(ssl_private_key, ssl_certificate) siptrackd_ssl_xmlrpc_service = internet.SSLServer( ssl_port, server.Site(siptrackd_rpc), ssl_context) siptrackd_ssl_xmlrpc_service.setServiceParent(root_service) application = service.Application('siptrackd') root_service.setServiceParent(application) reactor.callWhenRunning(siptrackd_twisted_init, object_store, application) if reload_interval: reactor.callLater(reload_interval, object_store_reloader, session_handler, object_store, reload_interval) reactor.run() log.msg('Shutting down siptrackd server.') return 0
def make_object_store(config): storage = make_storage(config) searcher = siptrackdlib.search.get_searcher('whoosh') object_store = siptrackdlib.ObjectStore(storage, searcher=searcher) yield object_store.init() defer.returnValue(object_store)