MCPcopy
hub / github.com/saltstack/salt / connect

Function connect

salt/modules/network.py:1577–1674  ·  view source on GitHub ↗

Test connectivity to a host using a particular port from the minion. .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' network.connect archlinux.org 80 salt '*' network.connect archlinux.org 80 timeout=3 salt '*' network.connect

(host, port=None, **kwargs)

Source from the content-addressed store, hash-verified

1575
1576
1577def connect(host, port=None, **kwargs):
1578 """
1579 Test connectivity to a host using a particular
1580 port from the minion.
1581
1582 .. versionadded:: 2014.7.0
1583
1584 CLI Example:
1585
1586 .. code-block:: bash
1587
1588 salt '*' network.connect archlinux.org 80
1589
1590 salt '*' network.connect archlinux.org 80 timeout=3
1591
1592 salt '*' network.connect archlinux.org 80 timeout=3 family=ipv4
1593
1594 salt '*' network.connect google-public-dns-a.google.com port=53 proto=udp timeout=3
1595 """
1596
1597 ret = {"result": None, "comment": ""}
1598
1599 if not host:
1600 ret["result"] = False
1601 ret["comment"] = "Required argument, host, is missing."
1602 return ret
1603
1604 if not port:
1605 ret["result"] = False
1606 ret["comment"] = "Required argument, port, is missing."
1607 return ret
1608
1609 proto = kwargs.get("proto", "tcp")
1610 timeout = kwargs.get("timeout", 5)
1611 family = kwargs.get("family", None)
1612
1613 if salt.utils.validate.net.ipv4_addr(host) or salt.utils.validate.net.ipv6_addr(
1614 host
1615 ):
1616 address = host
1617 else:
1618 address = "{}".format(__utils__["network.sanitize_host"](host))
1619
1620 try:
1621 if proto == "udp":
1622 __proto = socket.SOL_UDP
1623 else:
1624 __proto = socket.SOL_TCP
1625 proto = "tcp"
1626
1627 if family:
1628 if family == "ipv4":
1629 __family = socket.AF_INET
1630 elif family == "ipv6":
1631 __family = socket.AF_INET6
1632 else:
1633 __family = 0
1634 else:

Callers 1

_spawn_syndicsMethod · 0.50

Calls 9

formatMethod · 0.80
nowMethod · 0.80
getMethod · 0.45
socketMethod · 0.45
updateMethod · 0.45
sendtoMethod · 0.45
closeMethod · 0.45
connectMethod · 0.45
shutdownMethod · 0.45

Tested by

no test coverage detected