def create_server_id(localroot, server_id, p4): """ Create the server-id file and p4key using method in p4gf_super_init.""" ensure_dir(localroot) if server_id: p4gf_super_init.ID_FROM_ARGV = server_id[0] p4gf_super_init.p4 = p4 p4gf_super_init.ensure_server_id() return p4gf_util.read_server_id_from_file()
def ensure_server_id(): """Write this machine's permanent server-id assignment to P4GF_HOME/server-id . NOP if we already have a server-id stored in that file. We'll just keep using it. """ id_from_file = p4gf_util.read_server_id_from_file() server_id = ID_FROM_ARGV if ID_FROM_ARGV else p4gf_util.get_hostname() # when re-running super_init, do not replace the server-id file when # the server_id file exists an no --id parameter is present # assume in the case that the existing file is correct if id_from_file and not ID_FROM_ARGV: server_id = id_from_file do_reset = True if server_id_counter_exists(server_id): do_reset = False if id_from_file == server_id: Verbosity.report(Verbosity.INFO, _("Git Fusion server ID already set to '{0}'.").format(id_from_file)) else: if not OVERRULE_SERVERID_CONFLICT: Verbosity.report(Verbosity.INFO, _("Git Fusion server ID is already assigned: " \ "'{0}' set on host on '{1}'.\n" \ "Retry with a different --id server_id.") \ .format(server_id, server_id_counter_exists(server_id))) Verbosity.report(Verbosity.INFO, _("If you are certain no other Git Fusion instance is using this server ID," "\nyou may overrule this conflict and set the local server-id file to" "\n'{0}' with:" "\n p4gf_super_init.py --force").format(server_id)) if id_from_file: Verbosity.report(Verbosity.INFO, _("Git Fusion server ID already set to '{0}'.").format(id_from_file)) else: Verbosity.report(Verbosity.INFO, _("This Git Fusion's server ID is unset. Stopping.")) show_all_server_ids() sys.exit(0) else: do_reset = True if do_reset: if id_from_file and id_from_file != server_id: # delete the previous counter if server_id_counter_exists(id_from_file): unset_server_id_counter(id_from_file) set_server_id_counter(server_id) p4gf_util.write_server_id_to_file(server_id) Verbosity.report(Verbosity.INFO, _("Git Fusion server ID set to '{0}' in file '{1}'") .format(server_id, p4gf_util.server_id_file_path())) show_all_server_ids()
def create_server_id(localroot, server_id, p4): """ Create the server-id file and counter using method in p4gf_super_init. """ ensure_dir(localroot) if server_id: p4gf_super_init.ID_FROM_ARGV = server_id[0] p4gf_super_init.p4 = p4 p4gf_super_init.ensure_server_id() return p4gf_util.read_server_id_from_file()
def _prepare_logging_args(environ=None): """Generate a dict containing extra logging arguments.""" if environ is None: environ = os.environ args = dict() args['epoch'] = int(time.time()) args['clientIp'] = p4gf_protect.get_remote_client_addr() server_id = p4gf_util.read_server_id_from_file() args['serverId'] = server_id if server_id else 'no-server-id' pusher = environ.get(p4gf_const.P4GF_AUTH_P4USER, None) if not pusher: pusher = environ.get('REMOTE_USER', 'unknown') args['userName'] = pusher return args
def _prepare_logging_args(environ=None): """Generate a dict containing extra logging arguments.""" if environ is None: environ = os.environ args = dict() args['epoch'] = int(time.time()) args['clientIp'] = p4gf_protect.get_remote_client_addr() server_id = p4gf_util.read_server_id_from_file() args['serverId'] = server_id if server_id else 'no-server-id' pusher = environ.get(p4gf_const.P4GF_AUTH_P4USER, None) if not pusher: pusher = environ.get('REMOTE_USER', 'unknown') args['userName'] = pusher return args
def _add_logging_extra(args): """Return dict containing some extra logging arguments.""" epoch = int(time.time()) server_id = p4gf_util.read_server_id_from_file() or 'no-server-id' # add defaults for anything that's missing return dict( { 'epoch': epoch, 'serverId': server_id, 'userName': '******', 'serverIp': 'no-server-ip', 'clientIp': 'no-client-ip', 'command': 'no-command', 'repo': 'no-repo' }, **args)
def show_all_server_ids(): '''List current Git Fusion server ids.''' server_ids = p4.run('counters', '-u', '-e', p4gf_const.P4GF_COUNTER_SERVER_ID + '*') ids = [] this_server = p4gf_util.read_server_id_from_file() for eyed in server_ids: if 'counter' in eyed : id_ = eyed['counter'].replace(p4gf_const.P4GF_COUNTER_SERVER_ID,'') if this_server == id_: id_ = "* " + id_ ids.append(( id_, eyed['value'])) if ids: Verbosity.report(Verbosity.INFO, _("Git Fusion server IDs: {0}").format(ids))
def show_all_server_ids(): '''List current Git Fusion server ids.''' server_ids = p4.run('counters', '-u', '-e', p4gf_const.P4GF_COUNTER_SERVER_ID + '*') ids = [] this_server = p4gf_util.read_server_id_from_file() for eyed in server_ids: if 'counter' in eyed: id_ = eyed['counter'].replace(p4gf_const.P4GF_COUNTER_SERVER_ID, '') if this_server == id_: id_ = "* " + id_ ids.append((id_, eyed['value'])) if ids: Verbosity.report(Verbosity.INFO, _("Git Fusion server IDs: {0}").format(ids))
def show_all_server_ids(): """List current Git Fusion server ids.""" server_ids = P4Key.get_all(p4, p4gf_const.P4GF_P4KEY_SERVER_ID + '*') ids = [] this_server = p4gf_util.read_server_id_from_file() for key, value in server_ids.items(): id_ = key.replace(p4gf_const.P4GF_P4KEY_SERVER_ID, '') if this_server == id_: id_ = id_ + " *" ids.append((id_, value)) if ids: Verbosity.report( Verbosity.INFO, _("Git Fusion server IDs: {server_id: <30} {hostname: <30}" " (* marks this instance)") .format(server_id="server-id", hostname="hostname")) for sid in ids: Verbosity.report( Verbosity.INFO, _(" {server_id: <30} {hostname: <30}") .format(server_id=sid[0], hostname=sid[1]))
def ensure_server_id(): """Write this machine's permanent server-id assignment to P4GF_HOME/server-id. NOP if we already have a server-id stored in that file. We'll just keep using it. """ # pylint: disable=too-many-branches if ID_FROM_ARGV: if re.search(r'[/@#*%]|\.\.\.', ID_FROM_ARGV): msg = _('Special characters (*, #, %) not allowed in Git Fusion server ID {server_id}.') Verbosity.report(Verbosity.ERROR, msg.format(server_id=ID_FROM_ARGV)) sys.exit(1) id_from_file = p4gf_util.read_server_id_from_file() if id_from_file and ID_FROM_ARGV and id_from_file != ID_FROM_ARGV: if not OVERRULE_SERVERID_CONFLICT: # msg = _("Git Fusion server ID already set to '{0}', cannot initialize again.") Verbosity.report( Verbosity.ERROR, _("Git Fusion server ID already set to '{server_id}'. " + "To reinitialize Git Fusion with '{id_from_argv}' use the --force option.") .format(server_id=id_from_file, id_from_argv=ID_FROM_ARGV)) sys.exit(1) server_id = ID_FROM_ARGV if ID_FROM_ARGV else p4gf_util.get_hostname() # when re-running super_init, do not replace the server-id file when # the server_id file exists an no --id parameter is present # assume in the case that the existing file is correct if id_from_file and not ID_FROM_ARGV: server_id = id_from_file check_for_localhost(id_from_file, server_id) do_reset = True if server_id_p4key_exists(server_id): do_reset = False if id_from_file == server_id: Verbosity.report( Verbosity.INFO, _("Git Fusion server ID already set to '{server_id}'.") .format(server_id=id_from_file)) else: if not OVERRULE_SERVERID_CONFLICT: Verbosity.report( Verbosity.INFO, _("Git Fusion server ID is already assigned: " "'{server_id}' set on host on '{exists}'.\n" "Retry with a different --id server_id.") .format(server_id=server_id, exists=server_id_p4key_exists(server_id))) Verbosity.report( Verbosity.INFO, _("If you are certain no other Git Fusion instance is using this server ID," "\nyou may overrule this conflict and set the local server-id file to" "\n'{server_id}' with:" "\n configure-git-fusion.sh --id") .format(server_id=server_id)) if id_from_file: Verbosity.report( Verbosity.INFO, _("Git Fusion server ID already set to '{server_id}'.") .format(server_id=id_from_file)) else: Verbosity.report( Verbosity.INFO, _("This Git Fusion's server ID is unset. Stopping.")) show_all_server_ids() sys.exit(1) else: do_reset = True if do_reset: if id_from_file and id_from_file != server_id: # delete the previous p4key if server_id_p4key_exists(id_from_file): unset_server_id_p4key(id_from_file) set_server_id_p4key(server_id) p4gf_util.write_server_id_to_file(server_id) Verbosity.report( Verbosity.INFO, _("Git Fusion server ID set to '{server_id}' in file '{path}'") .format(server_id=server_id, path=p4gf_util.server_id_file_path())) show_all_server_ids()
def ensure_server_id(): """Write this machine's permanent server-id assignment to P4GF_HOME/server-id . NOP if we already have a server-id stored in that file. We'll just keep using it. """ id_from_file = p4gf_util.read_server_id_from_file() server_id = ID_FROM_ARGV if ID_FROM_ARGV else p4gf_util.get_hostname() # when re-running super_init, do not replace the server-id file when # the server_id file exists an no --id parameter is present # assume in the case that the existing file is correct if id_from_file and not ID_FROM_ARGV: server_id = id_from_file do_reset = True if server_id_counter_exists(server_id): do_reset = False if id_from_file == server_id: Verbosity.report( Verbosity.INFO, _("Git Fusion server ID already set to '{0}'.").format( id_from_file)) else: if not OVERRULE_SERVERID_CONFLICT: Verbosity.report(Verbosity.INFO, _("Git Fusion server ID is already assigned: " \ "'{0}' set on host on '{1}'.\n" \ "Retry with a different --id server_id.") \ .format(server_id, server_id_counter_exists(server_id))) Verbosity.report( Verbosity.INFO, _("If you are certain no other Git Fusion instance is using this server ID," "\nyou may overrule this conflict and set the local server-id file to" "\n'{0}' with:" "\n p4gf_super_init.py --force").format(server_id)) if id_from_file: Verbosity.report( Verbosity.INFO, _("Git Fusion server ID already set to '{0}'.").format( id_from_file)) else: Verbosity.report( Verbosity.INFO, _("This Git Fusion's server ID is unset. Stopping.")) show_all_server_ids() sys.exit(0) else: do_reset = True if do_reset: if id_from_file and id_from_file != server_id: # delete the previous counter if server_id_counter_exists(id_from_file): unset_server_id_counter(id_from_file) set_server_id_counter(server_id) p4gf_util.write_server_id_to_file(server_id) Verbosity.report( Verbosity.INFO, _("Git Fusion server ID set to '{0}' in file '{1}'").format( server_id, p4gf_util.server_id_file_path())) show_all_server_ids()