def update_attributes_after_status(self): self.is_locked = self.lockstate is not None lockinfo = get_user_info() lock_owner = None if self.lockstate: lock_owner = self.lockstate.get("owner") self.is_locked_by_me = self.is_locked and lock_owner and lock_owner == lockinfo["owner"] self.is_locked_by_other = self.is_locked and not self.is_locked_by_me logger.debug("is_locked=" + repr(self.is_locked) + ", is_locked_by_me=" + repr( self.is_locked_by_me) + ", is_locked_by_other=" + repr(self.is_locked_by_other))
def lock(self, message=None, force=False, **kwargs): def strip_quotes_from_message(message): return message.replace("'", "").replace('"', '') if not message: raise ValueError('the "message" parameter is mandatory') lockinfo = get_user_info() lockinfo["message"] = message lockinfo["force"] = force return self.remote_call( "yadt-host-lock '%s'" % strip_quotes_from_message(message), 'lock_host', force)
def update_attributes_after_status(self): self.is_locked = self.lockstate is not None lockinfo = get_user_info() lock_owner = None if self.lockstate: lock_owner = self.lockstate.get("owner") self.is_locked_by_me = self.is_locked and lock_owner and lock_owner == lockinfo[ "owner"] self.is_locked_by_other = self.is_locked and not self.is_locked_by_me logger.debug("is_locked=" + repr(self.is_locked) + ", is_locked_by_me=" + repr(self.is_locked_by_me) + ", is_locked_by_other=" + repr(self.is_locked_by_other))
def remote_call(self, cmd, tag=None, force=False): if not cmd: return if type(cmd) not in [str, unicode]: cmd = '\n'.join(cmd) ssh_cmd = yadtshell.settings.SSH if hasattr(self, 'fqdn'): host = self.fqdn else: # TODO valid for uninitialized hosts host = self.host # TODO only suitable for service objects! service = self.name remotecall_script = '/usr/bin/yadt-remotecall' log_file = self.create_remote_log_filename(tag=tag) owner = get_user_info()['owner'] force_flag = {False: '', True: ' --force'}[force] complete_cmd = '%(ssh_cmd)s %(host)s WHO="%(owner)s" YADT_LOG_FILE="%(log_file)s" "yadt-command %(cmd)s%(force_flag)s" ' % locals() return complete_cmd
def remote_call(self, cmd, tag=None, force=False): if not cmd: return if type(cmd) not in [str, unicode]: cmd = '\n'.join(cmd) ssh_cmd = yadtshell.settings.SSH if hasattr(self, 'fqdn'): host = self.fqdn else: # TODO valid for uninitialized hosts host = self.host # TODO only suitable for service objects! service = self.name remotecall_script = '/usr/bin/yadt-remotecall' log_file = self.create_remote_log_filename(tag=tag) owner = get_user_info()['owner'] force_flag = {False: '', True: ' --force'}[force] complete_cmd = '%(ssh_cmd)s %(host)s WHO="%(owner)s" YADT_LOG_FILE="%(log_file)s" "yadt-command %(cmd)s%(force_flag)s" ' % locals( ) return complete_cmd
import shutil import yaml import socket import hostexpand.HostExpander import yadtshell.TerminalController import yadtshell.helper from yadtshell.helper import condense_hosts, condense_hosts2, get_user_info from yadtshell.loggingtools import create_next_log_file_name_with_command_arguments_as_tag from yadtshell.loggingtools import configure_logger_output_stream_by_level sys.path.append('/etc/yadtshell') DEFAULT_LOG_DIR = '/tmp/logs/yadtshell' USER_INFO = get_user_info() OUTPUT_DIR = os.path.expanduser('~%s/.yadtshell/%s' % (USER_INFO['user'], socket.gethostname())) reboot_disabled = False ignore_unreachable_hosts = False OUT_DIR = os.path.join(OUTPUT_DIR, 'tmp', os.getcwd().lstrip('/')) TODAY = None STARTED_ON = None SSH = 'ssh' # overwritten later for SSH multiplexing root_logger = logging.getLogger() root_logger.setLevel(logging.DEBUG) message_formatter = logging.Formatter('%(levelname)-8s %(message)s') # DO NOT USE A KWARG : it's 'strm' in python<2.6 and has # been renamed to 'stream' in 2.7 with NO DOCUMENTATION...