MCPcopy Create free account
hub / github.com/saltstack/salt / is_enabled

Function is_enabled

salt/modules/win_ip.py:179–211  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

177
178
179def 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
214def is_disabled(iface):

Callers

nothing calls this directly

Calls 2

runMethod · 0.45

Tested by

no test coverage detected