mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #9100 from yousong/bugfix/yousong-qcloud-nic
Bugfix/yousong qcloud nic
This commit is contained in:
@@ -21,6 +21,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
qcommon "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
qvpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
@@ -288,18 +291,40 @@ func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
}
|
||||
|
||||
func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) {
|
||||
nics := make([]cloudprovider.ICloudNic, 0)
|
||||
classic := false
|
||||
if len(self.VirtualPrivateCloud.VpcId) == 0 {
|
||||
classic = true
|
||||
var (
|
||||
classic = self.VirtualPrivateCloud.VpcId == ""
|
||||
region = self.host.zone.region
|
||||
|
||||
nics []cloudprovider.ICloudNic
|
||||
)
|
||||
client, err := region.client.getVpcClient(region.GetId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, ip := range self.VirtualPrivateCloud.PrivateIpAddresses {
|
||||
nic := SInstanceNic{instance: self, ipAddr: ip}
|
||||
nics = append(nics, &nic)
|
||||
req := qvpc.NewDescribeNetworkInterfacesRequest()
|
||||
req.Filters = []*qvpc.Filter{
|
||||
&qvpc.Filter{
|
||||
Values: qcommon.StringPtrs([]string{self.InstanceId}),
|
||||
Name: qcommon.StringPtr("attachment.instance-id"),
|
||||
},
|
||||
}
|
||||
for _, ip := range self.PrivateIpAddresses {
|
||||
nic := SInstanceNic{instance: self, ipAddr: ip, classic: classic}
|
||||
nics = append(nics, &nic)
|
||||
resp, err := client.DescribeNetworkInterfaces(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, networkInterface := range resp.Response.NetworkInterfaceSet {
|
||||
nic := &SInstanceNic{
|
||||
instance: self,
|
||||
id: String(networkInterface.NetworkInterfaceId),
|
||||
macAddr: strings.ToLower(String(networkInterface.MacAddress)),
|
||||
classic: classic,
|
||||
}
|
||||
for _, addr := range networkInterface.PrivateIpAddressSet {
|
||||
if Bool(addr.Primary) {
|
||||
nic.ipAddr = String(addr.PrivateIpAddress)
|
||||
}
|
||||
}
|
||||
nics = append(nics, nic)
|
||||
}
|
||||
return nics, nil
|
||||
}
|
||||
|
||||
@@ -15,21 +15,22 @@
|
||||
package qcloud
|
||||
|
||||
import (
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
type SInstanceNic struct {
|
||||
instance *SInstance
|
||||
ipAddr string
|
||||
classic bool
|
||||
|
||||
id string
|
||||
ipAddr string
|
||||
macAddr string
|
||||
classic bool
|
||||
|
||||
cloudprovider.DummyICloudNic
|
||||
}
|
||||
|
||||
func (self *SInstanceNic) GetId() string {
|
||||
return ""
|
||||
return self.id
|
||||
}
|
||||
|
||||
func (self *SInstanceNic) GetIP() string {
|
||||
@@ -37,8 +38,7 @@ func (self *SInstanceNic) GetIP() string {
|
||||
}
|
||||
|
||||
func (self *SInstanceNic) GetMAC() string {
|
||||
ip, _ := netutils.NewIPV4Addr(self.ipAddr)
|
||||
return ip.ToMac("00:16:")
|
||||
return self.macAddr
|
||||
}
|
||||
|
||||
func (self *SInstanceNic) GetDriver() string {
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
sdkerrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
|
||||
tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
qvpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
|
||||
@@ -130,9 +131,13 @@ func NewQcloudClient(cfg *QcloudClientConfig) (*SQcloudClient, error) {
|
||||
// 部分接口支持金融区地域。由于金融区和非金融区是隔离不互通的,因此当公共参数 Region 为金融区地域(例如 ap-shanghai-fsi)时,需要同时指定带金融区地域的域名,最好和 Region 的地域保持一致,例如:clb.ap-shanghai-fsi.tencentcloudapi.com
|
||||
// https://cloud.tencent.com/document/product/416/6479
|
||||
func apiDomain(product string, params map[string]string) string {
|
||||
region, ok := params["Region"]
|
||||
if ok && strings.HasSuffix(region, "-fsi") {
|
||||
return product + "." + region + ".tencentcloudapi.com"
|
||||
regionId, _ := params["Region"]
|
||||
return apiDomainByRegion(product, regionId)
|
||||
}
|
||||
|
||||
func apiDomainByRegion(product, regionId string) string {
|
||||
if strings.HasSuffix(regionId, "-fsi") {
|
||||
return product + "." + regionId + ".tencentcloudapi.com"
|
||||
} else {
|
||||
return product + ".tencentcloudapi.com"
|
||||
}
|
||||
@@ -508,7 +513,11 @@ func (client *SQcloudClient) GetRegions() []SRegion {
|
||||
}
|
||||
|
||||
func (client *SQcloudClient) getDefaultClient() (*common.Client, error) {
|
||||
cli, err := common.NewClientWithSecretId(client.secretId, client.secretKey, QCLOUD_DEFAULT_REGION)
|
||||
return client.getSdkClient(QCLOUD_DEFAULT_REGION)
|
||||
}
|
||||
|
||||
func (client *SQcloudClient) getSdkClient(regionId string) (*common.Client, error) {
|
||||
cli, err := common.NewClientWithSecretId(client.secretId, client.secretKey, regionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -517,6 +526,20 @@ func (client *SQcloudClient) getDefaultClient() (*common.Client, error) {
|
||||
return cli, nil
|
||||
}
|
||||
|
||||
func (client *SQcloudClient) getVpcClient(regionId string) (*qvpc.Client, error) {
|
||||
cli, err := client.getSdkClient(regionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vpcClient := &qvpc.Client{
|
||||
Client: *cli,
|
||||
}
|
||||
cpf := profile.NewClientProfile()
|
||||
cpf.HttpProfile.Endpoint = apiDomainByRegion("vpc", regionId)
|
||||
vpcClient.WithProfile(cpf)
|
||||
return vpcClient, nil
|
||||
}
|
||||
|
||||
func (client *SQcloudClient) vpcRequest(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
cli, err := client.getDefaultClient()
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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 qcloud
|
||||
|
||||
func String(sp *string) string {
|
||||
if sp != nil {
|
||||
return *sp
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func Bool(sb *bool) bool {
|
||||
if sb != nil {
|
||||
return *sb
|
||||
}
|
||||
return false
|
||||
}
|
||||
Generated
Vendored
-1
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
//"log"
|
||||
"net/http"
|
||||
|
||||
|
||||
Generated
Vendored
+4753
File diff suppressed because it is too large
Load Diff
Generated
Vendored
+9438
File diff suppressed because it is too large
Load Diff
Vendored
+1
@@ -586,6 +586,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312
|
||||
# github.com/tencentyun/cos-go-sdk-v5 v0.7.10
|
||||
github.com/tencentyun/cos-go-sdk-v5
|
||||
github.com/tencentyun/cos-go-sdk-v5/debug
|
||||
|
||||
Reference in New Issue
Block a user