# -*- coding: utf-8 -*-
import logging
from util import full_stack, call_script
from django.conf import settings
from drivers import factory_for
from notification.util import get_clone_args
from workflow.steps.util.base import BaseStep
from workflow.exceptions.error_codes import DBAAS_0017

LOG = logging.getLogger(__name__)


class CloneDatabase(BaseStep):

    def __unicode__(self):
        return "Replicating database data..."

    def do(self, workflow_dict):
        try:

            if 'databaseinfra' not in workflow_dict \
                    or 'clone' not in workflow_dict:
                return False

            args = get_clone_args(
                workflow_dict['clone'], workflow_dict['database'])
            script_name = factory_for(
                workflow_dict['clone'].databaseinfra).clone()

            return_code, output = call_script(
                script_name, working_dir=settings.SCRIPTS_PATH, args=args, split_lines=False,)

            LOG.info("Script Output: {}".format(output))
            LOG.info("Return code: {}".format(return_code))

            if return_code != 0:
                workflow_dict['exceptions']['traceback'].append(output)
                return False

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0017)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False

    def undo(self, workflow_dict):
        LOG.info("Nothing to do here...")
        return True

@@ -52,20 +52,8 @@
 port
- full_stack,
  cal
@@ -216,67 +216,20 @@
 Base
-Step%0Afrom workflow.exceptions.error_codes import DBAAS_0017
+InstanceStep
 %0A%0ALO
@@ -285,12 +285,24 @@
 base
-(Bas
+Data(BaseInstanc
 eSte
@@ -391,39 +391,24 @@
  def do(self
-, workflow_dict
 ):%0A        t
@@ -415,146 +415,8 @@
 ry:%0A
-%0A            if 'databaseinfra' not in workflow_dict %5C%0A                    or 'clone' not in workflow_dict:%0A                return False%0A%0A
     
@@ -466,55 +466,56 @@
     
-workflow_dict%5B'clone'%5D, workflow_dict%5B'
+self.step_manager.origin_database, self.
 database
 '%5D)%0A
@@ -510,18 +510,16 @@
 database
-'%5D
 )%0A      
@@ -554,56 +554,13 @@
 for(
-%0A                workflow_dict%5B'clone'%5D.database
+self.
 infr
@@ -681,16 +681,32 @@
 TS_PATH,
+%0A               
  args=ar
@@ -726,17 +726,29 @@
 es=False
-,
+%0A            
 )%0A%0A     
@@ -913,55 +913,23 @@
     
-workflow_dict%5B'exceptions'%5D%5B'traceback'%5D.append
+raise Exception
 (out
@@ -1015,313 +1015,106 @@
 tion
-:%0A            traceback = full_stack()%0A%0A            workflow_dict%5B'exceptions'%5D%5B'error_codes'%5D.append(DBAAS_0017)%0A            workflow_dict%5B'exceptions'%5D%5B'traceback'%5D.append(traceback)%0A%0A            return False%0A%0A    def undo(self, workflow_dict):%0A        LOG.info(%22Nothing to do here...%22)%0A        return True
+ as err:%0A            raise Exception(err)%0A%0A            return False%0A%0A    def undo(self):%0A        pass
 %0A

Create CloneDatabaseData Step