# Path: opennode/knot/model/compute.py
# class ICompute(Interface):
#     # Network parameters
#     hostname = RestrictedHostname(title=u"Host name", min_length=1)
#     mac_address = schema.TextLine(title=u'MAC address', min_length=17, max_length=23, required=False,
#                                   description=u'MAC address, formatted as a set of colon-separated '
#                                   'hexadecimal octet values')
#     ipv4_address = schema.TextLine(title=u"IPv4 address", min_length=7, required=False)
#     ipv6_address = schema.TextLine(title=u"IPv6 address", min_length=6, required=False)
#     nameservers = schema.List(title=u"Nameservers", description=u"IPs of DNS servers",
#                               value_type=schema.TextLine(), required=False)
#     dns_domains = schema.List(
#         title=u"DNS Domains", description=u"Domain names used for DNS host name lookup",
#         value_type=schema.TextLine(), required=False)
# 
#     # Hardware/platform info
#     architecture = schema.Tuple(
#         title=u"Architecture", description=u"OS arch, OS type, OS distribution/flavour",
#         value_type=schema.TextLine(), max_length=3, min_length=3,
#         required=False, readonly=True)
#     cpu_info = schema.TextLine(
#         title=u"CPU Info", description=u"Info about the CPU such as model, speed in Hz, cache size",
#         required=False, readonly=True)
#     os_release = schema.TextLine(
#         title=u"OS Release", description=u"OS version info",
#         required=False, readonly=True)
#     kernel = schema.TextLine(
#         title=u"Kernel", description=u"Kernel version (if applicable)",
#         required=False, readonly=True)
# 
#     # State
#     state = schema.Choice(
#         title=u"State", values=(u'starting', u'active', u'stopping', u'inactive', u'suspended'),
#         required=False, default=u'inactive')
#     effective_state = schema.TextLine(
#         title=u"Effective state", readonly=True, required=False)
# 
#     autostart = schema.Bool(title=u"Autostart", description=u"Start on boot", required=False)
# 
#     # Processing/network capabilities:
#     num_cores = schema.Int(
#         title=u"Num. Cores", description=u"Total number of cores across all CPUs",
#         required=False)
#     memory = schema.Int(
#         title=u"RAM Size in MB", description=u"RAM size in MB",
#         required=False)
#     diskspace = schema.Dict(
#         title=u"Disk size in MB", description=u"List of disk partition sizes",
#         key_type=schema.TextLine(), value_type=schema.Float(),
#         required=False, readonly=True)
#     network = schema.Float(
#         title=u"Network", description=u"Network bandwidth in Bps",
#         required=False, readonly=True)
#     swap_size = schema.Int(
#         title=u"Swap Size in MB", description=u"Swap size",
#         required=False)
# 
#     # Resource utilization/load:
#     uptime = schema.Float(
#         title=u"Uptime", description=u"Uptime in seconds",
#         required=False, readonly=True)
#     cpu_usage = schema.Tuple(
#         title=u"CPU Load", description=u"CPU load during the past 1, 5 and 15 minutes",
#         value_type=schema.Float(),
#         required=False, readonly=True)
#     memory_usage = schema.Float(
#         title=u"Memory Usage", description=u"Memory usage in MB",
#         required=False, readonly=True)
#     diskspace_usage = schema.Dict(
#         title=u"Diskspace Utilization", description=u"List of disk partition usages",
#         key_type=schema.TextLine(), value_type=schema.Float(),
#         required=False, readonly=True)
#     network_usage = schema.Tuple(
#         title=u"Network Load", description=u"Network load in B/s (incoming and outgoing)",
#         value_type=schema.Float(),
#         required=False, readonly=True)
# 
#     # availability
#     last_ping = schema.Bool(title=u'Success of the last ping', required=False,
#                             readonly=True, default=False)
# 
#     pingcheck = schema.List(title=u'Ping history', required=False,
#                             readonly=True, default=[],
#                             value_type=schema.Dict(title=u'Ping result',
#                                                    required=False,
#                                                    readonly=True))
# 
#     suspicious = schema.Bool(title=u'Suspicion of unavailability',
#                              required=False, readonly=True, default=False)
# 
#     failure = schema.Bool(title=u'Availability failure', required=False,
#                           readonly=True, default=False)
# 
#     agent_version = schema.TextLine(title=u'Agent version', required=False,
#                                     readonly=True, default=u'')
# 
#     exclude_from_allocation = schema.Bool(title=u'Exclude from allocation', required=False, default=False)


from grokcore.component import implements
from zope.component import provideSubscriptionAdapter
from opennode.knot.utils.icmp import ping
from opennode.knot.model.compute import ICompute
from opennode.oms.endpoint.ssh.cmd.base import Cmd
from opennode.oms.endpoint.ssh.cmd.completers import PathCompleter
from opennode.oms.endpoint.ssh.cmd.directives import command
from opennode.oms.endpoint.ssh.cmdline import ICmdArgumentsSyntax, VirtualConsoleArgumentParser
from opennode.oms.zodb import db



class PingCmd(Cmd):
    implements(ICmdArgumentsSyntax)
    command('ping')

    def arguments(self):

