Py4HEAppE 1.0.0__py3-none-any.whl

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 (183) hide show
  1. __init__.py +1 -0
  2. py4heappe/__init__.py +1 -0
  3. py4heappe/cli/__init__.py +1 -0
  4. py4heappe/cli/auth.py +153 -0
  5. py4heappe/cli/command_template.py +370 -0
  6. py4heappe/cli/configuration.py +65 -0
  7. py4heappe/cli/information.py +163 -0
  8. py4heappe/cli/job_management.py +211 -0
  9. py4heappe/cli/report.py +173 -0
  10. py4heappe/core/__init__.py +167 -0
  11. py4heappe/core/api/__init__.py +12 -0
  12. py4heappe/core/api/cluster_information_api.py +308 -0
  13. py4heappe/core/api/data_transfer_api.py +405 -0
  14. py4heappe/core/api/file_transfer_api.py +498 -0
  15. py4heappe/core/api/job_management_api.py +866 -0
  16. py4heappe/core/api/job_reporting_api.py +692 -0
  17. py4heappe/core/api/management_api.py +2540 -0
  18. py4heappe/core/api/user_and_limitation_management_api.py +676 -0
  19. py4heappe/core/api_client.py +632 -0
  20. py4heappe/core/base/__init__.py +1 -0
  21. py4heappe/core/base/exceptions.py +41 -0
  22. py4heappe/core/base/logger.py +11 -0
  23. py4heappe/core/base/utils.py +43 -0
  24. py4heappe/core/configuration.py +247 -0
  25. py4heappe/core/models/__init__.py +155 -0
  26. py4heappe/core/models/adaptor_user.py +398 -0
  27. py4heappe/core/models/adaptor_user_group.py +268 -0
  28. py4heappe/core/models/adaptor_user_role.py +242 -0
  29. py4heappe/core/models/adaptor_user_role_ext.py +138 -0
  30. py4heappe/core/models/adaptor_user_role_type.py +95 -0
  31. py4heappe/core/models/adaptor_user_type.py +91 -0
  32. py4heappe/core/models/adaptor_user_user_group_role.py +320 -0
  33. py4heappe/core/models/allocated_nodes_ips_model.py +136 -0
  34. py4heappe/core/models/authenticate_lexis_token_model.py +110 -0
  35. py4heappe/core/models/authenticate_user_digital_signature_model.py +110 -0
  36. py4heappe/core/models/authenticate_user_open_id_model.py +110 -0
  37. py4heappe/core/models/authenticate_user_open_id_open_stack_model.py +136 -0
  38. py4heappe/core/models/authenticate_user_password_model.py +110 -0
  39. py4heappe/core/models/authentication_credentials.py +110 -0
  40. py4heappe/core/models/bad_request_result.py +110 -0
  41. py4heappe/core/models/cancel_job_model.py +136 -0
  42. py4heappe/core/models/cluster.py +478 -0
  43. py4heappe/core/models/cluster_authentication_credentials.py +375 -0
  44. py4heappe/core/models/cluster_authentication_credentials_auth_type.py +97 -0
  45. py4heappe/core/models/cluster_connection_protocol.py +91 -0
  46. py4heappe/core/models/cluster_detailed_report_ext.py +214 -0
  47. py4heappe/core/models/cluster_ext.py +188 -0
  48. py4heappe/core/models/cluster_init_report_ext.py +136 -0
  49. py4heappe/core/models/cluster_node_type.py +528 -0
  50. py4heappe/core/models/cluster_node_type_detailed_report_ext.py +240 -0
  51. py4heappe/core/models/cluster_node_type_ext.py +292 -0
  52. py4heappe/core/models/cluster_node_type_for_task_ext.py +188 -0
  53. py4heappe/core/models/cluster_node_type_report_ext.py +214 -0
  54. py4heappe/core/models/cluster_node_type_requested_group.py +136 -0
  55. py4heappe/core/models/cluster_node_type_resource_usage_ext.py +292 -0
  56. py4heappe/core/models/cluster_node_usage_ext.py +318 -0
  57. py4heappe/core/models/cluster_project.py +347 -0
  58. py4heappe/core/models/cluster_project_credential.py +294 -0
  59. py4heappe/core/models/cluster_proxy_connection.py +243 -0
  60. py4heappe/core/models/cluster_proxy_connection_ext.py +214 -0
  61. py4heappe/core/models/cluster_report_ext.py +215 -0
  62. py4heappe/core/models/command_template.py +557 -0
  63. py4heappe/core/models/command_template_ext.py +240 -0
  64. py4heappe/core/models/command_template_parameter.py +347 -0
  65. py4heappe/core/models/command_template_parameter_ext.py +136 -0
  66. py4heappe/core/models/command_template_parameter_value_ext.py +136 -0
  67. py4heappe/core/models/contact.py +269 -0
  68. py4heappe/core/models/copy_job_data_from_temp_model.py +162 -0
  69. py4heappe/core/models/copy_job_data_to_temp_model.py +162 -0
  70. py4heappe/core/models/create_command_inner_template_parameter_model.py +162 -0
  71. py4heappe/core/models/create_command_template_from_generic_model.py +292 -0
  72. py4heappe/core/models/create_command_template_model.py +318 -0
  73. py4heappe/core/models/create_command_template_parameter_model.py +214 -0
  74. py4heappe/core/models/create_job_by_project_model.py +136 -0
  75. py4heappe/core/models/create_project_assignment_to_cluster_model.py +188 -0
  76. py4heappe/core/models/create_project_model.py +318 -0
  77. py4heappe/core/models/create_secure_shell_key_model.py +162 -0
  78. py4heappe/core/models/create_secure_shell_key_model_obsolete.py +188 -0
  79. py4heappe/core/models/current_cluster_node_usage_model.py +136 -0
  80. py4heappe/core/models/current_info_for_job_model.py +136 -0
  81. py4heappe/core/models/data_transfer_method_ext.py +188 -0
  82. py4heappe/core/models/delete_job_model.py +136 -0
  83. py4heappe/core/models/deployment_type_ext.py +91 -0
  84. py4heappe/core/models/digital_signature_credentials_ext.py +162 -0
  85. py4heappe/core/models/download_file_from_cluster_model.py +162 -0
  86. py4heappe/core/models/download_parts_of_job_files_from_cluster_model.py +162 -0
  87. py4heappe/core/models/end_data_transfer_model.py +136 -0
  88. py4heappe/core/models/end_file_transfer_model.py +162 -0
  89. py4heappe/core/models/environment_variable_ext.py +136 -0
  90. py4heappe/core/models/extended_command_template_ext.py +370 -0
  91. py4heappe/core/models/extended_command_template_parameter_ext.py +188 -0
  92. py4heappe/core/models/extended_project_info_ext.py +318 -0
  93. py4heappe/core/models/file_information_ext.py +136 -0
  94. py4heappe/core/models/file_transfer_cipher_type.py +94 -0
  95. py4heappe/core/models/file_transfer_cipher_type_ext.py +93 -0
  96. py4heappe/core/models/file_transfer_key_credentials_ext.py +240 -0
  97. py4heappe/core/models/file_transfer_method.py +294 -0
  98. py4heappe/core/models/file_transfer_method_ext.py +240 -0
  99. py4heappe/core/models/file_transfer_protocol.py +91 -0
  100. py4heappe/core/models/file_transfer_protocol_ext.py +91 -0
  101. py4heappe/core/models/get_command_template_parameters_name_model.py +188 -0
  102. py4heappe/core/models/get_current_usage_and_limitations_for_current_user_model.py +110 -0
  103. py4heappe/core/models/get_data_transfer_method_model.py +188 -0
  104. py4heappe/core/models/get_file_transfer_method_model.py +136 -0
  105. py4heappe/core/models/http_get_to_job_node_model.py +241 -0
  106. py4heappe/core/models/http_header_ext.py +136 -0
  107. py4heappe/core/models/http_post_to_job_node_model.py +267 -0
  108. py4heappe/core/models/initialize_cluster_script_directory_model.py +162 -0
  109. py4heappe/core/models/instance_information_ext.py +344 -0
  110. py4heappe/core/models/job_detailed_report_ext.py +318 -0
  111. py4heappe/core/models/job_file_content_ext.py +214 -0
  112. py4heappe/core/models/job_report_ext.py +188 -0
  113. py4heappe/core/models/job_specification_by_project_ext.py +448 -0
  114. py4heappe/core/models/job_specification_ext.py +448 -0
  115. py4heappe/core/models/job_state_aggregation_report_ext.py +162 -0
  116. py4heappe/core/models/job_state_ext.py +96 -0
  117. py4heappe/core/models/lexis_credentials_ext.py +137 -0
  118. py4heappe/core/models/list_changed_files_for_job_model.py +136 -0
  119. py4heappe/core/models/list_jobs_for_current_user_model.py +110 -0
  120. py4heappe/core/models/modify_command_template_from_generic_model.py +292 -0
  121. py4heappe/core/models/modify_command_template_model.py +292 -0
  122. py4heappe/core/models/modify_command_template_parameter_model.py +214 -0
  123. py4heappe/core/models/modify_project_assignment_to_cluster_model.py +188 -0
  124. py4heappe/core/models/modify_project_model.py +292 -0
  125. py4heappe/core/models/node_used_cores_and_limitation_ext.py +110 -0
  126. py4heappe/core/models/open_id_credentials_ext.py +137 -0
  127. py4heappe/core/models/open_stack_application_credentials_ext.py +136 -0
  128. py4heappe/core/models/password_credentials_ext.py +136 -0
  129. py4heappe/core/models/problem_details.py +89 -0
  130. py4heappe/core/models/project.py +482 -0
  131. py4heappe/core/models/project_contact.py +215 -0
  132. py4heappe/core/models/project_detailed_report_ext.py +292 -0
  133. py4heappe/core/models/project_ext.py +266 -0
  134. py4heappe/core/models/project_for_task_ext.py +214 -0
  135. py4heappe/core/models/project_list_report_ext.py +214 -0
  136. py4heappe/core/models/project_reference_ext.py +137 -0
  137. py4heappe/core/models/project_report_ext.py +240 -0
  138. py4heappe/core/models/project_resource_usage_ext.py +266 -0
  139. py4heappe/core/models/proxy_type.py +91 -0
  140. py4heappe/core/models/proxy_type_ext.py +91 -0
  141. py4heappe/core/models/public_key_ext.py +188 -0
  142. py4heappe/core/models/recreate_secure_shell_key_model.py +214 -0
  143. py4heappe/core/models/regenerate_secure_shell_key_model.py +188 -0
  144. py4heappe/core/models/regenerate_secure_shell_key_model_obsolete.py +188 -0
  145. py4heappe/core/models/remove_command_template_model.py +136 -0
  146. py4heappe/core/models/remove_command_template_parameter_model.py +136 -0
  147. py4heappe/core/models/remove_project_assignment_to_cluster_model.py +162 -0
  148. py4heappe/core/models/remove_project_model.py +136 -0
  149. py4heappe/core/models/remove_secure_shell_key_model.py +162 -0
  150. py4heappe/core/models/remove_secure_shell_key_model_obsolete.py +162 -0
  151. py4heappe/core/models/resource_allocation_type_ext.py +91 -0
  152. py4heappe/core/models/resource_limitation_ext.py +136 -0
  153. py4heappe/core/models/resource_usage_ext.py +163 -0
  154. py4heappe/core/models/scheduler_type.py +92 -0
  155. py4heappe/core/models/ssh_key_user_credentials_model.py +136 -0
  156. py4heappe/core/models/submit_job_model.py +136 -0
  157. py4heappe/core/models/submitted_job_info_ext.py +318 -0
  158. py4heappe/core/models/submitted_task_info_ext.py +370 -0
  159. py4heappe/core/models/synchronizable_files_ext.py +92 -0
  160. py4heappe/core/models/task_detailed_report_ext.py +318 -0
  161. py4heappe/core/models/task_file_offset_ext.py +162 -0
  162. py4heappe/core/models/task_paralization_parameter_ext.py +162 -0
  163. py4heappe/core/models/task_priority_ext.py +97 -0
  164. py4heappe/core/models/task_report_ext.py +266 -0
  165. py4heappe/core/models/task_specification_ext.py +682 -0
  166. py4heappe/core/models/task_state_ext.py +95 -0
  167. py4heappe/core/models/test_cluster_access_for_account_model.py +162 -0
  168. py4heappe/core/models/test_cluster_access_for_account_model_obsolete.py +162 -0
  169. py4heappe/core/models/unauthorized_result.py +110 -0
  170. py4heappe/core/models/usage_type.py +90 -0
  171. py4heappe/core/models/usage_type_ext.py +90 -0
  172. py4heappe/core/models/user_group_detailed_report_ext.py +240 -0
  173. py4heappe/core/models/user_group_list_report_ext.py +240 -0
  174. py4heappe/core/models/user_group_report_ext.py +240 -0
  175. py4heappe/core/models/version_information_ext.py +162 -0
  176. py4heappe/core/rest.py +311 -0
  177. py4heappe-1.0.0.dist-info/METADATA +147 -0
  178. py4heappe-1.0.0.dist-info/RECORD +183 -0
  179. py4heappe-1.0.0.dist-info/WHEEL +5 -0
  180. py4heappe-1.0.0.dist-info/entry_points.txt +2 -0
  181. py4heappe-1.0.0.dist-info/licenses/LICENSE +20 -0
  182. py4heappe-1.0.0.dist-info/top_level.txt +3 -0
  183. py4heappe_cli.py +22 -0
