Browse Source

fixed start and add new target

master
Sebastian Rieger 6 years ago
parent
commit
3e56dff5ee
  1. 4
      example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/create-loadbalancer.py
  2. 48
      example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/start-and-add-new-target.py
  3. 12
      example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/start.py
  4. 2
      example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/stop.py

4
example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/create-loadbalancer.py

@ -83,4 +83,8 @@ for reservation in reservations:
],
)
print('Waiting for Load Balancer to become available...')
waiter = elbv2Client.get_waiter('load_balancer_available')
waiter.wait(LoadBalancerArns=[loadbalancer_arn])
print('Load Balancer should be reachable at: ' + loadbalancer_dns)

48
example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/start-and-add-new-target.py

@ -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'}
],
}

12
example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/start.py

@ -140,11 +140,15 @@ userDataWebServer = ('#!/bin/bash\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'
# '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'
'tar zxvf tug-of-war-in-the-clouds.tar.gz\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'
@ -170,7 +174,7 @@ for i in range(1, 3):
{
'ResourceType': 'instance',
'Tags': [
{'Key': 'Name', 'Value': 'tug-of-war-webserver' + i},
{'Key': 'Name', 'Value': 'tug-of-war-webserver' + str(i)},
{'Key': 'tug-of-war', 'Value': 'webserver'}
],
}

2
example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/stop.py

@ -34,7 +34,7 @@ except ClientError as e:
print("Deleting old instance...")
print("Deleting old instances...")
print("------------------------------------")
response = ec2Client.describe_instances(Filters=[{'Name': 'tag-key', 'Values': ['tug-of-war']}])

Loading…
Cancel
Save