# -*- coding: utf-8 -*-
import logging
from base import BaseStep
from logical.models import Database


LOG = logging.getLogger(__name__)


class BuildDatabase(BaseStep):

    def __unicode__(self):
        return "Creating logical database..."

    def do(self, workflow_dict):
        try:

            if not workflow_dict['team'] or not workflow_dict['description'] or not workflow_dict['databaseinfra']:
                return False

            LOG.info("Creating Database...")
            database = Database.provision(name= workflow_dict['name'], databaseinfra= workflow_dict['databaseinfra'])
            workflow_dict['database'] = database

            database.team = workflow_dict['team']

            if 'project' in workflow_dict:
                database.project = workflow_dict['project']

            database.description = workflow_dict['description']
            database.save()

            return True
        except Exception, e:
            print e
            return False

    def undo(self, workflow_dict):
        try:

            LOG.info("Destroying the database....")

            workflow_dict['database'].delete()

            return True
        except Exception, e:
            print e
            return False

# -*- coding: utf-8 -*-
import logging
from base import BaseStep
from logical.models import Database
import datetime


LOG = logging.getLogger(__name__)


class BuildDatabase(BaseStep):

    def __unicode__(self):
        return "Creating logical database..."

    def do(self, workflow_dict):
        try:

            if not workflow_dict['team'] or not workflow_dict['description'] or not workflow_dict['databaseinfra']:
                return False

            LOG.info("Creating Database...")
            database = Database.provision(name= workflow_dict['name'], databaseinfra= workflow_dict['databaseinfra'])

            LOG.info("Database %s created!" % database)
            workflow_dict['database'] = database

            LOG.info("Updating database team")
            database.team = workflow_dict['team']

            if 'project' in workflow_dict:
                LOG.info("Updating database project")
                database.project = workflow_dict['project']

            LOG.info("Updating database description")
            database.description = workflow_dict['description']

            database.save()

            return True
        except Exception, e:
            print e
            return False

    def undo(self, workflow_dict):
        try:

            if not 'database' in workflow_dict:
                return False

            LOG.info("Destroying the database....")

            if not workflow_dict['database'].is_in_quarantine:
                LOG.info("Putting Database in quarentine...")
                database = workflow_dict['database']
                database.is_in_quarantine= True
                database.quarantine_dt = datetime.datetime.now().date()
                database.save()

            database.delete()

            return True
        except Exception, e:
            print e
            return False

Improve logs and change delete pos
Improve logs and change delete pos
