junos¶
JunOS module.
- class homer.transports.junos.ConnectedDevice(fqdn: str, *, username: str = '', ssh_config: str | None = None, port: int = 22, timeout: int = 30)[source]¶
Bases:
object
Juniper transport to manage a JunOS connected device.
Initialize the instance and open the connection to the device.
- Parameters:
fqdn (str) -- the FQDN of the Juniper device.
username (str) -- the username to use to connect to the Juniper device.
ssh_config (Optional[str]) -- an ssh_config file if you want other than ~/.ssh/config
port (int, optional) -- the port to use to connect to the device.
timeout (int, optional) -- the timeout in seconds to use when operating on the device.
- commit(config: str, message: str, callback: Callable, *, ignore_warning: bool | str | List[str] = False, is_retry: bool = False) None [source]¶
Commit the loaded configuration.
- Parameters:
config (str) -- the device new configuration.
message (str) -- the commit message to use.
callback (callable) -- a callable function that accepts two parameters: a string with the FQDN of the current device and a string with the diff between the current configuration and the new one. The callback must raise any exception if the execution should be interrupted and the config rollbacked or return
None
.ignore_warning (mixed, optional) -- the warnings to tell JunOS to ignore, see: https://junos-pyez.readthedocs.io/en/2.3.0/jnpr.junos.utils.html#jnpr.junos.utils.config.Config.load
is_retry (bool, optional) -- whether this is a retry and the commit_check should be run anyway, also if the diff is empty.
- Raises:
HomerTimeoutError -- on timeout.
HomerError -- on commit error.
Exception -- on generic failure.
- commit_check(config: str, ignore_warning: bool | str | List[str] = False) Tuple[bool, str | None] [source]¶
Perform commit check, reuturn the diff and rollback.
- Parameters:
config (str) -- the device new configuration.
- Returns:
a two-element tuple with a boolean as first item that is
True
on success andFalse
on failure and a string as second item with the difference between the current configuration and the new one, empty string on no diff andNone
on failure.- Return type:
- homer.transports.junos.color_diff(diff: str) str [source]¶
Color the diff based on JunOS diff syntax.
- homer.transports.junos.connected_device(fqdn: str, *, username: str = '', ssh_config: str | None = None, port: int = 22, timeout: int = 30) Iterator[ConnectedDevice] [source]¶
Context manager to perform actions on a connected Juniper device.
- Parameters:
fqdn (str) -- the FQDN of the Juniper device.
username (str) -- the username to use to connect to the Juniper device.
ssh_config (Optional[str]) -- an ssh_config file if you want other than ~/.ssh/config
port (int, optional) -- the port to use to connect to the device.
timeout (int, optional) -- the timeout in seconds to use when operating on the device.
- Yields:
ConnectedDevice -- the Juniper connected device instance.