# 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/backend/compute.py
# class ShutdownComputeAction(VComputeAction):
#     action('shutdown')
# 
#     action_name = "shutting down"
#     job = IShutdownVM
#     state = u'stopping'


import collections
import json
import yaml
from grokcore.component import implements
from twisted.internet import defer
from twisted.python import log
from zope.authentication.interfaces import IAuthentication
from zope.component import getUtility
from zope.schema.interfaces import WrongType, RequiredMissing
from zope.security.proxy import removeSecurityProxy
from zope.securitypolicy.interfaces import IPrincipalRoleManager
from zope.securitypolicy.rolepermission import rolePermissionManager
from opennode.oms.endpoint.ssh.cmd.base import Cmd
from opennode.oms.endpoint.ssh.cmd.directives import command
from opennode.oms.endpoint.ssh.cmdline import ICmdArgumentsSyntax
from opennode.oms.endpoint.ssh.cmdline import VirtualConsoleArgumentParser
from opennode.oms.endpoint.ssh.cmd.security import require_admins_only
from opennode.oms.endpoint.ssh.cmd.security import SetAclMixin
from opennode.oms.endpoint.ssh.detached import DetachedProtocol
from opennode.oms.model.form import RawDataApplier
from opennode.oms.model.form import RawDataValidatingFactory
from opennode.oms.model.form import NoSchemaFound
from opennode.oms.model.model.base import IContainer, IIncomplete
from opennode.oms.model.model.symlink import follow_symlinks
from opennode.oms.model.schema import model_to_dict
from opennode.oms.model.schema import get_schema_fields
from opennode.oms.model.traversal import canonical_path, traverse1
from opennode.oms.security.principals import Group
from opennode.oms.security.permissions import Role
from opennode.oms.zodb import db
from opennode.knot.model.compute import IVirtualCompute
from opennode.knot.backend.compute import ShutdownComputeAction
        # Force renewal of the validation
        delattr(form, '_errors')

        assert not form.errors, format_error_message(form.errors)
        return getattr(form, action)(ignore_readonly=True)

    @db.assert_transact
    def _do_create_or_set(self, data, obj, attrs=[], marker=None):
        if 'features' in data:
            feature_set = data['features']
        else:
            feature_set = set()

        data_filtered = dict(filter(lambda (k, v): k not in self.attr_blacklist,
                                    data.iteritems()))

        if isinstance(obj, type):
            obj = self.apply_form(RawDataValidatingFactory, data_filtered, obj, 'create', marker=marker)

            if obj is None:
                return
        else:
            self.apply_form(RawDataApplier, data_filtered, obj, 'apply', marker=marker)

        if '__name__' in data:
            obj.__name__ = data['__name__']

        if 'owner' in attrs:
            obj.__owner__ = data['owner']


# 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/backend/compute.py
# class ShutdownComputeAction(VComputeAction):
#     action('shutdown')
# 
#     action_name = "shutting down"
#     job = IShutdownVM
#     state = u'stopping'


# Path: opennode/knot/backend/admin.py
import collections
import json
import yaml
from grokcore.component import implements
from twisted.internet import defer
from twisted.python import log
from zope.authentication.interfaces import IAuthentication
from zope.component import getUtility
from zope.schema.interfaces import WrongType, RequiredMissing
from zope.security.proxy import removeSecurityProxy
from zope.securitypolicy.interfaces import IPrincipalRoleManager
from zope.securitypolicy.rolepermission import rolePermissionManager
from opennode.oms.endpoint.ssh.cmd.base import Cmd
from opennode.oms.endpoint.ssh.cmd.directives import command
from opennode.oms.endpoint.ssh.cmdline import ICmdArgumentsSyntax
from opennode.oms.endpoint.ssh.cmdline import VirtualConsoleArgumentParser
from opennode.oms.endpoint.ssh.cmd.security import require_admins_only
from opennode.oms.endpoint.ssh.cmd.security import SetAclMixin
from opennode.oms.endpoint.ssh.detached import DetachedProtocol
from opennode.oms.model.form import RawDataApplier
from opennode.oms.model.form import RawDataValidatingFactory
from opennode.oms.model.form import NoSchemaFound
from opennode.oms.model.model.base import IContainer, IIncomplete
from opennode.oms.model.model.symlink import follow_symlinks
from opennode.oms.model.schema import model_to_dict
from opennode.oms.model.schema import get_schema_fields
from opennode.oms.model.traversal import canonical_path, traverse1
from opennode.oms.security.principals import Group
from opennode.oms.security.permissions import Role
from opennode.oms.zodb import db
from opennode.knot.model.compute import IVirtualCompute
from opennode.knot.backend.compute import ShutdownComputeAction

        # Force renewal of the validation
        delattr(form, '_errors')

        assert not form.errors, format_error_message(form.errors)
        return getattr(form, action)(ignore_readonly=True)

    @db.assert_transact
    def _do_create_or_set(self, data, obj, attrs=[], marker=None):
        if 'features' in data:
            feature_set = data['features']
        else:
            feature_set = set()

        data_filtered = dict(filter(lambda (k, v): k not in self.attr_blacklist,
                                    data.iteritems()))

        if isinstance(obj, type):
            obj = self.apply_form(RawDataValidatingFactory, data_filtered, obj, 'create', marker=marker)

            if obj is None:
                return
        else:
            self.apply_form(RawDataApplier, data_filtered, obj, 'apply', marker=marker)

        if '__name__' in data:
            obj.__name__ = data['__name__']

        if 'owner' in attrs:
            obj.__owner__ = data['owner']


        obj.features = feature_set