def _send_magic_packets(task, dest_host, dest_port):
"""Create and send magic packets.
Creates and sends a magic packet for each MAC address registered in
the Node.
:param task: a TaskManager instance containing the node to act on.
:param dest_host: The broadcast to this IP address.
:param dest_port: The destination port.
:raises: WOLOperationError if an error occur when connecting to the
host or sending the magic packets
"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
with contextlib.closing(s) as sock:
for port in task.ports:
address = port.address.replace(':', '')
# TODO(lucasagomes): Implement sending the magic packets with
# SecureON password feature. If your NIC is capable of, you can
# set the password of your SecureON using the ethtool utility.
data = 'FFFFFFFFFFFF' + (address * 16)
packet = bytearray.fromhex(data)
try:
sock.sendto(packet, (dest_host, dest_port))
except socket.error as e:
msg = (_("Failed to send Wake-On-Lan magic packets to "
"node %(node)s port %(port)s. Error: %(error)s") %
{'node': task.node.uuid, 'port': port.address,
'error': e})
LOG.exception(msg)
raise exception.WOLOperationError(msg)
# let's not flood the network with broadcast packets
time.sleep(0.5)
评论列表
文章目录