add option required for metadata server grains

This commit is contained in:
Daniel Wallace 2016-11-16 15:36:51 -06:00
parent f12af379ec
commit 7b946e5fb9
3 changed files with 18 additions and 1 deletions

View file

@ -19,6 +19,7 @@ grains modules
junos
marathon
mdadm
metadata
napalm
opts
philips_hue

View file

@ -0,0 +1,6 @@
=================
salt.grains.metadata
=================
.. automodule:: salt.grains.metadata
:members:

View file

@ -5,6 +5,14 @@ Grains from cloud metadata servers at 169.254.169.254
.. versionadded:: Nitrogen
:depends: requests
To enable these grains that pull from the http://169.254.169.254/latest
metadata server set `metadata_server_grains: True`.
.. code-block:: yaml
metadata_server_grains: True
'''
from __future__ import absolute_import
@ -22,8 +30,10 @@ HOST = 'http://{0}/'.format(IP)
def __virtual__():
if __salt__['config.get']('metadata_server_grains', False) is False:
return False
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
sock.settimeout(.1)
result = sock.connect_ex((IP, 80))
if result != 0:
return False