ankaios-sdk 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. ankaios_sdk-0.5.0/LICENSE +202 -0
  2. ankaios_sdk-0.5.0/MANIFEST.in +8 -0
  3. ankaios_sdk-0.5.0/PKG-INFO +187 -0
  4. ankaios_sdk-0.5.0/README.md +143 -0
  5. ankaios_sdk-0.5.0/ankaios_sdk/__init__.py +24 -0
  6. ankaios_sdk-0.5.0/ankaios_sdk/_components/__init__.py +44 -0
  7. ankaios_sdk-0.5.0/ankaios_sdk/_components/complete_state.py +317 -0
  8. ankaios_sdk-0.5.0/ankaios_sdk/_components/control_interface.py +392 -0
  9. ankaios_sdk-0.5.0/ankaios_sdk/_components/manifest.py +170 -0
  10. ankaios_sdk-0.5.0/ankaios_sdk/_components/request.py +183 -0
  11. ankaios_sdk-0.5.0/ankaios_sdk/_components/response.py +299 -0
  12. ankaios_sdk-0.5.0/ankaios_sdk/_components/workload.py +791 -0
  13. ankaios_sdk-0.5.0/ankaios_sdk/_components/workload_state.py +508 -0
  14. ankaios_sdk-0.5.0/ankaios_sdk/_protos/0.5.0/ank_base.proto +376 -0
  15. ankaios_sdk-0.5.0/ankaios_sdk/_protos/0.5.0/control_api.proto +65 -0
  16. ankaios_sdk-0.5.0/ankaios_sdk/_protos/__init__.py +34 -0
  17. ankaios_sdk-0.5.0/ankaios_sdk/_protos/ank_base_pb2.py +154 -0
  18. ankaios_sdk-0.5.0/ankaios_sdk/_protos/ank_base_pb2_grpc.py +24 -0
  19. ankaios_sdk-0.5.0/ankaios_sdk/_protos/control_api_pb2.py +43 -0
  20. ankaios_sdk-0.5.0/ankaios_sdk/_protos/control_api_pb2_grpc.py +24 -0
  21. ankaios_sdk-0.5.0/ankaios_sdk/ankaios.py +899 -0
  22. ankaios_sdk-0.5.0/ankaios_sdk/exceptions.py +87 -0
  23. ankaios_sdk-0.5.0/ankaios_sdk/utils.py +87 -0
  24. ankaios_sdk-0.5.0/ankaios_sdk.egg-info/PKG-INFO +187 -0
  25. ankaios_sdk-0.5.0/ankaios_sdk.egg-info/SOURCES.txt +89 -0
  26. ankaios_sdk-0.5.0/ankaios_sdk.egg-info/dependency_links.txt +1 -0
  27. ankaios_sdk-0.5.0/ankaios_sdk.egg-info/requires.txt +15 -0
  28. ankaios_sdk-0.5.0/ankaios_sdk.egg-info/top_level.txt +2 -0
  29. ankaios_sdk-0.5.0/pyproject.toml +3 -0
  30. ankaios_sdk-0.5.0/setup.cfg +33 -0
  31. ankaios_sdk-0.5.0/setup.py +148 -0
  32. ankaios_sdk-0.5.0/tests/__init__.py +13 -0
  33. ankaios_sdk-0.5.0/tests/response/__init__.py +13 -0
  34. ankaios_sdk-0.5.0/tests/response/test_response.py +125 -0
  35. ankaios_sdk-0.5.0/tests/response/test_response_event.py +41 -0
  36. ankaios_sdk-0.5.0/tests/response/test_update_state_success.py +60 -0
  37. ankaios_sdk-0.5.0/tests/test_ankaios.py +740 -0
  38. ankaios_sdk-0.5.0/tests/test_complete_state.py +288 -0
  39. ankaios_sdk-0.5.0/tests/test_control_interface.py +329 -0
  40. ankaios_sdk-0.5.0/tests/test_manifest.py +154 -0
  41. ankaios_sdk-0.5.0/tests/test_request.py +90 -0
  42. ankaios_sdk-0.5.0/tests/test_utils.py +35 -0
  43. ankaios_sdk-0.5.0/tests/workload/__init__.py +13 -0
  44. ankaios_sdk-0.5.0/tests/workload/test_workload.py +347 -0
  45. ankaios_sdk-0.5.0/tests/workload/test_workload_builder.py +208 -0
  46. ankaios_sdk-0.5.0/tests/workload_state/__init__.py +13 -0
  47. ankaios_sdk-0.5.0/tests/workload_state/test_workload_execution_state.py +54 -0
  48. ankaios_sdk-0.5.0/tests/workload_state/test_workload_instance_name.py +64 -0
  49. ankaios_sdk-0.5.0/tests/workload_state/test_workload_state.py +55 -0
  50. ankaios_sdk-0.5.0/tests/workload_state/test_workload_state_collection.py +142 -0
  51. ankaios_sdk-0.5.0/tests/workload_state/test_workload_state_enum.py +35 -0
  52. ankaios_sdk-0.5.0/tests/workload_state/test_workload_substate_enum.py +85 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,8 @@
