mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
Merge pull request #2332 from tb365/bugfix/tb-bugfix-0812
aws & huawei & ucloud fix
This commit is contained in:
@@ -33,6 +33,7 @@ const (
|
||||
NETWORK_STATUS_INIT = "init"
|
||||
NETWORK_STATUS_PENDING = "pending"
|
||||
NETWORK_STATUS_AVAILABLE = "available"
|
||||
NETWORK_STATUS_UNAVAILABLE = "unavailable"
|
||||
NETWORK_STATUS_FAILED = "failed"
|
||||
NETWORK_STATUS_UNKNOWN = "unknown"
|
||||
NETWORK_STATUS_START_DELETE = "start_delete"
|
||||
|
||||
@@ -534,7 +534,7 @@ func (lbbg *SLoadbalancerBackendGroup) GetAwsCachedlbbg() ([]SAwsCachedLbbg, err
|
||||
func (lbbg *SLoadbalancerBackendGroup) GetHuaweiCachedlbbg() ([]SHuaweiCachedLbbg, error) {
|
||||
ret := []SHuaweiCachedLbbg{}
|
||||
q := HuaweiCachedLbbgManager.Query().Equals("backend_group_id", lbbg.GetId())
|
||||
err := db.FetchModelObjects(AwsCachedLbbgManager, q, &ret)
|
||||
err := db.FetchModelObjects(HuaweiCachedLbbgManager, q, &ret)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "loadbalancerBackendGroup.GetHuaweiCachedlbbg")
|
||||
}
|
||||
|
||||
@@ -218,6 +218,12 @@ func (self *SInstance) GetMetadata() *jsonutils.JSONDict {
|
||||
|
||||
data.Add(jsonutils.NewString(self.host.zone.GetGlobalId()), "zone_ext_id")
|
||||
|
||||
if strings.Contains(strings.ToLower(self.OSType), "window") {
|
||||
if loginKey, err := self.host.zone.region.getPasswordData(self.GetId()); err == nil {
|
||||
data.Add(jsonutils.NewString(loginKey), "login_key")
|
||||
}
|
||||
}
|
||||
|
||||
// no need to sync image metadata
|
||||
/*
|
||||
if len(self.ImageId) > 0 {
|
||||
@@ -419,11 +425,16 @@ func (self *SInstance) RebuildRoot(ctx context.Context, imageId string, passwd s
|
||||
}
|
||||
}
|
||||
|
||||
keypairName := self.KeyPairName
|
||||
loginUser := cloudinit.NewUser(api.VM_AWS_DEFAULT_LOGIN_USER)
|
||||
loginUser.SudoPolicy(cloudinit.USER_SUDO_NOPASSWD)
|
||||
if len(publicKey) > 0 {
|
||||
loginUser.SshKey(publicKey)
|
||||
cloudconfig.MergeUser(loginUser)
|
||||
keypairName, err = self.host.zone.region.syncKeypair(publicKey)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("RebuildRoot.syncKeypair %s", err)
|
||||
}
|
||||
} else if len(passwd) > 0 {
|
||||
loginUser.Password(passwd)
|
||||
cloudconfig.MergeUser(loginUser)
|
||||
@@ -440,7 +451,7 @@ func (self *SInstance) RebuildRoot(ctx context.Context, imageId string, passwd s
|
||||
}
|
||||
}
|
||||
|
||||
diskId, err := self.host.zone.region.ReplaceSystemDisk(ctx, self.InstanceId, imageId, sysSizeGB, cloudconfig.UserDataBase64())
|
||||
diskId, err := self.host.zone.region.ReplaceSystemDisk(ctx, self.InstanceId, imageId, sysSizeGB, keypairName, cloudconfig.UserDataBase64())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -674,9 +685,10 @@ func (self *SRegion) CreateInstance(name string, imageId string, instanceType st
|
||||
var count int64 = 1
|
||||
// disk
|
||||
blockDevices := []*ec2.BlockDeviceMapping{}
|
||||
for i, disk := range disks {
|
||||
for i := range disks {
|
||||
var ebs ec2.EbsBlockDevice
|
||||
var deviceName string
|
||||
disk := disks[i]
|
||||
|
||||
if i == 0 {
|
||||
var size int64
|
||||
@@ -897,7 +909,7 @@ func (self *SRegion) UpdateVM(instanceId string, hostname string) error {
|
||||
return fmt.Errorf("aws not support change hostname.")
|
||||
}
|
||||
|
||||
func (self *SRegion) ReplaceSystemDisk(ctx context.Context, instanceId string, imageId string, sysDiskSizeGB int, userdata string) (string, error) {
|
||||
func (self *SRegion) ReplaceSystemDisk(ctx context.Context, instanceId string, imageId string, sysDiskSizeGB int, keypair string, userdata string) (string, error) {
|
||||
instance, err := self.GetInstance(instanceId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -931,7 +943,7 @@ func (self *SRegion) ReplaceSystemDisk(ctx context.Context, instanceId string, i
|
||||
instance.Description,
|
||||
[]SDisk{{Size: sysDiskSizeGB, Category: rootDisk.Category}},
|
||||
"",
|
||||
"",
|
||||
keypair,
|
||||
userdata)
|
||||
if err == nil {
|
||||
defer self.DeleteVM(_id)
|
||||
@@ -1078,6 +1090,18 @@ func (self *SRegion) deleteProtectVM(instanceId string, disableDelete bool) erro
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SRegion) getPasswordData(instanceId string) (string, error) {
|
||||
params := &ec2.GetPasswordDataInput{}
|
||||
params.SetInstanceId(instanceId)
|
||||
|
||||
ret, err := self.ec2Client.GetPasswordData(params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return *ret.PasswordData, nil
|
||||
}
|
||||
|
||||
func (self *SInstance) CreateDisk(ctx context.Context, sizeMb int, uuid string, driver string) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
@@ -62,6 +62,10 @@ func (self *SNetwork) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (self *SNetwork) GetStatus() string {
|
||||
if self.wire != nil && self.wire.vpc != nil && self.wire.vpc.InstanceTenancy == "dedicated" {
|
||||
return api.NETWORK_STATUS_UNAVAILABLE
|
||||
}
|
||||
|
||||
return strings.ToLower(self.Status)
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ func init() {
|
||||
|
||||
shellutils.R(&InstanceRebuildRootOptions{}, "instance-rebuild-root", "Reinstall virtual server system image", func(cli *aws.SRegion, args *InstanceRebuildRootOptions) error {
|
||||
ctx := context.Background()
|
||||
diskID, err := cli.ReplaceSystemDisk(ctx, args.ID, args.Image, args.Size, "")
|
||||
diskID, err := cli.ReplaceSystemDisk(ctx, args.ID, args.Image, args.Size, "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+25
-16
@@ -41,14 +41,15 @@ type SVpc struct {
|
||||
iwires []cloudprovider.ICloudWire
|
||||
secgroups []cloudprovider.ICloudSecurityGroup
|
||||
|
||||
RegionId string
|
||||
VpcId string
|
||||
VpcName string
|
||||
CidrBlock string
|
||||
IsDefault bool
|
||||
Status string
|
||||
InstanceTenancy string
|
||||
Tags map[string]string // 名称、描述等
|
||||
RegionId string
|
||||
VpcId string
|
||||
VpcName string
|
||||
CidrBlock string
|
||||
CidrBlockAssociationSet []string
|
||||
IsDefault bool
|
||||
Status string
|
||||
InstanceTenancy string
|
||||
Tags map[string]string // 名称、描述等
|
||||
}
|
||||
|
||||
func (self *SVpc) addWire(wire *SWire) {
|
||||
@@ -106,7 +107,7 @@ func (self *SVpc) GetIsDefault() bool {
|
||||
}
|
||||
|
||||
func (self *SVpc) GetCidrBlock() string {
|
||||
return self.CidrBlock
|
||||
return strings.Join(self.CidrBlockAssociationSet, ",")
|
||||
}
|
||||
|
||||
func (self *SVpc) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
@@ -323,17 +324,25 @@ func (self *SRegion) GetVpcs(vpcId []string, offset int, limit int) ([]SVpc, int
|
||||
if err := FillZero(item); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
cidrBlockAssociationSet := []string{}
|
||||
for i := range item.CidrBlockAssociationSet {
|
||||
cidr := item.CidrBlockAssociationSet[i]
|
||||
if *cidr.CidrBlockState.State == "associated" {
|
||||
cidrBlockAssociationSet = append(cidrBlockAssociationSet, *cidr.CidrBlock)
|
||||
}
|
||||
}
|
||||
|
||||
vpcs = append(vpcs, SVpc{
|
||||
region: self,
|
||||
// secgroups: nil,
|
||||
RegionId: self.RegionId,
|
||||
VpcId: *item.VpcId,
|
||||
VpcName: *item.VpcId,
|
||||
CidrBlock: *item.CidrBlock,
|
||||
IsDefault: *item.IsDefault,
|
||||
Status: *item.State,
|
||||
InstanceTenancy: *item.InstanceTenancy,
|
||||
RegionId: self.RegionId,
|
||||
VpcId: *item.VpcId,
|
||||
VpcName: *item.VpcId,
|
||||
CidrBlock: *item.CidrBlock,
|
||||
CidrBlockAssociationSet: cidrBlockAssociationSet,
|
||||
IsDefault: *item.IsDefault,
|
||||
Status: *item.State,
|
||||
InstanceTenancy: *item.InstanceTenancy,
|
||||
// Tags: *item.Tags,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ func (self *SDisk) Attach(device string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return cloudprovider.WaitStatus(self, api.DISK_READY, 5*time.Second, 60*time.Second)
|
||||
return cloudprovider.WaitStatusWithDelay(self, api.DISK_READY, 10*time.Second, 5*time.Second, 60*time.Second)
|
||||
}
|
||||
|
||||
// 在线卸载磁盘 https://support.huaweicloud.com/usermanual-ecs/zh-cn_topic_0036046828.html
|
||||
|
||||
@@ -50,40 +50,42 @@ const (
|
||||
type SImage struct {
|
||||
storageCache *SStoragecache
|
||||
|
||||
Schema string `json:"schema"`
|
||||
MinDiskGB int64 `json:"min_disk"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ImageSourceType string `json:"__image_source_type"`
|
||||
ContainerFormat string `json:"container_format"`
|
||||
File string `json:"file"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Protected bool `json:"protected"`
|
||||
Checksum string `json:"checksum"`
|
||||
ID string `json:"id"`
|
||||
Isregistered string `json:"__isregistered"`
|
||||
MinRamMB int `json:"min_ram"`
|
||||
Lazyloading string `json:"__lazyloading"`
|
||||
Owner string `json:"owner"`
|
||||
OSType string `json:"__os_type"`
|
||||
Imagetype string `json:"__imagetype"`
|
||||
Visibility string `json:"visibility"`
|
||||
VirtualEnvType string `json:"virtual_env_type"`
|
||||
Platform string `json:"__platform"`
|
||||
SizeGB int `json:"size"`
|
||||
ImageSize int64 `json:"__image_size"`
|
||||
OSBit string `json:"__os_bit"`
|
||||
OSVersion string `json:"__os_version"`
|
||||
Name string `json:"name"`
|
||||
Self string `json:"self"`
|
||||
DiskFormat string `json:"disk_format"`
|
||||
Status string `json:"status"`
|
||||
SupportKVMFPGAType string `json:"__support_kvm_fpga_type"`
|
||||
SupportKVMNVMEHIGHIO string `json:"__support_nvme_highio"`
|
||||
SupportLargeMemory string `json:"__support_largememory"`
|
||||
SupportDiskIntensive string `json:"__support_diskintensive"`
|
||||
SupportXENGPUType string `json:"__support_xen_gpu_type"`
|
||||
SupportKVMGPUType string `json:"__support_kvm_gpu_type"`
|
||||
SupportArm string `json:"__support_arm"`
|
||||
Schema string `json:"schema"`
|
||||
MinDiskGB int64 `json:"min_disk"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ImageSourceType string `json:"__image_source_type"`
|
||||
ContainerFormat string `json:"container_format"`
|
||||
File string `json:"file"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Protected bool `json:"protected"`
|
||||
Checksum string `json:"checksum"`
|
||||
ID string `json:"id"`
|
||||
Isregistered string `json:"__isregistered"`
|
||||
MinRamMB int `json:"min_ram"`
|
||||
Lazyloading string `json:"__lazyloading"`
|
||||
Owner string `json:"owner"`
|
||||
OSType string `json:"__os_type"`
|
||||
Imagetype string `json:"__imagetype"`
|
||||
Visibility string `json:"visibility"`
|
||||
VirtualEnvType string `json:"virtual_env_type"`
|
||||
Platform string `json:"__platform"`
|
||||
SizeGB int `json:"size"`
|
||||
ImageSize int64 `json:"__image_size"`
|
||||
OSBit string `json:"__os_bit"`
|
||||
OSVersion string `json:"__os_version"`
|
||||
Name string `json:"name"`
|
||||
Self string `json:"self"`
|
||||
DiskFormat string `json:"disk_format"`
|
||||
Status string `json:"status"`
|
||||
SupportKVMFPGAType string `json:"__support_kvm_fpga_type"`
|
||||
SupportKVMNVMEHIGHIO string `json:"__support_nvme_highio"`
|
||||
SupportLargeMemory string `json:"__support_largememory"`
|
||||
SupportDiskIntensive string `json:"__support_diskintensive"`
|
||||
SupportHighPerformance string `json:"__support_highperformance"`
|
||||
SupportXENGPUType string `json:"__support_xen_gpu_type"`
|
||||
SupportKVMGPUType string `json:"__support_kvm_gpu_type"`
|
||||
SupportKVMAscend310 string `json:"__support_kvm_ascend_310"`
|
||||
SupportArm string `json:"__support_arm"`
|
||||
}
|
||||
|
||||
func (self *SImage) GetMinRamSizeMb() int {
|
||||
@@ -221,11 +223,15 @@ func (self *SRegion) GetImage(imageId string) (SImage, error) {
|
||||
}
|
||||
|
||||
func excludeImage(image SImage) bool {
|
||||
if image.VirtualEnvType == "Ironic" {
|
||||
return true
|
||||
}
|
||||
|
||||
if len(image.SupportDiskIntensive) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
if len(image.SupportKVMFPGAType) > 0 {
|
||||
if len(image.SupportKVMFPGAType) > 0 || len(image.SupportKVMAscend310) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -245,6 +251,10 @@ func excludeImage(image SImage) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if len(image.SupportHighPerformance) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
if len(image.SupportArm) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -577,6 +577,11 @@ func (self *SRegion) CreateEIP(eip *cloudprovider.SEip) (cloudprovider.ICloudEIP
|
||||
}
|
||||
}
|
||||
|
||||
// 华为云EIP名字最大长度64
|
||||
if len(eip.Name) > 64 {
|
||||
eip.Name = eip.Name[:64]
|
||||
}
|
||||
|
||||
ieip, err := self.AllocateEIP(eip.Name, eip.BandwidthMbps, ctype, eip.BGPType)
|
||||
ieip.region = self
|
||||
if err != nil {
|
||||
|
||||
@@ -252,7 +252,7 @@ func (self *SDisk) GetISnapshot(idStr string) (cloudprovider.ICloudSnapshot, err
|
||||
}
|
||||
|
||||
func (self *SDisk) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) {
|
||||
snapshots, err := self.storage.zone.region.GetSnapshots(self.GetId(), "")
|
||||
snapshots, err := self.storage.zone.region.GetSnapshots("", self.GetId(), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func init() {
|
||||
Name string `help:"Snapshot Name"`
|
||||
}
|
||||
shellutils.R(&SnapshotListOptions{}, "snapshot-list", "List snapshot", func(cli *ucloud.SRegion, args *SnapshotListOptions) error {
|
||||
snapshots, err := cli.GetSnapshots(args.DiskId, args.Name)
|
||||
snapshots, err := cli.GetSnapshots("", args.DiskId, args.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ func (self *SSnapshot) Delete() error {
|
||||
}
|
||||
|
||||
func (self *SRegion) GetSnapshotById(zoneId string, snapshotId string) (SSnapshot, error) {
|
||||
snapshots, err := self.GetSnapshots("", snapshotId)
|
||||
snapshots, err := self.GetSnapshots(zoneId, "", snapshotId)
|
||||
if err != nil {
|
||||
return SSnapshot{}, err
|
||||
}
|
||||
@@ -144,7 +144,7 @@ func (self *SRegion) GetSnapshotById(zoneId string, snapshotId string) (SSnapsho
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SRegion) GetSnapshots(diskId string, snapshotId string) ([]SSnapshot, error) {
|
||||
func (self *SRegion) GetSnapshots(zoneId string, diskId string, snapshotId string) ([]SSnapshot, error) {
|
||||
params := NewUcloudParams()
|
||||
if len(diskId) > 0 {
|
||||
disk, err := self.GetDisk(diskId)
|
||||
@@ -156,11 +156,11 @@ func (self *SRegion) GetSnapshots(diskId string, snapshotId string) ([]SSnapshot
|
||||
params.Set("Zone", disk.Zone)
|
||||
}
|
||||
|
||||
if len(snapshotId) > 0 {
|
||||
if len(diskId) == 0 {
|
||||
return nil, fmt.Errorf("GetSnapshots required parameter diskId.")
|
||||
}
|
||||
if len(zoneId) > 0 {
|
||||
params.Set("Zone", zoneId)
|
||||
}
|
||||
|
||||
if len(snapshotId) > 0 {
|
||||
params.Set("SnapshotId", snapshotId)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user