This repository has been archived by the owner on Dec 7, 2019. It is now read-only.
forked from docker/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate_v0_v1.go
73 lines (65 loc) · 2.32 KB
/
migrate_v0_v1.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package host
import (
"github.com/docker/machine/libmachine/auth"
"github.com/docker/machine/libmachine/engine"
"github.com/docker/machine/libmachine/swarm"
)
// In the 0.1.0 => 0.2.0 transition, the JSON representation of
// machines changed from a "flat" to a more "nested" structure
// for various options and configuration settings. To preserve
// compatibility with existing machines, these migration functions
// have been introduced. They preserve backwards compat at the expense
// of some duplicated information.
// MigrateHostV0ToHostV1 validates host config and modifies if needed
// this is used for configuration updates
func MigrateHostV0ToHostV1(hostV0 *V0) *V1 {
hostV1 := &V1{
Driver: hostV0.Driver,
DriverName: hostV0.DriverName,
}
hostV1.HostOptions = &OptionsV1{}
hostV1.HostOptions.EngineOptions = &engine.Options{
TLSVerify: true,
InstallURL: "https://get.docker.com",
}
hostV1.HostOptions.SwarmOptions = &swarm.Options{
Address: "",
Discovery: hostV0.SwarmDiscovery,
Host: hostV0.SwarmHost,
Master: hostV0.SwarmMaster,
}
hostV1.HostOptions.AuthOptions = &AuthOptionsV1{
StorePath: hostV0.StorePath,
CaCertPath: hostV0.CaCertPath,
CaCertRemotePath: "",
ServerCertPath: hostV0.ServerCertPath,
ServerKeyPath: hostV0.ServerKeyPath,
ClientKeyPath: hostV0.ClientKeyPath,
ServerCertRemotePath: "",
ServerKeyRemotePath: "",
PrivateKeyPath: hostV0.PrivateKeyPath,
ClientCertPath: hostV0.ClientCertPath,
}
return hostV1
}
// MigrateHostMetadataV0ToHostMetadataV1 fills nested host metadata and modifies if needed
// this is used for configuration updates
func MigrateHostMetadataV0ToHostMetadataV1(m *MetadataV0) *Metadata {
hostMetadata := &Metadata{}
hostMetadata.DriverName = m.DriverName
hostMetadata.HostOptions.EngineOptions = &engine.Options{}
hostMetadata.HostOptions.AuthOptions = &auth.Options{
StorePath: m.StorePath,
CaCertPath: m.CaCertPath,
CaCertRemotePath: "",
ServerCertPath: m.ServerCertPath,
ServerKeyPath: m.ServerKeyPath,
ClientKeyPath: "",
ServerCertRemotePath: "",
ServerKeyRemotePath: "",
CaPrivateKeyPath: m.PrivateKeyPath,
ClientCertPath: m.ClientCertPath,
}
hostMetadata.ConfigVersion = m.ConfigVersion
return hostMetadata
}