1
+ # Include all .proto files in the _protos directory
2
+ recursive-include ankaios_sdk/_protos *.proto
3
+
4
+ # Include the README file
5
+ include README.md
6
+
7
+ # Include the license file
8
+ include LICENSE
@@ -0,0 +1,187 @@
1
+ Metadata-Version: 2.2
2
+ Name: ankaios-sdk
3
+ Version: 0.5.0
4
+ Summary: Eclipse Ankaios Python SDK - provides a convenient Python interface for interacting with the Ankaios platform.
5
+ Home-page: https://eclipse-ankaios.github.io/ankaios/latest/
6
+ Author: Elektrobit Automotive GmbH and Ankaios contributors
7
+ License: Apache-2.0
8
+ Project-URL: Documentation, https://eclipse-ankaios.github.io/ank-sdk-python/
9
+ Project-URL: Source, https://github.com/eclipse-ankaios/ank-sdk-python
10
+ Project-URL: Bug Tracker, https://github.com/eclipse-ankaios/ank-sdk-python/issues
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: protobuf==5.27.2
23
+ Requires-Dist: PyYAML
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest; extra == "dev"
26
+ Requires-Dist: pytest-cov; extra == "dev"
27
+ Requires-Dist: pylint; extra == "dev"
28
+ Requires-Dist: pycodestyle; extra == "dev"
29
+ Provides-Extra: docs
30
+ Requires-Dist: sphinx; extra == "docs"
31
+ Requires-Dist: sphinx-rtd-theme; extra == "docs"
32
+ Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
33
+ Requires-Dist: sphinx-mdinclude; extra == "docs"
34
+ Requires-Dist: google-api-python-client; extra == "docs"
35
+ Dynamic: classifier
36
+ Dynamic: description
37
+ Dynamic: description-content-type
38
+ Dynamic: home-page
39
+ Dynamic: project-url
40
+ Dynamic: provides-extra
41
+ Dynamic: requires-dist
42
+ Dynamic: requires-python
43
+ Dynamic: summary
44
+
45
+ <picture style="padding-bottom: 1em;">
46
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/eclipse-ankaios/ankaios/refs/heads/main/logo/Ankaios__logo_for_dark_bgrd_clipped.png">
47
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/eclipse-ankaios/ankaios/refs/heads/main/logo/Ankaios__logo_for_light_bgrd_clipped.png">
48
+ <img alt="Shows Ankaios logo" src="https://raw.githubusercontent.com/eclipse-ankaios/ankaios/refs/heads/main/logo/Ankaios__logo_for_light_bgrd_clipped.png">
49
+ </picture>
50
+
51
+ # Python SDK for Eclipse Ankaios
52
+
53
+ ![Build](https://github.com/eclipse-ankaios/ank-sdk-python/actions/workflows/build.yml/badge.svg?job=build)
54
+ ![PyPI - Version](https://img.shields.io/pypi/v/ankaios_sdk)
55
+ ![Python](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20|%203.13-blue)
56
+
57
+ ![License](https://img.shields.io/badge/license-Apache%202.0-blue)
58
+ [![Ankaios](https://img.shields.io/badge/main_project-repo-blue)](https://github.com/eclipse-ankaios/ankaios)
59
+ [![Slack](https://img.shields.io/badge/slack-join-blue?logo=slack)](https://join.slack.com/t/ankaios/shared_invite/zt-2inyhbehh-iVp3YZD09VIgybv8D1gDpQ)
60
+
61
+ [Eclipse Ankaios](https://github.com/eclipse-ankaios/ankaios) provides workload and container orchestration for automotive
62
+ High Performance Computers (HPCs). While it can be used for various fields of
63
+ applications, it is developed from scratch for automotive use cases and provides
64
+ a slim yet powerful solution to manage containerized applications.
65
+
66
+ The Python SDK provides easy access from the container (workload) point-of-view
67
+ to manage the Ankaios system. A workload can use the Python SDK to start, stop and
68
+ update other workloads and configs and get the state of the Ankaios system.
69
+
70
+ ## Installation
71
+
72
+ ### Install via pip
73
+
74
+ ```sh
75
+ pip install ankaios-sdk
76
+ ```
77
+
78
+ ### Clone and Local Build
79
+
80
+ ```sh
81
+ # Clone repository
82
+ git clone https://github.com/eclipse-ankaios/ank-sdk-python.git
83
+ cd ank-sdk-python
84
+
85
+ # Install in editable mode
86
+ pip install -e .
87
+
88
+ # If you plan on contributing or running tests locally
89
+ pip install -e ".[dev]"
90
+ ```
91
+
92
+ > **Note:**
93
+ > Depending on your Linux distribution, it could be that you need to create and activate a [virtual environment](https://docs.python.org/3/library/venv.html) to run the pip commands.
94
+
95
+ ## Compatibility
96
+
97
+ Please make sure the Python SDK is compatible with the version of Ankaios you are using. For information regarding versioning, please refer to this table:
98
+
99
+ | Ankaios | Python SDK |
100
+ | -------- | ------- |
101
+ | 0.4.x and below | No Python SDK available. Please update Ankaios. |
102
+ | 0.5.x | 0.5.x |
103
+
104
+ ## Usage
105
+
106
+ After installation, you can use the Ankaios SDK to configure and run workloads and request
107
+ the state of the Ankaios system and the connected agents.
108
+
109
+ The following example assumes that the code is running in a managed by
110
+ Ankaios workload with configured control interface access:
111
+
112
+ ```python
113
+ from ankaios_sdk import Workload, Ankaios, WorkloadStateEnum, AnkaiosException
114
+
115
+ # Create a new Ankaios object.
116
+ # The connection to the control interface is automatically done at this step.
117
+ # The Ankaios class supports context manager syntax:
118
+ with Ankaios() as ankaios:
119
+
120
+ # Create a new workload
121
+ workload = Workload.builder() \
122
+ .workload_name("dynamic_nginx") \
123
+ .agent_name("agent_A") \
124
+ .runtime("podman") \
125
+ .restart_policy("NEVER") \
126
+ .runtime_config("image: docker.io/library/nginx\ncommandOptions: [\"-p\", \"8080:80\"]") \
127
+ .build()
128
+
129
+ try:
130
+ # Run the workload
131
+ update_response = ankaios.apply_workload(workload)
132
+
133
+ # Get the WorkloadInstanceName to check later if the workload is running
134
+ workload_instance_name = update_response.added_workloads[0]
135
+
136
+ # Request the execution state based on the workload instance name
137
+ ret = ankaios.get_execution_state_for_instance_name(workload_instance_name)
138
+ if ret is not None:
139
+ print(f"State: {ret.state}, substate: {ret.substate}, info: {ret.additional_info}")
140
+
141
+ # Wait until the workload reaches the running state
142
+ try:
143
+ ankaios.wait_for_workload_to_reach_state(
144
+ workload_instance_name,
145
+ state=WorkloadStateEnum.RUNNING,
146
+ timeout=5
147
+ )
148
+ except TimeoutError:
149
+ print("Workload didn't reach the required state in time.")
150
+ else:
151
+ print("Workload reached the RUNNING state.")
152
+
153
+ # Catch the AnkaiosException in case something went wrong with apply_workload
154
+ except AnkaiosException as e:
155
+ print("Ankaios Exception occurred: ", e)
156
+
157
+ # Request the state of the system, filtered with the workloadStates
158
+ complete_state = ankaios.get_state(
159
+ timeout=5,
160
+ field_masks=["workloadStates"])
161
+
162
+ # Get the workload states present in the complete_state
163
+ workload_states_dict = complete_state.get_workload_states().get_as_dict()
164
+
165
+ # Print the states of the workloads:
166
+ for agent_name in workload_states_dict:
167
+ for workload_name in workload_states_dict[agent_name]:
168
+ for workload_id in workload_states_dict[agent_name][workload_name]:
169
+ print(f"Workload {workload_name} on agent {agent_name} has the state "
170
+ + str(workload_states_dict[agent_name] \
171
+ [workload_name][workload_id].state))
172
+ ```
173
+
174
+ For more details, please visit:
175
+ * [Ankaios documentation](https://eclipse-ankaios.github.io/ankaios/latest/)
176
+ * [Python SDK documentation](https://eclipse-ankaios.github.io/ank-sdk-python/)
177
+
178
+ Especially the Ankaios [fleet management tutorial](https://eclipse-ankaios.github.io/ankaios/latest/usage/tutorial-fleet-management/) gives a great overview on the usage of the SDK.
179
+
180
+ ## Contributing
181
+
182
+ This project welcomes contributions and suggestions. Before contributing, make sure to read the
183
+ [contribution guideline](https://github.com/eclipse-ankaios/ank-sdk-python/blob/main/CONTRIBUTING.md).
184
+
185
+ ## License
186
+
187
+ Ankaios Python SDK is licensed using the Apache License Version 2.0.
@@ -0,0 +1,143 @@
1
+ <picture style="padding-bottom: 1em;">
2
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/eclipse-ankaios/ankaios/refs/heads/main/logo/Ankaios__logo_for_dark_bgrd_clipped.png">
3
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/eclipse-ankaios/ankaios/refs/heads/main/logo/Ankaios__logo_for_light_bgrd_clipped.png">
4
+ <img alt="Shows Ankaios logo" src="https://raw.githubusercontent.com/eclipse-ankaios/ankaios/refs/heads/main/logo/Ankaios__logo_for_light_bgrd_clipped.png">
5
+ </picture>
6
+
7
+ # Python SDK for Eclipse Ankaios
8
+
9
+ ![Build](https://github.com/eclipse-ankaios/ank-sdk-python/actions/workflows/build.yml/badge.svg?job=build)
10
+ ![PyPI - Version](https://img.shields.io/pypi/v/ankaios_sdk)
11
+ ![Python](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20|%203.13-blue)
12
+
13
+ ![License](https://img.shields.io/badge/license-Apache%202.0-blue)
14
+ [![Ankaios](https://img.shields.io/badge/main_project-repo-blue)](https://github.com/eclipse-ankaios/ankaios)
15
+ [![Slack](https://img.shields.io/badge/slack-join-blue?logo=slack)](https://join.slack.com/t/ankaios/shared_invite/zt-2inyhbehh-iVp3YZD09VIgybv8D1gDpQ)
16
+
17
+ [Eclipse Ankaios](https://github.com/eclipse-ankaios/ankaios) provides workload and container orchestration for automotive
18
+ High Performance Computers (HPCs). While it can be used for various fields of
19
+ applications, it is developed from scratch for automotive use cases and provides
20
+ a slim yet powerful solution to manage containerized applications.
21
+
22
+ The Python SDK provides easy access from the container (workload) point-of-view
23
+ to manage the Ankaios system. A workload can use the Python SDK to start, stop and
24
+ update other workloads and configs and get the state of the Ankaios system.
25
+
26
+ ## Installation
27
+
28
+ ### Install via pip
29
+
30
+ ```sh
31
+ pip install ankaios-sdk
32
+ ```
33
+
34
+ ### Clone and Local Build
35
+
36
+ ```sh
37
+ # Clone repository
38
+ git clone https://github.com/eclipse-ankaios/ank-sdk-python.git
39
+ cd ank-sdk-python
40
+
41
+ # Install in editable mode
42
+ pip install -e .
43
+
44
+ # If you plan on contributing or running tests locally
45
+ pip install -e ".[dev]"
46
+ ```
47
+
48
+ > **Note:**
49
+ > Depending on your Linux distribution, it could be that you need to create and activate a [virtual environment](https://docs.python.org/3/library/venv.html) to run the pip commands.
50
+
51
+ ## Compatibility
52
+
53
+ Please make sure the Python SDK is compatible with the version of Ankaios you are using. For information regarding versioning, please refer to this table:
54
+
55
+ | Ankaios | Python SDK |
56
+ | -------- | ------- |
57
+ | 0.4.x and below | No Python SDK available. Please update Ankaios. |
58
+ | 0.5.x | 0.5.x |
59
+
60
+ ## Usage
61
+
62
+ After installation, you can use the Ankaios SDK to configure and run workloads and request
63
+ the state of the Ankaios system and the connected agents.
64
+
65
+ The following example assumes that the code is running in a managed by
66
+ Ankaios workload with configured control interface access:
67
+
68
+ ```python
69
+ from ankaios_sdk import Workload, Ankaios, WorkloadStateEnum, AnkaiosException
70
+
71
+ # Create a new Ankaios object.
72
+ # The connection to the control interface is automatically done at this step.
73
+ # The Ankaios class supports context manager syntax:
74
+ with Ankaios() as ankaios:
75
+
76
+ # Create a new workload
77
+ workload = Workload.builder() \
78
+ .workload_name("dynamic_nginx") \
79
+ .agent_name("agent_A") \
80
+ .runtime("podman") \
81
+ .restart_policy("NEVER") \
82
+ .runtime_config("image: docker.io/library/nginx\ncommandOptions: [\"-p\", \"8080:80\"]") \
83
+ .build()
84
+
85
+ try:
86
+ # Run the workload
87
+ update_response = ankaios.apply_workload(workload)
88
+
89
+ # Get the WorkloadInstanceName to check later if the workload is running
90
+ workload_instance_name = update_response.added_workloads[0]
91
+
92
+ # Request the execution state based on the workload instance name
93
+ ret = ankaios.get_execution_state_for_instance_name(workload_instance_name)
94
+ if ret is not None:
95
+ print(f"State: {ret.state}, substate: {ret.substate}, info: {ret.additional_info}")
96
+
97
+ # Wait until the workload reaches the running state
98
+ try:
99
+ ankaios.wait_for_workload_to_reach_state(
100
+ workload_instance_name,
101
+ state=WorkloadStateEnum.RUNNING,
102
+ timeout=5
103
+ )
104
+ except TimeoutError:
105
+ print("Workload didn't reach the required state in time.")
106
+ else:
107
+ print("Workload reached the RUNNING state.")
108
+
109
+ # Catch the AnkaiosException in case something went wrong with apply_workload
110
+ except AnkaiosException as e:
111
+ print("Ankaios Exception occurred: ", e)
112
+
113
+ # Request the state of the system, filtered with the workloadStates
114
+ complete_state = ankaios.get_state(
115
+ timeout=5,
116
+ field_masks=["workloadStates"])
117
+
118
+ # Get the workload states present in the complete_state
119
+ workload_states_dict = complete_state.get_workload_states().get_as_dict()
120
+
121
+ # Print the states of the workloads:
122
+ for agent_name in workload_states_dict:
123
+ for workload_name in workload_states_dict[agent_name]:
124
+ for workload_id in workload_states_dict[agent_name][workload_name]:
125
+ print(f"Workload {workload_name} on agent {agent_name} has the state "
126
+ + str(workload_states_dict[agent_name] \
127
+ [workload_name][workload_id].state))
128
+ ```
129
+
130
+ For more details, please visit:
131
+ * [Ankaios documentation](https://eclipse-ankaios.github.io/ankaios/latest/)
132
+ * [Python SDK documentation](https://eclipse-ankaios.github.io/ank-sdk-python/)
133
+
134
+ Especially the Ankaios [fleet management tutorial](https://eclipse-ankaios.github.io/ankaios/latest/usage/tutorial-fleet-management/) gives a great overview on the usage of the SDK.
135
+
136
+ ## Contributing
137
+
138
+ This project welcomes contributions and suggestions. Before contributing, make sure to read the
139
+ [contribution guideline](https://github.com/eclipse-ankaios/ank-sdk-python/blob/main/CONTRIBUTING.md).
140
+
141
+ ## License
142
+
143
+ Ankaios Python SDK is licensed using the Apache License Version 2.0.
@@ -0,0 +1,24 @@
1
+ # Copyright (c) 2024 Elektrobit Automotive GmbH
2
+ #
3
+ # This program and the accompanying materials are made available under the
4
+ # terms of the Apache License, Version 2.0 which is available at
5
+ # https://www.apache.org/licenses/LICENSE-2.0.
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+ # License for the specific language governing permissions and limitations
11
+ # under the License.
12
+ #
13
+ # SPDX-License-Identifier: Apache-2.0
14
+
15
+ """
16
+ Ankaios Python SDK main imports.
17
+ """
18
+
19
+ from .exceptions import *
20
+ from .ankaios import *
21
+ from ._components import *
22
+ from .utils import AnkaiosLogLevel
23
+
24
+ __all__ = [name for name in globals() if not name.startswith('_')]
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2024 Elektrobit Automotive GmbH
2
+ #
3
+ # This program and the accompanying materials are made available under the
4
+ # terms of the Apache License, Version 2.0 which is available at
5
+ # https://www.apache.org/licenses/LICENSE-2.0.
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+ # License for the specific language governing permissions and limitations
11
+ # under the License.
12
+ #
13
+ # SPDX-License-Identifier: Apache-2.0
14
+
15
+ """
16
+ This module initializes the ankaios_sdk package by importing all
17
+ necessary components.
18
+
19
+ Imports
20
+ -------
21
+
22
+ - Workload component:
23
+ responsible for defining the workload of the system.
24
+ - WorkloadState component:
25
+ responsible for accessing the state of the workload.
26
+ - CompleteState component:
27
+ responsible for accessing the complete state of the system.
28
+ - Request component:
29
+ responsible for defining a request to be sent to the system.
30
+ - Response component:
31
+ responsible for defining a response from the system.
32
+ - Manifest component:
33
+ responsible for defining a manifest object.
34
+ """
35
+
36
+ from .workload import *
37
+ from .workload_state import *
38
+ from .complete_state import *
39
+ from .request import *
40
+ from .response import *
41
+ from .manifest import *
42
+ from .control_interface import *
43
+
44
+ __all__ = [name for name in globals() if not name.startswith('_')]