Skip to content

Commit 49feb33

Browse files
Nathan LeClaire and Simon Thulbornnathanleclaire
authored andcommitted
Implement majority of provisioning changes
Signed-off-by: Simon Thulborn <simon+github@thulborn.com> Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
1 parent 8d5a59b commit 49feb33

File tree

16 files changed

+1094
-578
lines changed

16 files changed

+1094
-578
lines changed

commands.go

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
_ "github.com/docker/machine/drivers/vmwarevcloudair"
3131
_ "github.com/docker/machine/drivers/vmwarevsphere"
3232
"github.com/docker/machine/libmachine"
33+
"github.com/docker/machine/libmachine/auth"
3334
"github.com/docker/machine/libmachine/engine"
3435
"github.com/docker/machine/libmachine/swarm"
3536
"github.com/docker/machine/state"
@@ -39,26 +40,24 @@ import (
3940
type machineConfig struct {
4041
machineName string
4142
machineDir string
42-
caCertPath string
43-
caKeyPath string
44-
clientCertPath string
43+
machineUrl string
4544
clientKeyPath string
4645
serverCertPath string
46+
clientCertPath string
47+
caCertPath string
48+
caKeyPath string
4749
serverKeyPath string
48-
machineUrl string
49-
swarmMaster bool
50-
swarmHost string
51-
swarmDiscovery string
50+
AuthConfig auth.AuthOptions
51+
SwarmConfig swarm.SwarmOptions
5252
}
5353

5454
type hostListItem struct {
55-
Name string
56-
Active bool
57-
DriverName string
58-
State state.State
59-
URL string
60-
SwarmMaster bool
61-
SwarmDiscovery string
55+
Name string
56+
Active bool
57+
DriverName string
58+
State state.State
59+
URL string
60+
SwarmConfig swarm.SwarmOptions
6261
}
6362

6463
type certPathInfo struct {
@@ -406,18 +405,26 @@ func cmdCreate(c *cli.Context) {
406405
log.Fatal(err)
407406
}
408407

409-
hostOptions := &libmachine.HostOptions{
410-
DriverOptions: c,
411-
EngineOptions: &engine.EngineOptions{},
412-
SwarmOptions: &swarm.SwarmOptions{
408+
hostConfig := &libmachine.HostOptions{
409+
AuthConfig: &auth.AuthOptions{
410+
CaCertPath: c.GlobalString("tls-ca-cert"),
411+
PrivateKeyPath: c.GlobalString("tls-ca-key"),
412+
ClientCertPath: c.GlobalString("tls-client-cert"),
413+
ClientKeyPath: filepath.Join(utils.GetMachineCertDir(), "key.pem"),
414+
ServerCertPath: filepath.Join(utils.GetMachineDir(), name, "server.pem"),
415+
ServerKeyPath: filepath.Join(utils.GetMachineDir(), name, "server-key.pem"),
416+
},
417+
EngineConfig: &engine.EngineOptions{},
418+
SwarmConfig: &swarm.SwarmOptions{
419+
IsSwarm: c.Bool("swarm"),
413420
Master: c.GlobalBool("swarm-master"),
414421
Discovery: c.GlobalString("swarm-discovery"),
415422
Address: c.GlobalString("swarm-addr"),
416423
Host: c.GlobalString("swarm-host"),
417424
},
418425
}
419426

420-
host, err := mcn.Create(name, driver, hostOptions)
427+
host, err := mcn.Create(name, driver, hostConfig, c)
421428
if err != nil {
422429
log.Errorf("Error creating machine: %s", err)
423430
log.Warn("You will want to check the provider to make sure the machine and associated resources were properly removed.")
@@ -456,10 +463,10 @@ func cmdConfig(c *cli.Context) {
456463
}
457464

458465
if c.Bool("swarm") {
459-
if !cfg.swarmMaster {
466+
if !cfg.SwarmConfig.Master {
460467
log.Fatalf("%s is not a swarm master", cfg.machineName)
461468
}
462-
u, err := url.Parse(cfg.swarmHost)
469+
u, err := url.Parse(cfg.SwarmConfig.Host)
463470
if err != nil {
464471
log.Fatal(err)
465472
}
@@ -563,13 +570,14 @@ func cmdLs(c *cli.Context) {
563570
swarmInfo := make(map[string]string)
564571

565572
for _, host := range hostList {
573+
swarmConfig := host.HostConfig.SwarmConfig
566574
if !quiet {
567-
if host.SwarmOptions.Master {
568-
swarmMasters[host.SwarmOptions.Discovery] = host.Name
575+
if swarmConfig.Master {
576+
swarmMasters[swarmConfig.Discovery] = host.Name
569577
}
570578

571-
if host.SwarmOptions.Discovery != "" {
572-
swarmInfo[host.Name] = host.SwarmOptions.Discovery
579+
if swarmConfig.Discovery != "" {
580+
swarmInfo[host.Name] = swarmConfig.Discovery
573581
}
574582

575583
go getHostState(*host, defaultStore, hostListItems)
@@ -596,9 +604,9 @@ func cmdLs(c *cli.Context) {
596604

597605
swarmInfo := ""
598606

599-
if item.SwarmDiscovery != "" {
600-
swarmInfo = swarmMasters[item.SwarmDiscovery]
601-
if item.SwarmMaster {
607+
if item.SwarmConfig.Discovery != "" {
608+
swarmInfo = swarmMasters[item.SwarmConfig.Discovery]
609+
if item.SwarmConfig.Master {
602610
swarmInfo = fmt.Sprintf("%s (master)", swarmInfo)
603611
}
604612
}
@@ -674,10 +682,10 @@ func cmdEnv(c *cli.Context) {
674682

675683
dockerHost := cfg.machineUrl
676684
if c.Bool("swarm") {
677-
if !cfg.swarmMaster {
685+
if !cfg.SwarmConfig.Master {
678686
log.Fatalf("%s is not a swarm master", cfg.machineName)
679687
}
680-
u, err := url.Parse(cfg.swarmHost)
688+
u, err := url.Parse(cfg.SwarmConfig.Host)
681689
if err != nil {
682690
log.Fatal(err)
683691
}
@@ -1032,13 +1040,12 @@ func getHostState(host libmachine.Host, store libmachine.Store, hostListItems ch
10321040
}
10331041

10341042
hostListItems <- hostListItem{
1035-
Name: host.Name,
1036-
Active: isActive,
1037-
DriverName: host.Driver.DriverName(),
1038-
State: currentState,
1039-
URL: url,
1040-
SwarmMaster: host.SwarmOptions.Master,
1041-
SwarmDiscovery: host.SwarmOptions.Discovery,
1043+
Name: host.Name,
1044+
Active: isActive,
1045+
DriverName: host.Driver.DriverName(),
1046+
State: currentState,
1047+
URL: url,
1048+
SwarmConfig: *host.HostConfig.SwarmConfig,
10421049
}
10431050
}
10441051

@@ -1096,16 +1103,15 @@ func getMachineConfig(c *cli.Context) (*machineConfig, error) {
10961103
return &machineConfig{
10971104
machineName: name,
10981105
machineDir: machineDir,
1099-
caCertPath: caCert,
1100-
caKeyPath: caKey,
1101-
clientCertPath: clientCert,
1106+
machineUrl: machineUrl,
11021107
clientKeyPath: clientKey,
1108+
clientCertPath: clientCert,
11031109
serverCertPath: serverCert,
1110+
caKeyPath: caKey,
1111+
caCertPath: caCert,
11041112
serverKeyPath: serverKey,
1105-
machineUrl: machineUrl,
1106-
swarmMaster: machine.SwarmOptions.Master,
1107-
swarmHost: machine.SwarmOptions.Host,
1108-
swarmDiscovery: machine.SwarmOptions.Discovery,
1113+
AuthConfig: *machine.HostConfig.AuthConfig,
1114+
SwarmConfig: *machine.HostConfig.SwarmConfig,
11091115
}, nil
11101116
}
11111117

drivers/amazonec2/amz/ec2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func (e *EC2) awsApiCall(v url.Values) (*http.Response, error) {
158158
fmt.Printf("client encountered error while doing the request: %s", err.Error())
159159
return resp, fmt.Errorf("client encountered error while doing the request: %s", err)
160160
}
161+
161162
if resp.StatusCode != http.StatusOK {
162163
return resp, newAwsApiResponseError(*resp)
163164
}

libmachine/auth/auth_options.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package auth
2+
3+
type AuthOptions struct {
4+
StorePath string
5+
CaCertPath string
6+
CaCertRemotePath string
7+
ServerCertPath string
8+
ServerKeyPath string
9+
ClientKeyPath string
10+
ServerCertRemotePath string
11+
ServerKeyRemotePath string
12+
PrivateKeyPath string
13+
ClientCertPath string
14+
}

0 commit comments

Comments
 (0)