Test connectivity to a host using a particular port from the minion. .. versionadded:: 2016.3.0 Args: host (str): The host to connect to port (:obj:`int`, optional): The port to connect to Default is ``None``. CLI Example: .. co
(host, port=None, **kwargs)
| 506 | |
| 507 | |
| 508 | def connect(host, port=None, **kwargs): |
| 509 | """ |
| 510 | Test connectivity to a host using a particular |
| 511 | port from the minion. |
| 512 | |
| 513 | .. versionadded:: 2016.3.0 |
| 514 | |
| 515 | Args: |
| 516 | |
| 517 | host (str): The host to connect to |
| 518 | |
| 519 | port (:obj:`int`, optional): |
| 520 | The port to connect to |
| 521 | |
| 522 | Default is ``None``. |
| 523 | |
| 524 | CLI Example: |
| 525 | |
| 526 | .. code-block:: bash |
| 527 | |
| 528 | salt '*' network.connect archlinux.org 80 |
| 529 | |
| 530 | salt '*' network.connect archlinux.org 80 timeout=3 |
| 531 | |
| 532 | salt '*' network.connect archlinux.org 80 timeout=3 family=ipv4 |
| 533 | |
| 534 | salt '*' network.connect google-public-dns-a.google.com port=53 proto=udp timeout=3 |
| 535 | """ |
| 536 | |
| 537 | ret = {"result": None, "comment": ""} |
| 538 | |
| 539 | if not host: |
| 540 | ret["result"] = False |
| 541 | ret["comment"] = "Required argument, host, is missing." |
| 542 | return ret |
| 543 | |
| 544 | if not port: |
| 545 | ret["result"] = False |
| 546 | ret["comment"] = "Required argument, port, is missing." |
| 547 | return ret |
| 548 | |
| 549 | proto = kwargs.get("proto", "tcp") |
| 550 | timeout = kwargs.get("timeout", 5) |
| 551 | family = kwargs.get("family", None) |
| 552 | |
| 553 | if salt.utils.validate.net.ipv4_addr(host) or salt.utils.validate.net.ipv6_addr( |
| 554 | host |
| 555 | ): |
| 556 | address = host |
| 557 | else: |
| 558 | address = f"{salt.utils.network.sanitize_host(host)}" |
| 559 | |
| 560 | # just in case we encounter error on getaddrinfo |
| 561 | _address = ("unknown",) |
| 562 | |
| 563 | try: |
| 564 | if proto == "udp": |
| 565 | __proto = socket.SOL_UDP |