cluster_creator.py 3.66 KB
Newer Older
1
import argparse
2
import time
3 4 5 6
import os
import inspect
from fokia.provisioner import Provisioner
from fokia.ansible_manager import Manager
7 8

if __name__ == "__main__":
9
    start_time = time.time()
10
    script_path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
11

12 13 14 15 16
    parser = argparse.ArgumentParser(description="Okeanos VM provisioning")
    parser.add_argument('--cloud', type=str, dest="cloud", default="lambda")
    parser.add_argument('--project-name', type=str, dest="project_name",
                        default="lambda.grnet.gr")

Ioannis Tsafaras's avatar
Ioannis Tsafaras committed
17
    parser.add_argument('--slaves', type=int, dest='slaves', default=1)
18 19 20 21 22 23 24 25
    parser.add_argument('--vcpus_master', type=int, dest='vcpus_master', default=4)
    parser.add_argument('--vcpus_slave', type=int, dest='vcpus_slave', default=4)
    parser.add_argument('--ram_master', type=int, dest='ram_master', default=4096)  # in MB
    parser.add_argument('--ram_slave', type=int, dest='ram_slave', default=4096)  # in MB
    parser.add_argument('--disk_master', type=int, dest='disk_master', default=40)  # in GB
    parser.add_argument('--disk_slave', type=int, dest='disk_slave', default=40)  # in GB
    parser.add_argument('--ip_request', type=int, dest='ip_request', default=1)
    parser.add_argument('--network_request', type=int, dest='network_request', default=1)
26
    parser.add_argument('--image_name', type=str, dest='image_name', default='debian')
27 28 29 30
    parser.add_argument('--cluster_size', type=int, dest='cluster_size', default=2)

    args = parser.parse_args()
    provisioner = Provisioner(cloud_name=args.cloud)
31
    provisioner.create_lambda_cluster('lambda-master', slaves=args.slaves,
32 33 34 35 36 37 38 39 40 41
                                      cluster_size=args.cluster_size,
                                      vcpus_master=args.vcpus_master,
                                      vcpus_slave=args.vcpus_slave,
                                      ram_master=args.ram_master,
                                      ram_slave=args.ram_slave,
                                      disk_master=args.disk_master,
                                      disk_slave=args.disk_slave,
                                      ip_request=args.ip_request,
                                      network_request=args.network_request,
                                      project_name=args.project_name)
42 43

    provisioner_response = provisioner.get_cluster_details()
44
    master_id = provisioner_response['nodes']['master']['id']
45
    master_ip = provisioner.get_server_private_ip(master_id)
46 47 48 49 50
    provisioner_response['nodes']['master']['internal_ip'] = master_ip
    slave_ids = [slave['id'] for slave in provisioner_response['nodes']['slaves']]
    for i, slave in enumerate(provisioner_response['nodes']['slaves']):
        slave_ip = provisioner.get_server_private_ip(slave['id'])
        provisioner_response['nodes']['slaves'][i]['internal_ip'] = slave_ip
51
    provisioner_response['pk'] = provisioner.get_private_key()
52

53 54
    print 'response =', provisioner_response
    provisioner_time = time.time()
55

56 57
    manager = Manager(provisioner_response)
    manager.create_inventory()
Ioannis Tsafaras's avatar
Ioannis Tsafaras committed
58 59
    # manager.run_playbook(playbook_file=script_path + "/../../ansible/playbooks/test/testinventory.yml", tags=['hosts'])
    # manager.run_playbook(playbook_file=script_path + "/../../ansible/playbooks/test/testproxy.yml", tags=['install'])
60

Ioannis Tsafaras's avatar
Ioannis Tsafaras committed
61
    manager.run_playbook(playbook_file=script_path + "/../../ansible/playbooks/cluster-install.yml")
62 63

    manager.cleanup()
64 65 66 67

    provisioner_duration = provisioner_time - start_time
    ansible_duration = time.time() - provisioner_time

Ioannis Tsafaras's avatar
Ioannis Tsafaras committed
68 69
    print 'VM provisioning took', round(provisioner_duration), 'seconds'
    print 'Ansible playbooks took', round(ansible_duration), 'seconds'