in google_guest_agent/snapshot_listener.go [103:146]
func getSnapshotResponse(ctx context.Context, timeout time.Duration, guestMessage *sspb.GuestMessage) *sspb.SnapshotResponse {
request := guestMessage.GetSnapshotRequest()
if request == nil {
logger.Warningf("Invalid snapshot request [%v], ignoring", request)
return nil
}
response := &sspb.SnapshotResponse{
OperationId: request.GetOperationId(),
Type: request.GetType(),
}
var scriptPath string
switch request.GetType() {
case sspb.OperationType_PRE_SNAPSHOT:
logger.Infof("Handling pre snapshot request for operation id %d.", request.GetOperationId())
_, found := seenPreSnapshotOperationIds.Get(request.GetOperationId())
if found {
logger.Infof("Duplicate pre snapshot request operation id %d.", request.GetOperationId())
return nil
}
seenPreSnapshotOperationIds.Add(request.GetOperationId(), request.GetOperationId())
scriptPath = filepath.Join(scriptsDir, "pre.sh")
case sspb.OperationType_POST_SNAPSHOT:
logger.Infof("Handling post snapshot request for operation id %d.", request.GetOperationId())
_, found := seenPostSnapshotOperationIds.Get(request.GetOperationId())
if found {
logger.Infof("Duplicate post snapshot request operation id %d.", request.GetOperationId())
return nil
}
seenPostSnapshotOperationIds.Add(request.GetOperationId(), request.GetOperationId())
scriptPath = filepath.Join(scriptsDir, "post.sh")
default:
logger.Errorf("Unhandled operation type %d.", request.GetType())
return nil
}
scriptsReturnCode, agentErrorCode := runScript(ctx, scriptPath, request.GetDiskList(), timeout)
response.ScriptsReturnCode = int32(scriptsReturnCode)
response.AgentReturnCode = agentErrorCode
return response
}