Browse Source

Merge "Helper scripts for modifying cloud-config-novajoin.json"

tags/1.2.0
Zuul 5 months ago
parent
commit
323efaad22
4 changed files with 112 additions and 0 deletions
  1. +14
    -0
      files/README
  2. +81
    -0
      files/cloud-config-novajoin.yaml
  3. +9
    -0
      tools/cloud-config-pack.py
  4. +8
    -0
      tools/cloud-config-unpack.py

+ 14
- 0
files/README View File

@@ -0,0 +1,14 @@
This directory contains configuration files placed in /etc/
(see setup.cfg for details)

IMPORTANT: cloud-config-novajoin.json is manually generated from
cloud-config-novajoin.yaml, by using tools/cloud-config-unpack.py and
tools/cloud-config-pack.py scripts.

Before editing cloud-config-novajoin.yaml, run tools/cloud-config-unpack.py.
After editing cloud-config-novajoin.yaml, run tools/cloud-config-pack.py.
This will place your edits in cloud-config-novajoin.json, which is the only
file that is installed in /etc/.

cloud-config-novajoin.json cannot be automatically generated, because we use a
setup.py provided by the global requirements repo, which we cannot modify.

+ 81
- 0
files/cloud-config-novajoin.yaml View File

@@ -0,0 +1,81 @@
#cloud-config
packages:
- python-simplejson
- ipa-client
- ipa-admintools
- openldap-clients
- hostname
write_files:
- content: |
#!/bin/sh
function get_metadata_config_drive {
if [ -f /run/cloud-init/status.json ]; then
# Get metadata from config drive
data=`cat /run/cloud-init/status.json`
config_drive=`echo $data | python -c 'import json,re,sys;obj=json.load(sys.stdin);ds=obj.get("v1", {}).get("datasource"); print(re.findall(r"source=(.*)]", ds)[0])'`
if [[ -b $config_drive ]]; then
temp_dir=`mktemp -d`
mount $config_drive $temp_dir
if [ -f $temp_dir/openstack/latest/vendor_data2.json ]; then
data=`cat $temp_dir/openstack/latest/vendor_data2.json`
umount $config_drive
rmdir $temp_dir
else
umount $config_drive
rmdir $temp_dir
fi
else
echo "Unable to retrieve metadata from config drive."
return 1
fi
else
echo "Unable to retrieve metadata from config drive."
return 1
fi
return 0
}
function get_metadata_network {
# Get metadata over the network
data=$(timeout 300 /bin/bash -c 'data=""; while [ -z "$data" ]; do sleep $[ ( $RANDOM % 10 ) + 1 ]s; data=`curl -s http://169.254.169.254/openstack/2016-10-06/vendor_data2.json 2>/dev/null`; done; echo $data')
if [[ $? != 0 ]] ; then
echo "Unable to retrieve metadata from metadata service."
return 1
fi
}
if ! get_metadata_config_drive; then
if ! get_metadata_network; then
echo "FATAL: No metadata available"
exit 1
fi
fi
# Get the instance hostname out of the metadata
fqdn=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get("join", {}).get("hostname", ""))'`
if [ -z "$fqdn" ]; then
echo "Unable to determine hostname"
exit 1
fi
realm=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get("join", {}).get("krb_realm", ""))'`
otp=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get("join", {}).get("ipaotp", ""))'`
hostname=`/bin/hostname -f`
# run ipa-client-install
OPTS="-U -w $otp --hostname $fqdn --mkhomedir"
if [ -n "$realm" ]; then
OPTS="$OPTS --realm=$realm"
fi
ipa-client-install $OPTS
path: /root/setup-ipa-client.sh
permissions: '0700'
owner: root:root
runcmd:
- sh -x /root/setup-ipa-client.sh > /var/log/setup-ipa-client.log 2>&1

+ 9
- 0
tools/cloud-config-pack.py View File

@@ -0,0 +1,9 @@
#!/usr/bin/env python

import json

with open('files/cloud-config-novajoin.yaml') as config_unpacked:
config = config_unpacked.read()
with open('files/cloud-config-novajoin.json', 'w') as cloud_config:
json.dump({'cloud-init': config}, cloud_config)
cloud_config.write('\n')

+ 8
- 0
tools/cloud-config-unpack.py View File

@@ -0,0 +1,8 @@
#!/usr/bin/env python

import json

with open('files/cloud-config-novajoin.json') as cloud_config:
config = json.load(cloud_config)['cloud-init']
with open('files/cloud-config-novajoin.yaml', 'w') as config_unpacked:
config_unpacked.write(config)

Loading…
Cancel
Save