Returns ``True`` if interface is enabled, otherwise ``False`` Args: iface (str): The name of the interface to manage CLI Example: .. code-block:: bash salt -G 'os_family:Windows' ip.is_enabled 'Local Area Connection #2'
(iface)
| 177 | |
| 178 | |
| 179 | def is_enabled(iface): |
| 180 | """ |
| 181 | Returns ``True`` if interface is enabled, otherwise ``False`` |
| 182 | |
| 183 | Args: |
| 184 | |
| 185 | iface (str): The name of the interface to manage |
| 186 | |
| 187 | CLI Example: |
| 188 | |
| 189 | .. code-block:: bash |
| 190 | |
| 191 | salt -G 'os_family:Windows' ip.is_enabled 'Local Area Connection #2' |
| 192 | """ |
| 193 | with salt.utils.win_pwsh.PowerShellSession() as session: |
| 194 | # Using SilentlyContinue ensures we get None/Empty if 'junk' is passed |
| 195 | cmd = f""" |
| 196 | [int](Get-NetAdapter -Name '{iface}' ` |
| 197 | -ErrorAction SilentlyContinue).AdminStatus |
| 198 | """ |
| 199 | status = session.run(cmd) |
| 200 | |
| 201 | try: |
| 202 | # Use 0 as a fallback for None to trigger your "not found" check |
| 203 | status = int(status if status is not None else 0) |
| 204 | except (ValueError, TypeError): |
| 205 | msg = f"Interface '{iface}' not found or invalid response." |
| 206 | raise CommandExecutionError(msg) |
| 207 | |
| 208 | if status == 0: |
| 209 | raise CommandExecutionError(f"Interface '{iface}' not found") |
| 210 | |
| 211 | return status == 1 # 1 is enabled |
| 212 | |
| 213 | |
| 214 | def is_disabled(iface): |
nothing calls this directly
no test coverage detected