Skip to content

Commit

Permalink
Merge branch 'tomerlf-snapshot-fr' of https://github.com/GoogleCloudP…
Browse files Browse the repository at this point in the history
…latform/gce-rescue into tomerlf-snapshot-fr
  • Loading branch information
tomerlf1 committed Jun 18, 2023
2 parents 1fdb566 + fcf894b commit caf43d2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gce_rescue/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def process_args():
help='Print to the log file in debug leve')
parser.add_argument('-f', '--force', action='store_true',
help='Don\'t ask for confirmation.')
parser.add_argument('-s', '--skip-snapshot', action='store_true',
parser.add_argument('--skip-snapshot', action='store_true',
help='Skip backing up the disk using a snapshot.')
return parser

Expand Down
7 changes: 3 additions & 4 deletions gce_rescue/tasks/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,15 @@ def _list_tasks(vm: Instance, action: str) -> List:
def call_tasks(vm: Instance, action: str) -> None:
""" Loop tasks dict and execute """
tasks = _list_tasks(vm = vm, action = action)
if get_config('skip-snapshot'):
_logger.info(f'Skipping snapshot backup.')
tasks = [task for task in tasks if task['name'].__name__ != 'take_snapshot']
total_tasks = len(tasks)

tracker = Tracker(total_tasks)
tracker.start()

for task in tasks:
if task['name'].__name__ == 'take_snapshot':
if get_config('skip-snapshot'):
_logger.info(f'Skipping snapshot backup.')
continue
execute = task['name']
args = task['args'][0]

Expand Down
2 changes: 1 addition & 1 deletion gce_rescue/tasks/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def backup_metadata_items(data: Dict) -> List:
return data['metadata']['items']
return []

def _create_snapshot(vm) -> Dict:
def create_snapshot(vm) -> Dict:
"""
Create a snaphost of the instance boot disk, adding self._ts to the disk name.
https://cloud.google.com/compute/docs/reference/rest/v1/disks/createSnapshot
Expand Down
2 changes: 1 addition & 1 deletion gce_rescue/tasks/backup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_backup_metadata_items(self):

def test_backup(self):
"""Test backup task."""
backup._create_snapshot(self.vm)
backup.create_snapshot(self.vm)


if __name__ == '__main__':
Expand Down
6 changes: 3 additions & 3 deletions gce_rescue/tasks/disks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import googleapiclient.errors

from gce_rescue.tasks.keeper import wait_for_operation
from gce_rescue.tasks.backup import _create_snapshot
from gce_rescue.tasks.backup import create_snapshot
from gce_rescue.utils import ThreadHandler as Handler
from googleapiclient.errors import HttpError

Expand Down Expand Up @@ -179,7 +179,7 @@ def _detach_disk(vm, disk: str) -> Dict:


def take_snapshot(vm) -> None:
_create_snapshot(vm)
create_snapshot(vm)


def create_rescue_disk(vm) -> None:
Expand Down Expand Up @@ -210,7 +210,7 @@ def list_snapshot(vm) -> str:
snapshot=lookup_filter,
project=vm.project
).execute()
except HttpError as e:
except HttpError:
_logger.info('Snapshot was not found for VM in active rescue mode')
return ''
return 'ok'
Expand Down

0 comments on commit caf43d2

Please sign in to comment.