mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix(region): sync aliyun gtm and aws traffic policy address (#21103)
This commit is contained in:
@@ -89,14 +89,14 @@ require (
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
k8s.io/cri-api v0.22.17
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240807034251-7e6d1a5ccb32
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240826095603-487cdd2b3e0d
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
|
||||
yunion.io/x/jsonutils v1.0.1-0.20240203102553-4096f103b401
|
||||
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
|
||||
yunion.io/x/pkg v1.10.1-0.20240812013427-0163ba9c86b1
|
||||
yunion.io/x/pkg v1.10.1-0.20240826001854-ac73b70d75b7
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20240624023332-82a08f917568
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20240823033059-be6fe90dab22
|
||||
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c
|
||||
)
|
||||
|
||||
|
||||
@@ -1214,8 +1214,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240807034251-7e6d1a5ccb32 h1:DZI70cvO94i/UTcmPnf4nMcvOdhfkbA+MP0rbKlth6s=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240807034251-7e6d1a5ccb32/go.mod h1:iLoBHVR2Eur/1WJSGcbZaEwpzh/iqXvbFCsX9/xt8CI=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240826095603-487cdd2b3e0d h1:3+D8fZOD25IL188XKfgXheD25xqVCaJhVRhMxTopoMU=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240826095603-487cdd2b3e0d/go.mod h1:iLoBHVR2Eur/1WJSGcbZaEwpzh/iqXvbFCsX9/xt8CI=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
@@ -1229,11 +1229,11 @@ yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 h1:Hu/4ERvoWaN6aiFs4h4/yvVB
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900/go.mod h1:0vLkNEhlmA64HViPBAnSTUMrx5QP1CLsxXmxDKQ80tc=
|
||||
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v1.10.1-0.20240812013427-0163ba9c86b1 h1:UJ5mmoZWrO3golljJaMchFQNzSZdRWGM32Xf3lI5YVk=
|
||||
yunion.io/x/pkg v1.10.1-0.20240812013427-0163ba9c86b1/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
|
||||
yunion.io/x/pkg v1.10.1-0.20240826001854-ac73b70d75b7 h1:ceNLYp6CKYccbFw/ug9ohSaUbEk5THipaA4K+SAHEKc=
|
||||
yunion.io/x/pkg v1.10.1-0.20240826001854-ac73b70d75b7/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20240624023332-82a08f917568 h1:Ytz3G6z3/U+yzkM3KM/am1ndPWHB0nDlOLi9OJWduPc=
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20240624023332-82a08f917568/go.mod h1:5W8ghvJ4TNt/r2yDjjD3i4QsZgIiJX45dhRQBGWPHsQ=
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20240823033059-be6fe90dab22 h1:H+lxDpb8e2y2DwMRvo6Ujq3NK1zbR0gfVS9tdvjG4X0=
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20240823033059-be6fe90dab22/go.mod h1:5W8ghvJ4TNt/r2yDjjD3i4QsZgIiJX45dhRQBGWPHsQ=
|
||||
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c h1:QuLab2kSRECZRxo4Lo2KcYn6XjQFDGaZ1+x0pYDVVwQ=
|
||||
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
@@ -78,6 +79,9 @@ type SDnsRecord struct {
|
||||
PolicyType string `width:"36" charset:"ascii" nullable:"false" list:"user" update:"user" create:"optional"`
|
||||
// 解析线路
|
||||
PolicyValue string `width:"256" charset:"ascii" nullable:"false" list:"user" update:"user" create:"optional"`
|
||||
|
||||
// 目前存储阿里云GTM设置地址及AWS TrafficPolicy端点地址, 仅支持同步
|
||||
ExtraAddresses []string `width:"512" charset:"utf8" nullable:"true" list:"user"`
|
||||
}
|
||||
|
||||
func (manager *SDnsRecordManager) EnableGenerateName() bool {
|
||||
@@ -492,6 +496,12 @@ func (self *SDnsRecord) syncWithDnsRecord(ctx context.Context, userCred mcclient
|
||||
self.DnsValue = ext.GetDnsValue()
|
||||
self.PolicyType = string(ext.GetPolicyType())
|
||||
self.PolicyValue = string(ext.GetPolicyValue())
|
||||
extraAddresses, err := ext.GetExtraAddresses()
|
||||
if err != nil {
|
||||
log.Errorf("GetExtraAddresses for record %s error: %v", self.Name, err)
|
||||
return nil
|
||||
}
|
||||
self.ExtraAddresses = extraAddresses
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -520,6 +530,7 @@ func (self *SDnsZone) newFromCloudDnsRecord(ctx context.Context, userCred mcclie
|
||||
record.ExternalId = ext.GetGlobalId()
|
||||
record.PolicyType = string(ext.GetPolicyType())
|
||||
record.PolicyValue = string(ext.GetPolicyValue())
|
||||
record.ExtraAddresses, _ = ext.GetExtraAddresses()
|
||||
|
||||
err := DnsRecordManager.TableSpec().Insert(ctx, record)
|
||||
if err != nil {
|
||||
|
||||
Vendored
+3
-3
@@ -1489,7 +1489,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240807034251-7e6d1a5ccb32
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240826095603-487cdd2b3e0d
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
@@ -1586,7 +1586,7 @@ yunion.io/x/log/hooks
|
||||
yunion.io/x/ovsdb/cli_util
|
||||
yunion.io/x/ovsdb/schema/ovn_nb
|
||||
yunion.io/x/ovsdb/types
|
||||
# yunion.io/x/pkg v1.10.1-0.20240812013427-0163ba9c86b1
|
||||
# yunion.io/x/pkg v1.10.1-0.20240826001854-ac73b70d75b7
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/pkg/appctx
|
||||
yunion.io/x/pkg/errors
|
||||
@@ -1641,7 +1641,7 @@ yunion.io/x/pkg/utils
|
||||
# yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
## explicit; go 1.12
|
||||
yunion.io/x/s3cli
|
||||
# yunion.io/x/sqlchemy v1.1.3-0.20240624023332-82a08f917568
|
||||
# yunion.io/x/sqlchemy v1.1.3-0.20240823033059-be6fe90dab22
|
||||
## explicit; go 1.17
|
||||
yunion.io/x/sqlchemy
|
||||
yunion.io/x/sqlchemy/backends
|
||||
|
||||
+1
@@ -1319,6 +1319,7 @@ type ICloudDnsRecord interface {
|
||||
GetDnsValue() string
|
||||
GetTTL() int64
|
||||
GetMxPriority() int64
|
||||
GetExtraAddresses() ([]string, error)
|
||||
|
||||
Update(*DnsRecord) error
|
||||
|
||||
|
||||
+58
@@ -15,10 +15,12 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
@@ -320,6 +322,62 @@ func (self *SDomainRecord) Disable() error {
|
||||
return self.domain.client.SetDomainRecordStatus(self.RecordId, "Disable")
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) GetDnsExtraAddresses(dnsValue string) ([]string, error) {
|
||||
ret := []string{}
|
||||
if !strings.HasPrefix(dnsValue, "gtm") {
|
||||
return ret, nil
|
||||
}
|
||||
instances, err := self.DescribeDnsGtmInstances()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "DescribeDnsGtmInstances")
|
||||
}
|
||||
for _, instance := range instances {
|
||||
if instance.Config.PublicZoneName == dnsValue {
|
||||
pools, err := self.DescribeDnsGtmInstanceAddressPools(instance.InstanceId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "DescribeDnsGtmInstanceAddressPools")
|
||||
}
|
||||
for _, pool := range pools {
|
||||
address, err := self.DescribeDnsGtmInstanceAddressPool(pool.AddrPoolId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "DescribeDnsGtmInstanceAddressPools")
|
||||
}
|
||||
for _, addr := range address.Addrs.Addr {
|
||||
if !utils.IsInStringArray(addr.Addr, ret) {
|
||||
ret = append(ret, addr.Addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
}
|
||||
gtm3, err := self.ListCloudGtmInstanceConfigs()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "ListCloudGtmInstanceConfigs")
|
||||
}
|
||||
for _, instance := range gtm3 {
|
||||
if instance.ScheduleDomainName == dnsValue || dnsValue == fmt.Sprintf("%s.%s", instance.InstanceId, instance.ScheduleZoneName) {
|
||||
for _, pool := range instance.AddressPools.AddressPool {
|
||||
pool, err := self.DescribeCloudGtmAddressPool(pool.AddressPoolId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "DescribeCloudGtmAddressPool")
|
||||
}
|
||||
for _, addr := range pool.Addresses.Address {
|
||||
if !utils.IsInStringArray(addr.Address, ret) {
|
||||
ret = append(ret, addr.Address)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SDomainRecord) GetExtraAddresses() ([]string, error) {
|
||||
return self.domain.client.GetDnsExtraAddresses(self.GetDnsValue())
|
||||
}
|
||||
|
||||
// line
|
||||
func (client *SAliyunClient) UpdateDomainRecord(id string, opts *cloudprovider.DnsRecord) error {
|
||||
line := GetRecordLineLineType(opts.PolicyValue)
|
||||
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
)
|
||||
|
||||
type SDnsGtmInstance struct {
|
||||
InstanceId string
|
||||
Config struct {
|
||||
PublicZoneName string
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) DescribeDnsGtmInstances() ([]SDnsGtmInstance, error) {
|
||||
params := map[string]string{
|
||||
"PageSize": "100",
|
||||
}
|
||||
ret := []SDnsGtmInstance{}
|
||||
pageNumber := 1
|
||||
for {
|
||||
params["PageNumber"] = fmt.Sprintf("%d", pageNumber)
|
||||
resp, err := self.alidnsRequest("DescribeDnsGtmInstances", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
part := struct {
|
||||
GtmInstances []SDnsGtmInstance
|
||||
TotalItems int
|
||||
}{}
|
||||
err = resp.Unmarshal(&part)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, part.GtmInstances...)
|
||||
if len(ret) >= part.TotalItems || len(part.GtmInstances) == 0 {
|
||||
break
|
||||
}
|
||||
pageNumber++
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
type SDnsGtmInstanceAddressPool struct {
|
||||
Name string
|
||||
AddrPoolId string
|
||||
AddrCount int
|
||||
Addrs struct {
|
||||
Addr []struct {
|
||||
Addr string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) DescribeDnsGtmInstanceAddressPools(id string) ([]SDnsGtmInstanceAddressPool, error) {
|
||||
params := map[string]string{"InstanceId": id, "PageSize": "100"}
|
||||
ret := []SDnsGtmInstanceAddressPool{}
|
||||
pageNumber := 1
|
||||
for {
|
||||
params["PageNumber"] = fmt.Sprintf("%d", pageNumber)
|
||||
resp, err := self.alidnsRequest("DescribeDnsGtmInstanceAddressPools", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
part := struct {
|
||||
AddrPools struct {
|
||||
AddrPool []SDnsGtmInstanceAddressPool
|
||||
}
|
||||
TotalItems int
|
||||
}{}
|
||||
err = resp.Unmarshal(&part)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, part.AddrPools.AddrPool...)
|
||||
if len(ret) >= part.TotalItems || len(part.AddrPools.AddrPool) == 0 {
|
||||
break
|
||||
}
|
||||
pageNumber++
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) DescribeDnsGtmInstanceAddressPool(id string) (*SDnsGtmInstanceAddressPool, error) {
|
||||
params := map[string]string{"AddrPoolId": id}
|
||||
resp, err := self.alidnsRequest("DescribeDnsGtmInstanceAddressPool", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := &SDnsGtmInstanceAddressPool{}
|
||||
err = resp.Unmarshal(ret)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Unmarshal")
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package aliyun
|
||||
|
||||
import "fmt"
|
||||
|
||||
type SGtmInstanceConfigs struct {
|
||||
InstanceId string
|
||||
ScheduleDomainName string
|
||||
ScheduleZoneName string
|
||||
AddressPools struct {
|
||||
AddressPool []struct {
|
||||
AddressPoolId string
|
||||
AddressPoolName string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) ListCloudGtmInstanceConfigs() ([]SGtmInstanceConfigs, error) {
|
||||
params := map[string]string{"PageSize": "100"}
|
||||
ret := []SGtmInstanceConfigs{}
|
||||
pageNumber := 1
|
||||
for {
|
||||
params["PageNumber"] = fmt.Sprintf("%d", pageNumber)
|
||||
resp, err := self.alidnsRequest("ListCloudGtmInstanceConfigs", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
part := struct {
|
||||
InstanceConfigs struct {
|
||||
InstanceConfig []SGtmInstanceConfigs
|
||||
}
|
||||
TotalItems int
|
||||
}{}
|
||||
err = resp.Unmarshal(&part)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, part.InstanceConfigs.InstanceConfig...)
|
||||
if len(ret) >= part.TotalItems || len(part.InstanceConfigs.InstanceConfig) == 0 {
|
||||
break
|
||||
}
|
||||
pageNumber++
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
type SGtmAddressPool struct {
|
||||
AddressPoolId string
|
||||
Addresses struct {
|
||||
Address []struct {
|
||||
Address string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) DescribeCloudGtmAddressPool(id string) (*SGtmAddressPool, error) {
|
||||
params := map[string]string{"AddressPoolId": id}
|
||||
resp, err := self.alidnsRequest("DescribeCloudGtmAddressPool", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := &SGtmAddressPool{}
|
||||
err = resp.Unmarshal(ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
+4
@@ -163,6 +163,10 @@ func (self *SPvtzRecord) Delete() error {
|
||||
return self.szone.client.DeleteZoneRecord(self.RecordId)
|
||||
}
|
||||
|
||||
func (self *SPvtzRecord) GetExtraAddresses() ([]string, error) {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
func (self *SPvtzRecord) GetMxPriority() int64 {
|
||||
if self.GetDnsType() == cloudprovider.DnsTypeMX {
|
||||
return self.Priority
|
||||
|
||||
+2
@@ -303,6 +303,8 @@ func jsonRequest(cli *client.Client, apiName string, params map[string]string, r
|
||||
"ListHostedZones": "hostedzone",
|
||||
"ListGeoLocations": "geolocations",
|
||||
"CreateHostedZone": "hostedzone",
|
||||
"GetTrafficPolicyInstance": "trafficpolicyinstance",
|
||||
"GetTrafficPolicy": "trafficpolicy",
|
||||
"GetHostedZone": "",
|
||||
"DeleteHostedZone": "",
|
||||
"AssociateVPCWithHostedZone": "",
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package aws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SDnsTrafficPolicyInstance struct {
|
||||
Id string `xml:"Id"`
|
||||
Name string `xml:"Name"`
|
||||
TrafficPolicyId string `xml:"TrafficPolicyId"`
|
||||
TrafficPolicyType string `xml:"TrafficPolicyType"`
|
||||
TrafficPolicyVersion string `xml:"TrafficPolicyVersion"`
|
||||
}
|
||||
|
||||
func (self *SAwsClient) GetDnsTrafficPolicyInstance(id string) (*SDnsTrafficPolicyInstance, error) {
|
||||
params := map[string]string{"Id": fmt.Sprintf("trafficpolicyinstance/%s", id)}
|
||||
ret := &struct {
|
||||
TrafficPolicyInstance SDnsTrafficPolicyInstance `xml:"TrafficPolicyInstance"`
|
||||
}{}
|
||||
err := self.dnsRequest("GetTrafficPolicyInstance", params, ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ret.TrafficPolicyInstance, nil
|
||||
}
|
||||
|
||||
type SDnsTrafficPolicy struct {
|
||||
Comment string `xml:"Comment"`
|
||||
Document string `xml:"Document"`
|
||||
Name string `xml:"Name"`
|
||||
Type string `xml:"Type"`
|
||||
}
|
||||
|
||||
func (self *SAwsClient) GetTrafficPolicy(id string, version string) (*SDnsTrafficPolicy, error) {
|
||||
params := map[string]string{"Id": fmt.Sprintf("trafficpolicy/%s/%s", id, version)}
|
||||
ret := &struct {
|
||||
TrafficPolicy SDnsTrafficPolicy `xml:"TrafficPolicy"`
|
||||
}{}
|
||||
err := self.dnsRequest("GetTrafficPolicy", params, ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ret.TrafficPolicy, nil
|
||||
}
|
||||
+37
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
)
|
||||
@@ -139,6 +140,9 @@ func (self *SDnsRecord) GetDnsValue() string {
|
||||
}
|
||||
records = append(records, value)
|
||||
}
|
||||
if len(self.AliasTarget.DNSName) > 0 {
|
||||
records = append(records, self.AliasTarget.DNSName)
|
||||
}
|
||||
return strings.Join(records, "\n")
|
||||
}
|
||||
|
||||
@@ -146,6 +150,39 @@ func (self *SDnsRecord) GetTTL() int64 {
|
||||
return self.TTL
|
||||
}
|
||||
|
||||
func (self *SAwsClient) GetDnsExtraAddresses(instanceId string) ([]string, error) {
|
||||
ret := []string{}
|
||||
if len(instanceId) > 0 {
|
||||
instance, err := self.GetDnsTrafficPolicyInstance(instanceId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDnsTrafficPolicyInstance")
|
||||
}
|
||||
policy, err := self.GetTrafficPolicy(instance.TrafficPolicyId, instance.TrafficPolicyVersion)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
obj, err := jsonutils.ParseString(policy.Document)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "ParseString")
|
||||
}
|
||||
endpoints, err := obj.GetMap("Endpoints")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Get Endpoints")
|
||||
}
|
||||
for _, endpoint := range endpoints {
|
||||
v, _ := endpoint.GetString("Value")
|
||||
if !utils.IsInStringArray(v, ret) && len(v) > 0 {
|
||||
ret = append(ret, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SDnsRecord) GetExtraAddresses() ([]string, error) {
|
||||
return self.zone.client.GetDnsExtraAddresses(self.TrafficPolicyInstanceId)
|
||||
}
|
||||
|
||||
func (self *SDnsRecord) GetMxPriority() int64 {
|
||||
if self.GetDnsType() != cloudprovider.DnsTypeMX {
|
||||
return 0
|
||||
|
||||
+52
-4
@@ -219,6 +219,53 @@ func (self *SHuaweiClient) getAkClient() *akClient {
|
||||
}
|
||||
}
|
||||
|
||||
type sHuaweiError struct {
|
||||
RequestId string `json:"request_id"`
|
||||
ErrorMsg string `json:"error_msg"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
Code string
|
||||
Message string
|
||||
ErrorInfo struct {
|
||||
Message string
|
||||
Code string
|
||||
Title string
|
||||
} `json:"error"`
|
||||
Errorcode []string `json:"errorcode"`
|
||||
ConvertMsg string
|
||||
RawMsg jsonutils.JSONObject
|
||||
}
|
||||
|
||||
func (self *sHuaweiError) Error() string {
|
||||
return jsonutils.Marshal(self).String()
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-iam/iam_02_0006.html
|
||||
var convertMsg = map[string]string{
|
||||
"1101": "用户名校验失败,请检查用户名",
|
||||
"1103": "密码校验失败,请检查密码",
|
||||
"1104": "手机号校验失败,请检查手机号",
|
||||
"1108": "新密码不能与原密码相同,请修改新密码",
|
||||
"1109": "用户名已存在,请修改用户名",
|
||||
"1118": "密码是弱密码,重新选择密码",
|
||||
}
|
||||
|
||||
func (self *sHuaweiError) ParseErrorFromJsonResponse(statusCode int, status string, body jsonutils.JSONObject) error {
|
||||
if body != nil {
|
||||
body.Unmarshal(self)
|
||||
// 特殊错误将返回原始错误信息
|
||||
if self.Error() == jsonutils.Marshal(sHuaweiError{}).String() {
|
||||
self.RawMsg = body
|
||||
}
|
||||
}
|
||||
for _, code := range self.Errorcode {
|
||||
self.ConvertMsg = convertMsg[code]
|
||||
}
|
||||
if statusCode == 404 {
|
||||
return errors.Wrapf(cloudprovider.ErrNotFound, self.Error())
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) request(method httputils.THttpMethod, regionId, url string, query url.Values, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
client := self.getAkClient()
|
||||
if len(query) > 0 {
|
||||
@@ -244,11 +291,12 @@ func (self *SHuaweiClient) request(method httputils.THttpMethod, regionId, url s
|
||||
strings.Contains(url, "eps.myhuaweicloud.com")) && len(self.ownerId) > 0 {
|
||||
header.Set("X-Domain-Id", self.ownerId)
|
||||
}
|
||||
_, resp, err := httputils.JSONRequest(client, context.Background(), method, url, header, body, self.debug)
|
||||
req := httputils.NewJsonRequest(method, url, body)
|
||||
req.SetHeader(header)
|
||||
hwErr := &sHuaweiError{}
|
||||
cli := httputils.NewJsonClient(client)
|
||||
_, resp, err := cli.Send(context.Background(), req, hwErr, self.debug)
|
||||
if err != nil {
|
||||
if e, ok := err.(*httputils.JSONClientError); ok && e.Code == 404 {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, err.Error())
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if gotypes.IsNil(resp) {
|
||||
|
||||
+8
@@ -15,9 +15,11 @@
|
||||
package objectstore
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -126,6 +128,12 @@ func NewObjectStoreClientAndFetch(cfg *ObjectStoreClientConfig, doFetch bool) (*
|
||||
|
||||
tr := httputils.GetTransport(true)
|
||||
tr.Proxy = cfg.cpcfg.ProxyFunc
|
||||
tr.DialContext = (&net.Dialer{
|
||||
Timeout: 60 * time.Second,
|
||||
KeepAlive: 60 * time.Second,
|
||||
DualStack: true,
|
||||
}).DialContext
|
||||
tr.IdleConnTimeout = 90 * time.Second
|
||||
cli.SetCustomTransport(tr)
|
||||
|
||||
client.client = cli
|
||||
|
||||
+4
@@ -258,6 +258,10 @@ func (self *SDnsRecord) Delete() error {
|
||||
return self.domain.client.DeleteDnsRecord(self.GetGlobalId(), self.domain.Name)
|
||||
}
|
||||
|
||||
func (self *SDnsRecord) GetExtraAddresses() ([]string, error) {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
func (self *SDnsRecord) GetPolicyValue() cloudprovider.TDnsPolicyValue {
|
||||
switch self.Line {
|
||||
case "境内":
|
||||
|
||||
+6
-1
@@ -152,7 +152,7 @@ func normalizeOsDistribution(osDist string, imageName string) string {
|
||||
return OS_DIST_KYLIN
|
||||
} else if strings.Contains(osDist, "uos") {
|
||||
return OS_DIST_UOS
|
||||
} else if strings.Contains(osDist, "windows") {
|
||||
} else if strings.Contains(osDist, "windows") || regexp.MustCompile(".+win(xp|7|8|10|11|2003|2008|2012|2016|2019|2022)*").MatchString(osDist) {
|
||||
for _, ver := range []string{"2003", "2008", "2012", "2016", "2019", "2022"} {
|
||||
if strings.Contains(osDist, ver) {
|
||||
return OS_DIST_WINDOWS_SERVER
|
||||
@@ -218,6 +218,11 @@ func normalizeOsVersion(imageName string, osDist string, osVersion string) strin
|
||||
}
|
||||
}
|
||||
}
|
||||
for i := len(versions) - 1; i > 0; i-- {
|
||||
if strings.Contains(imageName, versions[i]) {
|
||||
return versions[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
+3
-2
@@ -50,7 +50,8 @@ type sQueryJoin struct {
|
||||
}
|
||||
|
||||
// SQuery is a data structure represents a SQL query in the form of
|
||||
// SELECT ... FROM ... JOIN ... ON ... WHERE ... GROUP BY ... ORDER BY ... HAVING ...
|
||||
//
|
||||
// SELECT ... FROM ... JOIN ... ON ... WHERE ... GROUP BY ... ORDER BY ... HAVING ...
|
||||
type SQuery struct {
|
||||
rawSql string
|
||||
fields []IQueryField
|
||||
@@ -342,7 +343,7 @@ func (tq *SQuery) Distinct() *SQuery {
|
||||
// SubQuery of SQuery generates a SSubQuery from a Query
|
||||
func (tq *SQuery) SubQuery() *SSubQuery {
|
||||
sq := SSubQuery{
|
||||
query: tq,
|
||||
query: tq.Copy(),
|
||||
alias: getTableAliasName(),
|
||||
referedFields: make(map[string]IQueryField),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user