Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Add an option to the CLI to enable automatic backups #1121

Merged
merged 1 commit into from
Jan 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions tools/cli/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
env:
- name: DATALAB_ENV
value: GCE
- name: DATALAB_SETTINGS_OVERRIDES
value: '{{"enableAutoGCSBackups": "{1}"}}'
volumeMounts:
- name: home
mountPath: /content
Expand Down Expand Up @@ -164,6 +166,13 @@ def flags(parser):
default=False,
help='do not connect to the newly created instance')

parser.add_argument(
'--no-backups',
dest='no_backups',
action='store_true',
default=False,
help='do not automatically backup the disk contents to GCS')

connect.connection_flags(parser)
return

Expand Down Expand Up @@ -365,13 +374,15 @@ def run(args, gcloud_compute):
disk_cfg = (
'auto-delete=no,boot=no,device-name=datalab-pd,mode=rw,name=' +
disk_name)
enable_backups = "false" if args.no_backups else "true"
with tempfile.NamedTemporaryFile(delete=False) as startup_script_file:
with tempfile.NamedTemporaryFile(delete=False) as manifest_file:
try:
startup_script_file.write(_DATALAB_STARTUP_SCRIPT)
startup_script_file.close()
manifest_file.write(
_DATALAB_CONTAINER_SPEC.format(args.image_name))
_DATALAB_CONTAINER_SPEC.format(
args.image_name, enable_backups))
manifest_file.close()
metadata_from_file = (
'startup-script={0},google-container-manifest={1}'.format(
Expand All @@ -388,9 +399,9 @@ def run(args, gcloud_compute):
'--scopes', 'cloud-platform',
instance])
gcloud_compute(args, cmd)
except:
os.remove(startup_script_file)
os.remove(manifest_file)
finally:
os.remove(startup_script_file.name)
os.remove(manifest_file.name)

if not args.no_connect:
connect.connect(args, gcloud_compute)
Expand Down