Skip to content

Commit cdf335a

Browse files
author
Mike Savochkin
authored
Merge pull request #1018 from subutai-io/dev
Dev
2 parents d0b7d29 + 8f34a4b commit cdf335a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+568
-5806
lines changed

Gopkg.lock

Lines changed: 2 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ all: vet test build
1818
$(GODEP):
1919
go get -u github.com/golang/dep/cmd/dep
2020

21-
Gopkg.toml: $(GODEP)
22-
$(GODEP_BIN) init
21+
#Gopkg.toml: $(GODEP)
22+
# $(GODEP_BIN) init
2323

2424
vendor: ## Vendor the packages using dep
25-
vendor: $(GODEP) Gopkg.toml Gopkg.lock
26-
@ echo "No vendor dir found. Fetching dependencies now..."
27-
GOPATH=$(GOPATH):. $(GODEP_BIN) ensure
25+
@echo "skip"
26+
#vendor: $(GODEP) Gopkg.toml Gopkg.lock
27+
# @ echo "No vendor dir found. Fetching dependencies now..."
28+
# GOPATH=$(GOPATH):. $(GODEP_BIN) ensure
2829

2930
version:
3031
@ echo $(VERSION)

agent/monitor/collect.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ package monitor
44
import (
55
"bufio"
66
"bytes"
7+
exc "github.com/subutai-io/agent/lib/exec"
78
"io/ioutil"
89
"os"
910
"os/exec"
10-
exc "github.com/subutai-io/agent/lib/exec"
1111
"runtime"
1212
"strconv"
1313
"strings"
1414
"time"
1515

1616
"github.com/influxdata/influxdb/client/v2"
1717

18+
"github.com/subutai-io/agent/agent/util"
1819
"github.com/subutai-io/agent/config"
20+
"github.com/subutai-io/agent/lib/common"
1921
"github.com/subutai-io/agent/lib/container"
20-
"github.com/subutai-io/agent/log"
21-
"github.com/subutai-io/agent/agent/util"
2222
"github.com/subutai-io/agent/lib/fs"
23+
"github.com/subutai-io/agent/log"
2324
"path"
24-
"github.com/subutai-io/agent/lib/common"
2525
)
2626