__init__.py ADDED
@@ -0,0 +1 @@
1
+ # __init__.py
py4heappe/__init__.py ADDED
@@ -0,0 +1 @@
1
+ # __init__.py
@@ -0,0 +1 @@
1
+ # __init__.py
py4heappe/cli/auth.py ADDED
@@ -0,0 +1,153 @@
1
+ import json
2
+ import typer
3
+ import os
4
+
5
+ import py4heappe.cli.configuration as configuration
6
+ import py4heappe.core.base.utils as utils
7
+ import py4heappe.core as heappeCore
8
+
9
+ from py4heappe.core.base import exceptions
10
+ from py4heappe.core import rest
11
+ # from py4lexis.session import LexisSession
12
+
13
+
14
+ app = typer.Typer(name="HEAppEAuthCLI", no_args_is_help=True, pretty_exceptions_short=True)
15
+
16
+ @app.command(name="UserPass")
17
+ def authentication_credentials():
18
+ """Username and password authentication"""
19
+ try:
20
+ utils.print_and_log("Username and password authentication")
21
+ client = configuration.get_api_instance()
22
+ if "CREDENTIALS_USERNAME" in os.environ:
23
+ username = os.environ["CREDENTIALS_USERNAME"]
24
+ else:
25
+ username = typer.prompt("Username:")
26
+
27
+ if "CREDENTIALS_PASSWORD" in os.environ:
28
+ password = os.environ["CREDENTIALS_PASSWORD"]
29
+ else:
30
+ password = typer.prompt("Password:", hide_input=True)
31
+
32
+ cred = {
33
+ "_preload_content": False,
34
+ "body": {
35
+ "Credentials": {
36
+ "Username": username,
37
+ "Password": password
38
+ }
39
+ }
40
+ }
41
+
42
+ response = heappeCore.UserAndLimitationManagementApi(client).heappe_user_and_limitation_management_authenticate_user_password_post(**cred)
43
+ session_code = json.loads(response.data)
44
+
45
+ if "CREDENTIALS_PASSWORD" in os.environ:
46
+ print(session_code)
47
+
48
+ utils.print_and_log("User was authenticated.")
49
+ utils.store_session(session_code)
50
+
51
+ except rest.ApiException as exception:
52
+ try:
53
+ response_data = json.loads(exception.body)
54
+ raise exceptions.Py4HEAppEAPIException(response_data['title'], response_data['detail'], response_data['status']) from None
55
+ except json.JSONDecodeError:
56
+ raise exceptions.Py4HEAppEException("Link to a HEAppE instance is not set or valid. Please check Conf Init option.") from None
57
+
58
+ except exceptions.Py4HEAppEAPIInternalException as exception:
59
+ raise exceptions.Py4HEAppEException(exception.message) from None
60
+
61
+ except exceptions.Py4HEAppEInternalException as exception:
62
+ raise exceptions.Py4HEAppEException(exception.message) from None
63
+
64
+ except Exception as exception:
65
+ raise exceptions.Py4HEAppEInternalException(f"Other exception: {str(exception)}") from None
66
+
67
+ @app.command(name="OpenId")
68
+ def authentication_openid():
69
+ """OpenID authentication"""
70
+ try:
71
+ utils.print_and_log("OpenID authentication")
72
+ client = configuration.get_api_instance()
73
+ if "CREDENTIALS_TOKEN" in os.environ:
74
+ openIdToken = os.environ["CREDENTIALS_TOKEN"]
75
+ else:
76
+ openIdToken = typer.prompt("OpenID token:")
77
+
78
+ cred = {
79
+ "_preload_content": False,
80
+ "body": {
81
+ "Credentials": {
82
+ "Username": None,
83
+ "OpenIdAccessToken": openIdToken
84
+ }
85
+ }
86
+ }
87
+
88
+ response = heappeCore.UserAndLimitationManagementApi(client).heappe_user_and_limitation_management_authenticate_user_open_id_post(**cred)
89
+ session_code = json.loads(response.data)
90
+
91
+ if "CREDENTIALS_TOKEN" in os.environ:
92
+ print(session_code)
93
+
94
+ utils.print_and_log("User was authenticated.")
95
+ utils.store_session(session_code)
96
+
97
+ except rest.ApiException as exception:
98
+ try:
99
+ response_data = json.loads(exception.body)
100
+ raise exceptions.Py4HEAppEAPIException(response_data['title'], response_data['detail'], response_data['status']) from None
101
+ except json.JSONDecodeError:
102
+ raise exceptions.Py4HEAppEException("Link to a HEAppE instance is not set or valid. Please check Conf Init option.") from None
103
+
104
+ except exceptions.Py4HEAppEAPIInternalException as exception:
105
+ raise exceptions.Py4HEAppEException(exception.message) from None
106
+
107
+ except exceptions.Py4HEAppEInternalException as exception:
108
+ raise exceptions.Py4HEAppEException(exception.message) from None
109
+
110
+ except Exception as exception:
111
+ raise exceptions.Py4HEAppEInternalException(f"Other exception: {str(exception)}") from None
112
+
113
+ # @app.command(name="Lexis")
114
+ # def authentication_lexis(useCredentials:bool = typer.Option(default=False, help='Use Credentials for authentication to LEXIS')):
115
+ # """LEXIS token authentication"""
116
+ # try:
117
+ # utils.print_and_log("LEXIS AAI authentication")
118
+ # client = configuration.get_api_instance()
119
+ # session = LexisSession(login_method='credentials' if useCredentials else 'url')
120
+ # cred = {
121
+ # "_preload_content": False,
122
+ # "body": {
123
+ # "Credentials": {
124
+ # "Username": None,
125
+ # "OpenIdAccessToken": session.get_access_token()
126
+ # }
127
+ # }
128
+ # }
129
+
130
+ # response = heappeCore.UserAndLimitationManagementApi(client).heappe_user_and_limitation_management_authenticate_lexis_token_post(**cred)
131
+ # session_code = json.loads(response.data)
132
+ # utils.print_and_log("User was authenticated.")
133
+ # utils.store_session(session_code)
134
+
135
+ # except rest.ApiException as exception:
136
+ # try:
137
+ # response_data = json.loads(exception.body)
138
+ # raise exceptions.Py4HEAppEAPIException(response_data['title'], response_data['detail'], response_data['status']) from None
139
+ # except json.JSONDecodeError:
140
+ # raise exceptions.Py4HEAppEException("Link to a HEAppE instance is not set or valid. Please check Conf Init option.") from None
141
+
142
+ # except exceptions.Py4HEAppEAPIInternalException as exception:
143
+ # raise exceptions.Py4HEAppEException(exception.message) from None
144
+
145
+ # except exceptions.Py4HEAppEInternalException as exception:
146
+ # raise exceptions.Py4HEAppEException(exception.message) from None
147
+
148
+ # except Exception as exception:
149
+ # raise exceptions.Py4HEAppEInternalException(f"Other exception: {str(exception)}") from None
150
+
151
+
152
+ if __name__ == '__main__':
153
+ app()
@@ -0,0 +1,370 @@
1
+ import json
2
+ import typer
3
+
4
+ import py4heappe.cli.configuration as configuration
5
+ import py4heappe.cli.information as infoCLI
6
+ import py4heappe.core.base.utils as utils
7
+ import py4heappe.core as heappeCore
8
+
9
+ from py4heappe.core.base import exceptions
10
+ from py4heappe.core import rest
11
+
12
+
13
+ app = typer.Typer(name="HEAppECommandTemplateCLI", no_args_is_help=True, pretty_exceptions_short=True)
14
+
15
+ @app.command(name="List")
16
+ def get_command_templates_for_project():
17
+ """List all command templates"""
18
+ try:
19
+ utils.print_and_log("Fetching command templates of a configured HEAppE project …")
20
+ projectId : int = infoCLI.get_hpc_project()["Id"]
21
+ parameters = {
22
+ "_preload_content": False,
23
+ "ProjectId": projectId,
24
+ "SessionCode": utils.load_stored_session()
25
+ }
26
+
27
+ response = heappeCore.ManagementApi(configuration.get_api_instance()).heappe_management_command_templates_get(**parameters)
28
+ commandTemplates = json.loads(response.data)
29
+ print(f"\nList of command templates for HEAppE project {projectId}:")
30
+ print(json.dumps(commandTemplates, indent = 3))
31
+
32
+ except rest.ApiException as exception:
33
+ try:
34
+ response_data = json.loads(exception.body)
35
+ raise exceptions.Py4HEAppEAPIException(response_data['title'], response_data['detail'], response_data['status']) from None
36
+ except json.JSONDecodeError:
37
+ raise exceptions.Py4HEAppEException("Link to a HEAppE instance is not set or valid. Please check Conf Init option.") from None
38
+
39
+ except exceptions.Py4HEAppEAPIInternalException as exception:
40
+ raise exceptions.Py4HEAppEException(exception.message) from None
41
+
42
+ except exceptions.Py4HEAppEInternalException as exception:
43
+ raise exceptions.Py4HEAppEException(exception.message) from None
44
+
45
+ except Exception as exception:
46
+ raise exceptions.Py4HEAppEInternalException(f"Other exception: {str(exception)}") from None
47
+
48
+ @app.command("Create")
49
+ def create_command_template(Name:str = typer.Option(..., help='Name'),
50
+ desc:str = typer.Option(..., help='Description'),
51
+ extAllocCommand:str = typer.Option(None, help='Extended allocation command'),
52
+ execScript:str = typer.Option(..., help='Path to executable file/script'),
53
+ prepScript:str = typer.Option(None, help='Path to preparation script or specific prerequisites/module loads'),
54
+ clusterNodeTypeId:int = typer.Option(..., help='Cluster node type identifier')):
55
+ """Create new command template"""
56
+ try:
57
+ utils.print_and_log("Creating new command template …")
58
+ body = {
59
+ "_preload_content": False,
60
+ "body": {
61
+ "Name": Name,
62
+ "Description": desc,
63
+ "ExtendedAllocationCommand": extAllocCommand,
64
+ "PreparationScript": prepScript,
65
+ "ExecutableFile": execScript,
66
+ "ClusterNodeTypeId": clusterNodeTypeId,
67
+ "TemplateParameters": [],
68
+ "ProjectId": infoCLI.get_hpc_project()["Id"],
69
+ "SessionCode": utils.load_stored_session()
70
+ }
71
+ }
72
+
73
+ response = heappeCore.ManagementApi(configuration.get_api_instance()).heappe_management_command_template_post(**body)
74
+ commandTemplateId = json.loads(response.data)["Id"]
75
+ utils.print_and_log(f"\nCommand template was created (Id: {commandTemplateId})")
76
+
77
+ except rest.ApiException as exception:
78
+ try:
79
+ response_data = json.loads(exception.body)
80
+ raise exceptions.Py4HEAppEAPIException(response_data['title'], response_data['detail'], response_data['status']) from None
81
+ except json.JSONDecodeError:
82
+ raise exceptions.Py4HEAppEException("Link to a HEAppE instance is not set or valid. Please check Conf Init option.") from None
83
+
84
+ except exceptions.Py4HEAppEAPIInternalException as exception:
85
+ raise exceptions.Py4HEAppEException(exception.message) from None
86
+
87
+ except exceptions.Py4HEAppEInternalException as exception:
88
+ raise exceptions.Py4HEAppEException(exception.message) from None
89
+
90
+ except Exception as exception:
91
+ raise exceptions.Py4HEAppEInternalException(f"Other exception: {str(exception)}") from None
92
+
93
+ @app.command("Modify")
94
+ def modify_command_template(id:int = typer.Option(..., help='Id (Command template)'),
95
+ Name:str = typer.Option(..., help='Name'),
96
+ desc:str = typer.Option(..., help='Description'),
97
+ extAllocCommand:str = typer.Option(None, help='Extended allocation command'),
98
+ execScript:str = typer.Option(..., help='Path to executable file/script'),
99
+ prepScript:str = typer.Option(None, help='Path to preparation script or specific prerequisites/module loads'),
100
+ clusterNodeTypeId:int = typer.Option(None, help='Cluster node type identifier')):
101
+ """Modify existing command template"""
102
+ try:
103
+ utils.print_and_log("Modifying the command template …")
104
+ body = {
105
+ "_preload_content": False,
106
+ "body": {
107
+ "Id": id,
108
+ "Name": Name,
109
+ "Description": desc,
110
+ "ExtendedAllocationCommand": extAllocCommand,
111
+ "PreparationScript": prepScript,
112
+ "ExecutableFile": execScript,
113
+ "ClusterNodeTypeId": clusterNodeTypeId,
114
+ "TemplateParameters": [],
115
+ "SessionCode": utils.load_stored_session()
116
+ }
117
+ }
118
+
119
+ _ = heappeCore.ManagementApi(configuration.get_api_instance()).heappe_management_command_template_put(**body)
120
+ utils.print_and_log(f"\nCommand template was modified.")
121
+
122
+ except rest.ApiException as exception:
123
+ try:
124
+ response_data = json.loads(exception.body)
125
+ raise exceptions.Py4HEAppEAPIException(response_data['title'], response_data['detail'], response_data['status']) from None
126
+ except json.JSONDecodeError:
127
+ raise exceptions.Py4HEAppEException("Link to a HEAppE instance is not set or valid. Please check Conf Init option.") from None
128
+
129
+ except exceptions.Py4HEAppEAPIInternalException as exception:
130
+ raise exceptions.Py4HEAppEException(exception.message) from None
131
+
132
+ except exceptions.Py4HEAppEInternalException as exception:
133
+ raise exceptions.Py4HEAppEException(exception.message) from None
134
+
135
+ except Exception as exception:
136
+ raise exceptions.Py4HEAppEInternalException(f"Other exception: {str(exception)}") from None
137
+
138
+ @app.command("Remove")
139
+ def remove_command_template(id:int = typer.Option(..., help='Id (Command template)')):
140
+ """Remove existing command template"""
141
+ try:
142
+ utils.print_and_log("Removing the command template …")
143
+ body = {
144
+ "_preload_content": False,
145
+ "body": {
146
+ "CommandTemplateId": id,
147
+ "SessionCode": utils.load_stored_session()
148
+ }
149
+ }
150
+
151
+ _ = heappeCore.ManagementApi(configuration.get_api_instance()).heappe_management_remove_command_template_delete(**body)
152
+ utils.print_and_log("\nCommand template was removed.")
153
+
154
+ except rest.ApiException as exception:
155
+ try:
156
+ response_data = json.loads(exception.body)
157
+ raise exceptions.Py4HEAppEAPIException(response_data['title'], response_data['detail'], response_data['status']) from None
158
+ except json.JSONDecodeError:
159
+ raise exceptions.Py4HEAppEException("Link to a HEAppE instance is not set or valid. Please check Conf Init option.") from None
160
+
161
+ except exceptions.Py4HEAppEAPIInternalException as exception:
162
+ raise exceptions.Py4HEAppEException(exception.message) from None
163
+
164
+ except exceptions.Py4HEAppEInternalException as exception:
165
+ raise exceptions.Py4HEAppEException(exception.message) from None
166
+
167
+ except Exception as exception:
168
+ raise exceptions.Py4HEAppEInternalException(f"Other exception: {str(exception)}") from None
169
+
170
+ @app.command("CreateFromGeneric")
171
+ def create_command_template_from_generic(id:str = typer.Option(..., help='Id (Generic command template)'),
172
+ name:str = typer.Option(..., help='Name'),
173
+ desc:str = typer.Option(..., help='Description'),
174
+ extAllocCommand:str = typer.Option(None, help='Extended allocation command'),
175
+ execScript:str = typer.Option(..., help='Path to executable file/script'),
176
+ prepScript:str = typer.Option(None, help='Path to preparation script or specific prerequisites/module loads')):
177
+ """Create new static command template from a generic one"""
178
+ try:
179
+ utils.print_and_log("Creating new static command template from a generic one …")
180
+ body = {
181
+ "_preload_content": False,
182
+ "body": {
183
+ "GenericCommandTemplateId": id,
184
+ "Name": name,
185
+ "Description": desc,
186
+ "ExtendedAllocationCommand": extAllocCommand,
187
+ "PreparationScript": prepScript,
188
+ "ExecutableFile": execScript,
189
+ "ProjectId": infoCLI.get_hpc_project()["Id"],
190
+ "SessionCode": utils.load_stored_session()
191
+ }
192
+ }
193
+
194
+ response = heappeCore.ManagementApi(configuration.get_api_instance()).heappe_management_command_template_from_generic_post(**body)
195
+ jsonData = json.loads(response.data)
196
+ commandTemplateId= jsonData["Id"]
197
+ utils.print_and_log(f"\nCommand template was created (Id: {commandTemplateId}):")
198
+ print(json.dumps(jsonData, indent = 3))
199
+
200
+ except rest.ApiException as exception:
201
+ try:
202
+ response_data = json.loads(exception.body)
203
+ raise exceptions.Py4HEAppEAPIException(response_data['title'], response_data['detail'], response_data['status']) from None
204
+ except json.JSONDecodeError:
205
+ raise exceptions.Py4HEAppEException("Link to a HEAppE instance is not set or valid. Please check Conf Init option.") from None
206
+
207
+ except exceptions.Py4HEAppEAPIInternalException as exception:
208
+ raise exceptions.Py4HEAppEException(exception.message) from None
209
+
210
+ except exceptions.Py4HEAppEInternalException as exception:
211
+ raise exceptions.Py4HEAppEException(exception.message) from None
212
+
213
+ except Exception as exception:
214
+ raise exceptions.Py4HEAppEInternalException(f"Other exception: {str(exception)}") from None
215
+
216
+ @app.command("ModifyFromGeneric")
217
+ def modify_command_template_from_generic(id:int = typer.Option(..., help='Id (Command template)'),
218
+ name:str = typer.Option(..., help='Name'),
219
+ desc:str = typer.Option(..., help='Description'),
220
+ extAllocCommand:str = typer.Option(None, help='Extended allocation command'),
221
+ execScript:str = typer.Option(..., help='Path to executable file/script'),
222
+ prepScript:str = typer.Option(None, help='Path to preparation script or specific prerequisites/module loads')):
223
+ """Modify existing command template created from a generic one"""
224
+ try:
225
+ utils.print_and_log("Modifying the command template …")
226
+ body = {
227
+ "_preload_content": False,
228
+ "body": {
229
+ "CommandTemplateId": id,
230
+ "Name": name,
231
+ "Description": desc,
232
+ "ExtendedAllocationCommand": extAllocCommand,
233
+ "PreparationScript": prepScript,
234
+ "ExecutableFile": execScript,
235
+ "ProjectId": infoCLI.get_hpc_project()["Id"],
236
+ "SessionCode": utils.load_stored_session()
237
+ }
238
+ }
239
+
240
+ _ = heappeCore.ManagementApi(configuration.get_api_instance()).heappe_management_command_template_from_generic_put(**body)
241
+ utils.print_and_log(f"\nCommand template was modified.")
242
+
243
+ except rest.ApiException as exception:
244
+ try:
245
+ response_data = json.loads(exception.body)
246
+ raise exceptions.Py4HEAppEAPIException(response_data['title'], response_data['detail'], response_data['status']) from None
247
+ except json.JSONDecodeError:
248
+ raise exceptions.Py4HEAppEException("Link to a HEAppE instance is not set or valid. Please check Conf Init option.") from None
249
+
250
+ except exceptions.Py4HEAppEAPIInternalException as exception:
251
+ raise exceptions.Py4HEAppEException(exception.message) from None
252
+
253
+ except exceptions.Py4HEAppEInternalException as exception:
254
+ raise exceptions.Py4HEAppEException(exception.message) from None
255
+
256
+ except Exception as exception:
257
+ raise exceptions.Py4HEAppEInternalException(f"Other exception: {str(exception)}") from None
258
+
259
+ @app.command("CreateParameter")
260
+ def create_command_template_parameter(uniqueName:str = typer.Option(..., help='Identifier (Name)'),
261
+ query:str = typer.Option(None, help='Query'),
262
+ desc:str = typer.Option(..., help='Description'),
263
+ cmdTemplateId:int = typer.Option(..., help='Id (Command template)')):
264
+ "Create new command template parameter"
265
+ try:
266
+ utils.print_and_log("Creating command template parameter …")
267
+ body = {
268
+ "_preload_content": False,
269
+ "body": {
270
+ "Identifier": uniqueName,
271
+ "Query": query if query is not None else "",
272
+ "Description": desc,
273
+ "CommandTemplateId": cmdTemplateId,
274
+ "SessionCode": utils.load_stored_session()
275
+ }
276
+ }
277
+
278
+ response = heappeCore.ManagementApi(configuration.get_api_instance()).heappe_management_command_template_parameter_post(**body)
279
+ commandTemplateParameterId = json.loads(response.data)["Id"]
280
+ utils.print_and_log(f"\nCommand template parameter was created (Id: {commandTemplateParameterId})")
281
+
282
+ except rest.ApiException as exception:
283
+ try:
284
+ response_data = json.loads(exception.body)
285
+ raise exceptions.Py4HEAppEAPIException(response_data['title'], response_data['detail'], response_data['status']) from None
286
+ except json.JSONDecodeError:
287
+ raise exceptions.Py4HEAppEException("Link to a HEAppE instance is not set or valid. Please check Conf Init option.") from None
288
+
289
+ except exceptions.Py4HEAppEAPIInternalException as exception:
290
+ raise exceptions.Py4HEAppEException(exception.message) from None
291
+
292
+ except exceptions.Py4HEAppEInternalException as exception:
293
+ raise exceptions.Py4HEAppEException(exception.message) from None
294
+
295
+ except Exception as exception:
296
+ raise exceptions.Py4HEAppEInternalException(f"Other exception: {str(exception)}") from None
297
+
298
+ @app.command("ModifyParameter")
299
+ def modify_command_template_parameter(id:int = typer.Option(..., help='Id (Command template parameter)'),
300
+ uniqueName:str = typer.Option(..., help='Identifier (Name)'),
301
+ query:str = typer.Option(None, help='Query'),
302
+ desc:str = typer.Option(..., help='Description')):
303
+ "Modify existing command template parameter"
304
+ try:
305
+ utils.print_and_log("Modifying the selected command template parameter …")
306
+ body = {
307
+ "_preload_content": False,
308
+ "body": {
309
+ "Id": id,
310
+ "Identifier": uniqueName,
311
+ "Query": query if query is not None else "",
312
+ "Description": desc,
313
+ "SessionCode": utils.load_stored_session()
314
+ }
315
+ }
316
+
317
+ _ = heappeCore.ManagementApi(configuration.get_api_instance()).heappe_management_command_template_parameter_put(**body)
318
+ utils.print_and_log(f"\nCommand template parameter was modified.")
319
+
320
+ except rest.ApiException as exception:
321
+ try:
322
+ response_data = json.loads(exception.body)
323
+ raise exceptions.Py4HEAppEAPIException(response_data['title'], response_data['detail'], response_data['status']) from None
324
+ except json.JSONDecodeError:
325
+ raise exceptions.Py4HEAppEException("Link to a HEAppE instance is not set or valid. Please check Conf Init option.") from None
326
+
327
+ except exceptions.Py4HEAppEAPIInternalException as exception:
328
+ raise exceptions.Py4HEAppEException(exception.message) from None
329
+
330
+ except exceptions.Py4HEAppEInternalException as exception:
331
+ raise exceptions.Py4HEAppEException(exception.message) from None
332
+
333
+ except Exception as exception:
334
+ raise exceptions.Py4HEAppEInternalException(f"Other exception: {str(exception)}") from None
335
+
336
+ @app.command("RemoveParameter")
337
+ def remove_command_template_parameter(id:int = typer.Option(..., help='Id (Command template parameter)')):
338
+ "Remove existing command template parameter"
339
+ try:
340
+ utils.print_and_log("Removing the command template parameter …")
341
+ body = {
342
+ "_preload_content": False,
343
+ "body": {
344
+ "Id": id,
345
+ "SessionCode": utils.load_stored_session()
346
+ }
347
+ }
348
+
349
+ _ = heappeCore.ManagementApi(configuration.get_api_instance()).heappe_management_command_template_parameter_delete(**body)
350
+ utils.print_and_log("\nCommand template parameter was removed.")
351
+
352
+ except rest.ApiException as exception:
353
+ try:
354
+ response_data = json.loads(exception.body)
355
+ raise exceptions.Py4HEAppEAPIException(response_data['title'], response_data['detail'], response_data['status']) from None
356
+ except json.JSONDecodeError:
357
+ raise exceptions.Py4HEAppEException("Link to a HEAppE instance is not set or valid. Please check Conf Init option.") from None
358
+
359
+ except exceptions.Py4HEAppEAPIInternalException as exception:
360
+ raise exceptions.Py4HEAppEException(exception.message) from None
361
+
362
+ except exceptions.Py4HEAppEInternalException as exception:
363
+ raise exceptions.Py4HEAppEException(exception.message) from None
364
+
365
+ except Exception as exception:
366
+ raise exceptions.Py4HEAppEInternalException(f"Other exception: {str(exception)}") from None
367
+
368
+
369
+ if __name__ == '__main__':
370
+ app()
@@ -0,0 +1,65 @@
1
+ import dotenv
2
+ import os
3
+ import typer
4
+ import validators
5
+
6
+ import py4heappe.core as hp
7
+ import py4heappe.core.base.utils as utils
8
+ from py4heappe.core.base import exceptions
9
+
10
+
11
+ app = typer.Typer(name="HEAppEConfigurationCLI", no_args_is_help=True, pretty_exceptions_show_locals=False)
12
+
13
+ def get_api_instance():
14
+ dotenv.load_dotenv(os.path.join(os.path.dirname(__file__), '.env'))
15
+ url : str = os.environ.get("url")
16
+
17
+ if url is None:
18
+ raise exceptions.Py4HEAppEInternalException("Py4HEappE is not configured. Please check Conf option.") from None
19
+
20
+ configuration = hp.Configuration()
21
+ configuration.host = url
22
+ api_instance = hp.ApiClient(configuration)
23
+ return api_instance
24
+
25
+ def get_project_from_configuration():
26
+ dotenv.load_dotenv(os.path.join(os.path.dirname(__file__), '.env'))
27
+
28
+ computationalProject : str = os.environ.get("project")
29
+ if computationalProject is None:
30
+ raise exceptions.Py4HEAppEInternalException("Py4HEappE is not configured. Please check Conf option.") from None
31
+
32
+ return computationalProject
33
+
34
+ @app.command(name="Init")
35
+ def environment_preparation():
36
+ """Initialization"""
37
+ utils.print_and_log("Preparation of Py4HEAppE Environment …")
38
+ dotenv.load_dotenv()
39
+
40
+ url: str = os.environ.get("url")
41
+ computationalProject: str = os.environ.get("project")
42
+
43
+ if url is not None or computationalProject is not None:
44
+ reconfigure = typer.confirm(f"Py4HEAppE is already configured (URL: \"{url}\", HEAppE accounting string (HPC Computational project): \"{computationalProject}\").\nDo you want to reconfigure it?")
45
+ if not reconfigure:
46
+ return
47
+
48
+ url = typer.prompt("Enter the HEAppE instance address (for example: https://heappe.domain.cz/production)")
49
+ if not validators.url(url):
50
+ raise exceptions.Py4HEAppEInternalException("The provided HEAppE URL is not valid.") from None
51
+
52
+ if "/swagger/index.html" in url:
53
+ url = url.replace("/swagger/index.html", "")
54
+
55
+ computationalProject = typer.prompt("Enter HEAppE accounting string", confirmation_prompt=True)
56
+
57
+ dotenv.set_key(os.path.join(os.path.dirname(__file__), '.env'), "url", url)
58
+ dotenv.set_key(os.path.join(os.path.dirname(__file__), '.env'), "project", computationalProject)
59
+
60
+ utils.print_and_log("Py4HEAppE is configured.")
61
+ return
62
+
63
+
64
+ if __name__ == '__main__':
65
+ app()