Browse Source

Make libmachine usable by outside world

- Clear out some cruft tightly coupling libmachine to filestore

- Comment out drivers other than virtualbox for now

- Change way too many things

- Mostly, break out the code to be more modular.

- Destroy all traces of "provider" in its current form.  It will be
brought back as something more sensible, instead of something which
overlaps in function with both Host and Store.

- Fix mis-managed config passthru

- Remove a few instances of state stored in env vars

- This should be explicitly communicated in Go-land, not through the
shell.

- Rename "store" module to "persist"

- This is done mostly to avoid confusion about the fact that a concrete
instance of a "Store" interface is oftentimes referred to as "store" in
the code.

- Rip out repetitive antipattern for getting store

- This replaces the previous repetive idiom for getting the cert info, and
consequently the store, with a much less repetitive idiom.

- Also, some redundant methods in commands.go for accessing hosts have
either been simplified or removed entirely.

- First steps towards fixing up tests

- Test progress continues

- Replace unit tests with integration tests

- MAKE ALL UNIT TESTS PASS YAY

- Add helper test files

- Don't write to disk in libmachine/host

- Heh.. coverage check strikes again

- Fix remove code

- Move cert code around

- Continued progress: simplify Driver

- Fixups and make creation work with new model

- Move drivers module inside of libmachine

- Move ssh module inside of libmachine

- Move state module to libmachine

- Move utils module to libmachine

- Move version module to libmachine

- Move log module to libmachine

- Modify some constructor methods around

- Change Travis build dep structure

- Boring gofmt fix

- Add version module

- Move NewHost to store

- Update some boring cert path infos to make API easier to use

- Fix up some issues around the new model

- Clean up some cert path stuff

- Don't use shady functions to get store path :D

- Continue artifact work

- Fix silly machines dir bug

- Continue fixing silly path issues

- Change up output of vbm a bit

- Continue work to make example go

- Change output a little more

- Last changes needed to make create finish properly

- Fix config.go to use libmachine

- Cut down code duplication and make both methods work with libmachine

- Add pluggable logging implementation

- Return error when machine already in desired state

- Update example to show log method

- Fix file:// bug

- Fix Swarm defaults

- Remove unused TLS settings from Engine and Swarm options

- Remove spurious error

- Correct bug detecting if migration was performed

- Fix compilation errors from tests

- Fix most of remaining test issues

- Fix final silly bug in tests

- Remove extraneous debug code

- Add -race to test command

- Appease the gofmt

- Appease the generate coverage

- Making executive decision to remove Travis coverage check

In the early days I thought this would be a good idea because it would
encourage people to write tests in case they added a new module.  Well,
in fact it has just turned into a giant nuisance and made refactoring
work like this even more difficult.

- Move Get to Load
- Move HostListItem code to CLI

Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
Nathan LeClaire 3 years ago
parent
commit
71069cfc1d

+ 5
- 5
drivers/openstack/client.go View File

