# Path: opennode/knot/model/template.py
# class GlobalTemplates(ReadonlyContainer):
#     __contains__ = Template
#     __name__ = 'templates'
# 
#     def __str__(self):
#         return 'Global template list'
# 
#     @property
#     def _items(self):
#         # break an import cycle
#         from opennode.oms.zodb import db
#         machines = db.get_root()['oms_root']['machines']
# 
#         templates = {}
# 
#         def allowed_classes_gen(item):
#             from opennode.knot.model.compute import ICompute, IVirtualCompute
#             from opennode.knot.model.machines import Machines
#             from opennode.knot.model.virtualizationcontainer import IVirtualizationContainer
#             yield isinstance(item, Machines)
#             yield isinstance(item, Templates)
#             yield IVirtualizationContainer.providedBy(item)
#             yield ICompute.providedBy(item)
#             yield IVirtualCompute.providedBy(item)
# 
#         def collect(container):
#             seen = set()
#             for item in container.listcontent():
#                 if ITemplate.providedBy(item) and item.__name__ not in templates:
#                     templates[item.__name__] = Symlink(item.__name__, item)
# 
#                 if any(allowed_classes_gen(item)):
#                     if item.__name__ not in seen:
#                         seen.add(item.__name__)
#                         collect(item)
# 
#         collect(machines)
#         return templates
# 
# Path: opennode/knot/model/template.py
# class ITemplate(Interface):
#     name = schema.TextLine(title=u"Template name", min_length=2)
#     base_type = schema.Choice(title=u"Template type", values=(u'xen', u'kvm', u'openvz'))
# 
#     cores = schema.Tuple(
#         title=u"Number of virtual cores", description=u"Minimum, suggested and maximum number of cores",
#         value_type=schema.Int(),
#         required=False)
#     memory = schema.Tuple(
#         title=u"Memory size", description=u"Minimum, suggested and maximum memory size (in GB)",
#         value_type=schema.Float(),
#         required=False)
#     swap = schema.Tuple(
#         title=u"Memory size", description=u"Minimum, suggested and maximum memory size (in GB)",
#         value_type=schema.Float(),
#         required=False)
#     disk = schema.Tuple(
#         title=u"Disk size", description=u"Minimum, suggested and maximum disk size",
#         value_type=schema.Float(),
#         required=False)
#     cpu_limit = schema.Tuple(
#         title=u"CPU usage limits", description=u"Minimum, suggested and maximum cpu_limit",
#         value_type=schema.Int(),
#         required=False)
# 
#     username = schema.TextLine(title=u"Default username", required=False)
#     password = schema.TextLine(title=u"Default password", required=False)
#     ip = schema.TextLine(title=u"Default IP", required=False)
#     nameserver = schema.TextLine(title=u"Default nameserver", required=False)


import transaction
from grokcore.component import context
from opennode.knot.model.template import GlobalTemplates
from opennode.knot.model.template import ITemplate
from opennode.oms.endpoint.ssh.cmdline import VirtualConsoleArgumentParser
from opennode.oms.endpoint.ssh.cmd.security import SetAclMixin
from opennode.oms.endpoint.ssh.cmd.security import require_admins_only_action
from opennode.oms.model.model.actions import Action, action
from opennode.oms.model.model.symlink import follow_symlinks
from opennode.oms.security.acl import NoSuchPermission
from opennode.oms.zodb import db




class SetGlobalTemplatePermissionsAction(Action, SetAclMixin):
    context(GlobalTemplates)
    action('set-template-perm')


# Path: opennode/knot/model/template.py
# class GlobalTemplates(ReadonlyContainer):
#     __contains__ = Template
#     __name__ = 'templates'
# 
#     def __str__(self):
#         return 'Global template list'
# 
#     @property
#     def _items(self):
#         # break an import cycle
#         from opennode.oms.zodb import db
#         machines = db.get_root()['oms_root']['machines']
# 
#         templates = {}
# 
#         def allowed_classes_gen(item):
#             from opennode.knot.model.compute import ICompute, IVirtualCompute
#             from opennode.knot.model.machines import Machines
#             from opennode.knot.model.virtualizationcontainer import IVirtualizationContainer
#             yield isinstance(item, Machines)
#             yield isinstance(item, Templates)
#             yield IVirtualizationContainer.providedBy(item)
#             yield ICompute.providedBy(item)
#             yield IVirtualCompute.providedBy(item)
# 
#         def collect(container):
#             seen = set()
#             for item in container.listcontent():
#                 if ITemplate.providedBy(item) and item.__name__ not in templates:
#                     templates[item.__name__] = Symlink(item.__name__, item)
# 
#                 if any(allowed_classes_gen(item)):
#                     if item.__name__ not in seen:
#                         seen.add(item.__name__)
#                         collect(item)
# 
#         collect(machines)
#         return templates
# 
# Path: opennode/knot/model/template.py
# class ITemplate(Interface):
#     name = schema.TextLine(title=u"Template name", min_length=2)
#     base_type = schema.Choice(title=u"Template type", values=(u'xen', u'kvm', u'openvz'))
# 
#     cores = schema.Tuple(
#         title=u"Number of virtual cores", description=u"Minimum, suggested and maximum number of cores",
#         value_type=schema.Int(),
#         required=False)
#     memory = schema.Tuple(
#         title=u"Memory size", description=u"Minimum, suggested and maximum memory size (in GB)",
#         value_type=schema.Float(),
#         required=False)
#     swap = schema.Tuple(
#         title=u"Memory size", description=u"Minimum, suggested and maximum memory size (in GB)",
#         value_type=schema.Float(),
#         required=False)
#     disk = schema.Tuple(
#         title=u"Disk size", description=u"Minimum, suggested and maximum disk size",
#         value_type=schema.Float(),
#         required=False)
#     cpu_limit = schema.Tuple(
#         title=u"CPU usage limits", description=u"Minimum, suggested and maximum cpu_limit",
#         value_type=schema.Int(),
#         required=False)
# 
#     username = schema.TextLine(title=u"Default username", required=False)
#     password = schema.TextLine(title=u"Default password", required=False)
#     ip = schema.TextLine(title=u"Default IP", required=False)
#     nameserver = schema.TextLine(title=u"Default nameserver", required=False)


# Path: opennode/knot/backend/template.py
import transaction
from grokcore.component import context
from opennode.knot.model.template import GlobalTemplates
from opennode.knot.model.template import ITemplate
from opennode.oms.endpoint.ssh.cmdline import VirtualConsoleArgumentParser
from opennode.oms.endpoint.ssh.cmd.security import SetAclMixin
from opennode.oms.endpoint.ssh.cmd.security import require_admins_only_action
from opennode.oms.model.model.actions import Action, action
from opennode.oms.model.model.symlink import follow_symlinks
from opennode.oms.security.acl import NoSuchPermission
from opennode.oms.zodb import db





class SetGlobalTemplatePermissionsAction(Action, SetAclMixin):
    context(GlobalTemplates)
    action('set-template-perm')


    @db.ro_transact(proxy=False)