|
|
@ -15,9 +15,9 @@ from libcloud.compute.types import Provider |
|
|
|
# web service endpoint of the private cloud infrastructure |
|
|
|
auth_url = 'https://private-cloud2.informatik.hs-fulda.de:5000' |
|
|
|
# your username in OpenStack |
|
|
|
auth_username = 'CloudCompX' |
|
|
|
auth_username = 'CloudComp30' |
|
|
|
# your project in OpenStack |
|
|
|
project_name = 'CloudCompGrpX' |
|
|
|
project_name = 'CloudCompGrp30' |
|
|
|
|
|
|
|
# default region |
|
|
|
region_name = 'RegionOne' |
|
|
@ -29,13 +29,11 @@ ubuntu_image_name = "Ubuntu 14.04 - Trusty Tahr - 64-bit - Cloud Based Image" |
|
|
|
|
|
|
|
flavor_name = 'm1.small' |
|
|
|
|
|
|
|
network_name = "CloudCompGrpX-net" |
|
|
|
network_name = "CloudCompGrp30-net" |
|
|
|
|
|
|
|
keypair_name = 'srieger-pub' |
|
|
|
pub_key_file = '~/.ssh/id_rsa.pub' |
|
|
|
|
|
|
|
api_1_ip = "192.168.0.x" |
|
|
|
services_ip = "192.168.0.y" |
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
@ -68,6 +66,91 @@ def main(): |
|
|
|
ex_force_service_region=region_name, |
|
|
|
ex_domain_name=domain_name) |
|
|
|
|
|
|
|
########################################################################### |
|
|
|
# |
|
|
|
# get image, flavor, network for instance creation |
|
|
|
# |
|
|
|
########################################################################### |
|
|
|
|
|
|
|
images = conn.list_images() |
|
|
|
image = '' |
|
|
|
for img in images: |
|
|
|
if img.name == ubuntu_image_name: |
|
|
|
image = img |
|
|
|
|
|
|
|
flavors = conn.list_sizes() |
|
|
|
flavor = '' |
|
|
|
for flav in flavors: |
|
|
|
if flav.name == flavor_name: |
|
|
|
flavor = conn.ex_get_size(flav.id) |
|
|
|
|
|
|
|
networks = conn.ex_list_networks() |
|
|
|
network = '' |
|
|
|
for net in networks: |
|
|
|
if net.name == network_name: |
|
|
|
network = net |
|
|
|
|
|
|
|
########################################################################### |
|
|
|
# |
|
|
|
# get fixed a ip for serivice and api instance |
|
|
|
# (better would be shared IP for the cluster etc.) |
|
|
|
# |
|
|
|
########################################################################### |
|
|
|
|
|
|
|
# find service instance |
|
|
|
for instance in conn.list_nodes(): |
|
|
|
if instance.name == 'app-services': |
|
|
|
services_ip = instance.private_ips[0] |
|
|
|
print('Found app-services fixed IP to be: ', services_ip) |
|
|
|
if instance.name == 'app-api-1': |
|
|
|
api_1_ip = instance.private_ips[0] |
|
|
|
print('Found app-api-1 fixed IP to be: ', api_1_ip) |
|
|
|
|
|
|
|
########################################################################### |
|
|
|
# |
|
|
|
# create keypair dependency |
|
|
|
# |
|
|
|
########################################################################### |
|
|
|
|
|
|
|
print('Checking for existing SSH key pair...') |
|
|
|
keypair_exists = False |
|
|
|
for keypair in conn.list_key_pairs(): |
|
|
|
if keypair.name == keypair_name: |
|
|
|
keypair_exists = True |
|
|
|
|
|
|
|
if keypair_exists: |
|
|
|
print('Keypair ' + keypair_name + ' already exists. Skipping import.') |
|
|
|
else: |
|
|
|
print('adding keypair...') |
|
|
|
conn.import_key_pair_from_file(keypair_name, pub_key_file) |
|
|
|
|
|
|
|
for keypair in conn.list_key_pairs(): |
|
|
|
print(keypair) |
|
|
|
|
|
|
|
########################################################################### |
|
|
|
# |
|
|
|
# create security group dependency |
|
|
|
# |
|
|
|
########################################################################### |
|
|
|
|
|
|
|
def get_security_group(connection, security_group_name): |
|
|
|
"""A helper function to check if security group already exists""" |
|
|
|
print('Checking for existing ' + security_group_name + ' security group...') |
|
|
|
for security_grp in connection.ex_list_security_groups(): |
|
|
|
if security_grp.name == security_group_name: |
|
|
|
print('Security Group ' + security_group_name + ' already exists. Skipping creation.') |
|
|
|
return security_grp |
|
|
|
return False |
|
|
|
|
|
|
|
if not get_security_group(conn, "worker"): |
|
|
|
worker_security_group = conn.ex_create_security_group('worker', 'for services that run on a worker node') |
|
|
|
conn.ex_create_security_group_rule(worker_security_group, 'TCP', 22, 22) |
|
|
|
else: |
|
|
|
worker_security_group = get_security_group(conn, "worker") |
|
|
|
|
|
|
|
for security_group in conn.ex_list_security_groups(): |
|
|
|
print(security_group) |
|
|
|
|
|
|
|
########################################################################### |
|
|
|
# |
|
|
|
# create worker instances |
|
|
|