cluster_creator.py 3.78 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 17
    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")
    parser.add_argument('--name', type=str, dest='name', default="to mikro debian sto livadi")

Ioannis Tsafaras's avatar
Ioannis Tsafaras committed
18
    parser.add_argument('--slaves', type=int, dest='slaves', default=1)
19 20 21 22 23 24 25 26
    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)
27
    parser.add_argument('--image_name', type=str, dest='image_name', default='debian')
28 29 30 31
    parser.add_argument('--cluster_size', type=int, dest='cluster_size', default=2)

    args = parser.parse_args()
    provisioner = Provisioner(cloud_name=args.cloud)
32
    provisioner.create_lambda_cluster('test_vm', slaves=args.slaves,
33 34 35 36 37 38 39 40 41 42
                                      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)
43 44

    provisioner_response = provisioner.get_cluster_details()
45
    master_id = provisioner_response['nodes']['master']['id']
46
    master_ip = provisioner.get_server_private_ip(master_id)
47 48 49 50 51
    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
52
    provisioner_response['pk'] = provisioner.get_private_key()
53

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

57 58
    manager = Manager(provisioner_response)
    manager.create_inventory()
Ioannis Tsafaras's avatar
Ioannis Tsafaras committed
59 60
    # 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'])
61

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

    # INSERT PLAYBOOKS HERE

    manager.cleanup()
67 68 69 70

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

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