|
|
@ -3,9 +3,10 @@ from botocore.exceptions import ClientError |
|
|
|
|
|
|
|
region = 'eu-central-1' |
|
|
|
availabilityZone = 'eu-central-1b' |
|
|
|
subnet1 = 'subnet-41422b28' |
|
|
|
subnet2 = 'subnet-5c5f6d16' |
|
|
|
subnet3 = 'subnet-6f2ea214' |
|
|
|
imageId = 'ami-0cc293023f983ed53' |
|
|
|
instanceType = 't3.nano' |
|
|
|
keyName = 'srieger-pub' |
|
|
|
|
|
|
|
|
|
|
|
client = boto3.setup_default_session(region_name=region) |
|
|
|
ec2Client = boto3.client("ec2") |
|
|
@ -16,6 +17,45 @@ vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '') |
|
|
|
|
|
|
|
elbv2Client = boto3.client('elbv2') |
|
|
|
|
|
|
|
response = ec2Client.describe_security_groups(Filters=[{'Name': 'group-name', 'Values': ['tug-of-war']}]) |
|
|
|
security_group_id = response.get('SecurityGroups', [{}])[0].get('GroupId', '') |
|
|
|
|
|
|
|
print("Getting DB IP...") |
|
|
|
print("------------------------------------") |
|
|
|
|
|
|
|
response = ec2Client.describe_instances(Filters=[{'Name': 'tag:tug-of-war', 'Values': ['db']}]) |
|
|
|
print(response) |
|
|
|
reservations = response['Reservations'] |
|
|
|
for reservation in reservations: |
|
|
|
for instance in reservation['Instances']: |
|
|
|
if instance['State']['Name'] == "running" or instance['State']['Name'] == "pending": |
|
|
|
instanceDB = ec2Resource.Instance(instance['InstanceId']) |
|
|
|
privateIpDB = instanceDB.private_ip_address |
|
|
|
|
|
|
|
userDataWebServer = ('#!/bin/bash\n' |
|
|
|
'# extra repo for RedHat rpms\n' |
|
|
|
'yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm\n' |
|
|
|
'# essential tools\n' |
|
|
|
'yum install -y joe htop git\n' |
|
|
|
'# mysql\n' |
|
|
|
'yum install -y httpd php php-mysql\n' |
|
|
|
'\n' |
|
|
|
'service httpd start\n' |
|
|
|
'service httpd start\n' |
|
|
|
'\n' |
|
|
|
# 'wget http://mmnet.informatik.hs-fulda.de/cloudcomp/tug-of-war-in-the-clouds.tar.gz\n' |
|
|
|
# 'cp tug-of-war-in-the-clouds.tar.gz /var/www/html/\n' |
|
|
|
# 'tar zxvf tug-of-war-in-the-clouds.tar.gz\n' |
|
|
|
'cd /var/www/html\n' |
|
|
|
'wget https://gogs.informatik.hs-fulda.de/srieger/cloud-computing-msc-ai-examples/raw/master/example-projects/tug-of-war-in-the-clouds/web-content/index.php\n' |
|
|
|
'wget https://gogs.informatik.hs-fulda.de/srieger/cloud-computing-msc-ai-examples/raw/master/example-projects/tug-of-war-in-the-clouds/web-content/cloud.php\n' |
|
|
|
'wget https://gogs.informatik.hs-fulda.de/srieger/cloud-computing-msc-ai-examples/raw/master/example-projects/tug-of-war-in-the-clouds/web-content/config.php\n' |
|
|
|
'\n' |
|
|
|
'# change hostname of db connection\n' |
|
|
|
'sed -i s/localhost/' + privateIpDB + '/g /var/www/html/config.php\n' |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
for i in range(3, 4): |
|
|
|
print("Running new Web Server instance...") |
|
|
|
print("------------------------------------") |
|
|
@ -36,7 +76,7 @@ for i in range(3, 4): |
|
|
|
{ |
|
|
|
'ResourceType': 'instance', |
|
|
|
'Tags': [ |
|
|
|
{'Key': 'Name', 'Value': 'tug-of-war-webserver1'}, |
|
|
|
{'Key': 'Name', 'Value': 'tug-of-war-webserver' + str(i)}, |
|
|
|
{'Key': 'tug-of-war', 'Value': 'webserver'} |
|
|
|
], |
|
|
|
} |
|
|
|