Skip to content

Commit

Permalink
Merge pull request #97 from datmo/snapshot-task
Browse files Browse the repository at this point in the history
Adding snapshot create from task in CLI + SDK
  • Loading branch information
asampat3090 committed May 8, 2018
2 parents da35cae + 084f0b9 commit 663f96b
Show file tree
Hide file tree
Showing 10 changed files with 506 additions and 139 deletions.
74 changes: 51 additions & 23 deletions datmo/cli/command/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from datmo.core.util.i18n import get as __
from datmo.core.util.misc_functions import mutually_exclusive
from datmo.core.util.exceptions import (SnapshotCreateFromTaskArgs)
from datmo.cli.command.project import ProjectCommand
from datmo.core.controller.snapshot import SnapshotController

Expand All @@ -18,37 +19,61 @@ def __init__(self, home, cli_helper, parser):
def create(self, **kwargs):
self.cli_helper.echo(__("info", "cli.snapshot.create"))

snapshot_dict = {"visible": True}
task_id = kwargs.get("task_id", None)
# creating snapshot with task id if it exists
if task_id is not None:
excluded_args = [
"code_id", "commit_id", "environment_id",
"environment_definition_filepath", "file_collection_id",
"filepaths", "config_filepath", "config_filename",
"stats_filepath", "stats_filename"
]
for arg in excluded_args:
if arg in kwargs and kwargs[arg] is not None:
raise SnapshotCreateFromTaskArgs(
"error", "cli.snapshot.create.task.args", arg)

message = kwargs.get("message", None)
label = kwargs.get("label", None)
# Create a new core snapshot object
snapshot_task_obj = self.snapshot_controller.create_from_task(
message, task_id, label=label)
return snapshot_task_obj.id
else:
# creating snapshot without task id
snapshot_dict = {"visible": True}

# Code
mutually_exclusive_args = ["code_id", "commit_id"]
mutually_exclusive(mutually_exclusive_args, kwargs, snapshot_dict)
# Code
mutually_exclusive_args = ["code_id", "commit_id"]
mutually_exclusive(mutually_exclusive_args, kwargs, snapshot_dict)

# Environment
mutually_exclusive_args = ["environment_id", "environment_def_path"]
mutually_exclusive(mutually_exclusive_args, kwargs, snapshot_dict)
# Environment
mutually_exclusive_args = [
"environment_id", "environment_definition_filepath"
]
mutually_exclusive(mutually_exclusive_args, kwargs, snapshot_dict)

# File
mutually_exclusive_args = ["file_collection_id", "filepaths"]
mutually_exclusive(mutually_exclusive_args, kwargs, snapshot_dict)
# File
mutually_exclusive_args = ["file_collection_id", "filepaths"]
mutually_exclusive(mutually_exclusive_args, kwargs, snapshot_dict)

# Config
mutually_exclusive_args = ["config_filepath", "config_filename"]
mutually_exclusive(mutually_exclusive_args, kwargs, snapshot_dict)
# Config
mutually_exclusive_args = ["config_filepath", "config_filename"]
mutually_exclusive(mutually_exclusive_args, kwargs, snapshot_dict)

# Stats
mutually_exclusive_args = ["stats_filepath", "stats_filename"]
mutually_exclusive(mutually_exclusive_args, kwargs, snapshot_dict)
# Stats
mutually_exclusive_args = ["stats_filepath", "stats_filename"]
mutually_exclusive(mutually_exclusive_args, kwargs, snapshot_dict)

optional_args = ["session_id", "task_id", "message", "label"]
optional_args = ["session_id", "message", "label"]

for arg in optional_args:
if arg in kwargs and kwargs[arg] is not None:
snapshot_dict[arg] = kwargs[arg]
for arg in optional_args:
if arg in kwargs and kwargs[arg] is not None:
snapshot_dict[arg] = kwargs[arg]

snapshot_obj = self.snapshot_controller.create(snapshot_dict)
snapshot_obj = self.snapshot_controller.create(snapshot_dict)

return snapshot_obj.id
return snapshot_obj.id

def delete(self, **kwargs):
self.cli_helper.echo(__("info", "cli.snapshot.delete"))
Expand Down Expand Up @@ -89,7 +114,10 @@ def ls(self, **kwargs):
]
t = prettytable.PrettyTable(header_list)
snapshot_objs = self.snapshot_controller.list(
session_id=session_id, visible=True)
session_id=session_id,
visible=True,
sort_key='created_at',
sort_order='descending')
for snapshot_obj in snapshot_objs:
t.add_row([
snapshot_obj.id,
Expand Down

0 comments on commit 663f96b

Please sign in to comment.