Add network info when list scalingGroup details

This commit is contained in:
rainzm
2020-07-27 15:18:40 +08:00
parent 260d259392
commit 951f53a96b
2 changed files with 36 additions and 3 deletions
+9 -3
View File
@@ -134,9 +134,15 @@ type ScalingGroupDetails struct {
// example: OneCloud
Brand string `json:"brand"`
// description: 网络ID
// example: net-12345
Networks []string `json:"networks"`
// description: 网络信息
Networks []ScalingGroupNetwork `json:"networks"`
}
type ScalingGroupNetwork struct {
Id string `json:"id"`
Name string `json:"name"`
GuestIpStart string `json:"guest_ip_start"`
GuestIpEnd string `json:"guest_ip_end"`
}
type ScalingGroupResourceInfo struct {
+27
View File
@@ -373,6 +373,21 @@ func (sgm *SScalingGroupManager) FetchCustomizeColumns(
n, _ = sg.ScalingPolicyNumber()
rows[i].ScalingPolicyNumber = n
rows[i].Brand = Hypervisor2Brand(sg.Hypervisor)
nets, err := sg.Networks()
if err != nil {
log.Errorf("sg.Networks error: %s", err)
continue
}
sgNets := make([]api.ScalingGroupNetwork, 0, len(nets))
for i := range nets {
sgNets = append(sgNets, api.ScalingGroupNetwork{
Id: nets[i].GetId(),
Name: nets[i].GetName(),
GuestIpStart: nets[i].GuestIpStart,
GuestIpEnd: nets[i].GuestIpEnd,
})
}
rows[i].Networks = sgNets
}
return rows
}
@@ -704,6 +719,18 @@ func (s *SGuest) PerformDetachScalingGroup(ctx context.Context, userCred mcclien
return nil, nil
}
func (sg *SScalingGroup) Networks() ([]SNetwork, error) {
nets := make([]SNetwork, 0, 1)
sgnQuery := ScalingGroupNetworkManager.Query("network_id").Equals("scaling_group_id", sg.Id).SubQuery()
netQuery := NetworkManager.Query().In("id", sgnQuery)
err := db.FetchModelObjects(NetworkManager, netQuery, &nets)
if err != nil {
return nil, errors.Wrap(err, "db.FetchModelObjects")
}
return nets, nil
}
func (sg *SScalingGroup) NetworkIds() ([]string, error) {
sgnQuery := ScalingGroupNetworkManager.Query("network_id").Equals("scaling_group_id", sg.Id)
rows, err := sgnQuery.Rows()