mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Automatic merge from release/2.3.0 -> release/2.4.0
* commit '7d4309fb6906fab70a1a43c8e9bbe9dc79efab0a': 补充同步腾讯云安全组规则 修正赋值顺序 添加disk hypervisor 关联安全组 私网IP同步及storage名称统一小写
This commit is contained in:
@@ -270,7 +270,7 @@ func (self *SInstance) GetMachine() string {
|
||||
}
|
||||
|
||||
func (self *SInstance) AssignSecurityGroup(secgroupId string) error {
|
||||
return self.host.zone.region.assignSecurityGroup(self.InstanceId, secgroupId)
|
||||
return self.host.zone.region.assignSecurityGroup(secgroupId, self.InstanceId)
|
||||
}
|
||||
|
||||
func (self *SInstance) GetHypervisor() string {
|
||||
|
||||
@@ -66,16 +66,14 @@ func (v SDiskSet) Less(i, j int) bool {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetMetadata() *jsonutils.JSONDict {
|
||||
// data := jsonutils.NewDict()
|
||||
data := jsonutils.NewDict()
|
||||
|
||||
// // The pricingInfo key structure is 'RegionId::DiskCategory::DiskType
|
||||
// priceKey := fmt.Sprintf("%s::%s::%s", self.RegionId, self.Category, self.Type)
|
||||
// data.Add(jsonutils.NewString(priceKey), "price_key")
|
||||
|
||||
// data.Add(jsonutils.NewString(models.HYPERVISOR_ALIYUN), "hypervisor")
|
||||
|
||||
// return data
|
||||
return nil
|
||||
data.Add(jsonutils.NewString(models.HYPERVISOR_QCLOUD), "hypervisor")
|
||||
return data
|
||||
}
|
||||
|
||||
func (self *SRegion) GetDisks(instanceId string, zoneId string, category string, diskIds []string, offset int, limit int) ([]SDisk, int, error) {
|
||||
|
||||
@@ -142,6 +142,12 @@ func (self *SInstance) GetMetadata() *jsonutils.JSONDict {
|
||||
data.Add(jsonutils.NewString(self.image.OsName), "os_distribution")
|
||||
}
|
||||
|
||||
secgroupIds := jsonutils.NewArray()
|
||||
for _, secgroupId := range self.SecurityGroupIds {
|
||||
data.Add(jsonutils.NewString(secgroupId), "secgroupId")
|
||||
secgroupIds.Add(jsonutils.NewString(secgroupId))
|
||||
}
|
||||
data.Add(secgroupIds, "secgroupIds")
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -226,6 +232,10 @@ func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) {
|
||||
nic := SInstanceNic{instance: self, ipAddr: ip}
|
||||
nics = append(nics, &nic)
|
||||
}
|
||||
for _, ip := range self.PrivateIpAddresses {
|
||||
nic := SInstanceNic{instance: self, ipAddr: ip}
|
||||
nics = append(nics, &nic)
|
||||
}
|
||||
return nics, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,9 @@ type SLocalDisk struct {
|
||||
}
|
||||
|
||||
func (self *SLocalDisk) GetMetadata() *jsonutils.JSONDict {
|
||||
return nil
|
||||
data := jsonutils.NewDict()
|
||||
data.Add(jsonutils.NewString(models.HYPERVISOR_QCLOUD), "hypervisor")
|
||||
return data
|
||||
}
|
||||
|
||||
func (self *SLocalDisk) CreateISnapshot(ctx context.Context, name, desc string) (cloudprovider.ICloudSnapshot, error) {
|
||||
|
||||
@@ -319,8 +319,70 @@ func (self *SRegion) SyncSecurityGroup(secgroupId string, vpcId string, name str
|
||||
return self.syncSecgroupRules(secgroupId, rules)
|
||||
}
|
||||
|
||||
func (self *SRegion) deleteAllRules(secgroupid string) error {
|
||||
params := map[string]string{"SecurityGroupId": secgroupid, "SecurityGroupPolicySet.Version": "0"}
|
||||
_, err := self.vpcRequest("ModifySecurityGroupPolicies", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SRegion) syncSecgroupRules(secgroupid string, rules []secrules.SecurityRule) (string, error) {
|
||||
return "", cloudprovider.ErrNotImplemented
|
||||
if err := self.deleteAllRules(secgroupid); err != nil {
|
||||
return "", err
|
||||
}
|
||||
egressIndex, ingressIndex := -1, -1
|
||||
for _, rule := range rules {
|
||||
params := map[string]string{}
|
||||
params["SecurityGroupId"] = secgroupid
|
||||
policyIndex := 0
|
||||
direction := "Egress"
|
||||
action := "accept"
|
||||
if rule.Action == secrules.SecurityRuleDeny {
|
||||
action = "drop"
|
||||
}
|
||||
protocol := "ALL"
|
||||
if rule.Protocol != secrules.PROTO_ANY {
|
||||
protocol = rule.Protocol
|
||||
}
|
||||
if rule.Direction == secrules.DIR_IN {
|
||||
ingressIndex++
|
||||
policyIndex = ingressIndex
|
||||
direction = "Ingress"
|
||||
} else {
|
||||
egressIndex++
|
||||
policyIndex = egressIndex
|
||||
}
|
||||
params[fmt.Sprintf("SecurityGroupPolicySet.%s.0.PolicyIndex", direction)] = fmt.Sprintf("%d", policyIndex)
|
||||
params[fmt.Sprintf("SecurityGroupPolicySet.%s.0.Action", direction)] = action
|
||||
params[fmt.Sprintf("SecurityGroupPolicySet.%s.0.PolicyDescription", direction)] = rule.Description
|
||||
params[fmt.Sprintf("SecurityGroupPolicySet.%s.0.Protocol", direction)] = protocol
|
||||
params[fmt.Sprintf("SecurityGroupPolicySet.%s.0.CidrBlock", direction)] = rule.IPNet.String()
|
||||
if rule.Protocol == secrules.PROTO_TCP || rule.Protocol == secrules.PROTO_UDP {
|
||||
port := "ALL"
|
||||
if rule.PortEnd > 0 && rule.PortStart > 0 {
|
||||
if rule.PortStart == rule.PortEnd {
|
||||
port = fmt.Sprintf("%d", rule.PortStart)
|
||||
} else {
|
||||
port = fmt.Sprintf("%d-%d", rule.PortStart, rule.PortEnd)
|
||||
}
|
||||
} else if len(rule.Ports) > 0 {
|
||||
ports := []string{}
|
||||
for _, _port := range rule.Ports {
|
||||
ports = append(ports, fmt.Sprintf("%d", _port))
|
||||
}
|
||||
port = strings.Join(ports, ",")
|
||||
}
|
||||
params[fmt.Sprintf("SecurityGroupPolicySet.%s.0.Port", direction)] = port
|
||||
}
|
||||
//为什么不一次创建完成?
|
||||
//答: 因为如果只有入方向安全组规则,创建时会提示缺少出方向规则。
|
||||
//为什么不分两次,一次创建入方向规则,一次创建出方向规则?
|
||||
//答: 因为这样就不能设置优先级了,一次性创建的出或入方向的优先级必须一样。
|
||||
_, err := self.vpcRequest("CreateSecurityGroupPolicies", params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return secgroupid, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetSecurityGroupDetails(secGroupId string) (*SSecurityGroup, error) {
|
||||
|
||||
@@ -21,15 +21,15 @@ func (self *SStorage) GetMetadata() *jsonutils.JSONDict {
|
||||
}
|
||||
|
||||
func (self *SStorage) GetId() string {
|
||||
return fmt.Sprintf("%s-%s-%s", self.zone.region.client.providerId, self.zone.GetId(), self.storageType)
|
||||
return fmt.Sprintf("%s-%s-%s", self.zone.region.client.providerId, self.zone.GetId(), strings.ToLower(self.storageType))
|
||||
}
|
||||
|
||||
func (self *SStorage) GetName() string {
|
||||
return fmt.Sprintf("%s-%s-%s", self.zone.region.client.providerName, self.zone.GetId(), self.storageType)
|
||||
return fmt.Sprintf("%s-%s-%s", self.zone.region.client.providerName, self.zone.GetId(), strings.ToLower(self.storageType))
|
||||
}
|
||||
|
||||
func (self *SStorage) GetGlobalId() string {
|
||||
return fmt.Sprintf("%s-%s-%s", self.zone.region.client.providerId, self.zone.GetGlobalId(), self.storageType)
|
||||
return fmt.Sprintf("%s-%s-%s", self.zone.region.client.providerId, self.zone.GetGlobalId(), strings.ToLower(self.storageType))
|
||||
}
|
||||
|
||||
func (self *SStorage) IsEmulated() bool {
|
||||
|
||||
Reference in New Issue
Block a user