def create_cluster(auth_token=None, master_name='lambda-master',
                   slaves=1, vcpus_master=4, vcpus_slave=4,
                   ram_master=4096, ram_slave=4096, disk_master=40, disk_slave=40,
                   ip_allocation='master', network_request=1, project_name='lambda.grnet.gr'):
    provisioner = Provisioner(auth_token=auth_token)
    provisioner.create_lambda_cluster(vm_name=master_name,
                                      slaves=slaves,
                                      vcpus_master=vcpus_master,
                                      vcpus_slave=vcpus_slave,
                                      ram_master=ram_master,
                                      ram_slave=ram_slave,
                                      disk_master=disk_master,
                                      disk_slave=disk_slave,
                                      ip_allocation=ip_allocation,
                                      network_request=network_request,
                                      project_name=project_name)

    provisioner_response = provisioner.get_cluster_details()
    master_id = provisioner_response['nodes']['master']['id']
    master_ip = provisioner.get_server_private_ip(master_id)
    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
    provisioner_response['pk'] = provisioner.get_private_key()

    ansible_manager = Manager(provisioner_response)
    ansible_manager.create_inventory()

    return ansible_manager, provisioner_response
Esempio n. 2
0
def test_playbook_run():
    with patch('fokia.ansible_manager.PlayBook') as pb, \
            patch('fokia.ansible_manager.callbacks') as cb, \
            patch('fokia.ansible_manager.utils') as ut:
        cb.PlaybookCallbacks.return_value = "a"
        cb.PlaybookRunnerCallbacks.return_value = "b"
        cb.AggregateStats.return_value = "c"
        manager = Manager(test_provisioner_response)
        manager.create_inventory()
        manager.run_playbook(playbook_file="../ansible/playbooks/testinventory.yml",
                             tags=["touch"])

    assert pb.call_args[1]['inventory'].groups[0].name == 'all'
    assert pb.call_args[1]['inventory'].groups[1].name == 'master'
    assert pb.call_args[1]['inventory'].groups[2].name == 'slaves'

    assert pb.call_args[1]['inventory'].groups[1].hosts[
               0].name == u'snf-666976.vm.okeanos.grnet.gr'
    assert pb.call_args[1]['inventory'].groups[2].hosts[
               0].name == u'snf-666977.local'
def create_lambda_instance(auth_token=None, master_name='lambda-master',
                           slaves=1, vcpus_master=4, vcpus_slave=4,
                           ram_master=4096, ram_slave=4096, disk_master=40, disk_slave=40,
                           ip_allocation='master', network_request=1,
                           project_name='lambda.grnet.gr'):
    start_time = time.time()

    provisioner = Provisioner(auth_token=auth_token)
    provisioner.create_lambda_cluster(vm_name=master_name,
                                      slaves=slaves,
                                      vcpus_master=vcpus_master,
                                      vcpus_slave=vcpus_slave,
                                      ram_master=ram_master,
                                      ram_slave=ram_slave,
                                      disk_master=disk_master,
                                      disk_slave=disk_slave,
                                      ip_allocation=ip_allocation,
                                      network_request=network_request,
                                      project_name=project_name)

    provisioner_response = provisioner.get_cluster_details()
    master_id = provisioner_response['nodes']['master']['id']
    master_ip = provisioner.get_server_private_ip(master_id)
    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
    provisioner_response['pk'] = provisioner.get_private_key()

    print 'response =', provisioner_response
    provisioner_time = time.time()

    ansible_manager = Manager(provisioner_response)
    ansible_manager.create_inventory()

    ansible_result = ansible_manager.run_playbook(
        playbook_file=script_path + "/../../ansible/playbooks/cluster-install.yml")

    ansible_manager.cleanup()

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

    print 'VM provisioning took', round(provisioner_duration), 'seconds'
    print 'Ansible playbooks took', round(ansible_duration), 'seconds'
    print 'Ansible result', ansible_result

    return ansible_result