# Path: opennode/knot/model/compute.py
# class IVirtualCompute(Interface):
#     """A virtual compute."""
#     template = Path(title=u"Template", base_path='../templates/by-name/', relative_to=Path.PARENT)
#     # 0 <= cpu_limit <= 1
#     cpu_limit = schema.Float(title=u"CPU Limit", description=u"CPU usage limit", required=False)
#     ctid = schema.Int(title=u'OpenVZ CTID', description=u'OpenVZ CTID (applies only to OpenVZ VMs)',
#                       required=False, default=101)
# 
#     license_activated = schema.Bool(title=u'License activated', required=False, default=True,
#                                     readonly=True)
# 
#     notify_admin = schema.Bool(title=u'Notify admin on deploy', required=False, default=False,
#                                readonly=True)
# 
# Path: opennode/knot/model/user.py
# class IUserStatisticsLogger(Interface):
# 
#     def log(self, data):
#         """ Log statistics collected using IUserStatisticsProvider """


from datetime import datetime, timedelta
from grokcore.component import implements, name, GlobalUtility
from twisted.internet import defer
from twisted.enterprise import adbapi
from zope.interface import Interface
from zope.component import getUtility
from opennode.knot.model.compute import IVirtualCompute
from opennode.knot.model.user import IUserStatisticsLogger
from opennode.knot.model.virtualizationcontainer import IVirtualizationContainer
from opennode.oms.config import get_config
from opennode.oms.model.model.hooks import IPreValidateHook
from opennode.oms.model.traversal import traverse1
from opennode.oms.zodb import db
import logging
import sys





log = logging.getLogger(__name__)


class UserStatsLogger(GlobalUtility):
    implements(IUserStatisticsLogger)
    name('user-stats-logger')

    def __init__(self):
        self.slog = logging.getLogger("%s.userstats" % __name__)

    def log(self, user, stats_data):
        data = {'username': user, 'stats': stats_data}
        self.slog.info('%s' % data, extra=data)


class SqlDBUserStatsLogger(GlobalUtility):

# Path: opennode/knot/model/compute.py
# class IVirtualCompute(Interface):
#     """A virtual compute."""
#     template = Path(title=u"Template", base_path='../templates/by-name/', relative_to=Path.PARENT)
#     # 0 <= cpu_limit <= 1
#     cpu_limit = schema.Float(title=u"CPU Limit", description=u"CPU usage limit", required=False)
#     ctid = schema.Int(title=u'OpenVZ CTID', description=u'OpenVZ CTID (applies only to OpenVZ VMs)',
#                       required=False, default=101)
# 
#     license_activated = schema.Bool(title=u'License activated', required=False, default=True,
#                                     readonly=True)
# 
#     notify_admin = schema.Bool(title=u'Notify admin on deploy', required=False, default=False,
#                                readonly=True)
# 
# Path: opennode/knot/model/user.py
# class IUserStatisticsLogger(Interface):
# 
#     def log(self, data):
#         """ Log statistics collected using IUserStatisticsProvider """


# Path: opennode/knot/backend/billing.py
from datetime import datetime, timedelta
from grokcore.component import implements, name, GlobalUtility
from twisted.internet import defer
from twisted.enterprise import adbapi
from zope.interface import Interface
from zope.component import getUtility
from opennode.knot.model.compute import IVirtualCompute
from opennode.knot.model.user import IUserStatisticsLogger
from opennode.knot.model.virtualizationcontainer import IVirtualizationContainer
from opennode.oms.config import get_config
from opennode.oms.model.model.hooks import IPreValidateHook
from opennode.oms.model.traversal import traverse1
from opennode.oms.zodb import db
import logging
import sys






log = logging.getLogger(__name__)


class UserStatsLogger(GlobalUtility):
    implements(IUserStatisticsLogger)
    name('user-stats-logger')

    def __init__(self):
        self.slog = logging.getLogger("%s.userstats" % __name__)

    def log(self, user, stats_data):
        data = {'username': user, 'stats': stats_data}
        self.slog.info('%s' % data, extra=data)


class SqlDBUserStatsLogger(GlobalUtility):

    implements(IUserStatisticsLogger)