Skip to content

Commit 9cb0cd1

Browse files
committed
refactored model class names
1 parent 4532416 commit 9cb0cd1

File tree

5 files changed

+42
-41
lines changed

5 files changed

+42
-41
lines changed

assets/polling-orchestrations/teardown_with_sleep/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from cloudshell.workflow.orchestration.sandbox import Sandbox
22
from cloudshell.workflow.orchestration.teardown.default_teardown_orchestrator import DefaultTeardownWorkflow
3+
import time
34

45
SLEEP_SECONDS = 30
5-
import time
66

77

88
def fake_config(sandbox, components=None):

requirements-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ pytest
22
python-dotenv
33
flake8
44
pylint
5-
pre-commit
5+
pre-commit
6+
cloudshell-orch-core

src/cloudshell/sandbox_rest/api.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def run_component_command(
283283
max_polling_minutes: int = 20,
284284
polling_frequency_seconds: int = 10,
285285
polling_log_level: int = logging.DEBUG
286-
) -> model.ResourceCommandExecutionDetails:
286+
) -> model.ComponentCommandExecutionDetails:
287287
"""Start a command on sandbox component"""
288288
self._validate_auth_header()
289289
uri = f"{self._v2_base_uri}/sandboxes/{sandbox_id}/components/{component_id}/commands/{command_name}/start"
@@ -294,11 +294,11 @@ def run_component_command(
294294
start_response = model.CommandStartResponse.dict_to_model(response_dict)
295295
component_details = self.get_sandbox_component_details(sandbox_id, component_id)
296296
model_wrapped_command_params = [model.CommandParameterNameValue(x.name, x.value) for x in params] if params else []
297-
command_context = model.ResourceCommandContextDetails(sandbox_id=sandbox_id,
298-
command_name=command_name,
299-
command_params=model_wrapped_command_params,
300-
component_name=component_details.name,
301-
component_id=component_details.id)
297+
command_context = model.ComponentCommandContextDetails(sandbox_id=sandbox_id,
298+
command_name=command_name,
299+
command_params=model_wrapped_command_params,
300+
component_name=component_details.name,
301+
component_id=component_details.id)
302302
if polling_execution:
303303
execution_details = self.poll_command_execution(execution_id=start_response.executionId,
304304
max_polling_minutes=max_polling_minutes,
@@ -307,13 +307,13 @@ def run_component_command(
307307
else:
308308
execution_details = self.get_execution_details(start_response.executionId)
309309

310-
return model.ResourceCommandExecutionDetails(id=start_response.executionId,
311-
status=execution_details.status,
312-
supports_cancellation=execution_details.supports_cancellation,
313-
started=execution_details.started,
314-
ended=execution_details.ended,
315-
output=execution_details.output,
316-
command_context=command_context)
310+
return model.ComponentCommandExecutionDetails(id=start_response.executionId,
311+
status=execution_details.status,
312+
supports_cancellation=execution_details.supports_cancellation,
313+
started=execution_details.started,
314+
ended=execution_details.ended,
315+
output=execution_details.output,
316+
command_context=command_context)
317317

318318
def extend_sandbox(self, sandbox_id: str, duration: str) -> model.ExtendResponse:
319319
"""Extend the sandbox

src/cloudshell/sandbox_rest/model.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from enum import Enum
88
from typing import TYPE_CHECKING, List, Optional
99

10-
from pydantic import BaseModel, Field
10+
from pydantic import BaseModel
1111

1212
RESPONSE_DICT_KEY = "response_dict"
1313

@@ -249,29 +249,6 @@ class CommandExecutionDetails(SandboxApiBaseModel):
249249
output: Optional[str]
250250

251251

252-
@_basemodel_decorator
253-
class CommandContextDetails(SandboxApiBaseModel):
254-
sandbox_id: Optional[str]
255-
command_name: Optional[str]
256-
command_params: Optional[List[CommandParameterNameValue]]
257-
258-
259-
@_basemodel_decorator
260-
class ResourceCommandContextDetails(CommandContextDetails):
261-
component_name: Optional[str]
262-
component_id: Optional[str]
263-
264-
265-
@_basemodel_decorator
266-
class EnvironmentCommandExecutionDetails(CommandExecutionDetails):
267-
command_context: Optional[CommandContextDetails]
268-
269-
270-
@_basemodel_decorator
271-
class ResourceCommandExecutionDetails(CommandExecutionDetails):
272-
command_context: Optional[ResourceCommandContextDetails]
273-
274-
275252
@_basemodel_decorator
276253
class ComponentAttribute(SandboxApiBaseModel):
277254
type: Optional[str]
@@ -330,7 +307,30 @@ class SandboxOutput(SandboxApiBaseModel):
330307
entries: Optional[List[SandboxOutputEntry]]
331308

332309

333-
# Missing from Swagger Schema Docs
310+
# ===== Custom Data Models NOT returned from endpoint responses
334311
@_basemodel_decorator
335312
class StopSandboxResponse(SandboxApiBaseModel):
336313
result: Optional[str] = "success"
314+
315+
316+
@_basemodel_decorator
317+
class CommandContextDetails(SandboxApiBaseModel):
318+
sandbox_id: Optional[str]
319+
command_name: Optional[str]
320+
command_params: Optional[List[CommandParameterNameValue]]
321+
322+
323+
@_basemodel_decorator
324+
class ComponentCommandContextDetails(CommandContextDetails):
325+
component_name: Optional[str]
326+
component_id: Optional[str]
327+
328+
329+
@_basemodel_decorator
330+
class EnvironmentCommandExecutionDetails(CommandExecutionDetails):
331+
command_context: Optional[CommandContextDetails]
332+
333+
334+
@_basemodel_decorator
335+
class ComponentCommandExecutionDetails(CommandExecutionDetails):
336+
command_context: Optional[ComponentCommandContextDetails]

tests/test_api_polling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ def test_component_command_blocking(admin_session: SandboxRestApiSession, sandbo
6565
polling_execution=True,
6666
polling_log_level=logging.INFO)
6767
common.fixed_sleep()
68-
assert isinstance(response, model.ResourceCommandExecutionDetails)
68+
assert isinstance(response, model.ComponentCommandExecutionDetails)
6969
print(f"Resource command finished after {default_timer() - start:.2f} seconds.\n"
7070
f"Execution response: {response.pretty_json()}")

0 commit comments

Comments
 (0)