@@ -6,9 +6,9 @@ import (
6 6
 	"net/http"
7 7
 	"time"
8 8
 
9
-	"github.com/docker/machine/log"
10
-	"github.com/docker/machine/utils"
11
-	"github.com/docker/machine/version"
9
+	"github.com/docker/machine/libmachine/log"
10
+	"github.com/docker/machine/libmachine/mcnutils"
11
+	"github.com/docker/machine/libmachine/version"
12 12
 	"github.com/rackspace/gophercloud"
13 13
 	"github.com/rackspace/gophercloud/openstack"
14 14
 	"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs"
@@ -136,7 +136,7 @@ func (c *GenericClient) DeleteInstance(d *Driver) error {
136 136
 }
137 137
 
138 138
 func (c *GenericClient) WaitForInstanceStatus(d *Driver, status string) error {
139
-	return utils.WaitForSpecificOrError(func() (bool, error) {
139
+	return mcnutils.WaitForSpecificOrError(func() (bool, error) {
140 140
 		current, err := servers.Get(c.Compute, d.MachineId).Extract()
141 141
 		if err != nil {
142 142
 			return true, err
@@ -437,7 +437,7 @@ func (c *GenericClient) Authenticate(d *Driver) error {
437 437
 		return err
438 438
 	}
439 439
 
440
-	provider.UserAgent.Prepend(fmt.Sprintf("docker-machine/v%s", version.Version))
440
+	provider.UserAgent.Prepend(fmt.Sprintf("docker-machine/v%d", version.ApiVersion))
441 441
 
442 442
 	if d.Insecure {
443 443
 		// Configure custom TLS settings.

+ 0
- 1
drivers/openstack/client_test.go View File

@@ -1 +0,0 @@
1
-package openstack

+ 28
- 22
drivers/openstack/openstack.go View File

@@ -7,11 +7,11 @@ import (
7 7
 	"time"
8 8
 
9 9
 	"github.com/codegangsta/cli"
10
-	"github.com/docker/machine/drivers"
11
-	"github.com/docker/machine/log"
12
-	"github.com/docker/machine/ssh"
13
-	"github.com/docker/machine/state"
14
-	"github.com/docker/machine/utils"
10
+	"github.com/docker/machine/libmachine/drivers"
11
+	"github.com/docker/machine/libmachine/log"
12
+	"github.com/docker/machine/libmachine/mcnutils"
13
+	"github.com/docker/machine/libmachine/ssh"
14
+	"github.com/docker/machine/libmachine/state"
15 15
 )
16 16
 
17 17
 type Driver struct {
@@ -42,9 +42,14 @@ type Driver struct {
42 42
 	client           Client
43 43
 }
44 44
 
45
+const (
46
+	defaultSSHUser       = "root"
47
+	defaultSSHPort       = 22
48
+	defaultActiveTimeout = 200
49
+)
50
+
45 51
 func init() {
46 52
 	drivers.Register("openstack", &drivers.RegisteredDriver{
47
-		New:            NewDriver,
48 53
 		GetCreateFlags: GetCreateFlags,
49 54
 	})
50 55
 }
@@ -158,35 +163,36 @@ func GetCreateFlags() []cli.Flag {
158 163
 		cli.StringFlag{
159 164
 			Name:  "openstack-ssh-user",
160 165
 			Usage: "OpenStack SSH user",
161
-			Value: "root",
166
+			Value: defaultSSHUser,
162 167
 		},
163 168
 		cli.IntFlag{
164 169
 			Name:  "openstack-ssh-port",
165 170
 			Usage: "OpenStack SSH port",
166
-			Value: 22,
171
+			Value: defaultSSHPort,
167 172
 		},
168 173
 		cli.IntFlag{
169 174
 			Name:  "openstack-active-timeout",
170 175
 			Usage: "OpenStack active timeout",
171
-			Value: 200,
176
+			Value: defaultActiveTimeout,
172 177
 		},
173 178
 	}
174 179
 }
175 180
 
176
-func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
177
-	log.WithFields(log.Fields{
178
-		"machineName": machineName,
179
-		"storePath":   storePath,
180
-		"caCert":      caCert,
181
-		"privateKey":  privateKey,
182
-	}).Debug("Instantiating OpenStack driver...")
183
-
184
-	return NewDerivedDriver(machineName, storePath, &GenericClient{}, caCert, privateKey)
181
+func NewDriver(hostName, storePath string) drivers.Driver {
182
+	return NewDerivedDriver(hostName, storePath)
185 183
 }
186 184
 
187
-func NewDerivedDriver(machineName string, storePath string, client Client, caCert string, privateKey string) (*Driver, error) {
188
-	inner := drivers.NewBaseDriver(machineName, storePath, caCert, privateKey)
189
-	return &Driver{BaseDriver: inner, client: client}, nil
185
+func NewDerivedDriver(hostName, storePath string) *Driver {
186
+	return &Driver{
187
+		client:        &GenericClient{},
188
+		ActiveTimeout: defaultActiveTimeout,
189
+		BaseDriver: &drivers.BaseDriver{
190
+			SSHUser:     defaultSSHUser,
191
+			SSHPort:     defaultSSHPort,
192
+			MachineName: hostName,
193
+			StorePath:   storePath,
194
+		},
195
+	}
190 196
 }
191 197
 
192 198
 func (d *Driver) GetSSHHostname() (string, error) {
@@ -310,7 +316,7 @@ func (d *Driver) PreCreateCheck() error {
310 316
 }
311 317
 
312 318
 func (d *Driver) Create() error {
313
-	d.KeyPairName = fmt.Sprintf("%s-%s", d.MachineName, utils.GenerateRandomID())
319
+	d.KeyPairName = fmt.Sprintf("%s-%s", d.MachineName, mcnutils.GenerateRandomID())
314 320
 
315 321
 	if err := d.resolveIds(); err != nil {
316 322
 		return err

+ 0
- 1
drivers/openstack/openstack_test.go View File

@@ -1 +0,0 @@
1
-package openstack

Loading…
Cancel
Save