# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2012 Pedro Navarro Perez
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""
Management class for Storage-related functions (attach, detach, etc).
"""
import time

from nova import block_device
from nova import flags
from nova.openstack.common import cfg
from nova.openstack.common import log as logging
from nova.virt import driver
from nova.virt.hyperv import baseops
from nova.virt.hyperv import vmutils
from nova.virt.hyperv import volumeutils

LOG = logging.getLogger(__name__)

hyper_volumeops_opts = [
    cfg.IntOpt('hyperv_attaching_volume_retry_count',
        default=10,
        help='The number of times we retry on attaching volume '),
    cfg.IntOpt('hyperv_wait_between_attach_retry',
        default=5,
        help='The seconds to wait between an volume attachment attempt'),
    ]

FLAGS = flags.FLAGS
FLAGS.register_opts(hyper_volumeops_opts)


class VolumeOps(baseops.BaseOps):
    """
    Management class for Volume-related tasks
    """

    def __init__(self):
        super(VolumeOps, self).__init__()

        self._vmutils = vmutils.VMUtils()
        self._driver = driver
        self._block_device = block_device
        self._time = time
        self._initiator = None
        self._default_root_device = 'vda'
        self._attaching_volume_retry_count = \
            FLAGS.hyperv_attaching_volume_retry_count
        self._wait_between_attach_retry = \
            FLAGS.hyperv_wait_between_attach_retry
        self._volutils = volumeutils.VolumeUtils()