def str_to_ou(self, ou_string): """ Generate a OU string with the path of the node. For example, for the node /root/first_child/grand_son, it's str_to_ou() is OU=grand_son,OU=first_child,OU=root,DC=myDomain,DC=local. The DC datas are read from the configuration file. Params: String ou_string contains the path of the node pointed. Returns: String which contains the result (i.e.: OU=grand_son,OU=first_child,OU=root,DC=myDomain,DC=local) or returns False if the string can't be generated """ config = PluginConfigFactory.new(BasePluginConfig, "base") if config.has_section('authentication_externalldap'): # Get the parameters from the config file suffix = config.get('authentication_externalldap', 'suffix') ou_list = ou_string.split('/') ou_list.reverse() ous = [] for ou in ou_list: ou = 'OU=' + ou ous.append(ou) ous.append(suffix) return ','.join(ous) else: return False
def get_openldap_config(): """Return OpenLdap credentials used by mmc base plugin""" mmc_base_config = PluginConfigFactory.new(BasePluginConfig, "base") return { 'base_dn': mmc_base_config.baseDN, 'bind_dn': mmc_base_config.username, 'bind_pw': mmc_base_config.password }
def get_conf_array(name): config = PluginConfigFactory.get(name) array = {} for section in config.sections(): config.options(section) dic = {} for opt in config.options(section): dic[opt] = config.get(section, opt) array[section] = dic return array
def get_openldap_config(): """ Return OpenLdap credentials used by mmc base plugin """ from mmc.support.config import PluginConfigFactory from mmc.plugins.base.config import BasePluginConfig mmc_base_config = PluginConfigFactory.new(BasePluginConfig, "base") return {'base_dn': mmc_base_config.baseDN, 'bind_dn': mmc_base_config.username, 'bind_pw': mmc_base_config.password}
def set_conf_array(args): print(args) name, values = args['filename'], args['values'] config = PluginConfigFactory.get(name) for option_name in values: section_name = values[option_name]['section_name'] value = values[option_name]['value'] if not config.has_section(section_name): config.add_section(section_name) config.set(section_name, option_name, value) # TODO check if the conf is OK, and return an error message if not return True
def loadInventoryConf(module_name): """ before commiting the config for the inventory module we are switching to, we make sure the config is loaded (if not we load it), to be able to modify its value before starting the module Also enable and disable the correct module (but they are not yet started, just the config is modified) """ inventory_config = PluginConfigFactory.new(InventoryConfig, "inventory") glpi_config = PluginConfigFactory.new(GlpiConfig, "glpi") print("Instance of inventory config in loadInventoryConf is %s" % inventory_config) # Enable and disable the right modules in their config # base_config = PluginConfigFactory.get("base") # base_config.set('computers', 'method', module_name) glpi_config.set("main", "disable", "0" if module_name == "glpi" else 1) inventory_config.init("inventory") inventory_config.cp.set("main", "disable", "0" if module_name == "inventory" else 1) print("Disable: ", inventory_config.disable)
def loadInventoryConf(module_name): """ before commiting the config for the inventory module we are switching to, we make sure the config is loaded (if not we load it), to be able to modify its value before starting the module Also enable and disable the correct module (but they are not yet started, just the config is modified) """ inventory_config = PluginConfigFactory.new(InventoryConfig, "inventory") glpi_config = PluginConfigFactory.new(GlpiConfig, "glpi") print('Instance of inventory config in loadInventoryConf is %s' % inventory_config) # Enable and disable the right modules in their config # base_config = PluginConfigFactory.get("base") # base_config.set('computers', 'method', module_name) glpi_config.set('main', 'disable', '0' if module_name == 'glpi' else 1) inventory_config.init('inventory') inventory_config.cp.set('main', 'disable', '0' if module_name == 'inventory' else 1) print('Disable: ', inventory_config.disable)
def __init__(self, config=None, init=True): Singleton.__init__(self) if not hasattr(self, "logaction"): if config == None: from mmc.plugins.base import BasePluginConfig from mmc.support.config import PluginConfigFactory try: # Read the configuration self.make(PluginConfigFactory.new(BasePluginConfig, "base"), init) except IOError: # Fallback on default configuration self.make(None, init) else: self.make(config, init)
def __init__(self, config=None, init=True): Singleton.__init__(self) if not hasattr(self, 'logaction'): if config == None: from mmc.plugins.base import BasePluginConfig from mmc.support.config import PluginConfigFactory try: # Read the configuration self.make( PluginConfigFactory.new(BasePluginConfig, 'base'), init) except IOError: # Fallback on default configuration self.make(None, init) else: self.make(config, init)
def getLdapRootDN(): """ Returns the LDAP root DN. """ config = PluginConfigFactory.new(BasePluginConfig, 'base') return {'LDAP root': config.baseDN}