def __virtual__(): """ Verify RabbitMQ is installed. """ global RABBITMQCTL global RABBITMQ_PLUGINS if salt.utils.platform.is_windows(): from salt.ext.six.moves import winreg key = None try: key = winreg.OpenKeyEx( winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\VMware, Inc.\\RabbitMQ Server", 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY, ) (dir_path, value_type) = winreg.QueryValueEx(key, "Install_Dir") if value_type != winreg.REG_SZ: raise TypeError( "Invalid RabbitMQ Server directory type: {0}".format( value_type)) if not os.path.isdir(dir_path): raise IOError( "RabbitMQ directory not found: {0}".format(dir_path)) subdir_match = "" for name in os.listdir(dir_path): if name.startswith("rabbitmq_server-"): subdir_path = os.path.join(dir_path, name) # Get the matching entry that is last in ASCII order. if os.path.isdir( subdir_path) and subdir_path > subdir_match: subdir_match = subdir_path if not subdir_match: raise IOError( '"rabbitmq_server-*" subdirectory not found in: {0}'. format(dir_path)) RABBITMQCTL = os.path.join(subdir_match, "sbin", "rabbitmqctl.bat") RABBITMQ_PLUGINS = os.path.join(subdir_match, "sbin", "rabbitmq-plugins.bat") except Exception: # pylint: disable=broad-except pass finally: if key is not None: winreg.CloseKey(key) else: RABBITMQCTL = salt.utils.path.which("rabbitmqctl") RABBITMQ_PLUGINS = salt.utils.path.which("rabbitmq-plugins") if not RABBITMQCTL: return ( False, "Module rabbitmq: module only works when RabbitMQ is installed") return True
def _open_registry_key(reg_hive, reg_key): reg_handle = None try: flags = _get_flags(reg_hive) reg_handle = _winreg.OpenKeyEx(reg_hive, reg_key, 0, flags) # Unsinstall key may not exist for all users except Exception: pass return reg_handle
def __virtual__(): ''' Verify RabbitMQ is installed. ''' global RABBITMQCTL global RABBITMQ_PLUGINS if salt.utils.is_windows(): from salt.ext.six.moves import winreg key = None try: key = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\VMware, Inc.\\RabbitMQ Server', 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY) (dir_path, value_type) = winreg.QueryValueEx(key, 'Install_Dir') if value_type != winreg.REG_SZ: raise TypeError( 'Invalid RabbitMQ Server directory type: {0}'.format( value_type)) if not os.path.isdir(dir_path): raise IOError( 'RabbitMQ directory not found: {0}'.format(dir_path)) subdir_match = '' for name in os.listdir(dir_path): if name.startswith('rabbitmq_server-'): subdir_path = os.path.join(dir_path, name) # Get the matching entry that is last in ASCII order. if os.path.isdir( subdir_path) and subdir_path > subdir_match: subdir_match = subdir_path if not subdir_match: raise IOError( '"rabbitmq_server-*" subdirectory not found in: {0}'. format(dir_path)) RABBITMQCTL = os.path.join(subdir_match, 'sbin', 'rabbitmqctl.bat') RABBITMQ_PLUGINS = os.path.join(subdir_match, 'sbin', 'rabbitmq-plugins.bat') except Exception: pass finally: if key is not None: winreg.CloseKey(key) else: RABBITMQCTL = salt.utils.which('rabbitmqctl') RABBITMQ_PLUGINS = salt.utils.which('rabbitmq-plugins') if not RABBITMQCTL: return ( False, 'Module rabbitmq: module only works when RabbitMQ is installed') return True
def read_key(hkey, path, key, reflection=True): ''' Read registry key value CLI Example: .. code-block:: bash salt '*' reg.read_key HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' ''' registry = Registry() hkey2 = getattr(registry, hkey) access_mask = registry.reflection_mask[reflection] try: handle = _winreg.OpenKeyEx(hkey2, path, 0, access_mask) return _winreg.QueryValueEx(handle, key)[0] except Exception: return None