mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
名称同步等问题修复
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/util/ansible"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -75,6 +76,20 @@ func (self *SAwsGuestDriver) ValidateCreateData(ctx context.Context, userCred mc
|
||||
return self.SManagedVirtualizedGuestDriver.ValidateCreateData(ctx, userCred, data)
|
||||
}
|
||||
|
||||
func (self *SAwsGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
|
||||
// https://docs.amazonaws.cn/AWSEC2/latest/UserGuide/stop-start.html
|
||||
if !utils.IsInStringArray(guest.Status, []string{models.VM_RUNNING, models.VM_READY}) {
|
||||
return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status)
|
||||
}
|
||||
if disk.DiskType == models.DISK_TYPE_SYS {
|
||||
return fmt.Errorf("Cannot resize system disk")
|
||||
}
|
||||
if !utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_GP2_SSD, models.STORAGE_IO1_SSD, models.STORAGE_ST1_HDD, models.STORAGE_SC1_SSD, models.STORAGE_STANDARD_SSD}) {
|
||||
return fmt.Errorf("Cannot resize %s disk", storage.StorageType)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SAwsGuestDriver) RequestDeployGuestOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error {
|
||||
config := guest.GetDeployConfigOnHost(ctx, host, task.GetParams())
|
||||
log.Debugf("RequestDeployGuestOnHost: %s", config)
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
)
|
||||
|
||||
type SCapabilities struct {
|
||||
Hypervisors []string `json:",allowempty"`
|
||||
StorageTypes []string `json:",allowempty"`
|
||||
GPUModels []string `json:",allowempty"`
|
||||
Hypervisors []string `json:",allowempty"`
|
||||
StorageTypes []string `json:",allowempty"`
|
||||
GPUModels []string `json:",allowempty"`
|
||||
MinNicCount int
|
||||
MaxNicCount int
|
||||
MinDataDiskCount int
|
||||
|
||||
+23
-2
@@ -30,6 +30,7 @@ type SEipAddress struct {
|
||||
NetworkInterfaceOwnerId string
|
||||
PrivateIpAddress string
|
||||
IpAddress string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (self *SEipAddress) GetId() string {
|
||||
@@ -37,7 +38,11 @@ func (self *SEipAddress) GetId() string {
|
||||
}
|
||||
|
||||
func (self *SEipAddress) GetName() string {
|
||||
return self.IpAddress
|
||||
if len(self.Name) == 0 {
|
||||
return self.IpAddress
|
||||
}
|
||||
|
||||
return self.Name
|
||||
}
|
||||
|
||||
func (self *SEipAddress) GetGlobalId() string {
|
||||
@@ -177,6 +182,7 @@ func (self *SRegion) GetEips(eipId string, offset int, limit int) ([]SEipAddress
|
||||
NetworkInterfaceOwnerId: *ip.NetworkInterfaceOwnerId,
|
||||
PrivateIpAddress: *ip.PrivateIpAddress,
|
||||
IpAddress: *ip.PublicIp,
|
||||
Name: tagspec.GetNameTag(),
|
||||
})
|
||||
}
|
||||
return eips, len(eips), nil
|
||||
@@ -212,7 +218,22 @@ func (self *SRegion) AllocateEIP(domainType string) (*SEipAddress, error) {
|
||||
func (self *SRegion) CreateEIP(name string, bwMbps int, chargeType string) (cloudprovider.ICloudEIP, error) {
|
||||
// todo: aws 不支持指定bwMbps, chargeType ?
|
||||
log.Debugf("CreateEip: aws not support specific params name/bwMbps/chargeType.")
|
||||
return self.AllocateEIP("vpc")
|
||||
ieip, err := self.AllocateEIP("vpc")
|
||||
if err == nil && len(name) > 0 {
|
||||
eipId := ieip.GetId()
|
||||
k := "Name"
|
||||
nameTag := &ec2.Tag{Key: &k, Value: &name}
|
||||
params := &ec2.CreateTagsInput{}
|
||||
params.SetResources([]*string{&eipId})
|
||||
params.SetTags([]*ec2.Tag{nameTag})
|
||||
|
||||
// name 创建成功与否不影响eip的正常使用
|
||||
if _, e := self.ec2Client.CreateTags(params); e != nil {
|
||||
log.Infof("CreateEIP create name tag failed: %s", e)
|
||||
}
|
||||
}
|
||||
|
||||
return ieip, err
|
||||
}
|
||||
|
||||
func (self *SRegion) DeallocateEIP(eipId string) error {
|
||||
|
||||
@@ -689,9 +689,23 @@ func (self *SRegion) DeleteVM(instanceId string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 检查删除保护状态.如果已开启则先关闭删除保护再进行删除操作
|
||||
protect, err := self.deleteProtectStatusVM(instanceId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if protect {
|
||||
log.Warningf("DeleteVM instance %s which termination protect is in open status", instanceId)
|
||||
err = self.deleteProtectVM(instanceId, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
params := &ec2.TerminateInstancesInput{}
|
||||
params.SetInstanceIds([]*string{&instanceId})
|
||||
_, err := self.ec2Client.TerminateInstances(params)
|
||||
_, err = self.ec2Client.TerminateInstances(params)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -855,6 +869,27 @@ func (self *SRegion) AttachDisk(instanceId string, diskId string, deviceName str
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SRegion) deleteProtectStatusVM(instanceId string) (bool, error) {
|
||||
p := &ec2.DescribeInstanceAttributeInput{}
|
||||
p.SetInstanceId(instanceId)
|
||||
p.SetAttribute("disableApiTermination")
|
||||
ret, err := self.ec2Client.DescribeInstanceAttribute(p)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return *ret.DisableApiTermination.Value, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) deleteProtectVM(instanceId string, disableDelete bool) error {
|
||||
p2 := &ec2.ModifyInstanceAttributeInput{
|
||||
DisableApiTermination: &ec2.AttributeBooleanValue{Value: &disableDelete},
|
||||
InstanceId: &instanceId,
|
||||
}
|
||||
_, err := self.ec2Client.ModifyInstanceAttribute(p2)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SInstance) CreateDisk(ctx context.Context, sizeMb int, uuid string, driver string) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
@@ -218,6 +218,9 @@ func (self *SRegion) createSecurityGroup(vpcId string, name string, secgroupIdTa
|
||||
}
|
||||
|
||||
tagspec := TagSpec{ResourceType: "security-group"}
|
||||
if len(secgroupIdTag) > 0 {
|
||||
tagspec.SetTag("id", secgroupIdTag)
|
||||
}
|
||||
tagspec.SetNameTag(name)
|
||||
tagspec.SetDescTag(desc)
|
||||
tags, _ := tagspec.GetTagSpecifications()
|
||||
@@ -288,7 +291,11 @@ func (self *SRegion) GetSecurityGroupDetails(secGroupId string) (*SSecurityGroup
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SRegion) getSecurityGroupByTag(vpcId, secgroupId string) (*SSecurityGroup, error) {
|
||||
func (self *SRegion) getSecurityGroupById(vpcId, secgroupId string) (*SSecurityGroup, error) {
|
||||
if len(secgroupId) == 0 {
|
||||
return nil, httperrors.NewInputParameterError("security group id should not be empty")
|
||||
}
|
||||
|
||||
secgroups, total, err := self.GetSecurityGroups(vpcId, secgroupId, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -408,15 +415,15 @@ func (self *SRegion) getSecRules(ingress []*ec2.IpPermission, egress []*ec2.IpPe
|
||||
return rules
|
||||
}
|
||||
|
||||
func (self *SRegion) GetSecurityGroups(vpcId string, secgroupIdTag string, offset int, limit int) ([]SSecurityGroup, int, error) {
|
||||
func (self *SRegion) GetSecurityGroups(vpcId string, secgroupId string, offset int, limit int) ([]SSecurityGroup, int, error) {
|
||||
params := &ec2.DescribeSecurityGroupsInput{}
|
||||
filters := make([]*ec2.Filter, 0)
|
||||
if len(vpcId) > 0 {
|
||||
filters = AppendSingleValueFilter(filters, "vpc-id", vpcId)
|
||||
}
|
||||
|
||||
if len(secgroupIdTag) > 0 {
|
||||
filters = AppendSingleValueFilter(filters, "tag:id", secgroupIdTag)
|
||||
if len(secgroupId) > 0 {
|
||||
params.SetGroupIds([]*string{&secgroupId})
|
||||
}
|
||||
|
||||
if len(filters) > 0 {
|
||||
|
||||
@@ -41,6 +41,10 @@ func (self *SSnapshot) GetId() string {
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetName() string {
|
||||
if len(self.SnapshotName) == 0 {
|
||||
return self.SnapshotId
|
||||
}
|
||||
|
||||
return self.SnapshotName
|
||||
}
|
||||
|
||||
@@ -108,10 +112,10 @@ func (self *SRegion) GetSnapshots(instanceId string, diskId string, snapshotName
|
||||
filters = AppendSingleValueFilter(filters, "volume-id", diskId)
|
||||
}
|
||||
|
||||
// not supported. use Tag?
|
||||
// if len(snapshotName) > 0 {
|
||||
// filters = AppendSingleValueFilter(filters, "volume-id", diskId)
|
||||
// }
|
||||
if len(snapshotName) > 0 {
|
||||
filters = AppendSingleValueFilter(filters, "tag:Name", snapshotName)
|
||||
}
|
||||
|
||||
if len(filters) > 0 {
|
||||
params.SetFilters(filters)
|
||||
}
|
||||
@@ -135,6 +139,9 @@ func (self *SRegion) GetSnapshots(instanceId string, diskId string, snapshotName
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
tagspec := TagSpec{ResourceType: "snapshot"}
|
||||
tagspec.LoadingEc2Tags(item.Tags)
|
||||
|
||||
snapshot := SSnapshot{}
|
||||
snapshot.SnapshotId = *item.SnapshotId
|
||||
snapshot.Status = SnapshotStatusType(*item.State)
|
||||
@@ -144,6 +151,7 @@ func (self *SRegion) GetSnapshots(instanceId string, diskId string, snapshotName
|
||||
snapshot.SourceDiskId = *item.VolumeId
|
||||
snapshot.SourceDiskSize = int32(*item.VolumeSize)
|
||||
// snapshot.SourceDiskType
|
||||
snapshot.SnapshotName = tagspec.GetNameTag()
|
||||
snapshots = append(snapshots, snapshot)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ func (self *SRegion) SyncSecurityGroup(secgroupId string, vpcId string, name str
|
||||
secgroupId = fmt.Sprintf("%s-%s", vpcId, secgroupId)
|
||||
}
|
||||
|
||||
if secgroup, err := self.getSecurityGroupByTag(vpcId, secgroupId); err != nil {
|
||||
if secgroup, err := self.getSecurityGroupById(vpcId, secgroupId); err != nil {
|
||||
if len(desc) == 0 {
|
||||
desc = fmt.Sprintf("security group %s for vpc %s", name, vpcId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user