Metadata Watchers¶
- class linode_metadata.watcher.MetadataWatcher(client: MetadataClient, default_poll_interval: timedelta | float | int = datetime.timedelta(seconds=60), debug: bool = False)¶
The constructor of the metadata watcher.
- Parameters:
client (MetadataClient) – The metadata client object.
default_poll_interval (Optional[Union[timedelta, float, int]]) – The default time interval for polling Linode metadata services. Defaults to 1 minute.
debug (bool) – Enables debug mode if set to True.
- poll(poller: Callable[[], NetworkResponse | InstanceResponse | SSHKeysResponse], poll_interval: timedelta | float | int | None = None, ignore_error: bool = False)¶
Continuously polling from Linode metadata services via the callable and yields a response when it differs from the last response.
- Parameters:
poller (Callable) – The callable that polls from Linode metadata services.
poll_interval (Optional[Union[timedelta, float, int]]) – The default time interval between polls of the linode metadata. Defaults to default_poll_interval setting of the watcher.
ignore_error (bool) – Whether to ignore the exception happen during the call to the metadata service. If it is set to True, it will print the exception with traceback when it occurs, and if set to False, it will raise the exception instead. Default to False.
- Returns:
A generator that yields next available response from linode metadata service.
- Return type:
Generator
- watch_instance(poll_interval: timedelta | float | int | None = None, ignore_error: bool = False) Generator[InstanceResponse, None, None]¶
Watches the instance changes. The new instance information will be yielded at the beginning of the iterating or when there is a change happened to the instance.
- Parameters:
poll_interval (Optional[Union[timedelta, float, int]]) – The default time interval for polling the instance info endpoint of the Linode metadata services. Defaults to default_poll_interval setting of the watcher instance.
ignore_error (bool) – Whether to ignore the exception happen during the call to the metadata service. If it is set to True, it will print the exception with traceback when it occurs, and if set to False, it will raise the exception instead. Default to False.
- Returns:
A generator that yields next available instance info.
- Return type:
Generator[InstanceResponse, None, None]
- watch_network(poll_interval: timedelta | float | int | None = None, ignore_error: bool = False) Generator[NetworkResponse, None, None]¶
Watches the network changes. The new networking information will be yielded at the beginning of the iterating or when there is a change happened to the networking environment.
- Parameters:
poll_interval (Optional[Union[timedelta, float, int]]) – The time interval between two polls of the networking info endpoint of the Linode metadata services. Defaults to default_poll_interval setting of the watcher instance.
ignore_error (bool) – Whether to ignore the exception happen during the call to the metadata service. If it is set to True, it will print the exception with traceback when it occurs, and if set to False, it will raise the exception instead. Default to False.
- Returns:
A generator that yields next available networking info.
- Return type:
Generator[NetworkResponse, None, None]
- watch_ssh_keys(poll_interval: timedelta | float | int | None = None, ignore_error: bool = False) Generator[SSHKeysResponse, None, None]¶
Watches the ssh keys changes. The new ssh keys information will be yielded at the beginning of the iterating or when there is a change happened to the ssh keys.
- Parameters:
poll_interval (Optional[Union[timedelta, float, int]]) – The default time interval for polling the ssh keys info endpoint of the Linode metadata services. Defaults to default_poll_interval setting of the watcher instance.
ignore_error (bool) – Whether to ignore the exception happen during the call to the metadata service. If it is set to True, it will print the exception with traceback when it occurs, and if set to False, it will raise the exception instead. Default to False.
- Returns:
A generator that yields next available ssh keys info.
- Return type:
Generator[SSHKeysResponse, None, None]
- class linode_metadata.watcher.AsyncMetadataWatcher(client: AsyncMetadataClient, default_poll_interval: timedelta | float | int = datetime.timedelta(seconds=60), debug: bool = False)¶
The constructor of the base metadata watcher. This should not be used directly by the end users.
- Parameters:
default_poll_interval (Optional[Union[timedelta, float, int]]) – The default time interval for polling Linode metadata services. Defaults to 1 minute.
debug (bool) – Enables debug mode if set to True.
- async poll(poller: Callable[[], Awaitable[NetworkResponse] | Awaitable[InstanceResponse] | Awaitable[SSHKeysResponse]], poll_interval: timedelta | float | int | None = None, ignore_error: bool = False)¶
Continuously and asynchronously polling from Linode metadata services via the provided callable and yields a response when it differs from the last response.
- Parameters:
poller (Callable) – The callable that polls from Linode metadata services.
poll_interval (Optional[Union[timedelta, float, int]]) – The default time interval between polls of the linode metadata. Defaults to default_poll_interval setting of the watcher.
ignore_error (bool) – Whether to ignore the exception happen during the call to the metadata service. If it is set to True, it will print the exception with traceback when it occurs, and if set to False, it will raise the exception instead. Default to False.
- Returns:
A generator that yields next available response from linode metadata service.
- Return type:
AsyncGenerator
- async watch_instance(poll_interval: timedelta | float | int | None = None, ignore_error: bool = False) AsyncGenerator[InstanceResponse, None]¶
Watches the instance changes. The new instance information will be yielded asynchronously at the beginning of the iterating or when there is a change happened to the instance.
- Parameters:
poll_interval (Optional[Union[timedelta, float, int]]) – The default time interval for polling the instance info endpoint of the Linode metadata services. Defaults to default_poll_interval setting of the watcher instance.
ignore_error (bool) – Whether to ignore the exception happen during the call to the metadata service. If it is set to True, it will print the exception with traceback when it occurs, and if set to False, it will raise the exception instead. Default to False.
- Returns:
A generator that asynchronously yields next available instance info.
- Return type:
AsyncGenerator[InstanceResponse, None]
- async watch_network(poll_interval: timedelta | float | int | None = None, ignore_error: bool = False) AsyncGenerator[NetworkResponse, None]¶
Watches the network changes. The new networking information will be yielded asynchronously at the beginning of the iterating or when there is a change happened to the networking environment.
- Parameters:
poll_interval (Optional[Union[timedelta, float, int]]) – The time interval between two polls of the networking info endpoint of the Linode metadata services. Defaults to default_poll_interval setting of the watcher instance.
ignore_error (bool) – Whether to ignore the exception happen during the call to the metadata service. If it is set to True, it will print the exception with traceback when it occurs, and if set to False, it will raise the exception instead. Default to False.
- Returns:
A generator that asynchronously yields next available networking info.
- Return type:
AsyncGenerator[NetworkResponse, None]
- async watch_ssh_keys(poll_interval: timedelta | float | int | None = None, ignore_error: bool = False) AsyncGenerator[SSHKeysResponse, None]¶
Watches the ssh keys changes. The new ssh keys information will be yielded asynchronously at the beginning of the iterating or when there is a change happened to the ssh keys.
- Parameters:
poll_interval (Optional[Union[timedelta, float, int]]) – The default time interval for polling the ssh keys info endpoint of the Linode metadata services. Defaults to default_poll_interval setting of the watcher instance.
ignore_error (bool) – Whether to ignore the exception happen during the call to the metadata service. If it is set to True, it will print the exception with traceback when it occurs, and if set to False, it will raise the exception instead. Default to False.
- Returns:
A generator that asynchronously yields next available ssh keys info.
- Return type:
AsyncGenerator[SSHKeysResponse, None]