nextmv 0.40.0__py3-none-any.whl → 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 (163) hide show
  1. nextmv/__about__.py +1 -1
  2. nextmv/__entrypoint__.py +1 -2
  3. nextmv/__init__.py +2 -4
  4. nextmv/cli/CONTRIBUTING.md +583 -0
  5. nextmv/cli/cloud/__init__.py +49 -0
  6. nextmv/cli/cloud/acceptance/__init__.py +27 -0
  7. nextmv/cli/cloud/acceptance/create.py +391 -0
  8. nextmv/cli/cloud/acceptance/delete.py +64 -0
  9. nextmv/cli/cloud/acceptance/get.py +103 -0
  10. nextmv/cli/cloud/acceptance/list.py +62 -0
  11. nextmv/cli/cloud/acceptance/update.py +95 -0
  12. nextmv/cli/cloud/account/__init__.py +28 -0
  13. nextmv/cli/cloud/account/create.py +83 -0
  14. nextmv/cli/cloud/account/delete.py +59 -0
  15. nextmv/cli/cloud/account/get.py +66 -0
  16. nextmv/cli/cloud/account/update.py +70 -0
  17. nextmv/cli/cloud/app/__init__.py +35 -0
  18. nextmv/cli/cloud/app/create.py +140 -0
  19. nextmv/cli/cloud/app/delete.py +57 -0
  20. nextmv/cli/cloud/app/exists.py +44 -0
  21. nextmv/cli/cloud/app/get.py +66 -0
  22. nextmv/cli/cloud/app/list.py +61 -0
  23. nextmv/cli/cloud/app/push.py +432 -0
  24. nextmv/cli/cloud/app/update.py +124 -0
  25. nextmv/cli/cloud/batch/__init__.py +29 -0
  26. nextmv/cli/cloud/batch/create.py +452 -0
  27. nextmv/cli/cloud/batch/delete.py +64 -0
  28. nextmv/cli/cloud/batch/get.py +104 -0
  29. nextmv/cli/cloud/batch/list.py +63 -0
  30. nextmv/cli/cloud/batch/metadata.py +66 -0
  31. nextmv/cli/cloud/batch/update.py +95 -0
  32. nextmv/cli/cloud/data/__init__.py +26 -0
  33. nextmv/cli/cloud/data/upload.py +162 -0
  34. nextmv/cli/cloud/ensemble/__init__.py +33 -0
  35. nextmv/cli/cloud/ensemble/create.py +413 -0
  36. nextmv/cli/cloud/ensemble/delete.py +63 -0
  37. nextmv/cli/cloud/ensemble/get.py +65 -0
  38. nextmv/cli/cloud/ensemble/list.py +63 -0
  39. nextmv/cli/cloud/ensemble/update.py +103 -0
  40. nextmv/cli/cloud/input_set/__init__.py +32 -0
  41. nextmv/cli/cloud/input_set/create.py +168 -0
  42. nextmv/cli/cloud/input_set/delete.py +64 -0
  43. nextmv/cli/cloud/input_set/get.py +63 -0
  44. nextmv/cli/cloud/input_set/list.py +63 -0
  45. nextmv/cli/cloud/input_set/update.py +123 -0
  46. nextmv/cli/cloud/instance/__init__.py +35 -0
  47. nextmv/cli/cloud/instance/create.py +289 -0
  48. nextmv/cli/cloud/instance/delete.py +61 -0
  49. nextmv/cli/cloud/instance/exists.py +39 -0
  50. nextmv/cli/cloud/instance/get.py +62 -0
  51. nextmv/cli/cloud/instance/list.py +60 -0
  52. nextmv/cli/cloud/instance/update.py +216 -0
  53. nextmv/cli/cloud/managed_input/__init__.py +31 -0
  54. nextmv/cli/cloud/managed_input/create.py +144 -0
  55. nextmv/cli/cloud/managed_input/delete.py +64 -0
  56. nextmv/cli/cloud/managed_input/get.py +63 -0
  57. nextmv/cli/cloud/managed_input/list.py +60 -0
  58. nextmv/cli/cloud/managed_input/update.py +97 -0
  59. nextmv/cli/cloud/run/__init__.py +37 -0
  60. nextmv/cli/cloud/run/cancel.py +37 -0
  61. nextmv/cli/cloud/run/create.py +524 -0
  62. nextmv/cli/cloud/run/get.py +199 -0
  63. nextmv/cli/cloud/run/input.py +86 -0
  64. nextmv/cli/cloud/run/list.py +80 -0
  65. nextmv/cli/cloud/run/logs.py +166 -0
  66. nextmv/cli/cloud/run/metadata.py +67 -0
  67. nextmv/cli/cloud/run/track.py +500 -0
  68. nextmv/cli/cloud/scenario/__init__.py +29 -0
  69. nextmv/cli/cloud/scenario/create.py +451 -0
  70. nextmv/cli/cloud/scenario/delete.py +61 -0
  71. nextmv/cli/cloud/scenario/get.py +102 -0
  72. nextmv/cli/cloud/scenario/list.py +63 -0
  73. nextmv/cli/cloud/scenario/metadata.py +67 -0
  74. nextmv/cli/cloud/scenario/update.py +93 -0
  75. nextmv/cli/cloud/secrets/__init__.py +33 -0
  76. nextmv/cli/cloud/secrets/create.py +206 -0
  77. nextmv/cli/cloud/secrets/delete.py +63 -0
  78. nextmv/cli/cloud/secrets/get.py +66 -0
  79. nextmv/cli/cloud/secrets/list.py +60 -0
  80. nextmv/cli/cloud/secrets/update.py +144 -0
  81. nextmv/cli/cloud/shadow/__init__.py +33 -0
  82. nextmv/cli/cloud/shadow/create.py +184 -0
  83. nextmv/cli/cloud/shadow/delete.py +64 -0
  84. nextmv/cli/cloud/shadow/get.py +61 -0
  85. nextmv/cli/cloud/shadow/list.py +63 -0
  86. nextmv/cli/cloud/shadow/metadata.py +66 -0
  87. nextmv/cli/cloud/shadow/start.py +43 -0
  88. nextmv/cli/cloud/shadow/stop.py +53 -0
  89. nextmv/cli/cloud/shadow/update.py +96 -0
  90. nextmv/cli/cloud/switchback/__init__.py +33 -0
  91. nextmv/cli/cloud/switchback/create.py +151 -0
  92. nextmv/cli/cloud/switchback/delete.py +64 -0
  93. nextmv/cli/cloud/switchback/get.py +62 -0
  94. nextmv/cli/cloud/switchback/list.py +63 -0
  95. nextmv/cli/cloud/switchback/metadata.py +68 -0
  96. nextmv/cli/cloud/switchback/start.py +43 -0
  97. nextmv/cli/cloud/switchback/stop.py +53 -0
  98. nextmv/cli/cloud/switchback/update.py +96 -0
  99. nextmv/cli/cloud/upload/__init__.py +22 -0
  100. nextmv/cli/cloud/upload/create.py +39 -0
  101. nextmv/cli/cloud/version/__init__.py +33 -0
  102. nextmv/cli/cloud/version/create.py +96 -0
  103. nextmv/cli/cloud/version/delete.py +61 -0
  104. nextmv/cli/cloud/version/exists.py +39 -0
  105. nextmv/cli/cloud/version/get.py +62 -0
  106. nextmv/cli/cloud/version/list.py +60 -0
  107. nextmv/cli/cloud/version/update.py +92 -0
  108. nextmv/cli/community/__init__.py +24 -0
  109. nextmv/cli/community/clone.py +20 -204
  110. nextmv/cli/community/list.py +61 -126
  111. nextmv/cli/configuration/__init__.py +23 -0
  112. nextmv/cli/configuration/config.py +103 -6
  113. nextmv/cli/configuration/create.py +17 -18
  114. nextmv/cli/configuration/delete.py +25 -13
  115. nextmv/cli/configuration/list.py +4 -4
  116. nextmv/cli/confirm.py +34 -0
  117. nextmv/cli/main.py +68 -36
  118. nextmv/cli/message.py +170 -0
  119. nextmv/cli/options.py +196 -0
  120. nextmv/cli/version.py +20 -1
  121. nextmv/cloud/__init__.py +17 -38
  122. nextmv/cloud/acceptance_test.py +20 -83
  123. nextmv/cloud/account.py +269 -30
  124. nextmv/cloud/application/__init__.py +898 -0
  125. nextmv/cloud/application/_acceptance.py +424 -0
  126. nextmv/cloud/application/_batch_scenario.py +845 -0
  127. nextmv/cloud/application/_ensemble.py +251 -0
  128. nextmv/cloud/application/_input_set.py +263 -0
  129. nextmv/cloud/application/_instance.py +289 -0
  130. nextmv/cloud/application/_managed_input.py +227 -0
  131. nextmv/cloud/application/_run.py +1393 -0
  132. nextmv/cloud/application/_secrets.py +294 -0
  133. nextmv/cloud/application/_shadow.py +320 -0
  134. nextmv/cloud/application/_switchback.py +332 -0
  135. nextmv/cloud/application/_utils.py +54 -0
  136. nextmv/cloud/application/_version.py +304 -0
  137. nextmv/cloud/batch_experiment.py +6 -2
  138. nextmv/cloud/community.py +446 -0
  139. nextmv/cloud/instance.py +11 -1
  140. nextmv/cloud/integration.py +8 -5
  141. nextmv/cloud/package.py +50 -9
  142. nextmv/cloud/shadow.py +254 -0
  143. nextmv/cloud/switchback.py +228 -0
  144. nextmv/deprecated.py +5 -3
  145. nextmv/input.py +20 -88
  146. nextmv/local/application.py +3 -15
  147. nextmv/local/runner.py +1 -1
  148. nextmv/model.py +50 -11
  149. nextmv/options.py +11 -256
  150. nextmv/output.py +0 -62
  151. nextmv/polling.py +54 -16
  152. nextmv/run.py +84 -37
  153. nextmv/status.py +1 -51
  154. {nextmv-0.40.0.dist-info → nextmv-1.0.0.dist-info}/METADATA +37 -11
  155. nextmv-1.0.0.dist-info/RECORD +185 -0
  156. nextmv-1.0.0.dist-info/entry_points.txt +2 -0
  157. nextmv/cli/community/community.py +0 -24
  158. nextmv/cli/configuration/configuration.py +0 -23
  159. nextmv/cli/error.py +0 -22
  160. nextmv/cloud/application.py +0 -4204
  161. nextmv-0.40.0.dist-info/RECORD +0 -66
  162. {nextmv-0.40.0.dist-info → nextmv-1.0.0.dist-info}/WHEEL +0 -0
  163. {nextmv-0.40.0.dist-info → nextmv-1.0.0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,66 @@
1
+ """
2
+ This module defines the cloud app get command for the Nextmv CLI.
3
+ """
4
+
5
+ import json
6
+ from typing import Annotated
7
+
8
+ import typer
9
+
10
+ from nextmv.cli.configuration.config import build_client
11
+ from nextmv.cli.message import in_progress, print_json, success
12
+ from nextmv.cli.options import AppIDOption, ProfileOption
13
+ from nextmv.cloud.application import Application
14
+
15
+ # Set up subcommand application.
16
+ app = typer.Typer()
17
+
18
+
19
+ @app.command()
20
+ def get(
21
+ app_id: AppIDOption,
22
+ output: Annotated[
23
+ str | None,
24
+ typer.Option(
25
+ "--output",
26
+ "-o",
27
+ help="Saves the app information to this location.",
28
+ metavar="OUTPUT_PATH",
29
+ ),
30
+ ] = None,
31
+ profile: ProfileOption = None,
32
+ ) -> None:
33
+ """
34
+ Get a Nextmv Cloud application.
35
+
36
+ This command is useful to get the attributes of an existing Nextmv Cloud
37
+ application by its ID.
38
+
39
+ [bold][underline]Examples[/underline][/bold]
40
+
41
+ - Get the application with the ID [magenta]hare-app[/magenta].
42
+ $ [dim]nextmv cloud app get --app-id hare-app[/dim]
43
+
44
+ - Get the application with the ID [magenta]hare-app[/magenta] and save the information to an
45
+ [magenta]app.json[/magenta] file.
46
+ $ [dim]nextmv cloud app get --app-id hare-app --output app.json[/dim]
47
+ """
48
+
49
+ client = build_client(profile)
50
+ in_progress(msg="Getting application...")
51
+
52
+ cloud_app = Application.get(
53
+ client=client,
54
+ id=app_id,
55
+ )
56
+ cloud_app_dict = cloud_app.to_dict()
57
+
58
+ if output is not None and output != "":
59
+ with open(output, "w") as f:
60
+ json.dump(cloud_app_dict, f, indent=2)
61
+
62
+ success(msg=f"Application information saved to [magenta]{output}[/magenta].")
63
+
64
+ return
65
+
66
+ print_json(cloud_app_dict)
@@ -0,0 +1,61 @@
1
+ """
2
+ This module defines the cloud app list command for the Nextmv CLI.
3
+ """
4
+
5
+ import json
6
+ from typing import Annotated
7
+
8
+ import typer
9
+
10
+ from nextmv.cli.configuration.config import build_client
11
+ from nextmv.cli.message import in_progress, print_json, success
12
+ from nextmv.cli.options import ProfileOption
13
+ from nextmv.cloud.application import list_applications
14
+
15
+ # Set up subcommand application.
16
+ app = typer.Typer()
17
+
18
+
19
+ @app.command()
20
+ def list(
21
+ output: Annotated[
22
+ str | None,
23
+ typer.Option(
24
+ "--output",
25
+ "-o",
26
+ help="Saves the app list information to this location.",
27
+ metavar="OUTPUT_PATH",
28
+ ),
29
+ ] = None,
30
+ profile: ProfileOption = None,
31
+ ) -> None:
32
+ """
33
+ List all Nextmv Cloud applications.
34
+
35
+ [bold][underline]Examples[/underline][/bold]
36
+
37
+ - List all applications.
38
+ $ [dim]nextmv cloud app list[/dim]
39
+
40
+ - List all applications using the profile named [magenta]hare[/magenta].
41
+ $ [dim]nextmv cloud app list --profile hare[/dim]
42
+
43
+ - List all applications and save the information to an [magenta]apps.json[/magenta] file.
44
+ $ [dim]nextmv cloud app list --output apps.json[/dim]
45
+ """
46
+
47
+ client = build_client(profile)
48
+ in_progress(msg="Listing applications...")
49
+
50
+ cloud_apps = list_applications(client)
51
+ cloud_apps_dicts = [app.to_dict() for app in cloud_apps]
52
+
53
+ if output is not None and output != "":
54
+ with open(output, "w") as f:
55
+ json.dump(cloud_apps_dicts, f, indent=2)
56
+
57
+ success(msg=f"Application list information saved to [magenta]{output}[/magenta].")
58
+
59
+ return
60
+
61
+ print_json(cloud_apps_dicts)
@@ -0,0 +1,432 @@
1
+ """
2
+ This module defines the cloud app push command for the Nextmv CLI.
3
+ """
4
+
5
+ import sys
6
+ from datetime import datetime, timezone
7
+ from typing import Annotated
8
+
9
+ import typer
10
+ from rich.prompt import Prompt
11
+
12
+ from nextmv.cli.configuration.config import build_app
13
+ from nextmv.cli.confirm import get_confirmation
14
+ from nextmv.cli.message import error, in_progress, info, success
15
+ from nextmv.cli.options import AppIDOption, ProfileOption
16
+ from nextmv.cloud.application import Application
17
+ from nextmv.manifest import Manifest
18
+
19
+ # Set up subcommand application.
20
+ app = typer.Typer()
21
+
22
+
23
+ @app.command()
24
+ def push(
25
+ app_id: AppIDOption,
26
+ app_dir: Annotated[
27
+ str | None,
28
+ typer.Option(
29
+ "--app-dir",
30
+ "-d",
31
+ help="The path to the application's root directory.",
32
+ metavar="APP_DIR",
33
+ ),
34
+ ] = ".",
35
+ manifest: Annotated[
36
+ str | None,
37
+ typer.Option(
38
+ "--manifest",
39
+ "-m",
40
+ help="Path to the application manifest file ([magenta]app.yaml[/magenta]).",
41
+ metavar="MANIFEST_PATH",
42
+ ),
43
+ ] = None,
44
+ # Options for version control.
45
+ version_id: Annotated[
46
+ str | None,
47
+ typer.Option(
48
+ "--version-id",
49
+ "-v",
50
+ help="Custom ID for version creation after app push. Automatically generated if not provided. "
51
+ "Activates --version-yes.",
52
+ metavar="VERSION_ID",
53
+ rich_help_panel="Version control",
54
+ ),
55
+ ] = None,
56
+ version_yes: Annotated[
57
+ bool,
58
+ typer.Option(
59
+ "--version-yes",
60
+ "-y",
61
+ help="Create a new version after push. Skips confirmation prompt. Useful for non-interactive sessions.",
62
+ rich_help_panel="Version control",
63
+ ),
64
+ ] = False,
65
+ # Options for instance control.
66
+ create_instance_id: Annotated[
67
+ str | None,
68
+ typer.Option(
69
+ "--create-instance-id",
70
+ "-c",
71
+ help="Link the newly created version to a [yellow]new[/yellow] instance with this ID. "
72
+ "Skips prompt to provide an instance ID. Useful for non-interactive sessions.",
73
+ metavar="CREATE_INSTANCE_ID",
74
+ rich_help_panel="Instance control",
75
+ ),
76
+ ] = None,
77
+ update_instance_id: Annotated[
78
+ str | None,
79
+ typer.Option(
80
+ "--update-instance-id",
81
+ "-u",
82
+ help="Link the newly created version to an [yellow]existing[/yellow] instance with this ID. "
83
+ "Skips prompt to provide an instance ID. Useful for non-interactive sessions.",
84
+ metavar="UPDATE_INSTANCE_ID",
85
+ rich_help_panel="Instance control",
86
+ ),
87
+ ] = None,
88
+ profile: ProfileOption = None,
89
+ ) -> None:
90
+ """
91
+ Push (deploy) a Nextmv application to Nextmv Cloud.
92
+
93
+ Use the --app-dir option to specify the path to your application's root
94
+ directory. By default, the current working directory is used.
95
+
96
+ You can also provide a custom manifest file using the --manifest option. If
97
+ not provided, the CLI will look for a file named
98
+ [magenta]app.yaml[/magenta] in the application's root.
99
+
100
+ By default, this command only pushes the app. After the push, you will be
101
+ prompted to create a new version. If a new version is created, you will be
102
+ prompted to link it to an instance. If the instance exists, you will be
103
+ asked if you want to update it. If it doesn't, you will be asked to create
104
+ it. You can use the following flags to skip the prompts, useful in
105
+ non-interactive sessions like in a CI/CD pipeline: --version-yes,
106
+ --version-id, --create-instance-id, and --update-instance-id.
107
+
108
+ [bold][underline]Examples[/underline][/bold]
109
+
110
+ - Push an application, with ID [magenta]hare-app[/magenta], from the current directory.
111
+ $ [dim]nextmv cloud app push --app-id hare-app[/dim]
112
+
113
+ - Push an application, with ID [magenta]hare-app[/magenta], from the [magenta]./my-app[/magenta] directory.
114
+ $ [dim]nextmv cloud app push --app-id hare-app --app-dir ./my-app[/dim]
115
+
116
+ - Push an application, with ID [magenta]hare-app[/magenta], using a custom manifest file.
117
+ $ [dim]nextmv cloud app push --app-id hare-app --manifest ./custom-manifest.yaml[/dim]
118
+
119
+ - Push and automatically create a new version (no prompt).
120
+ $ [dim]nextmv cloud app push --app-id hare-app --version-yes[/dim]
121
+
122
+ - Push and create a new version with a custom version ID (no prompt).
123
+ $ [dim]nextmv cloud app push --app-id hare-app --version-id v1.0.0[/dim]
124
+
125
+ - Push and create a new version, then link it to a new instance with a specific ID (no prompt).
126
+ $ [dim]nextmv cloud app push --app-id hare-app --version-yes --create-instance-id inst-1[/dim]
127
+
128
+ - Push and create a new version, then link it to an existing instance (no prompt).
129
+ $ [dim]nextmv cloud app push --app-id hare-app --version-yes --update-instance-id inst-1[/dim]
130
+ """
131
+
132
+ cloud_app = build_app(app_id=app_id, profile=profile)
133
+
134
+ # If a version already exists, we cannot create it.
135
+ if version_id is not None and version_id != "":
136
+ exists = cloud_app.version_exists(version_id=version_id)
137
+ if exists:
138
+ error(
139
+ f"Version [magenta]{version_id}[/magenta] already exists for application [magenta]{app_id}[/magenta]."
140
+ )
141
+
142
+ # We cannot create and update an instance at the same time.
143
+ update_defined = update_instance_id is not None and update_instance_id != ""
144
+ create_defined = create_instance_id is not None and create_instance_id != ""
145
+ if update_defined and create_defined:
146
+ error("Cannot use --update-instance-id and --create-instance-id at the same time.")
147
+
148
+ # We cannot update an instance that does not exist.
149
+ if update_defined and not cloud_app.instance_exists(instance_id=update_instance_id):
150
+ error(
151
+ f"Used option --update-instance-id but the instance [magenta]{update_instance_id}[/magenta] "
152
+ "does not exist. Use --create-instance-id instead."
153
+ )
154
+
155
+ # We cannot create an instance that already exists.
156
+ if create_defined and cloud_app.instance_exists(instance_id=create_instance_id):
157
+ error(
158
+ f"Used option --create-instance-id but the instance [magenta]{create_instance_id}[/magenta] "
159
+ "already exists. Use --update-instance-id instead."
160
+ )
161
+
162
+ # Do the normal push first.
163
+ loaded_manifest = Manifest.from_yaml(dirpath=manifest) if manifest is not None and manifest != "" else None
164
+ cloud_app.push(
165
+ manifest=loaded_manifest,
166
+ app_dir=app_dir,
167
+ verbose=True,
168
+ rich_print=True,
169
+ )
170
+
171
+ now = datetime.now(timezone.utc)
172
+ version_id, should_continue = _handle_version_creation(
173
+ cloud_app=cloud_app,
174
+ app_id=app_id,
175
+ version_id=version_id,
176
+ version_yes=version_yes,
177
+ now=now,
178
+ )
179
+ if not should_continue:
180
+ return
181
+
182
+ # If the override for updating an instance was used, we update the instance
183
+ # and we are done.
184
+ if update_defined:
185
+ info("Used option --update-instance-id to link version to existing instance.")
186
+ _update_instance(
187
+ cloud_app=cloud_app,
188
+ app_id=app_id,
189
+ version_id=version_id,
190
+ instance_id=update_instance_id,
191
+ )
192
+
193
+ return
194
+
195
+ # If the override for creating a new instance was used, we create the
196
+ # instance and we are done.
197
+ if create_defined:
198
+ info("Used option --create-instance-id to link version to new instance.")
199
+ _create_instance(
200
+ cloud_app=cloud_app,
201
+ app_id=app_id,
202
+ version_id=version_id,
203
+ instance_id=create_instance_id,
204
+ now=now,
205
+ )
206
+
207
+ return
208
+
209
+ # If no overrides are used, we handle instance prompting.
210
+ _handle_instance_prompting(
211
+ cloud_app=cloud_app,
212
+ app_id=app_id,
213
+ version_id=version_id,
214
+ now=now,
215
+ )
216
+
217
+
218
+ def _handle_version_creation(
219
+ cloud_app: Application,
220
+ app_id: str,
221
+ version_id: str | None,
222
+ version_yes: bool,
223
+ now: datetime,
224
+ ) -> tuple[str, bool]:
225
+ """
226
+ Handle the logic for version creation after pushing an application.
227
+
228
+ If a version ID is provided and exists, it is used directly. If not, the user is prompted (unless auto-confirmed)
229
+ to create a new version. If confirmed, a new version is created with an automatic description.
230
+
231
+ Parameters
232
+ ----------
233
+ cloud_app : Application
234
+ The cloud application object to interact with Nextmv Cloud.
235
+ app_id : str
236
+ The application ID.
237
+ version_id : str or None
238
+ The version ID to use or check for existence. If None or empty, a new version may be created.
239
+ version_yes : bool
240
+ Whether to skip the prompt and auto-create a new version.
241
+ now : datetime
242
+ The current datetime, used for version description.
243
+
244
+ Returns
245
+ -------
246
+ tuple[str, bool]
247
+ A tuple containing the version ID (empty string if not created) and a boolean indicating
248
+ whether to continue with subsequent steps (True if a version is selected or created, False otherwise).
249
+ """
250
+
251
+ # If the user provides a version, and it exists, we use it directly and we
252
+ # are done.
253
+ if version_id is not None and version_id != "":
254
+ info(f"Version [magenta]{version_id}[/magenta] does not exist. A new version will be created.")
255
+ version_yes = True # Activate auto-confirm since user provided a version ID.
256
+
257
+ # If we are not auto-confirming version creation, ask the user.
258
+ if not version_yes:
259
+ should_create = get_confirmation(
260
+ msg=f"Do you want to create a new version for application [magenta]{app_id}[/magenta] now?",
261
+ default=True,
262
+ )
263
+
264
+ # If the user does not want to create a new version, we are done.
265
+ if not should_create:
266
+ info("Will not create a new version.")
267
+ return "", False
268
+
269
+ # Create a new version if either the user confirms by prompt or by using
270
+ # the flag.
271
+ in_progress("Creating a new version...")
272
+ version_description = f"Version created automatically from push at {now.strftime('%Y-%m-%dT%H:%M:%SZ')}"
273
+ version = cloud_app.new_version(
274
+ id=version_id,
275
+ description=version_description,
276
+ )
277
+ version_id = version.id
278
+ success(f"New version [magenta]{version_id}[/magenta] created for application [magenta]{app_id}[/magenta].")
279
+
280
+ return version_id, True
281
+
282
+
283
+ def _handle_instance_prompting(
284
+ cloud_app: Application,
285
+ app_id: str,
286
+ version_id: str,
287
+ now: datetime,
288
+ ) -> None:
289
+ """
290
+ Handle interactive prompting for linking a version to an instance after a push.
291
+
292
+ In interactive terminals, prompts the user to link the new version to an existing or new instance.
293
+ If the terminal is non-interactive, skips prompting. Handles both updating existing instances and creating new ones.
294
+
295
+ Parameters
296
+ ----------
297
+ cloud_app : Application
298
+ The cloud application object to interact with Nextmv Cloud.
299
+ app_id : str
300
+ The application ID.
301
+ version_id : str
302
+ The version ID to link to an instance.
303
+ now : datetime
304
+ The current datetime, used for instance description if a new instance is created.
305
+ """
306
+
307
+ # If this is not an interactive terminal, do not ask for instance linking,
308
+ # to avoid hanging indefinitely waiting for a user response.
309
+ if not sys.stdin.isatty():
310
+ info("Non-interactive terminal detected. Skipping instance linking.")
311
+
312
+ return
313
+
314
+ # Prompt the user for an instance ID to link the new version to.
315
+ instance_id = Prompt.ask(
316
+ f"Do you want to link version [magenta]{version_id}[/magenta] to an instance? If so, enter the instance ID. "
317
+ "Leave blank to abort",
318
+ case_sensitive=False,
319
+ )
320
+ if instance_id == "":
321
+ info("No instance ID provided. Skipping instance linking.")
322
+ return
323
+
324
+ # Based on whether the instance exists or not, ask the user if they want to
325
+ # update or create it.
326
+ exists = cloud_app.instance_exists(instance_id=instance_id)
327
+
328
+ # If the instance exists, ask if we want to update it.
329
+ if exists:
330
+ should_update = get_confirmation(
331
+ msg=f"Instance [magenta]{instance_id}[/magenta] exists. "
332
+ f"Do you want to link it to version [magenta]{version_id}[/magenta]?",
333
+ default=True,
334
+ )
335
+
336
+ if not should_update:
337
+ info(f"Will not update instance [magenta]{instance_id}[/magenta].")
338
+ return
339
+
340
+ _update_instance(
341
+ cloud_app=cloud_app,
342
+ app_id=app_id,
343
+ version_id=version_id,
344
+ instance_id=instance_id,
345
+ )
346
+
347
+ return
348
+
349
+ # If the instance does not exist, ask if we want to create it.
350
+ should_create = get_confirmation(
351
+ msg=f"Instance [magenta]{instance_id}[/magenta] does not exist. "
352
+ f"Do you want to create it using version [magenta]{version_id}[/magenta]?",
353
+ default=True,
354
+ )
355
+
356
+ if not should_create:
357
+ info(f"Will not create instance [magenta]{instance_id}[/magenta].")
358
+ return
359
+
360
+ _create_instance(
361
+ cloud_app=cloud_app,
362
+ app_id=app_id,
363
+ version_id=version_id,
364
+ instance_id=instance_id,
365
+ now=now,
366
+ )
367
+
368
+
369
+ def _update_instance(
370
+ cloud_app: Application,
371
+ app_id: str,
372
+ version_id: str,
373
+ instance_id: str,
374
+ ) -> None:
375
+ """
376
+ Update an existing instance to use a new version.
377
+
378
+ Parameters
379
+ ----------
380
+ cloud_app : Application
381
+ The cloud application object to interact with Nextmv Cloud.
382
+ app_id : str
383
+ The application ID.
384
+ version_id : str
385
+ The version ID to link to the instance.
386
+ instance_id : str
387
+ The instance ID to update.
388
+ """
389
+
390
+ in_progress(f"Updating instance [magenta]{instance_id}[/magenta] to use version [magenta]{version_id}[/magenta]...")
391
+ cloud_app.update_instance(id=instance_id, version_id=version_id)
392
+ success(
393
+ f"Instance [magenta]{instance_id}[/magenta] updated to use version [magenta]{version_id}[/magenta] "
394
+ f"for application [magenta]{app_id}[/magenta]."
395
+ )
396
+
397
+
398
+ def _create_instance(
399
+ cloud_app: Application,
400
+ app_id: str,
401
+ version_id: str,
402
+ instance_id: str,
403
+ now: datetime,
404
+ ) -> None:
405
+ """
406
+ Create a new instance linked to a specific version.
407
+
408
+ Parameters
409
+ ----------
410
+ cloud_app : Application
411
+ The cloud application object to interact with Nextmv Cloud.
412
+ app_id : str
413
+ The application ID.
414
+ version_id : str
415
+ The version ID to link to the new instance.
416
+ instance_id : str
417
+ The instance ID to create.
418
+ now : datetime
419
+ The current datetime, used for the instance description.
420
+ """
421
+
422
+ in_progress(f"Creating a new instance with ID [magenta]{instance_id}[/magenta]...")
423
+ instance_description = f"Instance created automatically from push at {now.strftime('%Y-%m-%dT%H:%M:%SZ')}"
424
+ instance = cloud_app.new_instance(
425
+ version_id=version_id,
426
+ id=instance_id,
427
+ description=instance_description,
428
+ )
429
+ success(
430
+ f"New instance [magenta]{instance.id}[/magenta] created using version [magenta]{version_id}[/magenta] "
431
+ f"for application [magenta]{app_id}[/magenta]."
432
+ )
@@ -0,0 +1,124 @@
1
+ """
2
+ This module defines the cloud app update command for the Nextmv CLI.
3
+ """
4
+
5
+ import json
6
+ from typing import Annotated
7
+
8
+ import typer
9
+
10
+ from nextmv.cli.configuration.config import build_app
11
+ from nextmv.cli.message import error, print_json, success
12
+ from nextmv.cli.options import AppIDOption, ProfileOption
13
+
14
+ # Set up subcommand application.
15
+ app = typer.Typer()
16
+
17
+
18
+ @app.command()
19
+ def update(
20
+ app_id: AppIDOption,
21
+ default_experiment_instance: Annotated[
22
+ str | None,
23
+ typer.Option(
24
+ "--default-experiment-instance",
25
+ "-x",
26
+ help="A new default experiment instance ID for the application.",
27
+ metavar="DEFAULT_EXPERIMENT_INSTANCE",
28
+ ),
29
+ ] = None,
30
+ default_instance_id: Annotated[
31
+ str | None,
32
+ typer.Option(
33
+ "--default-instance-id",
34
+ "-i",
35
+ help="A new default instance ID for the application.",
36
+ metavar="DEFAULT_INSTANCE_ID",
37
+ ),
38
+ ] = None,
39
+ description: Annotated[
40
+ str | None,
41
+ typer.Option(
42
+ "--description",
43
+ "-d",
44
+ help="A new description for the application.",
45
+ metavar="DESCRIPTION",
46
+ ),
47
+ ] = None,
48
+ name: Annotated[
49
+ str | None,
50
+ typer.Option(
51
+ "--name",
52
+ "-n",
53
+ help="A new name for the application.",
54
+ metavar="NAME",
55
+ ),
56
+ ] = None,
57
+ output: Annotated[
58
+ str | None,
59
+ typer.Option(
60
+ "--output",
61
+ "-o",
62
+ help="Saves the updated app information to this location.",
63
+ metavar="OUTPUT_PATH",
64
+ ),
65
+ ] = None,
66
+ profile: ProfileOption = None,
67
+ ) -> None:
68
+ """
69
+ Updates a Nextmv Cloud application.
70
+
71
+ Please note that you cannot change the type of an application, you must
72
+ create a new one.
73
+
74
+ [bold][underline]Examples[/underline][/bold]
75
+
76
+ - Update an application's name.
77
+ $ [dim]nextmv cloud app update --app-id hare-app --name "New Hare App"[/dim]
78
+
79
+ - Update an application's description.
80
+ $ [dim]nextmv cloud app update --app-id hare-app --name "Hare App" \\
81
+ --description "An updated description for routing hares"[/dim]
82
+
83
+ - Update an application's default instance ID.
84
+ $ [dim]nextmv cloud app update --app-id hare-app --name "Hare App" \\
85
+ --default-instance-id burrow[/dim]
86
+
87
+ - Update an application's default experiment instance.
88
+ $ [dim]nextmv cloud app update --app-id hare-app --name "Hare App" \\
89
+ --default-experiment-instance experiment-v1[/dim]
90
+
91
+ - Update multiple application properties at once.
92
+ $ [dim]nextmv cloud app update --app-id hare-app --name "Hare App" \\
93
+ --description "Updated description" --default-instance-id burrow \\
94
+ --default-experiment-instance experiment-v1[/dim]
95
+
96
+ - Update an application and save the updated information to an [magenta]updated_app.json[/magenta] file.
97
+ $ [dim]nextmv cloud app update --app-id hare-app --name "New Hare App" --output updated_app.json[/dim]
98
+ """
99
+
100
+ if name is None and description is None and default_instance_id is None and default_experiment_instance is None:
101
+ error(
102
+ "Provide at least one option to update: --name, --description, "
103
+ "--default-instance-id, or --default-experiment-instance."
104
+ )
105
+
106
+ cloud_app = build_app(app_id=app_id, profile=profile)
107
+ updated_app = cloud_app.update(
108
+ name=name,
109
+ description=description,
110
+ default_instance_id=default_instance_id,
111
+ default_experiment_instance=default_experiment_instance,
112
+ )
113
+ success(f"Application [magenta]{app_id}[/magenta] updated successfully.")
114
+ updated_app_dict = updated_app.to_dict()
115
+
116
+ if output is not None and output != "":
117
+ with open(output, "w") as f:
118
+ json.dump(updated_app_dict, f, indent=2)
119
+
120
+ success(msg=f"Updated application information saved to [magenta]{output}[/magenta].")
121
+
122
+ return
123
+
124
+ print_json(updated_app_dict)