2727
var (
@@ -133,9 +133,13 @@ func cgroupStat(bp client.BatchPoints) {
133133
func netStat(bp client.BatchPoints) {
134134
lxcnic := make(map[string]string)
135135
files, err := ioutil.ReadDir(config.Agent.LxcPrefix)
136+
keyname := "lxc.net.0.veth.pair"
137+
if common.GetMajorVersion() < 3 {
138+
keyname = "lxc.network.veth.pair"
139+
}
136140
if err == nil {
137141
for _, f := range files {
138-
lxcnic[container.GetProperty(f.Name(), "lxc.network.veth.pair")] = f.Name()
142+
lxcnic[container.GetProperty(f.Name(), keyname)] = f.Name()
139143
}
140144
}
141145

cli/clone.go

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@ import (
44
"net"
55
"strings"
66

7+
"fmt"
8+
"github.com/nightlyone/lockfile"
9+
"github.com/subutai-io/agent/agent/util"
710
"github.com/subutai-io/agent/db"
11+
"github.com/subutai-io/agent/lib/common"
812
"github.com/subutai-io/agent/lib/container"
913
"github.com/subutai-io/agent/lib/gpg"
1014
"github.com/subutai-io/agent/log"
11-
"github.com/subutai-io/agent/agent/util"
12-
"regexp"
13-
"fmt"
1415
"reflect"
16+
"regexp"
1517
"sort"
16-
"github.com/nightlyone/lockfile"
1718
"time"
18-
"github.com/subutai-io/agent/lib/common"
1919
)
2020

2121
var (
2222
templateNameNOwnerNVersionRx = regexp.MustCompile(`^(?P<name>[a-zA-Z0-9._-]+)[@:](?P<owner>[a-zA-Z0-9._-]+):(?P<version>\d+\.\d+\.\d+)$`)
2323
templateNameNOwnerRx = regexp.MustCompile(`^(?P<name>[a-zA-Z0-9._-]+)[@:](?P<owner>[a-zA-Z0-9._-]+)$`)
2424
templateNameRx = regexp.MustCompile(`^(?P<name>[a-zA-Z0-9._-]+)$`)
2525
)
26+
2627
// LxcClone function creates new `child` container from a Subutai `parent` template.
2728
//
2829
// If the specified template argument is not deployed in system, Subutai first tries to import it, and if import succeeds, it then continues to clone from the imported template image.
@@ -86,12 +87,21 @@ func LxcClone(parent, child, envID, addr, consoleSecret string) {
8687
cont.Gateway = getOrGenerateGateway(addr)
8788
cont.Vlan = ip[1]
8889

89-
container.SetContainerConf(child, [][]string{
90-
{"lxc.network.flags", "up"},
91-
{"lxc.network.ipv4", fmt.Sprintf("%s/24", cont.Ip)},
92-
{"lxc.network.ipv4.gateway", cont.Gateway},
93-
{"#vlan_id", cont.Vlan},
94-
})
90+
if common.GetMajorVersion() < 3 {
91+
container.SetContainerConf(child, [][]string{
92+
{"lxc.network.flags", "up"},
93+
{"lxc.network.ipv4.address", fmt.Sprintf("%s/24", cont.Ip)},
94+
{"lxc.network.ipv4.gateway", cont.Gateway},
95+
{"#vlan_id", cont.Vlan},
96+
})
97+
} else {
98+
container.SetContainerConf(child, [][]string{
99+
{"lxc.net.0.flags", "up"},
100+
{"lxc.net.0.ipv4.address", fmt.Sprintf("%s/24", cont.Ip)},
101+
{"lxc.net.0.ipv4.gateway", cont.Gateway},
102+
{"#vlan_id", cont.Vlan},
103+
})
104+
}
95105
} else {
96106
//determine next free IP
97107
freeIPs := make(map[string]bool)
@@ -117,11 +127,19 @@ func LxcClone(parent, child, envID, addr, consoleSecret string) {
117127
cont.Ip = keys[0].String()
118128
cont.Gateway = "10.10.10.254"
119129

120-
container.SetContainerConf(child, [][]string{
121-
{"lxc.network.flags", "up"},
122-
{"lxc.network.ipv4", fmt.Sprintf("%s/24", cont.Ip)},
123-
{"lxc.network.ipv4.gateway", cont.Gateway},
124-
})
130+
if common.GetMajorVersion() < 3 {
131+
container.SetContainerConf(child, [][]string{
132+
{"lxc.network.flags", "up"},
133+
{"lxc.network.ipv4.address", fmt.Sprintf("%s/24", cont.Ip)},
134+
{"lxc.network.ipv4.gateway", cont.Gateway},
135+
})
136+
} else {
137+
container.SetContainerConf(child, [][]string{
138+
{"lxc.net.0.flags", "up"},
139+
{"lxc.net.0.ipv4.address", fmt.Sprintf("%s/24", cont.Ip)},
140+
{"lxc.net.0.ipv4.gateway", cont.Gateway},
141+
})
142+
}
125143

126144
}
127145
//changing from dhcp to manual
@@ -137,7 +155,11 @@ func LxcClone(parent, child, envID, addr, consoleSecret string) {
137155
//Security matters workaround. Need to change it in parent templates
138156
container.DisableSSHPwd(child)
139157

140-
cont.Interface = container.GetProperty(child, "lxc.network.veth.pair")
158+
if common.GetMajorVersion() < 3 {
159+
cont.Interface = container.GetProperty(child, "lxc.network.veth.pair")
160+
} else {
161+
cont.Interface = container.GetProperty(child, "lxc.net.0.veth.pair")
162+
}
141163

142164
log.Check(log.ErrorLevel, "Writing container metadata to database", db.SaveContainer(cont))
143165

cli/export.go

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ import (
66
"path/filepath"
77
"runtime"
88

9+
"encoding/json"
10+
"fmt"
11+
"github.com/subutai-io/agent/agent/util"
912
"github.com/subutai-io/agent/config"
13+
"github.com/subutai-io/agent/lib/common"
1014
"github.com/subutai-io/agent/lib/container"
1115
"github.com/subutai-io/agent/lib/fs"
1216
"github.com/subutai-io/agent/log"
13-
"github.com/subutai-io/agent/agent/util"
14-
"strings"
15-
"path"
16-
"regexp"
17-
"encoding/json"
18-
"mime/multipart"
1917
"gopkg.in/cheggaaa/pb.v1"
2018
"io"
21-
"fmt"
19+
"mime/multipart"
2220
"net/http"
23-
"time"
21+
"path"
22+
"regexp"
23+
"strings"
2424
"sync"
25+
"time"
2526
)
2627

2728
var (
@@ -101,10 +102,10 @@ func LxcExport(name, newname, version, prefsize, token string, local bool) {
101102
var dst string
102103
if newname != "" {
103104
dst = path.Join(config.Agent.CacheDir, newname+
104-
"-subutai-template_"+ version+ "_"+ runtime.GOARCH)
105+
"-subutai-template_"+version+"_"+runtime.GOARCH)
105106
} else {
106107
dst = path.Join(config.Agent.CacheDir, name+
107-
"-subutai-template_"+ version+ "_"+ runtime.GOARCH)
108+
"-subutai-template_"+version+"_"+runtime.GOARCH)
108109
}
109110

110111
os.MkdirAll(dst, 0755)
@@ -130,22 +131,41 @@ func LxcExport(name, newname, version, prefsize, token string, local bool) {
130131
log.Check(log.ErrorLevel, "Copying config file", fs.Copy(src+"/config", dst+"/config"))
131132

132133
//update template config
133-
templateConf := [][]string{
134-
{"subutai.template.owner", owner},
135-
{"subutai.template.version", version},
136-
{"subutai.template.size", pSize},
137-
{"lxc.network.ipv4.gateway"},
138-
{"lxc.network.ipv4"},
139-
{"lxc.network.veth.pair"},
140-
{"lxc.network.hwaddr"},
141-
{"lxc.network.mtu"},
142-
{"#vlan_id"},
134+
var templateConf [][]string
135+
if common.GetMajorVersion() < 3 {
136+
templateConf = [][]string{
137+
{"subutai.template.owner", owner},
138+
{"subutai.template.version", version},
139+
{"subutai.template.size", pSize},
140+
{"lxc.network.ipv4.gateway"},
141+
{"lxc.network.ipv4.address"},
142+
{"lxc.network.veth.pair"},
143+
{"lxc.network.hwaddr"},
144+
{"lxc.network.mtu"},
145+
{"#vlan_id"},
146+
}
147+
} else {
148+
templateConf = [][]string{
149+
{"subutai.template.owner", owner},
150+
{"subutai.template.version", version},
151+
{"subutai.template.size", pSize},
152+
{"lxc.net.0.ipv4.gateway"},
153+
{"lxc.net.0.ipv4.address"},
154+
{"lxc.net.0.veth.pair"},
155+
{"lxc.net.0.hwaddr"},
156+
{"lxc.net.0.mtu"},
157+
{"#vlan_id"},
158+
}
143159
}
144160

145161
if newname != "" {
146162
templateConf = append(templateConf, []string{"subutai.template", newname})
147163
templateConf = append(templateConf, []string{"lxc.utsname", newname})
148-
templateConf = append(templateConf, []string{"lxc.rootfs", path.Join(config.Agent.LxcPrefix, newname, "rootfs")})
164+
if common.GetMajorVersion() < 3 {
165+
templateConf = append(templateConf, []string{"lxc.rootfs", path.Join(config.Agent.LxcPrefix, newname, "rootfs")})
166+
} else {
167+
templateConf = append(templateConf, []string{"lxc.rootfs.path", "zfs:" + path.Join(config.Agent.LxcPrefix, newname, "rootfs")})
168+
}
149169
templateConf = append(templateConf, []string{"lxc.mount.entry", path.Join(config.Agent.LxcPrefix, newname, "home") + " home none bind,rw 0 0"})
150170
templateConf = append(templateConf, []string{"lxc.mount.entry", path.Join(config.Agent.LxcPrefix, newname, "var") + " var none bind,rw 0 0"})
151171
templateConf = append(templateConf, []string{"lxc.mount.entry", path.Join(config.Agent.LxcPrefix, newname, "opt") + " opt none bind,rw 0 0"})

0 commit comments

Comments
 (0)