
from __future__ import absolute_import
from __future__ import division

import logging
import os

from vdsm.common.constants import P_VDSM_RUN
from vdsm.common.fileutils import rm_file
from vdsm.common.fileutils import touch_file

TRACKED_INTERFACES_FOLDER = os.path.join(P_VDSM_RUN, 'trackedInterfaces')


def add(device_name):
    logging.debug('Add iface tracking for device %s', device_name)
    touch_file(_filepath(device_name))


def remove(device_name):
    logging.debug('Remove iface tracking for device %s', device_name)
    rm_file(_filepath(device_name))


def is_tracked(device_name):
    return os.path.exists(_filepath(device_name))


def _filepath(device_name):
    return os.path.join(TRACKED_INTERFACES_FOLDER, device_name)
