From fa49e138f26fbeb21a193ef48befb98dcbe37f99 Mon Sep 17 00:00:00 2001 From: TangBin Date: Sat, 16 Feb 2019 17:55:42 +0800 Subject: [PATCH] update vendor & bugfix --- Gopkg.lock | 5 +- pkg/util/huawei/disk.go | 57 ++++++++++++++++++- pkg/util/huawei/order.go | 2 +- pkg/util/huawei/region.go | 2 + pkg/util/huawei/securitygroup.go | 29 ++++++++++ .../yunion.io/x/pkg/util/regutils/regutils.go | 6 ++ .../x/pkg/util/timeutils/timeutils.go | 7 +++ 7 files changed, 104 insertions(+), 4 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index e8ae57e3c2..7e20fb308d 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1676,7 +1676,7 @@ [[projects]] branch = "master" - digest = "1:6277045f9c9a63d84e1aa48c7ad3c1f42ea6523bc54ea92e772d541c78e37404" + digest = "1:37d4e9b3030c077522fc5669b497a25ce53429da77d5e592226658e57cc604bb" name = "yunion.io/x/pkg" packages = [ "gotypes", @@ -1710,7 +1710,7 @@ "utils", ] pruneopts = "UT" - revision = "e2e42205d868c26829b9322b40cdc48f24fed379" + revision = "5fbe7b39e5f599aa49f6f597d57da460d93c26ff" [[projects]] branch = "master" @@ -1826,6 +1826,7 @@ "golang.org/x/net/ipv4", "golang.org/x/sys/unix", "gopkg.in/gin-gonic/gin.v1", + "gopkg.in/yaml.v2", "k8s.io/api/core/v1", "k8s.io/apimachinery/pkg/api/errors", "k8s.io/apimachinery/pkg/apis/meta/v1", diff --git a/pkg/util/huawei/disk.go b/pkg/util/huawei/disk.go index f3ffc34b73..58a131f9e1 100644 --- a/pkg/util/huawei/disk.go +++ b/pkg/util/huawei/disk.go @@ -270,6 +270,14 @@ func (self *SDisk) GetMountpoint() string { return "" } +func (self *SDisk) GetMountServerId() string { + if len(self.Attachments) > 0 { + return self.Attachments[0].ServerID + } + + return "" +} + func (self *SDisk) GetAccessPath() string { return "" } @@ -325,8 +333,55 @@ func (self *SDisk) Resize(ctx context.Context, newSizeMB int64) error { return self.storage.zone.region.resizeDisk(self.GetId(), sizeGb) } +func (self *SDisk) Detach() error { + err := self.storage.zone.region.DetachDisk(self.GetMountServerId(), self.GetId()) + if err != nil { + log.Debugf("detach server %s disk %s failed: %s", self.GetMountServerId(), self.GetId(), err) + return err + } + + return cloudprovider.WaitStatus(self, models.DISK_READY, 5*time.Second, 60*time.Second) +} + +func (self *SDisk) Attach(device string) error { + err := self.storage.zone.region.AttachDisk(self.GetMountServerId(), self.GetId(), device) + if err != nil { + log.Debugf("attach server %s disk %s failed: %s", self.GetMountServerId(), self.GetId(), err) + return err + } + + return cloudprovider.WaitStatus(self, models.DISK_READY, 5*time.Second, 60*time.Second) +} + +// 在线卸载磁盘 https://support.huaweicloud.com/usermanual-ecs/zh-cn_topic_0036046828.html +// 对于挂载在系统盘盘位(也就是“/dev/sda”或“/dev/vda”挂载点)上的磁盘,当前仅支持离线卸载 func (self *SDisk) Reset(ctx context.Context, snapshotId string) (string, error) { - return self.storage.zone.region.resetDisk(self.GetId(), snapshotId) + mountpoint := self.GetMountpoint() + if mountpoint == "/dev/sda" || mountpoint == "/dev/vda" { + err := self.Detach() + if err != nil { + return "", err + } + } + + diskId, err := self.storage.zone.region.resetDisk(self.GetId(), snapshotId) + if err != nil { + return diskId, err + } + + err = cloudprovider.WaitStatus(self, models.DISK_READY, 5*time.Second, 300*time.Second) + if err != nil { + return "", err + } + + if mountpoint == "/dev/sda" || mountpoint == "/dev/vda" { + err := self.Attach(mountpoint) + if err != nil { + return "", err + } + } + + return diskId, nil } // 华为云不支持重置 diff --git a/pkg/util/huawei/order.go b/pkg/util/huawei/order.go index af55deff3c..c408cfb865 100644 --- a/pkg/util/huawei/order.go +++ b/pkg/util/huawei/order.go @@ -105,7 +105,7 @@ func (self *SRegion) GetOrderResources(orderId string, resource_ids []string, on queries["only_main_resource"] = "1" } - err = DoList(self.ecsClient.Orders.GetPeriodResourceList, queries, &resources) + err = doListAll(self.ecsClient.Orders.GetPeriodResourceList, queries, &resources) return resources, err } diff --git a/pkg/util/huawei/region.go b/pkg/util/huawei/region.go index fbd8a01b30..4d686cd1f8 100644 --- a/pkg/util/huawei/region.go +++ b/pkg/util/huawei/region.go @@ -338,6 +338,8 @@ func (self *SRegion) SyncSecurityGroup(secgroupId string, vpcId string, name str secgroupId = extID } + // 华为云默认deny。不需要显式指定 + rules = SecurityRuleSetToAllowSet(rules) return secgroupId, self.syncSecgroupRules(secgroupId, rules) } diff --git a/pkg/util/huawei/securitygroup.go b/pkg/util/huawei/securitygroup.go index 1b30fac95c..96f852a263 100644 --- a/pkg/util/huawei/securitygroup.go +++ b/pkg/util/huawei/securitygroup.go @@ -13,6 +13,8 @@ https://support.huaweicloud.com/usermanual-vpc/zh-cn_topic_0073379079.html import ( "net" + "sort" + "yunion.io/x/jsonutils" "yunion.io/x/pkg/util/secrules" ) @@ -68,6 +70,33 @@ func compatibleSecurityGroupRule(r SecurityGroupRule) bool { return true } +// 将安全组规则全部转换为等价的allow规则 +func SecurityRuleSetToAllowSet(srs secrules.SecurityRuleSet) secrules.SecurityRuleSet { + inRuleSet := secrules.SecurityRuleSet{} + outRuleSet := secrules.SecurityRuleSet{} + + for _, rule := range srs { + if rule.Direction == secrules.SecurityRuleIngress { + inRuleSet = append(inRuleSet, rule) + } + + if rule.Direction == secrules.SecurityRuleEgress { + outRuleSet = append(outRuleSet, rule) + } + } + + sort.Sort(inRuleSet) + sort.Sort(outRuleSet) + + inRuleSet = inRuleSet.AllowList() + outRuleSet = outRuleSet.AllowList() + + ret := secrules.SecurityRuleSet{} + ret = append(ret, inRuleSet...) + ret = append(ret, outRuleSet...) + return ret +} + func (self *SSecurityGroup) GetId() string { return self.ID } diff --git a/vendor/yunion.io/x/pkg/util/regutils/regutils.go b/vendor/yunion.io/x/pkg/util/regutils/regutils.go index b196f2772f..6fd20266fc 100644 --- a/vendor/yunion.io/x/pkg/util/regutils/regutils.go +++ b/vendor/yunion.io/x/pkg/util/regutils/regutils.go @@ -27,6 +27,7 @@ var FULLISO_TIME_REG *regexp.Regexp var COMPACT_TIME_REG *regexp.Regexp var MYSQL_TIME_REG *regexp.Regexp var NORMAL_TIME_REG *regexp.Regexp +var FULLNORMAL_TIME_REG *regexp.Regexp var RFC2882_TIME_REG *regexp.Regexp var EMAIL_REG *regexp.Regexp var CHINA_MOBILE_REG *regexp.Regexp @@ -56,6 +57,7 @@ func init() { COMPACT_TIME_REG = regexp.MustCompile(`^\d{14}$`) MYSQL_TIME_REG = regexp.MustCompile(`^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$`) NORMAL_TIME_REG = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$`) + FULLNORMAL_TIME_REG = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}$`) RFC2882_TIME_REG = regexp.MustCompile(`[A-Z][a-z]{2}, [0-9]{1,2} [A-Z][a-z]{2} [0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2} [A-Z]{3}`) EMAIL_REG = regexp.MustCompile(`^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$`) CHINA_MOBILE_REG = regexp.MustCompile(`^1[0-9-]{10}$`) @@ -171,6 +173,10 @@ func MatchNormalTime(str string) bool { return NORMAL_TIME_REG.MatchString(str) } +func MatchFullNormalTime(str string) bool { + return FULLNORMAL_TIME_REG.MatchString(str) +} + func MatchRFC2882Time(str string) bool { return RFC2882_TIME_REG.MatchString(str) } diff --git a/vendor/yunion.io/x/pkg/util/timeutils/timeutils.go b/vendor/yunion.io/x/pkg/util/timeutils/timeutils.go index ed6522dd37..d92e34844f 100644 --- a/vendor/yunion.io/x/pkg/util/timeutils/timeutils.go +++ b/vendor/yunion.io/x/pkg/util/timeutils/timeutils.go @@ -26,6 +26,7 @@ const ( FullIsoTimeFormat = "2006-01-02T15:04:05.000000Z" MysqlTimeFormat = "2006-01-02 15:04:05" NormalTimeFormat = "2006-01-02T15:04:05" + FullNormalTimeFormat = "2006-01-02T15:04:05.000000" CompactTimeFormat = "20060102150405" DateFormat = "2006-01-02" ShortDateFormat = "20060102" @@ -84,6 +85,10 @@ func ParseNormalTime(str string) (time.Time, error) { return time.Parse(NormalTimeFormat, str) } +func ParseFullNormalTime(str string) (time.Time, error) { + return time.Parse(FullNormalTimeFormat, str) +} + func ParseCompactTime(str string) (time.Time, error) { return time.Parse(CompactTimeFormat, str) } @@ -111,6 +116,8 @@ func ParseTimeStr(str string) (time.Time, error) { return ParseMysqlTime(str) } else if regutils.MatchNormalTime(str) { return ParseNormalTime(str) + } else if regutils.MatchFullNormalTime(str) { + return ParseFullNormalTime(str) } else if regutils.MatchRFC2882Time(str) { return ParseRFC2882Time(str) } else if regutils.MatchCompactTime(str) {