# Copyright (c) 2014 Mirantis Inc.
#
# 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.


import copy
import hashlib
import os

from fabric.api import env
from fabric.api import run
from fabric.api import settings
from oslo_config import cfg

from cloudferrylib.base.action import action
from cloudferrylib.os.actions import task_transfer
from cloudferrylib.utils.utils import forward_agent
from cloudferrylib.utils import utils as utl
from cloudferrylib.utils import qemu_img as qemu_img_util

CONF = cfg.CONF

CLOUD = 'cloud'
BACKEND = 'backend'
CEPH = 'ceph'
ISCSI = 'iscsi'
COMPUTE = 'compute'
INSTANCES = 'instances'
INSTANCE_BODY = 'instance'
INSTANCE = 'instance'
DIFF = 'diff'
EPHEMERAL = 'ephemeral'
DIFF_OLD = 'diff_old'
EPHEMERAL_OLD = 'ephemeral_old'

PATH_DST = 'path_dst'
HOST_DST = 'host_dst'
PATH_SRC = 'path_src'
HOST_SRC = 'host_src'
BACKING_FILE_DST = 'backing_file_dst'

TEMP = 'temp'
FLAVORS = 'flavors'

TRANSPORTER_MAP = {CEPH: {CEPH: 'SSHCephToCeph',
                          ISCSI: 'SSHCephToFile'},
                   ISCSI: {CEPH: 'SSHFileToCeph',
                           ISCSI: 'SSHFileToFile'}}


class TransportEphemeral(action.Action):
    # TODO constants

    def run(self, info=None, **kwargs):
        info = copy.deepcopy(info)
        # Init before run
        new_info = {
            utl.INSTANCES_TYPE: {
            }
        }

        # Get next one instance
        for instance_id, instance in info[utl.INSTANCES_TYPE].iteritems():
            is_ephemeral = instance[utl.INSTANCE_BODY]['is_ephemeral']