Debian Codegraph @

ansible_collections/cisco/ios/plugins/modules/ios_ping.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2022 Red Hat
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9
10 __metaclass__ = type
11
12 DOCUMENTATION = """
13 module: ios_ping
14 short_description: Tests reachability using ping from IOS switch.
15 description:
16 - Tests reachability using ping from switch to a remote destination.
17 - For a general purpose network module, see the L(net_ping,https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/net_ping_module.html)
18 module.
19 - For Windows targets, use the L(win_ping,https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_ping_module.html)
20 module instead.
21 - For targets running Python, use the L(ping,https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ping_module.html)
22 module instead.
23 version_added: 1.0.0
24 author:
25 - Jacob McGill (@jmcgill298)
26 - Sagar Paul (@KB-perByte)
27 options:
28 count:
29 description:
30 - Number of packets to send.
31 type: int
32 afi:
33 description:
34 - Define echo type ip or ipv6.
35 choices:
36 - ip
37 - ipv6
38 default: ip
39 type: str
40 dest:
41 description:
42 - The IP Address or hostname (resolvable by switch) of the remote node.
43 required: true
44 type: str
45 df_bit:
46 description:
47 - Set the DF bit.
48 default: false
49 type: bool
50 source:
51 description:
52 - The source IP Address.
53 type: str
54 size:
55 description:
56 - Size of the packet to send.
57 type: int
58 egress:
59 description:
60 - Force egress interface bypassing routing.
61 type: str
62 ingress:
63 description:
64 - LAN source interface for Ingress.
65 type: str
66 timeout:
67 description:
68 - specify timeout interval.
69 type: int
70 state:
71 description:
72 - Determines if the expected result is success or fail.
73 choices:
74 - absent
75 - present
76 default: present
77 type: str
78 vrf:
79 description:
80 - The VRF to use for forwarding.
81 type: str
82 notes:
83 - Tested against Cisco IOSXE Version 17.3 on CML.
84 - For a general purpose network module, see the L(net_ping,https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/net_ping_module.html)
85 module.
86 - For Windows targets, use the L(win_ping,https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_ping_module.html)
87 module instead.
88 - For targets running Python, use the L(ping,https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ping_module.html) module instead.
89 """
90
91 EXAMPLES = """
92 - name: Test reachability to 198.51.100.251 using default vrf
93 cisco.ios.ios_ping:
94 dest: 198.51.100.251
95
96 - name: Test reachability to 198.51.100.252 using prod vrf
97 cisco.ios.ios_ping:
98 dest: 198.51.100.252
99 vrf: prod
100 afi: ip
101
102 - name: Test un reachability to 198.51.100.253 using default vrf
103 cisco.ios.ios_ping:
104 dest: 198.51.100.253
105 state: absent
106
107 - name: Test reachability to 198.51.100.250 using prod vrf and setting count and source
108 cisco.ios.ios_ping:
109 dest: 198.51.100.250
110 source: loopback0
111 vrf: prod
112 count: 20
113
114 - name: Test reachability to 198.51.100.249 using df-bit and size
115 cisco.ios.ios_ping:
116 dest: 198.51.100.249
117 df_bit: true
118 size: 1400
119
120 - name: Test reachability to ipv6 address
121 cisco.ios.ios_ping:
122 dest: 2001:db8:ffff:ffff:ffff:ffff:ffff:ffff
123 afi: ipv6
124 """
125
126 RETURN = """
127 commands:
128 description: Show the command sent.
129 returned: always
130 type: list
131 sample: ["ping vrf prod 198.51.100.251 count 20 source loopback0"]
132 packet_loss:
133 description: Percentage of packets lost.
134 returned: always
135 type: str
136 sample: "0%"
137 packets_rx:
138 description: Packets successfully received.
139 returned: always
140 type: int
141 sample: 20
142 packets_tx:
143 description: Packets successfully transmitted.
144 returned: always
145 type: int
146 sample: 20
147 rtt:
148 description: Show RTT stats.
149 returned: always
150 type: dict
151 sample: {"avg": 2, "max": 8, "min": 1}
152 """
153
154 from ansible.module_utils.basic import AnsibleModule
155
156 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.ping.ping import (
157 PingArgs,
158 )
159 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.ping.ping import Ping
160
161
162 def main():
163 """
164 Main entry point for module execution
165
166 :returns: the result form module invocation
167 """
168 module = AnsibleModule(argument_spec=PingArgs.argument_spec)
169
170 result = Ping(module).execute_module()
171 module.exit_json(**result)
172
173
174 if __name__ == "__main__":
175 main()