forked from tsuru/tsuru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswarm.go
62 lines (52 loc) · 1.31 KB
/
swarm.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
// Copyright 2017 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package integration
import (
"fmt"
"strings"
"github.com/mattn/go-shellwords"
check "gopkg.in/check.v1"
)
type SwarmClusterManager struct {
env *Environment
c *check.C
}
func (m *SwarmClusterManager) Name() string {
return "swarm"
}
func (m *SwarmClusterManager) Provisioner() string {
return swarmProvisioner
}
func (m *SwarmClusterManager) Start() *Result {
return &Result{}
}
func (m *SwarmClusterManager) Delete() *Result {
return &Result{}
}
func (m *SwarmClusterManager) RequiredNodes() int {
return 1
}
func (m *SwarmClusterManager) UpdateParams() ([]string, bool) {
opts := nodeOrRegisterOpts(m.c, m.env)
parts, _ := shellwords.Parse(opts)
var clusterParts []string
createNode := false
for _, part := range parts {
if part == "--register" {
continue
}
metadata := strings.SplitN(part, "=", 2)
if len(metadata) == 2 {
if metadata[0] == "address" {
clusterParts = append(clusterParts, "--addr", metadata[1])
} else {
createNode = true
clusterParts = append(clusterParts, "--create-data", fmt.Sprintf("'%s'", part))
}
} else {
clusterParts = append(clusterParts, part)
}
}
return clusterParts, createNode
}