mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 18:00:35 +00:00
add scripts to load ssh keys and execute ec2 user data if it is a script
This commit is contained in:
parent
ac6870e37d
commit
74398c099a
6 changed files with 58 additions and 8 deletions
|
@ -15,6 +15,7 @@ from tasks import network
|
|||
from tasks import initd
|
||||
from tasks import cleanup
|
||||
from tasks import fake
|
||||
from tasks import one
|
||||
|
||||
|
||||
def initialize():
|
||||
|
@ -57,9 +58,9 @@ def tasks(tasklist, manifest):
|
|||
network.RemoveDNSInfo(),
|
||||
network.ConfigureNetworkIF(),
|
||||
network.ConfigureDHCP(),
|
||||
fake.Fake(),
|
||||
initd.ResolveInitScripts(),
|
||||
initd.InstallInitScripts(),
|
||||
one.OpenNebulaContext(),
|
||||
cleanup.ClearMOTD(),
|
||||
cleanup.ShredHostkeys(),
|
||||
cleanup.CleanTMP(),
|
||||
|
|
BIN
providers/one/assets/one-context_3.8.1.deb
Normal file
BIN
providers/one/assets/one-context_3.8.1.deb
Normal file
Binary file not shown.
14
providers/one/assets/one-ec2.sh
Executable file
14
providers/one/assets/one-ec2.sh
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -n "$EC2_USER_DATA" ]; then
|
||||
# Check if EC2 user data is a script, if yes, execute
|
||||
if [[ $EC2_USER_DATA =~ ^#! ]]; then
|
||||
echo "EC2 data is an executable script, so execute it now"
|
||||
TMPFILE=$(mktemp /tmp/output.XXXXXXXXXX)
|
||||
chmod 755 $TMPFILE
|
||||
$TMPFILE
|
||||
cat $TMPFILE
|
||||
else
|
||||
print "Not an executable"
|
||||
fi
|
||||
fi
|
8
providers/one/assets/one-pubkey.sh
Executable file
8
providers/one/assets/one-pubkey.sh
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Copy public ssh keys to authorized_keys"
|
||||
for f in /mnt/*.pub
|
||||
do
|
||||
cat $f >> /root/.ssh/authorized_keys
|
||||
|
||||
done
|
31
providers/one/tasks/one.py
Normal file
31
providers/one/tasks/one.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
from base import Task
|
||||
from common import phases
|
||||
import os
|
||||
|
||||
|
||||
class OpenNebulaContext(Task):
|
||||
description = 'Setup OpenNebula init context'
|
||||
phase = phases.system_modification
|
||||
|
||||
def run(self, info):
|
||||
import stat
|
||||
rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
|
||||
stat.S_IRGRP | stat.S_IXGRP |
|
||||
stat.S_IROTH | stat.S_IXOTH)
|
||||
|
||||
from shutil import copy
|
||||
script_src = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/one-context_3.8.1.deb'))
|
||||
script_dst = os.path.join(info.root, 'tmp/one-context_3.8.1.deb')
|
||||
copy(script_src, script_dst)
|
||||
os.chmod(script_dst, rwxr_xr_x)
|
||||
|
||||
from common.tools import log_check_call
|
||||
log_check_call(['/usr/sbin/chroot', info.root, 'dpkg', '-i', '/tmp/one-context_3.8.1.deb'])
|
||||
|
||||
script_src = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/one-pubkey.sh'))
|
||||
script_dst = os.path.join(info.root, 'etc/one-context.d/one-pubkey.sh')
|
||||
copy(script_src, script_dst)
|
||||
script_src = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/one-ec2.sh'))
|
||||
script_dst = os.path.join(info.root, 'etc/one-context.d/one-ec2.sh')
|
||||
copy(script_src, script_dst)
|
||||
|
|
@ -7,7 +7,7 @@ class HostPackages(Task):
|
|||
phase = phases.preparation
|
||||
|
||||
def run(self, info):
|
||||
packages = set(['debootstrap', 'qemu-utils'])
|
||||
packages = set(['debootstrap', 'qemu-utils', 'parted', 'grub2'])
|
||||
if info.manifest.volume['filesystem'] == 'xfs':
|
||||
packages.add('xfsprogs')
|
||||
|
||||
|
@ -22,7 +22,6 @@ class ImagePackages(Task):
|
|||
manifest = info.manifest
|
||||
# Add some basic packages we are going to need
|
||||
include = set(['udev',
|
||||
'mbr',
|
||||
'parted',
|
||||
'openssh-server',
|
||||
# We could bootstrap without locales, but things just suck without them, error messages etc.
|
||||
|
@ -34,16 +33,13 @@ class ImagePackages(Task):
|
|||
'grub2',
|
||||
])
|
||||
|
||||
if manifest.virtualization == 'pvm':
|
||||
include.add('grub-pc')
|
||||
|
||||
exclude = set(['isc-dhcp-client',
|
||||
'isc-dhcp-common',
|
||||
])
|
||||
|
||||
# In squeeze, we need a special kernel flavor for xen
|
||||
kernels = {'squeeze': {'amd64': 'linux-image-xen-amd64',
|
||||
'i386': 'linux-image-xen-686', },
|
||||
kernels = {'squeeze': {'amd64': 'linux-image-amd64',
|
||||
'i386': 'linux-image-686', },
|
||||
'wheezy': {'amd64': 'linux-image-amd64',
|
||||
'i386': 'linux-image-686', }, }
|
||||
include.add(kernels.get(manifest.system['release']).get(manifest.system['architecture']))
|
||||
|
|
Loading…
Add table
Reference in a new issue