Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
remove generate-swarm-token command; fix tests; update docs
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
  • Loading branch information
ehazlett committed Feb 20, 2015
1 parent d017162 commit 82a686f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 80 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,26 @@ Machine is still in its early stages. If you'd like to try out a preview build,

Machine can create [Docker Swarm](https://github.com/docker/swarm) clusters.

First, create a Swarm token using `docker-machine generate-swarm-token`. Optionally, you can use another discovery service. See the Swarm docs for details.
First, create a Swarm token. Optionally, you can use another discovery service.
See the Swarm docs for details.

To create the token, first create a Machine. This example will use VirtualBox.

```
$ docker-machine create -d virtualbox local
```

Load the Machine configuration into your shell:

```
$ $(docker-machine env local)
```
Then run generate the token using the Swarm Docker image:

```
$ docker run swarm create
1257e0f0bbb499b5cd04b4c9bdb2dab3
```
Once you have the token, you can create the cluster.

### Swarm Master
Expand Down
17 changes: 0 additions & 17 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
_ "github.com/docker/machine/drivers/vmwarevsphere"
"github.com/docker/machine/state"
"github.com/docker/machine/utils"
"github.com/docker/swarm/discovery/token"
)

type machineConfig struct {
Expand Down Expand Up @@ -171,11 +170,6 @@ var Commands = []cli.Command{
Usage: "Create a machine",
Action: cmdCreate,
},
{
Name: "generate-swarm-token",
Usage: "Generate a Swarm Cluster Token",
Action: cmdGenerateSwarmToken,
},
{
Name: "config",
Usage: "Print the connection config for machine",
Expand Down Expand Up @@ -323,17 +317,6 @@ func cmdCreate(c *cli.Context) {
log.Infof("To point your Docker client at it, run this in your shell: $(%s env %s)", c.App.Name, name)
}

func cmdGenerateSwarmToken(c *cli.Context) {
discovery := &token.TokenDiscoveryService{}
discovery.Initialize("", 0)
token, err := discovery.CreateCluster()
if err != nil {
log.Fatal(err)

}
fmt.Println(token)
}

func cmdConfig(c *cli.Context) {
cfg, err := getMachineConfig(c)
if err != nil {
Expand Down
25 changes: 22 additions & 3 deletions docs/dockermachine.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,28 @@ clusters. This can be used with any driver and will be secured with TLS.
Note: please note that this is an experimental feature and the subcommands and
options will very likely change.

First, create a Swarm token using `docker-machine generate-swarm-token`.
Optionally, you can use another discovery service. See the Swarm docs for
details.
First, create a Swarm token. Optionally, you can use another discovery service.
See the Swarm docs for details.

To create the token, first create a Machine. This example will use VirtualBox.

```
$ docker-machine create -d virtualbox local
```

Load the Machine configuration into your shell:

```
$ $(docker-machine env local)
```
Then run generate the token using the Swarm Docker image:

```
$ docker run swarm create
1257e0f0bbb499b5cd04b4c9bdb2dab3
```
Once you have the token, you can create the cluster.


Once you have the token, you can create the cluster.

Expand Down
15 changes: 8 additions & 7 deletions host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ func getTestDriverFlags() *DriverOptionsMock {
name := hostTestName
flags := &DriverOptionsMock{
Data: map[string]interface{}{
"name": name,
"url": "unix:///var/run/docker.sock",
"swarm": false,
"swarm-host": "",
"swarm-master": false,
"name": name,
"url": "unix:///var/run/docker.sock",
"swarm": false,
"swarm-host": "",
"swarm-master": false,
"swarm-discovery": "",
},
}
return flags
}

func getDefaultTestHost() (*Host, error) {
host, err := NewHost(hostTestName, hostTestDriverName, hostTestStorePath, hostTestCaCert, hostTestPrivateKey, false, "")
host, err := NewHost(hostTestName, hostTestDriverName, hostTestStorePath, hostTestCaCert, hostTestPrivateKey, false, "", "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -150,7 +151,7 @@ func TestGenerateClientCertificate(t *testing.T) {
}

func TestGenerateDockerConfigNonLocal(t *testing.T) {
host, err := NewHost(hostTestName, hostTestDriverName, hostTestStorePath, hostTestCaCert, hostTestPrivateKey, false, "")
host, err := getDefaultTestHost()
if err != nil {
t.Fatal(err)
}
Expand Down
70 changes: 18 additions & 52 deletions store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,25 @@ func clearHosts() error {
return os.RemoveAll(utils.GetMachineDir())
}

func TestStoreCreate(t *testing.T) {
if err := clearHosts(); err != nil {
t.Fatal(err)
}

flags := &DriverOptionsMock{
func getDefaultTestDriverFlags() *DriverOptionsMock {
return &DriverOptionsMock{
Data: map[string]interface{}{
"name": "test",
"url": "unix:///var/run/docker.sock",
"swarm": false,
"swarm-host": "",
"swarm-master": false,
"swarm-master-ip": "",
"swarm-discovery": "",
},
}
}

func TestStoreCreate(t *testing.T) {
if err := clearHosts(); err != nil {
t.Fatal(err)
}

flags := getDefaultTestDriverFlags()

store := NewStore("", "", "")

Expand All @@ -64,15 +69,7 @@ func TestStoreRemove(t *testing.T) {
t.Fatal(err)
}

flags := &DriverOptionsMock{
Data: map[string]interface{}{
"url": "unix:///var/run/docker.sock",
"swarm": false,
"swarm-host": "",
"swarm-master": false,
"swarm-master-ip": "",
},
}
flags := getDefaultTestDriverFlags()

store := NewStore("", "", "")
_, err := store.Create("test", "none", flags)
Expand All @@ -97,15 +94,7 @@ func TestStoreList(t *testing.T) {
t.Fatal(err)
}

flags := &DriverOptionsMock{
Data: map[string]interface{}{
"url": "unix:///var/run/docker.sock",
"swarm": false,
"swarm-host": "",
"swarm-master": false,
"swarm-master-ip": "",
},
}
flags := getDefaultTestDriverFlags()

store := NewStore("", "", "")
_, err := store.Create("test", "none", flags)
Expand All @@ -126,15 +115,7 @@ func TestStoreExists(t *testing.T) {
t.Fatal(err)
}

flags := &DriverOptionsMock{
Data: map[string]interface{}{
"url": "unix:///var/run/docker.sock",
"swarm": false,
"swarm-host": "",
"swarm-master": false,
"swarm-master-ip": "",
},
}
flags := getDefaultTestDriverFlags()

store := NewStore("", "", "")
exists, err := store.Exists("test")
Expand All @@ -160,15 +141,8 @@ func TestStoreLoad(t *testing.T) {
}

expectedURL := "unix:///foo/baz"
flags := &DriverOptionsMock{
Data: map[string]interface{}{
"url": expectedURL,
"swarm": false,
"swarm-host": "",
"swarm-master": false,
"swarm-master-ip": "",
},
}
flags := getDefaultTestDriverFlags()
flags.Data["url"] = expectedURL

store := NewStore("", "", "")
_, err := store.Create("test", "none", flags)
Expand All @@ -195,15 +169,7 @@ func TestStoreGetSetActive(t *testing.T) {
t.Fatal(err)
}

flags := &DriverOptionsMock{
Data: map[string]interface{}{
"url": "unix:///var/run/docker.sock",
"swarm": false,
"swarm-host": "",
"swarm-master": false,
"swarm-master-ip": "",
},
}
flags := getDefaultTestDriverFlags()

store := NewStore("", "", "")

Expand Down

0 comments on commit 82a686f

Please sign in to comment.