Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFE] add a capability in the bootstrap script to 'preserve proxy' when reconfiguring/migrating the client. #283

Merged
merged 4 commits into from
Jan 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,30 @@ def is_fips():
return fips_status == "1"


def get_rhsm_proxy():
wbclark marked this conversation as resolved.
Show resolved Hide resolved
"""
Return the proxy server settings from /etc/rhsm/rhsm.conf as dictionary proxy_config.
"""
rhsmconfig = SafeConfigParser()
rhsmconfig.read('/etc/rhsm/rhsm.conf')
proxy_options = [option for option in rhsmconfig.options('server') if option.startswith('proxy')]
proxy_config = {}
for option in proxy_options:
proxy_config[option] = rhsmconfig.get('server', option)
return proxy_config


def set_rhsm_proxy(proxy_config):
"""
Set proxy server settings in /etc/rhsm/rhsm.conf from dictionary saved_proxy_config.
"""
rhsmconfig = SafeConfigParser()
rhsmconfig.read('/etc/rhsm/rhsm.conf')
for option in proxy_config.keys():
rhsmconfig.set('server', option, proxy_config[option])
rhsmconfig.write(open('/etc/rhsm/rhsm.conf', 'w'))
wbclark marked this conversation as resolved.
Show resolved Hide resolved


def get_bootstrap_rpm(clean=False, unreg=True):
"""
Retrieve Client CA Certificate RPMs from the Satellite 6 server.
Expand Down Expand Up @@ -1097,6 +1121,7 @@ def exec_service(service, command, failonerror=True):
parser.add_option("-t", "--timeout", dest="timeout", type="int", help="Timeout (in seconds) for API calls and subscription-manager registration. Defaults to %default", metavar="timeout", default=900)
parser.add_option("-c", "--comment", dest="comment", help="Add a host comment")
parser.add_option("--ignore-registration-failures", dest="ignore_registration_failures", action="store_true", help="Continue running even if registration via subscription-manager/rhn-migrate-classic-to-rhsm returns a non-zero return code.")
parser.add_option("--preserve-rhsm-proxy", dest="preserve_rhsm_proxy", help="Preserve proxy settings in /etc/rhsm/rhsm.conf when migrating RHSM -> RHSM")
(options, args) = parser.parse_args()

if options.no_foreman:
Expand Down Expand Up @@ -1214,6 +1239,7 @@ def exec_service(service, command, failonerror=True):
print "PUPPET CA SERVER - %s" % options.puppet_ca_server
print "PUPPET CA PORT - %s" % options.puppet_ca_port
print "IGNORE REGISTRATION FAILURES - %s" % options.ignore_registration_failures
print "PRESERVE RHSM PROXY CONFIGURATION - %s" % options.preserve_rhsm_proxy

# > Exit if the user isn't root.
# Done here to allow an unprivileged user to run the script to see
Expand Down Expand Up @@ -1249,6 +1275,9 @@ def exec_service(service, command, failonerror=True):
if not options.remove and int(RELEASE[0]) == 5 and not options.new_capsule:
prepare_rhel5_migration()

if options.preserve_rhsm_proxy:
saved_proxy_config = get_rhsm_proxy()

if options.remove:
# > IF remove, disassociate/delete host, unregister,
# > uninstall katello and optionally puppet agents
Expand Down Expand Up @@ -1366,6 +1395,8 @@ def exec_service(service, command, failonerror=True):
if 'foreman' not in options.skip:
create_host()
configure_subscription_manager()
if options.preserve_rhsm_proxy:
set_rhsm_proxy(saved_proxy_config)
register_systems(options.org, options.activationkey)
if options.enablerepos:
enable_repos()
Expand Down