# Path: opennode/knot/model/compute.py
# class ICompute(Interface):
#     # Network parameters
#     hostname = RestrictedHostname(title=u"Host name", min_length=1)
#     mac_address = schema.TextLine(title=u'MAC address', min_length=17, max_length=23, required=False,
#                                   description=u'MAC address, formatted as a set of colon-separated '
#                                   'hexadecimal octet values')
#     ipv4_address = schema.TextLine(title=u"IPv4 address", min_length=7, required=False)
#     ipv6_address = schema.TextLine(title=u"IPv6 address", min_length=6, required=False)
#     nameservers = schema.List(title=u"Nameservers", description=u"IPs of DNS servers",
#                               value_type=schema.TextLine(), required=False)
#     dns_domains = schema.List(
#         title=u"DNS Domains", description=u"Domain names used for DNS host name lookup",
#         value_type=schema.TextLine(), required=False)
# 
#     # Hardware/platform info
#     architecture = schema.Tuple(
#         title=u"Architecture", description=u"OS arch, OS type, OS distribution/flavour",
#         value_type=schema.TextLine(), max_length=3, min_length=3,
#         required=False, readonly=True)
#     cpu_info = schema.TextLine(
#         title=u"CPU Info", description=u"Info about the CPU such as model, speed in Hz, cache size",
#         required=False, readonly=True)
#     os_release = schema.TextLine(
#         title=u"OS Release", description=u"OS version info",
#         required=False, readonly=True)
#     kernel = schema.TextLine(
#         title=u"Kernel", description=u"Kernel version (if applicable)",
#         required=False, readonly=True)
# 
#     # State
#     state = schema.Choice(
#         title=u"State", values=(u'starting', u'active', u'stopping', u'inactive', u'suspended'),
#         required=False, default=u'inactive')
#     effective_state = schema.TextLine(
#         title=u"Effective state", readonly=True, required=False)
# 
#     autostart = schema.Bool(title=u"Autostart", description=u"Start on boot", required=False)
# 
#     # Processing/network capabilities:
#     num_cores = schema.Int(
#         title=u"Num. Cores", description=u"Total number of cores across all CPUs",
#         required=False)
#     memory = schema.Int(
#         title=u"RAM Size in MB", description=u"RAM size in MB",
#         required=False)
#     diskspace = schema.Dict(
#         title=u"Disk size in MB", description=u"List of disk partition sizes",
#         key_type=schema.TextLine(), value_type=schema.Float(),
#         required=False, readonly=True)
#     network = schema.Float(
#         title=u"Network", description=u"Network bandwidth in Bps",
#         required=False, readonly=True)
#     swap_size = schema.Int(
#         title=u"Swap Size in MB", description=u"Swap size",
#         required=False)
# 
#     # Resource utilization/load:
#     uptime = schema.Float(
#         title=u"Uptime", description=u"Uptime in seconds",
#         required=False, readonly=True)
#     cpu_usage = schema.Tuple(
#         title=u"CPU Load", description=u"CPU load during the past 1, 5 and 15 minutes",
#         value_type=schema.Float(),
#         required=False, readonly=True)
#     memory_usage = schema.Float(
#         title=u"Memory Usage", description=u"Memory usage in MB",
#         required=False, readonly=True)
#     diskspace_usage = schema.Dict(
#         title=u"Diskspace Utilization", description=u"List of disk partition usages",
#         key_type=schema.TextLine(), value_type=schema.Float(),
#         required=False, readonly=True)
#     network_usage = schema.Tuple(
#         title=u"Network Load", description=u"Network load in B/s (incoming and outgoing)",
#         value_type=schema.Float(),
#         required=False, readonly=True)
# 
#     # availability
#     last_ping = schema.Bool(title=u'Success of the last ping', required=False,
#                             readonly=True, default=False)
# 
#     pingcheck = schema.List(title=u'Ping history', required=False,
#                             readonly=True, default=[],
#                             value_type=schema.Dict(title=u'Ping result',
#                                                    required=False,
#                                                    readonly=True))
# 
#     suspicious = schema.Bool(title=u'Suspicion of unavailability',
#                              required=False, readonly=True, default=False)
# 
#     failure = schema.Bool(title=u'Availability failure', required=False,
#                           readonly=True, default=False)
# 
#     agent_version = schema.TextLine(title=u'Agent version', required=False,
#                                     readonly=True, default=u'')
# 
#     exclude_from_allocation = schema.Bool(title=u'Exclude from allocation', required=False, default=False)


# Path: opennode/knot/endpoint/ssh/ping.py
from grokcore.component import implements
from zope.component import provideSubscriptionAdapter
from opennode.knot.utils.icmp import ping
from opennode.knot.model.compute import ICompute
from opennode.oms.endpoint.ssh.cmd.base import Cmd
from opennode.oms.endpoint.ssh.cmd.completers import PathCompleter
from opennode.oms.endpoint.ssh.cmd.directives import command
from opennode.oms.endpoint.ssh.cmdline import ICmdArgumentsSyntax, VirtualConsoleArgumentParser
from opennode.oms.zodb import db




class PingCmd(Cmd):
    implements(ICmdArgumentsSyntax)
    command('ping')

    def arguments(self):

        parser = VirtualConsoleArgumentParser()