<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import salt . utils <EOL> import time <EOL> import logging <EOL> from salt . ext . six . moves import zip <EOL> from salt . ext . six . moves import range <EOL> log = logging . getLogger ( __name__ ) <EOL> __virtualname__ = '<STR_LIT>' <EOL> BUFFSIZE = <NUM_LIT> <EOL> SERVICE_STOP_DELAY_SECONDS = <NUM_LIT:15> <EOL> SERVICE_STOP_POLL_MAX_ATTEMPTS = <NUM_LIT:5> <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if salt . utils . is_windows ( ) : <EOL> return __virtualname__ <EOL> return ( False , "<STR_LIT>" ) <EOL> def get_enabled ( ) : <EOL> '''<STR_LIT>''' <EOL> return sorted ( [ service for service in get_all ( ) if enabled ( service ) ] ) <EOL> def get_disabled ( ) : <EOL> '''<STR_LIT>''' <EOL> return sorted ( [ service for service in get_all ( ) if disabled ( service ) ] ) <EOL> def available ( name ) : <EOL> '''<STR_LIT>''' <EOL> return name in get_all ( ) <EOL> def missing ( name ) : <EOL> '''<STR_LIT>''' <EOL> return name not in get_all ( ) <EOL> def get_all ( ) : <EOL> '''<STR_LIT>''' <EOL> ret = set ( ) <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:all>' , '<STR_LIT>' , str ( BUFFSIZE ) ] <EOL> lines = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) . splitlines ( ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> comps = line . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> if not len ( comps ) > <NUM_LIT:1> : <EOL> continue <EOL> ret . add ( comps [ <NUM_LIT:1> ] . strip ( ) ) <EOL> return sorted ( ret ) <EOL> def get_service_name ( * args ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> services = [ ] <EOL> display_names = [ ] <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:all>' , '<STR_LIT>' , str ( BUFFSIZE ) ] <EOL> lines = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) . splitlines ( ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> comps = line . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> if not len ( comps ) > <NUM_LIT:1> : <EOL> continue <EOL> services . append ( comps [ <NUM_LIT:1> ] . strip ( ) ) <EOL> if '<STR_LIT>' in line : <EOL> comps = line . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> if not len ( comps ) > <NUM_LIT:1> : <EOL> continue <EOL> display_names . append ( comps [ <NUM_LIT:1> ] . strip ( ) ) <EOL> if len ( services ) == len ( display_names ) : <EOL> service_dict = dict ( zip ( display_names , services ) ) <EOL> else : <EOL> return '<STR_LIT>' <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> return service_dict <EOL> for arg in args : <EOL> if arg in service_dict : <EOL> ret [ arg ] = service_dict [ arg ] <EOL> return ret <EOL> def start ( name ) : <EOL> '''<STR_LIT>''' <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT:start>' , name ] <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> def stop ( name ) : <EOL> '''<STR_LIT>''' <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , name ] <EOL> res = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> if '<STR_LIT>' in res : <EOL> return True <EOL> for attempt in range ( SERVICE_STOP_POLL_MAX_ATTEMPTS ) : <EOL> if not status ( name ) : <EOL> return True <EOL> log . debug ( '<STR_LIT>' , name ) <EOL> time . sleep ( SERVICE_STOP_DELAY_SECONDS ) <EOL> log . warning ( '<STR_LIT>' , name ) <EOL> return False <EOL> def restart ( name ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in name : <EOL> create_win_salt_restart_task ( ) <EOL> return execute_salt_restart_task ( ) <EOL> return stop ( name ) and start ( name ) <EOL> def create_win_salt_restart_task ( ) : <EOL> '''<STR_LIT>''' <EOL> cmd = '<STR_LIT>' <EOL> args = '<STR_LIT>' <EOL> return __salt__ [ '<STR_LIT>' ] ( name = '<STR_LIT>' , <EOL> user_name = '<STR_LIT>' , <EOL> force = True , <EOL> action_type = '<STR_LIT>' , <EOL> cmd = cmd , <EOL> arguments = args , <EOL> trigger_type = '<STR_LIT>' , <EOL> start_date = '<STR_LIT>' , <EOL> start_time = '<STR_LIT>' ) <EOL> def execute_salt_restart_task ( ) : <EOL> '''<STR_LIT>''' <EOL> return __salt__ [ '<STR_LIT>' ] ( name = '<STR_LIT>' ) <EOL> def status ( name , sig = None ) : <EOL> '''<STR_LIT>''' <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , name ] <EOL> statuses = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) . splitlines ( ) <EOL> for line in statuses : <EOL> if '<STR_LIT>' in line : <EOL> return True <EOL> elif '<STR_LIT>' in line : <EOL> return True <EOL> return False <EOL> def getsid ( name ) : <EOL> '''<STR_LIT>''' <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , name ] <EOL> lines = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) . splitlines ( ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> comps = line . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> try : <EOL> return comps [ <NUM_LIT:1> ] . strip ( ) <EOL> except ( AttributeError , IndexError ) : <EOL> return None <EOL> def enable ( name , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , name , '<STR_LIT>' , '<STR_LIT>' ] <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> def disable ( name , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , name , '<STR_LIT>' , '<STR_LIT>' ] <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> def enabled ( name , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , name ] <EOL> lines = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) . splitlines ( ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> return True <EOL> return False <EOL> def disabled ( name ) : <EOL> '''<STR_LIT>''' <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , name ] <EOL> lines = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) . splitlines ( ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> return True <EOL> elif '<STR_LIT>' in line : <EOL> return True <EOL> return False <EOL> def create ( name , <EOL> binpath , <EOL> DisplayName = None , <EOL> type = '<STR_LIT>' , <EOL> start = '<STR_LIT>' , <EOL> error = '<STR_LIT>' , <EOL> group = None , <EOL> tag = '<STR_LIT>' , <EOL> depend = None , <EOL> obj = None , <EOL> password = None , <EOL> ** kwargs ) : <EOL> r'''<STR_LIT>''' <EOL> cmd = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> name , <EOL> '<STR_LIT>' , binpath , <EOL> '<STR_LIT>' , type , <EOL> '<STR_LIT>' , start , <EOL> '<STR_LIT>' , error , <EOL> ] <EOL> if DisplayName is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , DisplayName ] ) <EOL> if group is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , group ] ) <EOL> if depend is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , depend ] ) <EOL> if obj is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , obj ] ) <EOL> if password is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , password ] ) <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> def config ( name , <EOL> bin_path = None , <EOL> display_name = None , <EOL> svc_type = None , <EOL> start_type = None , <EOL> error = None , <EOL> group = None , <EOL> tag = None , <EOL> depend = None , <EOL> obj = None , <EOL> password = None , <EOL> ** kwargs ) : <EOL> r'''<STR_LIT>''' <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , name ] <EOL> if bin_path is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , bin_path ] ) <EOL> if svc_type is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , svc_type ] ) <EOL> if start_type is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , start_type ] ) <EOL> if error is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , error ] ) <EOL> if display_name is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , display_name ] ) <EOL> if group is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , group ] ) <EOL> if tag is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , tag ] ) <EOL> if depend is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , depend ] ) <EOL> if obj is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , obj ] ) <EOL> if password is not None : <EOL> cmd . extend ( [ '<STR_LIT>' , password ] ) <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> def delete ( name ) : <EOL> '''<STR_LIT>''' <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , name ] <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) </s>
