mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Automatic merge from release/2.3.0 -> release/2.4.0
* commit 'de281472b02ce19a23d03cf50836d130ea67abd4': 修复密钥对同步问题及绑定eip问题
This commit is contained in:
@@ -274,12 +274,12 @@ func (region *SRegion) DeallocateEIP(eipId string) error {
|
||||
|
||||
func (region *SRegion) AssociateEip(eipId string, instanceId string) error {
|
||||
params := make(map[string]string)
|
||||
params["AllocationId"] = eipId
|
||||
params["AddressId"] = eipId
|
||||
params["InstanceId"] = instanceId
|
||||
|
||||
_, err := region.vpcRequest("AssociateEipAddress", params)
|
||||
_, err := region.vpcRequest("AssociateAddress", params)
|
||||
if err != nil {
|
||||
log.Errorf("AssociateEipAddress fail %s", err)
|
||||
log.Errorf("AssociateAddress fail %s", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/aokoli/goutils"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
)
|
||||
@@ -109,14 +110,47 @@ func (self *SRegion) CreateKeyPair(name string) (*SKeypair, error) {
|
||||
return &keypair, err
|
||||
}
|
||||
|
||||
func (self *SRegion) lookUpAliyunKeypair(publicKey string) (string, error) {
|
||||
keypairs, _, err := self.GetKeypairs("", []string{}, 0, 0)
|
||||
func (self *SRegion) getKeypairs() ([]SKeypair, error) {
|
||||
keypairs := []SKeypair{}
|
||||
for {
|
||||
parts, total, err := self.GetKeypairs("", []string{}, 0, 50)
|
||||
if err != nil {
|
||||
log.Errorf("Get keypairs fail %v", err)
|
||||
return nil, err
|
||||
}
|
||||
keypairs = append(keypairs, parts...)
|
||||
if len(keypairs) >= total {
|
||||
break
|
||||
}
|
||||
}
|
||||
return keypairs, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) getFingerprint(publicKey string) (string, error) {
|
||||
pk, _, _, _, err := ssh.ParseAuthorizedKey([]byte(publicKey))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("publicKey error %s", err)
|
||||
}
|
||||
return ssh.FingerprintLegacyMD5(pk), nil
|
||||
}
|
||||
|
||||
func (self *SRegion) lookUpQcloudKeypair(publicKey string) (string, error) {
|
||||
keypairs, err := self.getKeypairs()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
localFiger, err := self.getFingerprint(publicKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for i := 0; i < len(keypairs); i++ {
|
||||
if keypairs[i].PublicKey == publicKey {
|
||||
finger, err := self.getFingerprint(keypairs[i].PublicKey)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if finger == localFiger {
|
||||
return keypairs[i].KeyId, nil
|
||||
}
|
||||
}
|
||||
@@ -124,8 +158,8 @@ func (self *SRegion) lookUpAliyunKeypair(publicKey string) (string, error) {
|
||||
}
|
||||
|
||||
func (self *SRegion) syncKeypair(publicKey string) (string, error) {
|
||||
keypairId, e := self.lookUpAliyunKeypair(publicKey)
|
||||
if e == nil {
|
||||
keypairId, err := self.lookUpQcloudKeypair(publicKey)
|
||||
if err == nil {
|
||||
return keypairId, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user