@@ -2,11 +2,8 @@ package driver
2
2
3
3
import (
4
4
"bytes"
5
- "crypto/sha256"
6
- "encoding/hex"
7
5
"encoding/json"
8
6
"fmt"
9
- "io"
10
7
"log"
11
8
"os"
12
9
"os/exec"
@@ -17,9 +14,9 @@ import (
17
14
"strings"
18
15
"time"
19
16
20
- "github.com/hashicorp/go-getter"
21
17
"github.com/hashicorp/nomad/client/allocdir"
22
18
"github.com/hashicorp/nomad/client/config"
19
+ "github.com/hashicorp/nomad/client/getter"
23
20
"github.com/hashicorp/nomad/nomad/structs"
24
21
)
25
22
@@ -82,7 +79,7 @@ func (d *QemuDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool,
82
79
// image and save it to the Drivers Allocation Dir
83
80
func (d * QemuDriver ) Start (ctx * ExecContext , task * structs.Task ) (DriverHandle , error ) {
84
81
// Get the image source
85
- source , ok := task .Config ["image_source " ]
82
+ source , ok := task .Config ["artifact_source " ]
86
83
if ! ok || source == "" {
87
84
return nil , fmt .Errorf ("Missing source image Qemu driver" )
88
85
}
@@ -99,34 +96,18 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
99
96
return nil , fmt .Errorf ("Could not find task directory for task: %v" , d .DriverContext .taskName )
100
97
}
101
98
102
- // Create a location to download the binary.
103
- destDir := filepath .Join (taskDir , allocdir .TaskLocal )
104
- vmID := fmt .Sprintf ("qemu-vm-%s-%s" , structs .GenerateUUID (), filepath .Base (source ))
105
- vmPath := filepath .Join (destDir , vmID )
106
- if err := getter .GetFile (vmPath , source ); err != nil {
107
- return nil , fmt .Errorf ("Error downloading artifact for Qemu driver: %s" , err )
99
+ // Proceed to download an artifact to be executed.
100
+ vmPath , err := getter .GetArtifact (
101
+ filepath .Join (taskDir , allocdir .TaskLocal ),
102
+ task .Config ["artifact_source" ],
103
+ task .Config ["checksum" ],
104
+ d .logger ,
105
+ )
106
+ if err != nil {
107
+ return nil , err
108
108
}
109
109
110
- // compute and check checksum
111
- if check , ok := task .Config ["checksum" ]; ok {
112
- d .logger .Printf ("[DEBUG] Running checksum on (%s)" , vmID )
113
- hasher := sha256 .New ()
114
- file , err := os .Open (vmPath )
115
- if err != nil {
116
- return nil , fmt .Errorf ("Failed to open file for checksum" )
117
- }
118
-
119
- defer file .Close ()
120
- io .Copy (hasher , file )
121
-
122
- sum := hex .EncodeToString (hasher .Sum (nil ))
123
- if sum != check {
124
- return nil , fmt .Errorf (
125
- "Error in Qemu: checksums did not match.\n Expected (%s), got (%s)" ,
126
- check ,
127
- sum )
128
- }
129
- }
110
+ vmID := filepath .Base (vmPath )
130
111
131
112
// Parse configuration arguments
132
113
// Create the base arguments
0 commit comments