Skip to content

Commit

Permalink
Fix #23, #22, #20, #19
Browse files Browse the repository at this point in the history
  • Loading branch information
franklupo committed Oct 9, 2019
1 parent f28fbd6 commit f096973
Show file tree
Hide file tree
Showing 26 changed files with 363 additions and 1,622 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/dotnet/Corsinvest.ProxmoxVE.AutoSnap/bin/Debug/netcoreapp2.2/cv4pve-autosnap.dll",
"program": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.AutoSnap/bin/Debug/netcoreapp3.0/cv4pve-autosnap.dll",
"args": [],
"cwd": "${workspaceFolder}/src/dotnet/Corsinvest.ProxmoxVE.AutoSnap",
"cwd": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.AutoSnap",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
Expand Down
18 changes: 12 additions & 6 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/dotnet/Corsinvest.ProxmoxVE.AutoSnap/Corsinvest.ProxmoxVE.AutoSnap.csproj"
"${workspaceFolder}/src/Corsinvest.ProxmoxVE.AutoSnap/Corsinvest.ProxmoxVE.AutoSnap.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$tsc"
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/src/dotnet/Corsinvest.ProxmoxVE.AutoSnap/Corsinvest.ProxmoxVE.AutoSnap.csproj"
"${workspaceFolder}/src/Corsinvest.ProxmoxVE.AutoSnap/Corsinvest.ProxmoxVE.AutoSnap.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$tsc"
"problemMatcher": "$msCompile"
},
{
"label": "watch",
Expand All @@ -28,9 +32,11 @@
"args": [
"watch",
"run",
"${workspaceFolder}/src/dotnet/Corsinvest.ProxmoxVE.AutoSnap/Corsinvest.ProxmoxVE.AutoSnap.csproj"
"${workspaceFolder}/src/Corsinvest.ProxmoxVE.AutoSnap/Corsinvest.ProxmoxVE.AutoSnap.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$tsc"
"problemMatcher": "$msCompile"
}
]
}
39 changes: 39 additions & 0 deletions Corsinvest.ProxmoxVE.AutoSnap.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C6B0694C-362C-4BEE-8EBA-28ECF5780D57}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Corsinvest.ProxmoxVE.AutoSnap", "src\Corsinvest.ProxmoxVE.AutoSnap\Corsinvest.ProxmoxVE.AutoSnap.csproj", "{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}.Debug|x64.ActiveCfg = Debug|Any CPU
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}.Debug|x64.Build.0 = Debug|Any CPU
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}.Debug|x86.ActiveCfg = Debug|Any CPU
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}.Debug|x86.Build.0 = Debug|Any CPU
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}.Release|Any CPU.Build.0 = Release|Any CPU
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}.Release|x64.ActiveCfg = Release|Any CPU
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}.Release|x64.Build.0 = Release|Any CPU
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}.Release|x86.ActiveCfg = Release|Any CPU
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6D4D450B-25C7-4CC8-AFB5-3EFCBD32EC37} = {C6B0694C-362C-4BEE-8EBA-28ECF5780D57}
EndGlobalSection
EndGlobal
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ For the planning process using an external machine:
* Completely rewritten in C#
* Use native api REST Proxmox VE (library C#)
* Independent os (Windows, Linux, Macosx)
* Installation
* Portable all files request are included
* Native installation (deb, rpm, zip)
* Installation unzip file extract binary
* Not require installation in Proxmox VE
* Execute out side Proxmox VE
* For KVM and LXC
Expand All @@ -94,12 +92,12 @@ For the planning process using an external machine:

## Configuration and use

E.g. install on debian package
E.g. install on linux 64

Download last package e.g. Debian cv4pve-autosnap_?.?.?-?_all.deb, on your os and install:
Download last package e.g. Debian cv4pve-autosnap-linux-x64.zip, on your os and install:

```sh
root@debian:~# dpkg -i cv4pve-autosnap_?.?.?-?_all.deb
root@debian:~# unzip cv4pve-autosnap-linux-x64.zip
```

This tool need basically no configuration.
Expand Down Expand Up @@ -164,5 +162,9 @@ CV4PVE_AUTOSNAP_VMTYPE
CV4PVE_AUTOSNAP_LABEL
CV4PVE_AUTOSNAP_KEEP
CV4PVE_AUTOSNAP_SNAP_NAME
CV4PVE_AUTOSNAP_VMSTATE
CV4PVE_AUTOSNAP_VMSTATE #1/0
CV4PVE_AUTOSNAP_DEBUG #1/0
CV4PVE_AUTOSNAP_DRY_RUN #1/0
```

See example hook file script-hook.bat, script-hook.sh
39 changes: 39 additions & 0 deletions script-hook.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@ECHO OFF

REM Corsinvest automatic snapshot for Proxmox VE cv4pve-autosnap hook script.
REM Process environment variables as received from and set by cv4pve-autosnap.

ECHO CV4PVE_AUTOSNAP_PHASE: %CV4PVE_AUTOSNAP_PHASE%
ECHO CV4PVE_AUTOSNAP_VMID: %CV4PVE_AUTOSNAP_VMID%
ECHO CV4PVE_AUTOSNAP_VMTECHNOLOGY: %CV4PVE_AUTOSNAP_VMTECHNOLOGY%
ECHO CV4PVE_AUTOSNAP_LABEL: %CV4PVE_AUTOSNAP_LABEL%
ECHO CV4PVE_AUTOSNAP_KEEP: %CV4PVE_AUTOSNAP_KEEP%
ECHO CV4PVE_AUTOSNAP_VMSTATE: %CV4PVE_AUTOSNAP_VMSTATE%
ECHO CV4PVE_AUTOSNAP_SNAP_NAME: %CV4PVE_AUTOSNAP_SNAP_NAME%
ECHO CV4PVE_AUTOSNAP_DEBUG: %CV4PVE_AUTOSNAP_DEBUG%
ECHO CV4PVE_AUTOSNAP_DRY_RUN: %CV4PVE_AUTOSNAP_DRYRUN%

IF "%CV4PVE_AUTOSNAP_PHASE%"=="clean-job-start" (
REM
) ELSE IF "%CV4PVE_AUTOSNAP_PHASE%"=="clean-job-end" (
REM
) ELSE IF "%CV4PVE_AUTOSNAP_PHASE%"=="snap-job-start" (
REM
) ELSE IF "%CV4PVE_AUTOSNAP_PHASE%"=="snap-job-end" (
REM
) ELSE IF "%CV4PVE_AUTOSNAP_PHASE%"=="snap-create-pre" (
REM
) ELSE IF "%CV4PVE_AUTOSNAP_PHASE%"=="snap-create-post" (
REM
) ELSE IF "%CV4PVE_AUTOSNAP_PHASE%"=="snap-create-abort" (
REM
) ELSE IF "%CV4PVE_AUTOSNAP_PHASE%"=="snap-remove-pre" (
REM
) ELSE IF "%CV4PVE_AUTOSNAP_PHASE%"=="snap-remove-post" (
REM
) ELSE IF "%CV4PVE_AUTOSNAP_PHASE%"=="snap-remove-abort" (
REM
) ELSE (
ECHO "unknown phase '$CV4PVE_BARC_PHASE'"
EXIT 1
)
18 changes: 10 additions & 8 deletions src/bash/script-hook.sh → script-hook.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
# Process environment variables as received from and set by cv4pve-autosnap.

hook() {
echo "CV4PVE_AUTOSNAP_PHASE: $CV4PVE_AUTOSNAP_PHASE"
echo "CV4PVE_AUTOSNAP_VMID: $CV4PVE_AUTOSNAP_VMID"
echo "CV4PVE_AUTOSNAP_VMTECHNOLOGY: $CV4PVE_AUTOSNAP_VMTECHNOLOGY"
echo "CV4PVE_AUTOSNAP_LABEL: $CV4PVE_AUTOSNAP_LABEL"
echo "CV4PVE_AUTOSNAP_KEEP: $CV4PVE_AUTOSNAP_KEEP"
echo "CV4PVE_AUTOSNAP_VMSTATE: $CV4PVE_AUTOSNAP_VMSTATE"
echo "CV4PVE_AUTOSNAP_SNAP_NAME: $CV4PVE_AUTOSNAP_SNAP_NAME"

echo "CV4PVE_AUTOSNAP_PHASE: $CV4PVE_AUTOSNAP_PHASE"
echo "CV4PVE_AUTOSNAP_VMID: $CV4PVE_AUTOSNAP_VMID"
echo "CV4PVE_AUTOSNAP_VMTECHNOLOGY: $CV4PVE_AUTOSNAP_VMTECHNOLOGY"
echo "CV4PVE_AUTOSNAP_LABEL: $CV4PVE_AUTOSNAP_LABEL"
echo "CV4PVE_AUTOSNAP_KEEP: $CV4PVE_AUTOSNAP_KEEP"
echo "CV4PVE_AUTOSNAP_VMSTATE: $CV4PVE_AUTOSNAP_VMSTATE"
echo "CV4PVE_AUTOSNAP_SNAP_NAME: $CV4PVE_AUTOSNAP_SNAP_NAME"
echo "CV4PVE_AUTOSNAP_DEBUG: $CV4PVE_AUTOSNAP_DEBUG"
echo "CV4PVE_AUTOSNAP_DRY_RUN: $CV4PVE_AUTOSNAP_DRY_RUN"

case "$CV4PVE_AUTOSNAP_PHASE" in
#clean job status
clean-job-start);;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
using System;
/*
* This file is part of the cv4pve-autosnap https://github.com/Corsinvest/cv4pve-autosnap,
* Copyright (C) 2016 Corsinvest Srl
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -14,21 +32,21 @@ namespace Corsinvest.ProxmoxVE.AutoSnap
/// </summary>
public class Commands
{
private const string PREFIX = "auto";
private static readonly string PREFIX = "auto";

private const string TIMESTAMP_FORMAT = "yyMMddHHmmss";
private static readonly string TIMESTAMP_FORMAT = "yyMMddHHmmss";

/// <summary>
/// Application name
/// </summary>
public const string APPLICATION_NAME = "cv4pve-autosnap";
public static readonly string APPLICATION_NAME = "cv4pve-autosnap";

/// <summary>
/// Old application name
/// </summary>
private const string OLD_APPLICATION_NAME = "eve4pve-autosnap";
private static readonly string OLD_APPLICATION_NAME = "eve4pve-autosnap";

private readonly Client _client;
private readonly PveClient _client;
private readonly TextWriter _stdOut;
private readonly bool _dryRun;
private readonly bool _debug;
Expand All @@ -40,7 +58,7 @@ public class Commands
/// <param name="stdOut"></param>
/// <param name="dryRun"></param>
/// <param name="debug"></param>
public Commands(Client client, TextWriter stdOut, bool dryRun, bool debug)
public Commands(PveClient client, TextWriter stdOut, bool dryRun, bool debug)
=> (_client, _stdOut, _dryRun, _debug) = (client, stdOut, dryRun, debug);

/// <summary>
Expand Down Expand Up @@ -68,10 +86,21 @@ public void Status(string vmIdsOrNames, string label = null, OutputType outputTy

switch (outputType)
{
case OutputType.Text: _stdOut.Write(snapshots.Info(true)); break;
case OutputType.Json: _stdOut.Write(JsonConvert.SerializeObject((snapshots.Select(a => a.GetRowInfo(true))))); break;
case OutputType.JsonPretty: _stdOut.Write(JsonConvert.SerializeObject((snapshots.Select(a => a.GetRowInfo(true))), Formatting.Indented)); break;
default: _stdOut.Write(snapshots.Info(true)); break;
case OutputType.Text:
_stdOut.Write(snapshots.Info(true));
break;

case OutputType.Json:
_stdOut.Write(JsonConvert.SerializeObject((snapshots.Select(a => a.GetRowInfo(true)))));
break;

case OutputType.JsonPretty:
_stdOut.Write(JsonConvert.SerializeObject((snapshots.Select(a => a.GetRowInfo(true))), Formatting.Indented));
break;

default:
_stdOut.Write(snapshots.Info(true));
break;
}
}

Expand Down Expand Up @@ -134,7 +163,17 @@ public bool Snap(string vmIdsOrNames, string label, int keep, bool state)
var oldWaitTimeout = ResultExtension.WaitTimeout;
ResultExtension.WaitTimeout = 30000;

inError = vm.Snapshots.Create(snapName, APPLICATION_NAME, state, true).LogInError(_stdOut);
var result = vm.Snapshots.Create(snapName, APPLICATION_NAME, state, true);
inError = result.LogInError(_stdOut);

//check error in task
var task = _client.Nodes[vm.Node].Tasks[(result.Response.data as string)];
var data = task.Status.ReadTaskStatus().Response.data;
if (data.exitstatus != "OK")
{
_stdOut.WriteLine($"Error in task: {data.exitstatus}");
inError = true;
}

ResultExtension.WaitTimeout = oldWaitTimeout;
}
Expand All @@ -159,6 +198,8 @@ public bool Snap(string vmIdsOrNames, string label, int keep, bool state)

CallPhaseEvent("snap-job-end", null, label, keep, null, state);

if (_debug) { _stdOut.WriteLine($"Snap Exit: {ret}"); }

return ret;
}

Expand Down Expand Up @@ -211,6 +252,8 @@ private bool SnapshotsRemove(VMInfo vm, string label, int keep)

if (inError)
{
if (_debug) { _stdOut.WriteLine($"Snap remove: problem in remove "); }

CallPhaseEvent("snap-remove-abort", vm, label, keep, snapshot.Name, false);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Version>1.2.0</Version>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AssemblyName>cv4pve-autosnap</AssemblyName>
<Company>Corsinvest Srl</Company>
<Authors>Daniele Corsini</Authors>
<Copyright>Corsinvest Srl</Copyright>
<Product>Corsinvest for Proxmox VE Auto Snapshot</Product>
<AssemblyTitle>Corsinvest for Proxmox VE Auto Snapshot</AssemblyTitle>
<Description>Corsinvest for Proxmox VE Auto Snapshot</Description>
<PublishTrimmed>true</PublishTrimmed>
<!--
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
-->
</PropertyGroup>

<ItemGroup>
<Content Include="cv4pve-autosnap.sh" CopyToPublishDirectory="PreserveNewest">
<LinuxPath>/usr/sbin/cv4pve-autosnap</LinuxPath>
<LinuxFileMode>775</LinuxFileMode>
</Content>
</ItemGroup>

<ItemGroup>
<!--
<ProjectReference Include="..\..\..\..\cv4pve-api-dotnet\src\Corsinvest.ProxmoxVE.Api.Extension\Corsinvest.ProxmoxVE.Api.Extension.csproj" />
-->
<PackageReference Include="Corsinvest.ProxmoxVE.Api.Extension" Version="1.2.0" />
<PackageReference Include="Packaging.Targets" Version="0.1.80" />
</ItemGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Version>1.3.0</Version>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AssemblyName>cv4pve-autosnap</AssemblyName>
<Company>Corsinvest Srl</Company>
<Authors>Daniele Corsini</Authors>
<Copyright>Corsinvest Srl</Copyright>
<Product>Corsinvest for Proxmox VE Auto Snapshot</Product>
<AssemblyTitle>Corsinvest for Proxmox VE Auto Snapshot</AssemblyTitle>
<Description>Corsinvest for Proxmox VE Auto Snapshot</Description>
</PropertyGroup>

<ItemGroup>
<!-- Fix RedHat, Centos,Fedora -->
<RuntimeHostConfigurationOption Include="System.Globalization.Invariant" Value="true" />

<!--
<ProjectReference Include="..\..\..\..\cv4pve-api-dotnet\src\Corsinvest.ProxmoxVE.Api.Extension\Corsinvest.ProxmoxVE.Api.Extension.csproj" />
-->
<PackageReference Include="Corsinvest.ProxmoxVE.Api.Extension" Version="2.0.0" />
</ItemGroup>
</Project>

0 comments on commit f096973

Please sign in to comment.