web: hosts: Add WOL sender endpoint
parent
491b8ed491
commit
e5315a6792
|
@ -83,6 +83,7 @@ class Application(milla.Application):
|
|||
|
||||
r.add_route('/', hosts.HostListController())
|
||||
r.add_route('/api-doc', swagger.SwaggerController())
|
||||
r.add_route('/{host_id}/wake', hosts.WakeController())
|
||||
r.add_route('/{host_id}', hosts.HostController())
|
||||
|
||||
def make_request(self, environ):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
from . import controllers, model
|
||||
from .. import host
|
||||
import logging
|
||||
import milla
|
||||
import six
|
||||
|
@ -61,7 +62,7 @@ class HostListController(controllers.BaseController):
|
|||
return response
|
||||
|
||||
|
||||
class HostController(controllers.BaseController):
|
||||
class HostMixin(object):
|
||||
|
||||
@staticmethod
|
||||
def get_host(db, host_id):
|
||||
|
@ -74,6 +75,9 @@ class HostController(controllers.BaseController):
|
|||
raise milla.HTTPNotFound
|
||||
return host
|
||||
|
||||
|
||||
class HostController(controllers.BaseController, HostMixin):
|
||||
|
||||
def GET(self, request, host_id):
|
||||
host = self.get_host(request.db, host_id)
|
||||
|
||||
|
@ -110,3 +114,17 @@ class HostController(controllers.BaseController):
|
|||
response = request.ResponseClass()
|
||||
response.status_int = milla.HTTPNoContent.code
|
||||
return response
|
||||
|
||||
|
||||
class WakeController(controllers.BaseController, HostMixin):
|
||||
|
||||
def POST(self, request, host_id):
|
||||
h = self.get_host(request.db, host_id)
|
||||
|
||||
m = host.MagicPacket(h.macaddr)
|
||||
log.debug('Sending WOL magic packet to {}'.format(m.macaddr))
|
||||
m.send()
|
||||
|
||||
response = request.ResponseClass()
|
||||
response.status_int = milla.HTTPNoContent.code
|
||||
return response
|
||||
|
|
|
@ -100,6 +100,17 @@ paths:
|
|||
description: Host not found
|
||||
tags:
|
||||
- hosts
|
||||
/{host_id}/wake:
|
||||
post:
|
||||
description: >-
|
||||
Send Wake-on-LAN magic packet to a host
|
||||
parameters:
|
||||
- $ref: '#/parameters/host_id'
|
||||
responses:
|
||||
204:
|
||||
description: 'Magic packet sent'
|
||||
tags:
|
||||
- hosts
|
||||
parameters:
|
||||
host_id:
|
||||
name: host_id
|
||||
|
|
Loading…
Reference in New Issue