mirror of
https://github.com/labring/sealos.git
synced 2026-09-24 15:46:19 +08:00
feature(devlop): fix ips and md5
This commit is contained in:
@@ -3,7 +3,7 @@ module github.com/fanux/sealos
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/cuisongliu/sshcmd v1.4.1
|
||||
github.com/cuisongliu/sshcmd v1.4.2
|
||||
github.com/fanux/sealgate v0.0.4
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/spf13/cobra v0.0.5
|
||||
|
||||
@@ -18,8 +18,8 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
|
||||
github.com/cuisongliu/sshcmd v1.4.1 h1:wbtT1HnisY6ZszRqlljG/E9bfixxIa86g+Uqo0ejT/A=
|
||||
github.com/cuisongliu/sshcmd v1.4.1/go.mod h1:jAEBZhFW5kNey9B+59lR8mfQaCQsyp8b8QaI7RhESxE=
|
||||
github.com/cuisongliu/sshcmd v1.4.2 h1:4eJ1OXhMBUU9NPVEvKS5T24v0N+zKkKbtgP66pDVSKk=
|
||||
github.com/cuisongliu/sshcmd v1.4.2/go.mod h1:jAEBZhFW5kNey9B+59lR8mfQaCQsyp8b8QaI7RhESxE=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
||||
+29
-7
@@ -199,7 +199,30 @@ func NextIP(ip net.IP) net.IP {
|
||||
func ParseIPs(ips []string) []string {
|
||||
var hosts []string
|
||||
for _, nodes := range ips {
|
||||
// nodes 192.168.0.2-192.168.0.6
|
||||
var startIp, endIp string
|
||||
if !strings.Contains(nodes, "-") {
|
||||
hosts = append(hosts, nodes)
|
||||
continue
|
||||
} else {
|
||||
// nodes 192.168.0.2-192.168.0.6
|
||||
// 1.1.1.1 - 155.155.155.155
|
||||
hostSilts := strings.Split(nodes, "-")
|
||||
if len(hostSilts) > 2 {
|
||||
logger.Error("multi-nodes/multi-masters illegal; host spilt than more two .")
|
||||
os.Exit(-1)
|
||||
} else {
|
||||
startIp = strings.Split(nodes, "-")[0]
|
||||
endIp = strings.Split(nodes, "-")[1]
|
||||
if len(startIp) < 7 {
|
||||
logger.Error("multi-nodes/multi-masters illegal;start host length less 7 , like 1.1.1.1 can used, but not %s .", startIp)
|
||||
os.Exit(-1)
|
||||
}
|
||||
if len(endIp) < 7 {
|
||||
logger.Error("multi-nodes/multi-masters illegal;end host length less 7 , like 1.1.1.1 can used, but not s% .", endIp)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(nodes) > 15 {
|
||||
logger.Error("multi-nodes/multi-masters illegal.")
|
||||
os.Exit(-1)
|
||||
@@ -207,12 +230,11 @@ func ParseIPs(ips []string) []string {
|
||||
hosts = append(hosts, nodes)
|
||||
continue
|
||||
}
|
||||
startip := strings.Split(nodes, "-")[0]
|
||||
endip := strings.Split(nodes, "-")[1]
|
||||
hosts = append(hosts, startip)
|
||||
for Cmp(stringToIP(startip), stringToIP(endip)) < 0 {
|
||||
startip = NextIP(stringToIP(startip)).String()
|
||||
hosts = append(hosts, startip)
|
||||
|
||||
hosts = append(hosts, startIp)
|
||||
for Cmp(stringToIP(startIp), stringToIP(endIp)) < 0 {
|
||||
startIp = NextIP(stringToIP(startIp)).String()
|
||||
hosts = append(hosts, startIp)
|
||||
}
|
||||
}
|
||||
return hosts
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestPrint(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVersionToInt(t *testing.T) {
|
||||
t.Log(VersionToInt("v1.15.6"))
|
||||
t.Log(ParseIPs([]string{"1.1.1.1-1.1.1.5"}))
|
||||
}
|
||||
|
||||
func TestUrlGetMd5(t *testing.T) {
|
||||
|
||||
+3
@@ -8,6 +8,7 @@ import (
|
||||
"golang.org/x/crypto/ssh"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -22,6 +23,8 @@ func (ss *SSH) CopyForMD5(host, localFilePath, remoteFilePath, md5 string) bool
|
||||
ss.Copy(host, localFilePath, remoteFilePath)
|
||||
remoteMD5 := ss.Md5Sum(host, remoteFilePath)
|
||||
logger.Debug("host: %s , remote md5: %s", host, remoteMD5)
|
||||
remoteMD5 = strings.TrimSpace(remoteMD5)
|
||||
md5 = strings.TrimSpace(md5)
|
||||
if remoteMD5 == md5 {
|
||||
logger.Info("md5 validate true")
|
||||
return true
|
||||
|
||||
Vendored
+1
-1
@@ -10,7 +10,7 @@ github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests
|
||||
github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses
|
||||
github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils
|
||||
github.com/aliyun/alibaba-cloud-sdk-go/services/ecs
|
||||
# github.com/cuisongliu/sshcmd v1.4.1
|
||||
# github.com/cuisongliu/sshcmd v1.4.2
|
||||
github.com/cuisongliu/sshcmd/pkg/filesize
|
||||
github.com/cuisongliu/sshcmd/pkg/md5sum
|
||||
github.com/cuisongliu/sshcmd/pkg/sshutil
|
||||
|
||||
Reference in New Issue
Block a user