Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
uuids = request.get_json()['uuids']
hosts_data = Hosts\
.select(Hosts.uuid, Hosts.computer_fqdn, Hosts.mac_addresses, Hosts.wapt_status, Hosts.host_info)\
.where(Hosts.uuid.in_(uuids))\
.dicts()
result = []
for host in hosts_data:
macs = host['mac_addresses']
msg = u''
if macs:
logger.debug(
_('Sending magic wakeonlan packets to {} for machine {}').format(
macs,
host['computer_fqdn']
))
wakeonlan.wol.send_magic_packet(*macs)
for line in host['host_info']['networking']:
if 'broadcast' in line:
broadcast = line['broadcast']
wakeonlan.wol.send_magic_packet(
*
macs,
ip_address='%s' %
broadcast)
result.append(dict(uuid=host['uuid'], computer_fqdn=host['computer_fqdn'], mac_addresses=host['mac_addresses']))
msg = _(u'Wakeonlan packets sent to {} machines.').format(len(result))
result = result
return make_response(result,
msg=msg,
success=True)
except Exception as e:
logger.debug(traceback.format_exc())
uuids = request.get_json()['uuids']
hosts_data = Hosts\
.select(Hosts.uuid, Hosts.computer_fqdn, Hosts.mac_addresses, Hosts.wapt_status, Hosts.host_info)\
.where(Hosts.uuid.in_(uuids))\
.dicts()
result = []
for host in hosts_data:
macs = host['mac_addresses']
msg = u''
if macs:
logger.debug(
_('Sending magic wakeonlan packets to {} for machine {}').format(
macs,
host['computer_fqdn']
))
wakeonlan.wol.send_magic_packet(*macs)
for line in host['host_info']['networking']:
if 'broadcast' in line:
broadcast = line['broadcast']
wakeonlan.wol.send_magic_packet(
*
macs,
ip_address='%s' %
broadcast)
result.append(dict(uuid=host['uuid'], computer_fqdn=host['computer_fqdn'], mac_addresses=host['mac_addresses']))
msg = _(u'Wakeonlan packets sent to {} machines.').format(len(result))
result = result
return make_response(result,
msg=msg,
success=True)
except Exception as e:
return make_response_from_exception(e)
def wake_on_lan(self, hostname):
"""Start a machine that's currently shutdown."""
if hostname in self.fog_machines:
macaddr, download = self.fog_machines[hostname]
wakeonlan.wol.send_magic_packet(macaddr)
self.mac_address = kwargs.get('mac_address', None)
self.broadcast_address = kwargs.get('broadcast_address', '255.255.255.255')
self.port = kwargs.get('port', 9)
# check parameters
if self._is_parameters_ok():
# convert to unicode for testing
broadcast_address_unicode = self.broadcast_address.decode('utf-8')
# check the ip address is a valid one
ipaddress.ip_address(broadcast_address_unicode)
logger.debug("Call Wake_on_lan_neuron with parameters: mac_address: %s, broadcast_address: %s, port: %s"
% (self.mac_address, self.broadcast_address, self.port))
# send the magic packet, the mac address format will be check by the lib
wol.send_magic_packet(self.mac_address, ip_address=self.broadcast_address, port=self.port)
.dicts()
result = []
for host in hosts_data:
macs = host['mac_addresses']
msg = u''
if macs:
logger.debug(
_('Sending magic wakeonlan packets to {} for machine {}').format(
macs,
host['computer_fqdn']
))
wakeonlan.wol.send_magic_packet(*macs)
for line in host['host_info']['networking']:
if 'broadcast' in line:
broadcast = line['broadcast']
wakeonlan.wol.send_magic_packet(
*
macs,
ip_address='%s' %
broadcast)
result.append(dict(uuid=host['uuid'], computer_fqdn=host['computer_fqdn'], mac_addresses=host['mac_addresses']))
msg = _(u'Wakeonlan packets sent to {} machines.').format(len(result))
result = result
return make_response(result,
msg=msg,
success=True)
except Exception as e:
logger.debug(traceback.format_exc())
logger.critical('trigger_wakeonlan failed %s' % (repr(e)))
return make_response_from_exception(e)
.dicts()
result = []
for host in hosts_data:
macs = host['mac_addresses']
msg = u''
if macs:
logger.debug(
_('Sending magic wakeonlan packets to {} for machine {}').format(
macs,
host['computer_fqdn']
))
wakeonlan.wol.send_magic_packet(*macs)
for line in host['host_info']['networking']:
if 'broadcast' in line:
broadcast = line['broadcast']
wakeonlan.wol.send_magic_packet(
*
macs,
ip_address='%s' %
broadcast)
result.append(dict(uuid=host['uuid'], computer_fqdn=host['computer_fqdn'], mac_addresses=host['mac_addresses']))
msg = _(u'Wakeonlan packets sent to {} machines.').format(len(result))
result = result
return make_response(result,
msg=msg,
success=True)
except Exception as e:
return make_response_from_exception(e)