auto
  #   lY>d
n-jvOe1h ?     #
# Copyright (c) 2018 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. 
#

"""
  VDOOperation - an object representing a vdo script command

  $Id: //eng/vdo-releases/magnesium/src/python/vdo/vdomgmnt/VDOOperation.py#9 $
"""
from . import ArgumentError
from . import CommandLock
from . import Configuration
from . import Constants
from . import Defaults
from . import MgmntLogger
from . import MgmntUtils
from . import Service
from . import VDOKernelModuleService
from . import VDOService, VDOServiceError, VDOServicePreviousOperationError
from . import ExitStatus, SystemExitStatus, UserExitStatus
from utils import Command, CommandError, runCommand
from utils import Transaction, transactional
from functools import partial
import inspect
import __main__ as main
import os
import re
import sys
import yaml

vdoOperations = dict()

def lock(isExclusive, func, *args, **kwargs):
  commandArgs = args[1]
  confFile = os.path.abspath(commandArgs.confFile)
  confFile = os.path.realpath(confFile)
  # N.B.: We don't filter out shell special characters like " (){}"!
  #
  # Also, no quoting; if two config file names use "/" and "_" such
  # that they both map to the same lock file, so be it.
  lockFileBase = confFile.replace('/', '_') + '.lock'
  lockFile = os.path.join(Constants.LOCK_DIR, lockFileBase)
  with CommandLock(lockFile, isExclusive):
    return func(*args, **kwargs)

def exclusivelock(func):
  "Decorator that locks the configuration for exclusive (write) access."
  def wrap(*args, **kwargs):
    return lock(False, func, *args, **kwargs)
  return wrap

def sharedlock(func):
  "Decorator that locks the configuration for shared (read) access."
  def wrap(*args, **kwargs):
    return lock(False, func, *args, **kwargs)
  return wrap

########################################################################
class OperationError(ExitStatus, Exception):
  """Exception raised to indicate an error executing an operation."""

  ######################################################################
  # Public methods
  ######################################################################

  ######################################################################
  # Overridden methods
  ######################################################################

  ######################################################################
  # Protected methods
  ######################################################################
  def __init__(self, msg, *args, **kwargs):
    super(OperationError, self).__init__(*args, **kwargs)
    self._msg = msg

  def __str__(self):
    return self._msg

########################################################################
class VDOOperation(object):
  """Every instance of this class runs one of the subcommands
  requested when 'vdo [<options>] <subcommand>' is called via the
  execute() method."""

  ######################################################################
  # Public methods
  ######################################################################
  def getVdoServices(self, args, conf):
    """Return a list of VDOService objects to be operated on depending
    on the settings of the --name and --all options.
    Arguments:
      args: The arguments passed into vdo.
      conf: The config file
    Raises:
      ArgumentError
    """
    services = []
    if args.all:
      se