summaryrefslogtreecommitdiffstats
path: root/playbooks/adhoc/grow_docker_vg/filter_plugins/oo_filters.py
blob: d0264cde98de1c62ba269db1cbf090a11316f5e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vim: expandtab:tabstop=4:shiftwidth=4
'''
Custom filters for use in openshift-ansible
'''

import pdb


class FilterModule(object):
    ''' Custom ansible filters '''

    @staticmethod
    def oo_pdb(arg):
        ''' This pops you into a pdb instance where arg is the data passed in
            from the filter.
            Ex: "{{ hostvars | oo_pdb }}"
        '''
        pdb.set_trace()
        return arg

    @staticmethod
    def translate_volume_name(volumes, target_volume):
        '''
            This filter matches a device string /dev/sdX to /dev/xvdX
            It will then return the AWS volume ID
        '''
        for vol in volumes:
            translated_name = vol["attachment_set"]["device"].replace("/dev/sd", "/dev/xvd")
            if target_volume.startswith(translated_name):
                return vol["id"]

        return None


    def filters(self):
        ''' returns a mapping of filters to methods '''
        return {
            "translate_volume_name": self.translate_volume_name,
        }