-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LDAP-56: Server setup script for EC2 OpenLDAP server and keystore for…
… spring-ldap ad integration test instance.
- Loading branch information
1 parent
dc41258
commit fc5cf04
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
__author__ = 'Mattias Hellborg Arthursson' | ||
|
||
from time import sleep | ||
from fabric.api import task, settings, sudo, execute | ||
from boto.ec2 import EC2Connection, get_region, connect_to_region | ||
|
||
BASE_AMI_ID = 'ami-6d0be61a' | ||
KEYPAIR = 'dev-keypair' | ||
SECURITY_GROUPS = ['default'] | ||
INSTANCE_TYPE = "m1.small" | ||
KEY_FILE = '~/.ssh/dev-keypair.pem' | ||
SSH_USER = 'ubuntu' | ||
AMI_NAME = 'spring-ldap-openldap' | ||
AMI_DESCRIPTION = 'OpenLdap instance for Spring LDAP integration tests' | ||
|
||
@task | ||
def launch_instance(): | ||
conn = connect_to_region('eu-west-1') | ||
reservation = conn.run_instances( | ||
BASE_AMI_ID, | ||
key_name=KEYPAIR, | ||
instance_type=INSTANCE_TYPE, | ||
security_groups=SECURITY_GROUPS | ||
) | ||
|
||
instance = reservation.instances[0] | ||
while instance.state != 'running': | ||
print('Waiting for instance to start') | ||
sleep(10) | ||
instance.update() | ||
|
||
print('Instance started') | ||
return conn, instance | ||
|
||
@task | ||
def setup_openldap_instance(): | ||
conn, instance = launch_instance() | ||
|
||
with settings( | ||
host_string=instance.public_dns_name, | ||
key_filename=KEY_FILE, | ||
user=SSH_USER, | ||
connection_attempts=10): | ||
upgrade_instance() | ||
install_slapd() | ||
|
||
return conn, instance | ||
|
||
@task | ||
def bundle_openldap_instance(): | ||
conn, instance = setup_openldap_instance() | ||
bundle_instance(conn, instance.id, AMI_NAME, AMI_DESCRIPTION) | ||
|
||
|
||
def bundle_instance(conn, instance_id, ami_name, ami_description): | ||
print('Creating AMI') | ||
new_id = conn.create_image(instance_id, ami_name, ami_description) | ||
ami = conn.get_all_images([new_id])[0] | ||
|
||
while ami.state == 'pending': | ||
print('Waiting for image to become available to start') | ||
ami.update() | ||
sleep(20) | ||
|
||
conn.create_tags([ami.id], {'Name': ami_name}) | ||
conn.terminate_instances([instance_id]) | ||
|
||
|
||
def upgrade_instance(): | ||
sudo('apt-get update') | ||
sudo('apt-get upgrade -y') | ||
sudo('apt-get install debconf-utils -y') | ||
|
||
|
||
def install_slapd(): | ||
sudo('cp /etc/hosts /etc/hosts.old') | ||
sudo("sed -i '1i 127.0.1.1 open-ldap.261consulting.com open-ldap' /etc/hosts") | ||
sudo("echo 'slapd slapd/password1 password secret' | sudo debconf-set-selections") | ||
sudo("echo 'slapd slapd/password2 password secret' | sudo debconf-set-selections") | ||
sudo("echo 'slapd shared/organization string 261consulting.com' | sudo debconf-set-selections") | ||
sudo("echo 'slapd slapd/organization string 261consulting.com' | sudo debconf-set-selections") | ||
sudo("echo 'slapd slapd/domain string 261consulting.com' | sudo debconf-set-selections") | ||
sudo('apt-get install slapd ldap-utils -y') |
Binary file not shown.