003 File Manager
Current Path:
/usr/local/lib/python3.8/site-packages/salt/runners
usr
/
local
/
lib
/
python3.8
/
site-packages
/
salt
/
runners
/
📁
..
📄
__init__.py
(26 B)
📁
__pycache__
📄
asam.py
(11.2 KB)
📄
auth.py
(1.69 KB)
📄
bgp.py
(17.5 KB)
📄
cache.py
(12.72 KB)
📄
cloud.py
(4.18 KB)
📄
config.py
(913 B)
📄
ddns.py
(8.89 KB)
📄
digicertapi.py
(21.63 KB)
📄
doc.py
(1.39 KB)
📄
drac.py
(5.29 KB)
📄
error.py
(545 B)
📄
event.py
(2.1 KB)
📄
f5.py
(9.58 KB)
📄
fileserver.py
(17.37 KB)
📄
git_pillar.py
(3.98 KB)
📄
http.py
(2.35 KB)
📄
jobs.py
(17.45 KB)
📄
launchd.py
(1.35 KB)
📄
lxc.py
(18.14 KB)
📄
manage.py
(25.84 KB)
📄
mattermost.py
(4.68 KB)
📄
mine.py
(1.68 KB)
📄
nacl.py
(8.15 KB)
📄
net.py
(38.97 KB)
📄
network.py
(2.42 KB)
📄
pagerduty.py
(4.5 KB)
📄
pillar.py
(5.14 KB)
📄
pkg.py
(1.35 KB)
📄
queue.py
(8.88 KB)
📄
reactor.py
(4.97 KB)
📄
salt.py
(4.69 KB)
📄
saltutil.py
(21.5 KB)
📄
sdb.py
(2.14 KB)
📄
smartos_vmadm.py
(11.73 KB)
📄
spacewalk.py
(9.8 KB)
📄
ssh.py
(771 B)
📄
state.py
(8.88 KB)
📄
survey.py
(5.84 KB)
📄
test.py
(1.75 KB)
📄
thin.py
(1.74 KB)
📄
vault.py
(10.09 KB)
📄
venafiapi.py
(6.68 KB)
📄
virt.py
(17.59 KB)
📄
vistara.py
(5.6 KB)
📄
winrepo.py
(8.57 KB)
Editing: network.py
""" Network tools to run from the Master """ import logging import socket import salt.utils.files import salt.utils.network import salt.utils.stringutils log = logging.getLogger(__name__) def wollist(maclist, bcast="255.255.255.255", destport=9): """ Send a "Magic Packet" to wake up a list of Minions. This list must contain one MAC hardware address per line CLI Example: .. code-block:: bash salt-run network.wollist '/path/to/maclist' salt-run network.wollist '/path/to/maclist' 255.255.255.255 7 salt-run network.wollist '/path/to/maclist' 255.255.255.255 7 """ ret = [] try: with salt.utils.files.fopen(maclist, "r") as ifile: for mac in ifile: mac = salt.utils.stringutils.to_unicode(mac).strip() wol(mac, bcast, destport) print("Waking up {}".format(mac)) ret.append(mac) except Exception as err: # pylint: disable=broad-except __jid_event__.fire_event( {"error": "Failed to open the MAC file. Error: {}".format(err)}, "progress" ) return [] return ret def wol(mac, bcast="255.255.255.255", destport=9): """ Send a "Magic Packet" to wake up a Minion CLI Example: .. code-block:: bash salt-run network.wol 08-00-27-13-69-77 salt-run network.wol 080027136977 255.255.255.255 7 salt-run network.wol 08:00:27:13:69:77 255.255.255.255 7 """ dest = salt.utils.network.mac_str_to_bytes(mac) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) sock.sendto(b"\xff" * 6 + dest * 16, (bcast, int(destport))) return True def wolmatch(tgt, tgt_type="glob", bcast="255.255.255.255", destport=9): """ Send a "Magic Packet" to wake up Minions that are matched in the grains cache CLI Example: .. code-block:: bash salt-run network.wolmatch minion_id salt-run network.wolmatch 192.168.0.0/16 tgt_type='ipcidr' bcast=255.255.255.255 destport=7 """ ret = [] minions = __salt__["cache.grains"](tgt, tgt_type) for minion in minions: for iface, mac in minions[minion]["hwaddr_interfaces"].items(): if iface == "lo": continue mac = mac.strip() wol(mac, bcast, destport) log.info("Waking up %s", mac) ret.append(mac) return ret
Upload File
Create Folder