nextmv 0.18.0__py3-none-any.whl → 1.0.0.dev2__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 (175) hide show
  1. nextmv/__about__.py +1 -1
  2. nextmv/__entrypoint__.py +8 -13
  3. nextmv/__init__.py +53 -0
  4. nextmv/_serialization.py +96 -0
  5. nextmv/base_model.py +54 -9
  6. nextmv/cli/CONTRIBUTING.md +511 -0
  7. nextmv/cli/__init__.py +0 -0
  8. nextmv/cli/cloud/__init__.py +47 -0
  9. nextmv/cli/cloud/acceptance/__init__.py +27 -0
  10. nextmv/cli/cloud/acceptance/create.py +393 -0
  11. nextmv/cli/cloud/acceptance/delete.py +68 -0
  12. nextmv/cli/cloud/acceptance/get.py +104 -0
  13. nextmv/cli/cloud/acceptance/list.py +62 -0
  14. nextmv/cli/cloud/acceptance/update.py +95 -0
  15. nextmv/cli/cloud/account/__init__.py +28 -0
  16. nextmv/cli/cloud/account/create.py +83 -0
  17. nextmv/cli/cloud/account/delete.py +60 -0
  18. nextmv/cli/cloud/account/get.py +66 -0
  19. nextmv/cli/cloud/account/update.py +70 -0
  20. nextmv/cli/cloud/app/__init__.py +35 -0
  21. nextmv/cli/cloud/app/create.py +141 -0
  22. nextmv/cli/cloud/app/delete.py +58 -0
  23. nextmv/cli/cloud/app/exists.py +44 -0
  24. nextmv/cli/cloud/app/get.py +66 -0
  25. nextmv/cli/cloud/app/list.py +61 -0
  26. nextmv/cli/cloud/app/push.py +137 -0
  27. nextmv/cli/cloud/app/update.py +124 -0
  28. nextmv/cli/cloud/batch/__init__.py +29 -0
  29. nextmv/cli/cloud/batch/create.py +454 -0
  30. nextmv/cli/cloud/batch/delete.py +68 -0
  31. nextmv/cli/cloud/batch/get.py +104 -0
  32. nextmv/cli/cloud/batch/list.py +63 -0
  33. nextmv/cli/cloud/batch/metadata.py +66 -0
  34. nextmv/cli/cloud/batch/update.py +95 -0
  35. nextmv/cli/cloud/data/__init__.py +26 -0
  36. nextmv/cli/cloud/data/upload.py +162 -0
  37. nextmv/cli/cloud/ensemble/__init__.py +31 -0
  38. nextmv/cli/cloud/ensemble/create.py +414 -0
  39. nextmv/cli/cloud/ensemble/delete.py +67 -0
  40. nextmv/cli/cloud/ensemble/get.py +65 -0
  41. nextmv/cli/cloud/ensemble/update.py +103 -0
  42. nextmv/cli/cloud/input_set/__init__.py +30 -0
  43. nextmv/cli/cloud/input_set/create.py +170 -0
  44. nextmv/cli/cloud/input_set/get.py +63 -0
  45. nextmv/cli/cloud/input_set/list.py +63 -0
  46. nextmv/cli/cloud/input_set/update.py +123 -0
  47. nextmv/cli/cloud/instance/__init__.py +35 -0
  48. nextmv/cli/cloud/instance/create.py +290 -0
  49. nextmv/cli/cloud/instance/delete.py +62 -0
  50. nextmv/cli/cloud/instance/exists.py +39 -0
  51. nextmv/cli/cloud/instance/get.py +62 -0
  52. nextmv/cli/cloud/instance/list.py +60 -0
  53. nextmv/cli/cloud/instance/update.py +216 -0
  54. nextmv/cli/cloud/managed_input/__init__.py +31 -0
  55. nextmv/cli/cloud/managed_input/create.py +146 -0
  56. nextmv/cli/cloud/managed_input/delete.py +65 -0
  57. nextmv/cli/cloud/managed_input/get.py +63 -0
  58. nextmv/cli/cloud/managed_input/list.py +60 -0
  59. nextmv/cli/cloud/managed_input/update.py +97 -0
  60. nextmv/cli/cloud/run/__init__.py +37 -0
  61. nextmv/cli/cloud/run/cancel.py +37 -0
  62. nextmv/cli/cloud/run/create.py +530 -0
  63. nextmv/cli/cloud/run/get.py +199 -0
  64. nextmv/cli/cloud/run/input.py +86 -0
  65. nextmv/cli/cloud/run/list.py +80 -0
  66. nextmv/cli/cloud/run/logs.py +167 -0
  67. nextmv/cli/cloud/run/metadata.py +67 -0
  68. nextmv/cli/cloud/run/track.py +501 -0
  69. nextmv/cli/cloud/scenario/__init__.py +29 -0
  70. nextmv/cli/cloud/scenario/create.py +451 -0
  71. nextmv/cli/cloud/scenario/delete.py +65 -0
  72. nextmv/cli/cloud/scenario/get.py +102 -0
  73. nextmv/cli/cloud/scenario/list.py +63 -0
  74. nextmv/cli/cloud/scenario/metadata.py +67 -0
  75. nextmv/cli/cloud/scenario/update.py +93 -0
  76. nextmv/cli/cloud/secrets/__init__.py +33 -0
  77. nextmv/cli/cloud/secrets/create.py +206 -0
  78. nextmv/cli/cloud/secrets/delete.py +67 -0
  79. nextmv/cli/cloud/secrets/get.py +66 -0
  80. nextmv/cli/cloud/secrets/list.py +60 -0
  81. nextmv/cli/cloud/secrets/update.py +147 -0
  82. nextmv/cli/cloud/shadow/__init__.py +33 -0
  83. nextmv/cli/cloud/shadow/create.py +184 -0
  84. nextmv/cli/cloud/shadow/delete.py +68 -0
  85. nextmv/cli/cloud/shadow/get.py +61 -0
  86. nextmv/cli/cloud/shadow/list.py +63 -0
  87. nextmv/cli/cloud/shadow/metadata.py +66 -0
  88. nextmv/cli/cloud/shadow/start.py +43 -0
  89. nextmv/cli/cloud/shadow/stop.py +43 -0
  90. nextmv/cli/cloud/shadow/update.py +95 -0
  91. nextmv/cli/cloud/upload/__init__.py +22 -0
  92. nextmv/cli/cloud/upload/create.py +39 -0
  93. nextmv/cli/cloud/version/__init__.py +33 -0
  94. nextmv/cli/cloud/version/create.py +97 -0
  95. nextmv/cli/cloud/version/delete.py +62 -0
  96. nextmv/cli/cloud/version/exists.py +39 -0
  97. nextmv/cli/cloud/version/get.py +62 -0
  98. nextmv/cli/cloud/version/list.py +60 -0
  99. nextmv/cli/cloud/version/update.py +92 -0
  100. nextmv/cli/community/__init__.py +24 -0
  101. nextmv/cli/community/clone.py +270 -0
  102. nextmv/cli/community/list.py +265 -0
  103. nextmv/cli/configuration/__init__.py +23 -0
  104. nextmv/cli/configuration/config.py +195 -0
  105. nextmv/cli/configuration/create.py +94 -0
  106. nextmv/cli/configuration/delete.py +67 -0
  107. nextmv/cli/configuration/list.py +77 -0
  108. nextmv/cli/main.py +188 -0
  109. nextmv/cli/message.py +153 -0
  110. nextmv/cli/options.py +206 -0
  111. nextmv/cli/version.py +38 -0
  112. nextmv/cloud/__init__.py +71 -17
  113. nextmv/cloud/acceptance_test.py +757 -51
  114. nextmv/cloud/account.py +406 -17
  115. nextmv/cloud/application/__init__.py +957 -0
  116. nextmv/cloud/application/_acceptance.py +419 -0
  117. nextmv/cloud/application/_batch_scenario.py +860 -0
  118. nextmv/cloud/application/_ensemble.py +251 -0
  119. nextmv/cloud/application/_input_set.py +227 -0
  120. nextmv/cloud/application/_instance.py +289 -0
  121. nextmv/cloud/application/_managed_input.py +227 -0
  122. nextmv/cloud/application/_run.py +1393 -0
  123. nextmv/cloud/application/_secrets.py +294 -0
  124. nextmv/cloud/application/_shadow.py +314 -0
  125. nextmv/cloud/application/_utils.py +54 -0
  126. nextmv/cloud/application/_version.py +303 -0
  127. nextmv/cloud/assets.py +48 -0
  128. nextmv/cloud/batch_experiment.py +294 -33
  129. nextmv/cloud/client.py +307 -66
  130. nextmv/cloud/ensemble.py +247 -0
  131. nextmv/cloud/input_set.py +120 -2
  132. nextmv/cloud/instance.py +133 -8
  133. nextmv/cloud/integration.py +533 -0
  134. nextmv/cloud/package.py +168 -53
  135. nextmv/cloud/scenario.py +410 -0
  136. nextmv/cloud/secrets.py +234 -0
  137. nextmv/cloud/shadow.py +190 -0
  138. nextmv/cloud/url.py +73 -0
  139. nextmv/cloud/version.py +132 -4
  140. nextmv/default_app/.gitignore +1 -0
  141. nextmv/default_app/README.md +32 -0
  142. nextmv/default_app/app.yaml +12 -0
  143. nextmv/default_app/input.json +5 -0
  144. nextmv/default_app/main.py +37 -0
  145. nextmv/default_app/requirements.txt +2 -0
  146. nextmv/default_app/src/__init__.py +0 -0
  147. nextmv/default_app/src/visuals.py +36 -0
  148. nextmv/deprecated.py +47 -0
  149. nextmv/input.py +861 -90
  150. nextmv/local/__init__.py +5 -0
  151. nextmv/local/application.py +1251 -0
  152. nextmv/local/executor.py +1042 -0
  153. nextmv/local/geojson_handler.py +323 -0
  154. nextmv/local/local.py +97 -0
  155. nextmv/local/plotly_handler.py +61 -0
  156. nextmv/local/runner.py +274 -0
  157. nextmv/logger.py +80 -9
  158. nextmv/manifest.py +1466 -0
  159. nextmv/model.py +241 -66
  160. nextmv/options.py +708 -115
  161. nextmv/output.py +1301 -274
  162. nextmv/polling.py +325 -0
  163. nextmv/run.py +1702 -0
  164. nextmv/safe.py +145 -0
  165. nextmv/status.py +122 -0
  166. nextmv-1.0.0.dev2.dist-info/METADATA +311 -0
  167. nextmv-1.0.0.dev2.dist-info/RECORD +170 -0
  168. {nextmv-0.18.0.dist-info → nextmv-1.0.0.dev2.dist-info}/WHEEL +1 -1
  169. nextmv-1.0.0.dev2.dist-info/entry_points.txt +2 -0
  170. nextmv/cloud/application.py +0 -1405
  171. nextmv/cloud/manifest.py +0 -234
  172. nextmv/cloud/status.py +0 -29
  173. nextmv-0.18.0.dist-info/METADATA +0 -770
  174. nextmv-0.18.0.dist-info/RECORD +0 -25
  175. {nextmv-0.18.0.dist-info → nextmv-1.0.0.dev2.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,247 @@
1
+ """
2
+ Classes for working with Nextmv Cloud Ensemble Runs.
3
+
4
+ This module provides classes for interacting with ensemble runs in Nextmv Cloud.
5
+ It details the core data structures for ensemble definitions.
6
+
7
+ Classes
8
+ -------
9
+ RunGroup
10
+ A structure to group execution of child runs for an ensemble run.
11
+ RuleObjective
12
+ An enum that specifies the supported evaluation rule objectives.
13
+ ToleranceType
14
+ An enum that specifies the supported tolerance types for evaluation rules.
15
+ RuleTolerance
16
+ A structure for defining tolerance thresholds for an evaluation rule
17
+ EvaluationRule
18
+ A structure to evaluate run results for an ensemble run.
19
+ EnsembleDefinition
20
+ Representation of a Nextmv Cloud Ensemble Definition for an application.
21
+ """
22
+
23
+ from datetime import datetime
24
+ from enum import Enum
25
+
26
+ from nextmv.base_model import BaseModel
27
+
28
+
29
+ class RunGroup(BaseModel):
30
+ """A structure to group child runs for an ensemble run.
31
+
32
+ You can import the `RunGroup` class directly from `cloud`:
33
+
34
+ ```python
35
+ from nextmv.cloud import RunGroup
36
+ ```
37
+
38
+ This class represents a grouping of child runs that share a configuration
39
+ for ensemble run executions.
40
+
41
+ Parameters
42
+ ----------
43
+ id : str
44
+ The unique identifier of the run group.
45
+ instance_id : str
46
+ ID of the app instance that this run group executes on.
47
+ options : dict, optional
48
+ Runtime options/parameters for the application.
49
+ repetitions : int, optional
50
+ The number of times the run is to be repeated on the instance and with
51
+ the options defined in the run group
52
+ """
53
+
54
+ id: str
55
+ """The unique identifier of the run group."""
56
+ instance_id: str
57
+ """ID of the app instance that this run group executes on."""
58
+ options: dict | None = None
59
+ """Runtime options/parameters for the application."""
60
+ repetitions: int | None = None
61
+ """The number of times the run is to be repeated on the instance and with
62
+ the options defined in the run group"""
63
+
64
+
65
+ class RuleObjective(str, Enum):
66
+ """The value of this data determines how a value of a run is optimized to
67
+ determined which ensemble child run is the "best" for a given metric and
68
+ rule, as well as which other ones are within tolerance of that run for the
69
+ purposes of selecting a result for the ensemble run from among the child runs.
70
+
71
+ You can import the `RuleObjective` class directly from `cloud`:
72
+
73
+ ```python
74
+ from nextmv.cloud import RuleObjective
75
+ ```
76
+
77
+ This enum specifies the supported evaluation rule objectives.
78
+
79
+ Attributes
80
+ ----------
81
+ MAXIMIZE : str
82
+ Maximize the value of the evaluated metric.
83
+ MINIMIZE : str
84
+ Minimize the value of the evaluated metric.
85
+ """
86
+
87
+ MAXIMIZE = "maximize"
88
+ """Maximize the value of the evaluated metric."""
89
+ MINIMIZE = "minimize"
90
+ """Minimize the value of the evaluated metric."""
91
+
92
+
93
+ class RuleToleranceType(str, Enum):
94
+ """The type of comparison used to determine if a run metric is within
95
+ tolerance of a the "best" run for that rule and metric
96
+
97
+ You can import the `RuleToleranceType` class directly from `cloud`:
98
+
99
+ ```python
100
+ from nextmv.cloud import RuleToleranceType
101
+ ```
102
+
103
+ This enum specifies the supported tolerance types.
104
+
105
+ Attributes
106
+ ----------
107
+ ABSOLUTE : str
108
+ Uses the absolute difference between the value of the "best" run and
109
+ the run being evaluated for tolerance
110
+ RELATIVE : str
111
+ Uses the the percentage of the "best" run by which the run being
112
+ evaluted for tolerance differs. A value of `1` is 100%.
113
+ """
114
+
115
+ ABSOLUTE = "absolute"
116
+ """Uses the absolute difference between the value of the "best" run and
117
+ the run being evaluated for tolerance"""
118
+ RELATIVE = "relative"
119
+ """Uses the the percentage of the "best" run by which the run being
120
+ evaluted for tolerance differs. A value of `1` is 100%."""
121
+
122
+
123
+ class RuleTolerance(BaseModel):
124
+ """A structure used to determine if a run is within tolerance of of the best
125
+ run (as determined by the objective of the `EvaluationRule` it is defined on).
126
+
127
+ You can import the `RuleTolerance` class directly from `cloud`:
128
+
129
+ ```python
130
+ from nextmv.cloud import RuleTolerance
131
+ ```
132
+
133
+ This class represents the tolerance on a particular evaluation rule by
134
+ which a child run may be selected as the result of an ensemble run.
135
+
136
+ value : float
137
+ The value within which runs can deviate from the "best" run
138
+ for that metric to be considered within tolerance of it.
139
+ type : ToleranceType
140
+ The method by which runs are determined to be within tolerance.
141
+ """
142
+
143
+ value: float
144
+ """The value within which runs can deviate from the "best" run
145
+ for that metric to be considered within tolerance of it."""
146
+ type: RuleToleranceType
147
+ """The method by which runs are determined to be within tolerance."""
148
+
149
+
150
+ class EvaluationRule(BaseModel):
151
+ """A structure to evaluate run results for an ensemble run.
152
+
153
+ You can import the `EvaluationRule` class directly from `cloud`:
154
+
155
+ ```python
156
+ from nextmv.cloud import EvaluationRule
157
+ ```
158
+
159
+ This class represents a rule by which the child runs for an ensemble run
160
+ will be evaluated for the purpose of selecting an optimal result for the
161
+ ensemble run.
162
+
163
+ Parameters
164
+ ----------
165
+ id : str
166
+ The unique identifier of the evaluation rule.
167
+ statistics_path : str
168
+ The path within the statistics of a run output (conforming to Nextmv
169
+ statistics convention and flattened to a string starting with `$` and
170
+ delimited by `.` e.g. `$.result.value`.)
171
+ objective : RuleObjective
172
+ The objective by which runs are optimized for this rule
173
+ tolerance : RuleTolerance
174
+ The tolerance by which runs can be accepted as a potential result
175
+ for an evaluation rule
176
+ index : int, optional
177
+ The index (non-negative integer) of the evalutation rule. Lower indicies
178
+ are evaluated first.
179
+ """
180
+
181
+ id: str
182
+ """The unique identifier of the evaluation rule."""
183
+ statistics_path: str
184
+ """The path within the statistics of a run output (conforming to Nextmv
185
+ statistics convention and flattened to a string starting with `$` and
186
+ delimited by `.` e.g. `$.result.value`.)"""
187
+ objective: RuleObjective
188
+ """The objective by which runs are optimized for this rule"""
189
+ tolerance: RuleTolerance
190
+ """The tolerance by which runs can be accepted as a potential result
191
+ for an evaluation rule"""
192
+ index: int
193
+ """The index (non-negative integer) of the evalutation rule. Lower indicies
194
+ are evaluated first."""
195
+
196
+
197
+ class EnsembleDefinition(BaseModel):
198
+ """An ensemble definition for an application.
199
+
200
+ You can import the `EnsembleDefinition` class directly from `cloud`:
201
+
202
+ ```python
203
+ from nextmv.cloud import EnsembleDefinition
204
+ ```
205
+
206
+ A Nextmv Cloud ensemble definition represents a structure by which an
207
+ application can coordinate and execute, and determine the optimal result of
208
+ an ensemble run.
209
+
210
+ Parameters
211
+ ----------
212
+ id : str
213
+ The unique identifier of the ensemble definition.
214
+ application_id : str
215
+ ID of the application that this ensemble definition belongs to.
216
+ name : str
217
+ Human-readable name of the ensemble definition.
218
+ description : str
219
+ Detailed description of the ensemble definition.
220
+ run_groups : list[RunGroup], optional
221
+ The run groups that structure the execution of an ensemble run
222
+ rules : list[EvaluationRule], optional
223
+ The rules by which ensemble child runs are evaluated
224
+ to find an optimal result.
225
+ created_at : datetime
226
+ Timestamp when the ensemble definition was created.
227
+ updated_at : datetime
228
+ Timestamp when the ensemble definition was last updated.
229
+ """
230
+
231
+ id: str
232
+ """The unique identifier of the ensemble definition."""
233
+ application_id: str
234
+ """ID of the application that this ensemble definition belongs to."""
235
+ name: str = ""
236
+ """Human-readable name of the ensemble definition."""
237
+ description: str = ""
238
+ """Detailed description of the ensemble definition."""
239
+ run_groups: list[RunGroup]
240
+ """The run groups that structure the execution of an ensemble run"""
241
+ rules: list[EvaluationRule]
242
+ """The rules by which ensemble child runs are evaluated
243
+ to find an optimal result."""
244
+ created_at: datetime
245
+ """Timestamp when the ensemble definition was created."""
246
+ updated_at: datetime
247
+ """Timestamp when the ensemble definition was last updated."""
nextmv/cloud/input_set.py CHANGED
@@ -1,12 +1,128 @@
1
- """This module contains definitions for input sets."""
1
+ """Definitions for input sets and related cloud objects.
2
+
3
+ This module provides classes for managing inputs and input sets in the Nextmv Cloud.
4
+
5
+ Classes
6
+ -------
7
+ ManagedInput
8
+ An input created for experimenting with an application.
9
+ InputSet
10
+ A collection of inputs from associated runs.
11
+ """
2
12
 
3
13
  from datetime import datetime
4
14
 
5
15
  from nextmv.base_model import BaseModel
16
+ from nextmv.run import Format
17
+
18
+
19
+ class ManagedInput(BaseModel):
20
+ """An input created for experimenting with an application.
21
+
22
+ You can import the `ManagedInput` class directly from `cloud`:
23
+
24
+ ```python
25
+ from nextmv.cloud import ManagedInput
26
+ ```
27
+
28
+ This class represents an input that was uploaded to the Nextmv Cloud
29
+ for experimentation purposes. It contains metadata about the input,
30
+ such as its ID, name, description, and creation time.
31
+
32
+ Parameters
33
+ ----------
34
+ id : str
35
+ Unique identifier of the input.
36
+ name : str, optional
37
+ User-defined name of the input.
38
+ description : str, optional
39
+ User-defined description of the input.
40
+ run_id : str, optional
41
+ Identifier of the run that created this input.
42
+ upload_id : str, optional
43
+ Identifier of the upload that created this input.
44
+ format : Format, optional
45
+ Format of the input (e.g., JSON, CSV).
46
+ created_at : datetime, optional
47
+ Timestamp when the input was created.
48
+ updated_at : datetime, optional
49
+ Timestamp when the input was last updated.
50
+
51
+ Examples
52
+ --------
53
+ >>> input = ManagedInput(id="inp_123456789")
54
+ >>> print(input.id)
55
+ inp_123456789
56
+ """
57
+
58
+ id: str
59
+ """ID of the input."""
60
+
61
+ name: str | None = None
62
+ """Name of the input."""
63
+ description: str | None = None
64
+ """Description of the input."""
65
+ run_id: str | None = None
66
+ """ID of the run that created the input."""
67
+ upload_id: str | None = None
68
+ """ID of the upload that created the input."""
69
+ format: Format | None = None
70
+ """Format of the input."""
71
+ created_at: datetime | None = None
72
+ """Creation time of the input."""
73
+ updated_at: datetime | None = None
74
+ """Last update time of the input."""
6
75
 
7
76
 
8
77
  class InputSet(BaseModel):
9
- """An input set is the collection of inputs from the associated runs."""
78
+ """A collection of inputs from associated runs.
79
+
80
+ You can import the `InputSet` class directly from `cloud`:
81
+
82
+ ```python
83
+ from nextmv.cloud import InputSet
84
+ ```
85
+
86
+ An input set aggregates multiple inputs used for experimentation with an application
87
+ in the Nextmv Cloud. It allows organizing and managing related inputs
88
+ for comparison and analysis.
89
+
90
+ Parameters
91
+ ----------
92
+ app_id : str
93
+ Identifier of the application that the input set belongs to.
94
+ created_at : datetime
95
+ Timestamp when the input set was created.
96
+ description : str
97
+ User-defined description of the input set.
98
+ id : str
99
+ Unique identifier of the input set.
100
+ input_ids : list[str]
101
+ List of identifiers of the inputs in the input set.
102
+ name : str
103
+ User-defined name of the input set.
104
+ updated_at : datetime
105
+ Timestamp when the input set was last updated.
106
+ inputs : list[ManagedInput]
107
+ List of ManagedInput objects contained in this input set.
108
+
109
+ Examples
110
+ --------
111
+ >>> input_set = InputSet(
112
+ ... app_id="app_123456789",
113
+ ... id="is_987654321",
114
+ ... name="My Input Set",
115
+ ... description="A collection of routing inputs",
116
+ ... input_ids=["inp_111", "inp_222"],
117
+ ... created_at=datetime.now(),
118
+ ... updated_at=datetime.now(),
119
+ ... inputs=[]
120
+ ... )
121
+ >>> print(input_set.name)
122
+ My Input Set
123
+ >>> print(len(input_set.input_ids))
124
+ 2
125
+ """
10
126
 
11
127
  app_id: str
12
128
  """ID of the application that the input set belongs to."""
@@ -22,3 +138,5 @@ class InputSet(BaseModel):
22
138
  """Name of the input set."""
23
139
  updated_at: datetime
24
140
  """Last update time of the input set."""
141
+ inputs: list[ManagedInput]
142
+ """List of inputs in the input set."""
nextmv/cloud/instance.py CHANGED
@@ -1,22 +1,147 @@
1
- """This module contains definitions for instances."""
1
+ """Classes for working with Nextmv Cloud Instances.
2
+
3
+ This module provides classes for interacting with instances in Nextmv Cloud.
4
+ It defines the core data structures for both instance configuration and the
5
+ instance itself.
6
+
7
+ Classes
8
+ -------
9
+ InstanceConfiguration
10
+ Configuration settings for a Nextmv Cloud instance.
11
+ Instance
12
+ Representation of a Nextmv Cloud instance tied to an application version.
13
+ """
2
14
 
3
15
  from datetime import datetime
4
- from typing import Optional
5
16
 
6
17
  from nextmv.base_model import BaseModel
18
+ from nextmv.run import Format, RunQueuing
19
+
20
+
21
+ class InstanceConfiguration(BaseModel):
22
+ """Configuration for a Nextmv Cloud instance.
23
+
24
+ You can import the `InstanceConfiguration` class directly from `cloud`:
7
25
 
26
+ ```python
27
+ from nextmv.cloud import InstanceConfiguration
28
+ ```
8
29
 
9
- class Configuration(BaseModel):
10
- """Configuration for an instance."""
30
+ This class represents the configuration settings that can be applied to a
31
+ Nextmv Cloud instance, including execution class, options, and secrets.
11
32
 
12
- execution_class: Optional[str] = None
33
+ Parameters
34
+ ----------
35
+ execution_class : str, optional
36
+ The execution class for the instance, which determines compute resources.
37
+ options : dict, optional
38
+ Runtime options/parameters for the application.
39
+ secrets_collection_id : str, optional
40
+ ID of the secrets collection to use with this instance.
41
+ queuing : RunQueuing, optional
42
+ Queuing configuration for the instance.
43
+ integration_id : str, optional
44
+ ID of the integration to use for the instance.
45
+
46
+ Examples
47
+ --------
48
+ >>> config = InstanceConfiguration(
49
+ ... execution_class="small",
50
+ ... options={"max_runtime": 30},
51
+ ... secrets_collection_id="sc_1234567890"
52
+ ... )
53
+ """
54
+
55
+ execution_class: str | None = None
13
56
  """Execution class for the instance."""
14
- options: Optional[dict] = None
57
+ format: Format | None = None
58
+ """Input format for the instance, if applicable. When configuring an
59
+ instance, only the `format.format_input` attribute is used."""
60
+ options: dict | None = None
15
61
  """Options of the app that the instance uses."""
62
+ secrets_collection_id: str | None = None
63
+ """ID of the secrets collection that the instance uses."""
64
+ queuing: RunQueuing | None = None
65
+ """Queuing configuration for the instance."""
66
+ integration_id: str | None = None
67
+ """ID of the integration to use for the instance."""
68
+
69
+ def model_post_init(self, __context) -> None:
70
+ """
71
+ Validations done after parsing the model.
72
+
73
+ Raises
74
+ ------
75
+ ValueError
76
+ If execution_class is an empty string.
77
+ """
78
+
79
+ if self.integration_id is None or self.integration_id == "":
80
+ return
81
+
82
+ integration_val = "integration"
83
+ if self.execution_class is not None and self.execution_class != "" and self.execution_class != integration_val:
84
+ raise ValueError(f"When integration_id is set, execution_class must be `{integration_val}` or None.")
85
+
86
+ self.execution_class = integration_val
87
+
88
+ # Processes the format to ensure only format_input is set.
89
+ if self.format is not None and self.format.format_input is not None:
90
+ final_format = Format(format_input=self.format.format_input)
91
+ else:
92
+ final_format = None
93
+ self.format = final_format
16
94
 
17
95
 
18
96
  class Instance(BaseModel):
19
- """A instance of an application tied to a version and further configuration."""
97
+ """An instance of an application tied to a version with configuration.
98
+
99
+ You can import the `Instance` class directly from `cloud`:
100
+
101
+ ```python
102
+ from nextmv.cloud import Instance
103
+ ```
104
+
105
+ A Nextmv Cloud instance represents a deployable configuration of an application
106
+ version. Instances have their own unique identity and can be used to run jobs
107
+ with specific configurations.
108
+
109
+ Parameters
110
+ ----------
111
+ id : str
112
+ The unique identifier of the instance.
113
+ application_id : str
114
+ ID of the application that this instance belongs to.
115
+ version_id : str
116
+ ID of the application version this instance uses.
117
+ name : str
118
+ Human-readable name of the instance.
119
+ description : str
120
+ Detailed description of the instance.
121
+ configuration : InstanceConfiguration
122
+ Configuration settings for this instance.
123
+ locked : bool
124
+ Whether the instance is locked for modifications.
125
+ created_at : datetime
126
+ Timestamp when the instance was created.
127
+ updated_at : datetime
128
+ Timestamp when the instance was last updated.
129
+
130
+ Examples
131
+ --------
132
+ >>> from nextmv.cloud import Instance, InstanceConfiguration
133
+ >>> instance = Instance(
134
+ ... id="inst_1234567890",
135
+ ... application_id="app_1234567890",
136
+ ... version_id="ver_1234567890",
137
+ ... name="Production Routing Instance",
138
+ ... description="Instance for daily production routing jobs",
139
+ ... configuration=InstanceConfiguration(execution_class="small"),
140
+ ... locked=False,
141
+ ... created_at=datetime.now(),
142
+ ... updated_at=datetime.now()
143
+ ... )
144
+ """
20
145
 
21
146
  id: str
22
147
  """ID of the instance."""
@@ -28,7 +153,7 @@ class Instance(BaseModel):
28
153
  """Name of the instance."""
29
154
  description: str
30
155
  """Description of the instance."""
31
- configuration: Configuration
156
+ configuration: InstanceConfiguration
32
157
  """Configuration for the instance."""
33
158
  locked: bool
34
159
  """Whether the instance is locked."""