def detach_volume(profile, cluster, instance, volume, secret_key, girder_callback_info): playbook = os.path.join(get_playbook_directory(), 'volumes', 'ec2', 'detach.yml') extra_vars = { 'girder_volume_id': volume['_id'], 'girder_cluster_id': cluster['_id'], 'volume_id': volume['ec2']['id'], 'instance_id': instance['instance_id'], 'path': volume['path'], 'region': profile['regionName'], 'ansible_ssh_private_key_file': _key_path(profile), 'ansible_user': cluster['config']['ssh']['user'] } extra_vars.update(girder_callback_info) env = os.environ.copy() env.update({'AWS_ACCESS_KEY_ID': profile['accessKeyId'], 'AWS_SECRET_ACCESS_KEY': secret_key, 'ANSIBLE_HOST_KEY_CHECKING': 'false', 'ANSIBLE_CALLBACK_PLUGINS': get_callback_plugins_path(), 'ANSIBLE_LIBRARY': get_library_path()}) inventory = simple_inventory({'head': [instance['public_ip']]}) with inventory.to_tempfile() as inventory_path: run_playbook(playbook, inventory_path, extra_vars, verbose=2, env=env)
def detach_volume(profile, cluster, instance, volume, secret_key, log_write_url, girder_callback_info): playbook = os.path.join(get_playbook_directory(), 'volumes', 'ec2', 'detach.yml') extra_vars = { 'girder_volume_id': volume['_id'], 'girder_cluster_id': cluster['_id'], 'volume_id': volume['ec2']['id'], 'instance_id': instance['instance_id'], 'path': volume['path'], 'region': profile['regionName'], 'ansible_ssh_private_key_file': _key_path(profile), 'ansible_user': cluster['config']['ssh']['user'] } extra_vars.update(girder_callback_info) env = os.environ.copy() env.update({ 'AWS_ACCESS_KEY_ID': profile['accessKeyId'], 'AWS_SECRET_ACCESS_KEY': secret_key, 'ANSIBLE_HOST_KEY_CHECKING': 'false', 'ANSIBLE_CALLBACK_PLUGINS': get_callback_plugins_path(), 'LOG_WRITE_URL': log_write_url, 'GIRDER_TOKEN': girder_callback_info['girder_token'], 'ANSIBLE_LIBRARY': get_library_path() }) inventory = simple_inventory({'head': [instance['public_ip']]}) with inventory.to_tempfile() as inventory_path: run_playbook(playbook, inventory_path, extra_vars, verbose=2, env=env)
def delete_volume(profile, volume, secret_key, girder_callback_info): playbook = os.path.join(get_playbook_directory(), 'volumes', 'ec2', 'delete.yml') extra_vars = { 'girder_volume_id': volume['_id'], 'volume_id': volume['ec2']['id'], 'region': profile['regionName'], 'ansible_ssh_private_key_file': _key_path(profile), } extra_vars.update(girder_callback_info) env = os.environ.copy() env.update({'AWS_ACCESS_KEY_ID': profile['accessKeyId'], 'AWS_SECRET_ACCESS_KEY': secret_key, 'ANSIBLE_HOST_KEY_CHECKING': 'false', 'ANSIBLE_CALLBACK_PLUGINS': get_callback_plugins_path(), 'ANSIBLE_LIBRARY': get_library_path()}) inventory = simple_inventory('localhost') with inventory.to_tempfile() as inventory_path: run_playbook(playbook, inventory_path, extra_vars, verbose=2, env=env)
def provision_cluster(playbook, cluster, profile, secret_key, extra_vars, girder_token, log_write_url, post_status): playbook = get_playbook_path(playbook) playbook_variables = get_playbook_variables(cluster, profile, extra_vars) env = os.environ.copy() env.update({ 'AWS_ACCESS_KEY_ID': profile['accessKeyId'], 'AWS_SECRET_ACCESS_KEY': secret_key, 'GIRDER_TOKEN': girder_token, 'LOG_WRITE_URL': log_write_url, 'CLUSTER_ID': cluster['_id'], 'REGION_NAME': profile['regionName'], 'ANSIBLE_HOST_KEY_CHECKING': 'false', 'ANSIBLE_CALLBACK_PLUGINS': get_callback_plugins_path() }) inventory = os.path.join(os.path.dirname(__file__), 'providers', 'ec2.py') ansible = run_playbook(playbook, inventory, playbook_variables, env=env, verbose=3) check_girder_cluster_status(cluster, girder_token, post_status) check_ansible_return_code(ansible, cluster, girder_token)
def launch_cluster(playbook, cluster, profile, secret_key, extra_vars, girder_token, log_write_url, post_status): playbook = get_playbook_path(playbook) playbook_variables = get_playbook_variables(cluster, profile, extra_vars) env = os.environ.copy() env.update({'AWS_ACCESS_KEY_ID': profile['accessKeyId'], 'AWS_SECRET_ACCESS_KEY': secret_key, 'GIRDER_TOKEN': girder_token, 'LOG_WRITE_URL': log_write_url, 'CLUSTER_ID': cluster['_id']}) inventory = simple_inventory('localhost') with inventory.to_tempfile() as inventory_path: ansible = run_playbook(playbook, inventory_path, playbook_variables, env=env, verbose=3) p = CloudProvider(dict(secretAccessKey=secret_key, **profile)) master = p.get_master_instance(cluster['_id']) status_url = '%s/clusters/%s' % (cumulus.config.girder.baseUrl, cluster['_id']) updates = { 'config': { 'host': master['public_ip'] } } headers = {'Girder-Token': girder_token} r = requests.patch(status_url, headers=headers, json=updates) check_status(r) check_ansible_return_code(ansible, cluster, girder_token) check_girder_cluster_status(cluster, girder_token, post_status)
def terminate_cluster(playbook, cluster, profile, secret_key, extra_vars, girder_token, log_write_url, post_status): playbook = get_playbook_path(playbook) playbook_variables = get_playbook_variables(cluster, profile, extra_vars) env = os.environ.copy() env.update({ 'AWS_ACCESS_KEY_ID': profile['accessKeyId'], 'AWS_SECRET_ACCESS_KEY': secret_key, 'GIRDER_TOKEN': girder_token, 'LOG_WRITE_URL': log_write_url, 'CLUSTER_ID': cluster['_id'] }) # if there are any volumes, make sure to detach them first. if 'volumes' in cluster and len(cluster['volumes']): p = CloudProvider(dict(secretAccessKey=secret_key, **profile)) master = p.get_master_instance(cluster['_id']) for volume_id in cluster['volumes']: r = requests.get('%s/volumes/%s' % (cumulus.config.girder.baseUrl, volume_id), headers={'Girder-Token': girder_token}) check_status(r) volume = r.json() girder_callback_info = { 'girder_api_url': cumulus.config.girder.baseUrl, 'girder_token': girder_token } vol_log_url = '%s/volumes/%s/log' % (cumulus.config.girder.baseUrl, volume_id) detach_volume(profile, cluster, master, volume, secret_key, vol_log_url, girder_callback_info) inventory = simple_inventory('localhost') with inventory.to_tempfile() as inventory_path: ansible = run_playbook(playbook, inventory_path, playbook_variables, env=env, verbose=3) check_ansible_return_code(ansible, cluster, girder_token) check_girder_cluster_status(cluster, girder_token, post_status)
def terminate_cluster(playbook, cluster, profile, secret_key, extra_vars, girder_token, log_write_url, post_status): playbook = get_playbook_path(playbook) playbook_variables = get_playbook_variables(cluster, profile, extra_vars) env = os.environ.copy() env.update({'AWS_ACCESS_KEY_ID': profile['accessKeyId'], 'AWS_SECRET_ACCESS_KEY': secret_key, 'GIRDER_TOKEN': girder_token, 'LOG_WRITE_URL': log_write_url, 'CLUSTER_ID': cluster['_id']}) # if there are any volumes, make sure to detach them first. if 'volumes' in cluster and len(cluster['volumes']): p = CloudProvider(dict(secretAccessKey=secret_key, **profile)) master = p.get_master_instance(cluster['_id']) for volume_id in cluster['volumes']: r = requests.get('%s/volumes/%s' % (cumulus.config.girder.baseUrl, volume_id), headers={'Girder-Token': girder_token}) check_status(r) volume = r.json() girder_callback_info = { 'girder_api_url': cumulus.config.girder.baseUrl, 'girder_token': girder_token} detach_volume(profile, cluster, master, volume, secret_key, girder_callback_info) inventory = simple_inventory('localhost') with inventory.to_tempfile() as inventory_path: ansible = run_playbook(playbook, inventory_path, playbook_variables, env=env, verbose=3) check_ansible_return_code(ansible, cluster, girder_token) check_girder_cluster_status(cluster, girder_token, post_status)
def provision_cluster(playbook, cluster, profile, secret_key, extra_vars, girder_token, log_write_url, post_status): playbook = get_playbook_path(playbook) playbook_variables = get_playbook_variables(cluster, profile, extra_vars) env = os.environ.copy() env.update({'AWS_ACCESS_KEY_ID': profile['accessKeyId'], 'AWS_SECRET_ACCESS_KEY': secret_key, 'GIRDER_TOKEN': girder_token, 'LOG_WRITE_URL': log_write_url, 'CLUSTER_ID': cluster['_id'], 'REGION_NAME': profile['regionName'], 'ANSIBLE_HOST_KEY_CHECKING': 'false', 'ANSIBLE_CALLBACK_PLUGINS': get_callback_plugins_path()}) inventory = os.path.join(os.path.dirname(__file__), 'providers', 'ec2.py') ansible = run_playbook(playbook, inventory, playbook_variables, env=env, verbose=3) check_girder_cluster_status(cluster, girder_token, post_status) check_ansible_return_code(ansible, cluster, girder_token)
def launch_cluster(playbook, cluster, profile, secret_key, extra_vars, girder_token, log_write_url, post_status): playbook = get_playbook_path(playbook) playbook_variables = get_playbook_variables(cluster, profile, extra_vars) env = os.environ.copy() env.update({ 'AWS_ACCESS_KEY_ID': profile['accessKeyId'], 'AWS_SECRET_ACCESS_KEY': secret_key, 'GIRDER_TOKEN': girder_token, 'LOG_WRITE_URL': log_write_url, 'CLUSTER_ID': cluster['_id'] }) inventory = simple_inventory('localhost') with inventory.to_tempfile() as inventory_path: ansible = run_playbook(playbook, inventory_path, playbook_variables, env=env, verbose=3) p = CloudProvider(dict(secretAccessKey=secret_key, **profile)) master = p.get_master_instance(cluster['_id']) status_url = '%s/clusters/%s' % (cumulus.config.girder.baseUrl, cluster['_id']) updates = {'config': {'host': master['public_ip']}} headers = {'Girder-Token': girder_token} r = requests.patch(status_url, headers=headers, json=updates) check_status(r) check_ansible_return_code(ansible, cluster, girder_token) check_girder_cluster_status(cluster, girder_token, post_status)