forked from docker/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate_v2_v3.go
49 lines (39 loc) · 1.12 KB
/
migrate_v2_v3.go
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
package host
import (
"bytes"
"encoding/json"
"github.com/docker/machine/libmachine/log"
)
type RawHost struct {
Driver *json.RawMessage
}
func MigrateHostV2ToHostV3(hostV2 *V2, data []byte, storePath string) *Host {
// Migrate to include RawDriver so that driver plugin will work
// smoothly.
rawHost := &RawHost{}
if err := json.Unmarshal(data, &rawHost); err != nil {
log.Warnf("Could not unmarshal raw host for RawDriver information: %s", err)
}
m := make(map[string]interface{})
// Must migrate to include store path in driver since it was not
// previously stored in drivers directly
d := json.NewDecoder(bytes.NewReader(*rawHost.Driver))
d.UseNumber()
if err := d.Decode(&m); err != nil {
log.Warnf("Could not unmarshal raw host into map[string]interface{}: %s", err)
}
m["StorePath"] = storePath
// Now back to []byte
rawDriver, err := json.Marshal(m)
if err != nil {
log.Warnf("Could not re-marshal raw driver: %s", err)
}
h := &Host{
ConfigVersion: 2,
DriverName: hostV2.DriverName,
Name: hostV2.Name,
HostOptions: hostV2.HostOptions,
RawDriver: rawDriver,
}
return h
}