Created
July 26, 2016 21:02
-
-
Save harlowja/e0b5a98844554d459338e3d72bbf7b7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def do_spacewalk_register(mod_name, name, cfg, cloud, log, secrets): | |
# TODO(harlowja): turn this into a real cloud-init native module... | |
cfg = cfg.get("spacewalk", {}) | |
spacewalk_proxy = cfg.get('proxy') | |
spacewalk_activation_key = cfg.get('activation_key') | |
if spacewalk_proxy and spacewalk_activation_key: | |
# See: https://github.com/tmclaugh/puppet-spacewalk/blob/master/manifests/client.pp | |
distro = cloud.distro | |
distro.install_packages(['rhn-setup']) | |
# Check to see if already registered and don't bother; this is | |
# apparently done by trying to sync and if that fails then we | |
# assume we aren't registered; which is sorta ghetto... | |
already_registered = False | |
try: | |
util.subp(['rhn-profile-sync', '--verbose'], capture=False) | |
already_registered = True | |
except util.ProcessExecutionError as e: | |
if e.exit_code != 1: | |
raise | |
if not already_registered: | |
util.subp([ | |
'rhnreg_ks', | |
'--serverUrl=https://%s/XMLRPC' % spacewalk_proxy, | |
'--sslCACert=/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT', | |
'--activationkey=%s' % spacewalk_activation_key, | |
'--profilename=%s' % cloud.datasource.get_hostname(fqdn=True), | |
], capture=False) | |
else: | |
log.debug(("Skipping module named %s.%s," | |
" 'spacewalk_proxy' or 'spacewalk_activation_key' key(s)" | |
" were not found in configured data"), mod_name, name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment