Skip to content

Commit 2390532

Browse files
committed
feat: add support for new mitogen. Older version with patching is supported.
1 parent 6ffa2d8 commit 2390532

File tree

6 files changed

+391
-356
lines changed

6 files changed

+391
-356
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
This collection allows to use [Mitogen](https://github.com/mitogen-hq/mitogen)
44
strategy without the need to specify absolute path to the strategy file.
55

6-
It also performs live patching for Mitogen restrictions in Ansible
7-
versions, making it possible to use Mitogen with the current Ansible version.
6+
It also performs live patching for oler versions of Mitogen (3.4), removing
7+
Ansible version restrictions, making it possible to use Mitogen
8+
on unsupported versions.
89

910
Tested versions of ansible-core:
1011

1112
* 2.14
1213
* 2.15
1314
* 2.16
15+
* 2.17
1416

15-
It patches `ansible_mitogen` code and unpatches it
17+
When needed, it patches `ansible_mitogen` code and unpatches it
1618
back right after module import, so the original
1719
files are kept intact.
1820

21+
If no patching needed, it just passes mitogen content as it is.
22+
1923
## Install
2024
To use this collection, you need to install Mitogen:
2125

plugins/strategy/mitogen_free.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,17 @@
3131
# You should have received a copy of the GNU General Public License
3232
# along with this program. If not, see <https://www.gnu.org/licenses/>.
3333

34+
import importlib.metadata
3435

35-
from . import patching
36+
try:
37+
mitogen_version = importlib.metadata.version("mitogen")
38+
except importlib.metadata.PackageNotFoundError:
39+
raise ImportError("Unable to load mitogen module.")
3640

37-
with patching.patch_version():
41+
if mitogen_version == "0.3.4":
42+
from . import patching
43+
44+
with patching.patch_version():
45+
from ansible_mitogen.plugins.strategy.mitogen_free import *
46+
else:
3847
from ansible_mitogen.plugins.strategy.mitogen_free import *

plugins/strategy/mitogen_host_pinned.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@
1515
short_description: Mitogen patching strategy
1616
"""
1717

18-
from . import patching
18+
import importlib.metadata
1919

20-
with patching.patch_version():
20+
try:
21+
mitogen_version = importlib.metadata.version("mitogen")
22+
except importlib.metadata.PackageNotFoundError:
23+
raise ImportError("Unable to load mitogen module.")
24+
25+
if mitogen_version == "0.3.4":
26+
from . import patching
27+
28+
with patching.patch_version():
29+
from ansible_mitogen.plugins.strategy.mitogen_host_pinned import *
30+
else:
2131
from ansible_mitogen.plugins.strategy.mitogen_host_pinned import *

plugins/strategy/mitogen_linear.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@
1515
short_description: Mitogen patching strategy
1616
"""
1717

18-
from . import patching
18+
import importlib.metadata
1919

20-
with patching.patch_version():
20+
try:
21+
mitogen_version = importlib.metadata.version("mitogen")
22+
except importlib.metadata.PackageNotFoundError:
23+
raise ImportError("Unable to load mitogen module.")
24+
25+
if mitogen_version == "0.3.4":
26+
from . import patching
27+
28+
with patching.patch_version():
29+
from ansible_mitogen.plugins.strategy.mitogen_linear import *
30+
else:
2131
from ansible_mitogen.plugins.strategy.mitogen_linear import *

0 commit comments

Comments
 (0)