in tools/gsnapshot/Runner.cs [400:510]
public void DoAction(Options options) {
_logger.LogInformation($"gsnapshot {Version} - a snapshot/rollback utility");
switch (options.Command) {
case "snapshot":
_logger.LogInformation("Operation specified: begin changes (create snapshots)");
break;
case "schedule-snapshot":
_logger.LogInformation(
"Operation specified: schedule snapshots (attach snapshot schedule to all of instance's disks)");
break;
case "rollback":
_logger.LogInformation(
"Operation specified: rollback changes (create new disks from snapshots and attach)");
break;
case "rollback-scheduled":
_logger.LogInformation(
"Operation specified: rollback to previous state (create new disks from scheduled snapshots and attach)");
break;
case "commit":
_logger.LogInformation("Operation specified: commit changes (remove snapshots)");
break;
default:
_logger.LogCritical(
"Command not selected, select one of: snapshot, schedule-snapshot, rollback, rollback-scheduled, commit");
string fileName = "gsnapshot";
var currentProcess = System.Diagnostics.Process.GetCurrentProcess();
if (currentProcess?.MainModule?.FileName != null) {
fileName = currentProcess.MainModule.FileName;
}
_logger.LogCritical($" Usage: {fileName} command [parameters...]");
_logger.LogCritical("");
_logger.LogCritical(
" snapshot Takes a snapshot of a specified Compute Engine instance.");
_logger.LogCritical(
" schedule-snapshot Attaches a snapshot schedule to all disks of a Compute Engine instance.");
_logger.LogCritical(" rollback Rolls back to a previously made snapshot.");
_logger.LogCritical(
" rollback-scheduled Rolls back to a previous snapshot from a snapshot schedule.");
_logger.LogCritical(" commit Deletes previously made snapshots.");
_logger.LogCritical("");
System.Environment.Exit(2);
break;
}
ReadDefaultSettings(options);
if (String.IsNullOrEmpty(options.Project)) {
options.Project = PickProject();
if (String.IsNullOrEmpty(options.Project)) {
_logger.LogCritical(
"Project ID was not set, either enter it manually or specify via command line.");
System.Environment.Exit(2);
} else {
_logger.LogInformation($"Selected project: {options.Project}");
}
}
_resources.LoadAllZones(options.Project);
if (String.IsNullOrEmpty(options.Region)) {
_resources.LoadAllRegions(options.Project);
options.Region = PickRegion();
if (String.IsNullOrEmpty(options.Region)) {
foreach (string region in _resources.AllRegions.Keys) {
RegionsToQuery.Add(region);
}
_logger.LogWarning(
$"Region was not set, querying all regions ({RegionsToQuery.Count} regions).");
} else {
if (_resources.AllRegions.ContainsKey(options.Region)) {
_logger.LogInformation($"Selected region: {options.Region}");
RegionsToQuery.Add(options.Region);
} else {
_logger.LogCritical($"Invalid region selected (\"{options.Region}\").");
System.Environment.Exit(3);
}
}
} else {
_logger.LogInformation($"Selected region: {options.Region}");
RegionsToQuery.Add(options.Region);
}
_instances.LoadInstances(options.Project, RegionsToQuery, _resources.AllZones);
if (String.IsNullOrEmpty(options.Instance)) {
options.Instance = PickInstance();
}
if (String.IsNullOrEmpty(options.Instance) ||
!_instances.AllInstances.ContainsKey(options.Instance)) {
_logger.LogCritical("Instance ID was not set, or set to non-existing instance.");
System.Environment.Exit(4);
}
string description =
_instances.GetMachineDescription(_instances.AllInstances[options.Instance]);
_logger.LogInformation($"Selected instance: {options.Instance} ({description})");
switch (options.Command) {
case "snapshot":
Snapshot(options);
break;
case "schedule-snapshot":
ScheduleSnapshot(options);
break;
case "rollback":
Rollback(options);
break;
case "rollback-scheduled":
RollbackScheduled(options);
break;
case "commit":
Commit(options);
break;
}
}