Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
    def test_simple_inventory_dict(self):
        target = inventory.AnsibleInventory([], sections=[
            inventory.AnsibleInventoryGroup('test', ['localhost', 'localhost2'])])

        source = inventory.simple_inventory(
            {"test": ["localhost", "localhost2"]})

        self.assertEquals(source.to_string(), target.to_string())
Esempio n. 5
0
    def test_simple_inventory_list_and_dict(self):
        target = inventory.AnsibleInventory(
            ['localhost', 'localhost2'],
            sections=[
                inventory.AnsibleInventoryGroup('test',
                                                ['localhost', 'localhost2'])
            ])

        source = inventory.simple_inventory(
            ['localhost', 'localhost2'], {"test": ["localhost", "localhost2"]})

        self.assertEquals(source.to_string(), target.to_string())
Esempio n. 6
0
    def test_simple_inventory_list(self):
        target = inventory.AnsibleInventory(['localhost', 'localhost2'])
        source = inventory.simple_inventory(['localhost', 'localhost2'])

        self.assertEquals(source.to_string(), target.to_string())
Esempio n. 7
0
    def test_simple_inventory_list(self):
        target = inventory.AnsibleInventory(['localhost', 'localhost2'])
        source = inventory.simple_inventory(['localhost', 'localhost2'])

        self.assertEquals(source.to_string(), target.to_string())