-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDiagnostics.cs
84 lines (71 loc) · 2.38 KB
/
Diagnostics.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Godot;
using Godot.Collections;
public static class Diagnostics
{
private static void VagrantTest(ContainerAPI containers)
{
var testingOutput = containers.VagrantDebugExecute("echo hello");
if (testingOutput.StartsWith("hello")) // There might be some SSH output after this
{
GD.Print("[DIAGNOSTICS B] [OK] Vagrant box started successfully");
}
else
{
GD.PrintErr("[DIAGNOSTICS B] [ERROR] Vagrant box failed to start!");
}
}
private static void ContainerTest(ContainerAPI containers)
{
var dockerfile1 =
"FROM busybox\n" +
"CMD [\"sh\"]";
var customId = "1";
var code = containers.CreateContainer(customId, null, dockerfile1, new Array<string>());
if (code == (int) Errors.OK)
{
GD.Print("[DIAGNOSTICS B] [OK] Container created successfully.");
}
else
{
GD.PrintErr(
$"[DIAGNOSTICS B] [ERROR] Container failed to create, with error: {(Errors) code} (Note that for now, BuildError means literally anything from failed SSH to bad Dockerfile)");
}
code = containers.StartContainer(customId);
if (code == (int) Errors.OK)
{
GD.Print("[DIAGNOSTICS B] [OK] Container started successfully.");
}
else
{
GD.PrintErr($"[DIAGNOSTICS B] [ERROR] Container failed to start, with error: {(Errors) code}");
}
code = containers.CreateTTY(customId, out var stdin, out var stdout);
if (code == (int) Errors.OK)
{
GD.Print("[DIAGNOSTICS B] [OK] Successfully created TTY.");
}
else
{
GD.PrintErr($"[DIAGNOSTICS B] [ERROR] Container failed to create TTY, with error: {(Errors) code}");
}
stdin.WriteLine("echo hello");
stdin.Close();
var received = stdout.ReadLine();
if (received == "hello")
{
GD.Print("[DIAGNOSTICS B] [OK] Container responding");
}
else
{
GD.PrintErr("[DIAGNOSTICS B] [ERROR] Container not responding");
}
}
public static void Run()
{
var containers = new ContainerAPI();
containers.Begin();
VagrantTest(containers);
ContainerTest(containers);
containers.Stop();
}
}