003 File Manager
Current Path:
/usr/local/lib/python3.8/site-packages/salt/grains
usr
/
local
/
lib
/
python3.8
/
site-packages
/
salt
/
grains
/
📁
..
📄
__init__.py
(32 B)
📁
__pycache__
📄
chronos.py
(535 B)
📄
cimc.py
(635 B)
📄
core.py
(111.98 KB)
📄
disks.py
(5.62 KB)
📄
esxi.py
(2.52 KB)
📄
extra.py
(2.77 KB)
📄
fibre_channel.py
(1.76 KB)
📄
fx2.py
(3.06 KB)
📄
iscsi.py
(2.35 KB)
📄
junos.py
(1.51 KB)
📄
lvm.py
(1.43 KB)
📄
marathon.py
(928 B)
📄
mdadm.py
(800 B)
📄
mdata.py
(4.09 KB)
📄
metadata.py
(2.7 KB)
📄
minion_process.py
(988 B)
📄
napalm.py
(11.2 KB)
📄
nvme.py
(1.16 KB)
📄
nxos.py
(901 B)
📄
opts.py
(353 B)
📄
panos.py
(640 B)
📄
pending_reboot.py
(650 B)
📄
philips_hue.py
(1.03 KB)
📄
rest_sample.py
(1.03 KB)
📄
smartos.py
(6.32 KB)
📄
ssh_sample.py
(927 B)
📄
zfs.py
(2.13 KB)
Editing: metadata.py
""" Grains from cloud metadata servers at 169.254.169.254 .. versionadded:: 2017.7.0 :depends: requests To enable these grains that pull from the http://169.254.169.254/latest metadata server set `metadata_server_grains: True` in the minion config. .. code-block:: yaml metadata_server_grains: True """ import os import socket import salt.utils.data import salt.utils.http as http import salt.utils.json import salt.utils.stringutils # metadata server information IP = "169.254.169.254" HOST = "http://{}/".format(IP) def __virtual__(): if __opts__.get("metadata_server_grains", False) is False: return False sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(0.1) result = sock.connect_ex((IP, 80)) if result != 0: return False if http.query(os.path.join(HOST, "latest/"), status=True).get("status") != 200: return False return True def _search(prefix="latest/"): """ Recursively look up all grains in the metadata server """ ret = {} linedata = http.query(os.path.join(HOST, prefix), headers=True) if "body" not in linedata: return ret body = salt.utils.stringutils.to_unicode(linedata["body"]) if ( linedata["headers"].get("Content-Type", "text/plain") == "application/octet-stream" ): return body for line in body.split("\n"): if line.endswith("/"): ret[line[:-1]] = _search(prefix=os.path.join(prefix, line)) elif prefix == "latest/": # (gtmanfred) The first level should have a forward slash since # they have stuff underneath. This will not be doubled up though, # because lines ending with a slash are checked first. ret[line] = _search(prefix=os.path.join(prefix, line + "/")) elif line.endswith(("dynamic", "meta-data")): ret[line] = _search(prefix=os.path.join(prefix, line)) elif "=" in line: key, value = line.split("=") ret[value] = _search(prefix=os.path.join(prefix, key)) else: retdata = http.query(os.path.join(HOST, prefix, line)).get("body", None) # (gtmanfred) This try except block is slightly faster than # checking if the string starts with a curly brace if isinstance(retdata, bytes): try: ret[line] = salt.utils.json.loads( salt.utils.stringutils.to_unicode(retdata) ) except ValueError: ret[line] = salt.utils.stringutils.to_unicode(retdata) else: ret[line] = retdata return salt.utils.data.decode(ret) def metadata(): return _search()
Upload File
Create Folder