mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #12984 from ioito/hotfix/qx-vpc-topology
fix(region): add vpc topology
This commit is contained in:
@@ -36,6 +36,7 @@ func init() {
|
||||
cmd.Perform("public", &options.BasePublicOptions{})
|
||||
cmd.Perform("change-owner", &options.VpcChangeOwnerOptions{})
|
||||
cmd.Get("vpc-change-owner-candidate-domains", &options.VpcIdOptions{})
|
||||
cmd.Get("topology", &options.VpcIdOptions{})
|
||||
|
||||
R(&options.ResourceMetadataOptions{}, "vpc-set-user-metadata", "Set metadata of a vpc", func(s *mcclient.ClientSession, opts *options.ResourceMetadataOptions) error {
|
||||
params, err := opts.Params()
|
||||
|
||||
@@ -117,3 +117,31 @@ type VpcFilterListInput struct {
|
||||
RegionalFilterListInput
|
||||
ManagedResourceListInput
|
||||
}
|
||||
|
||||
type VpcTopologyInput struct {
|
||||
}
|
||||
|
||||
type NetworkTopologyOutput struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
GuestIpStart string `json:"guest_ip_start"`
|
||||
GuestIpEnd string `json:"guest_ip_end"`
|
||||
GuestIpMask int8 `json:"guest_ip_mask"`
|
||||
ServerType string `json:"server_type"`
|
||||
VlanId int `json:"vlan_id"`
|
||||
Address []SNetworkUsedAddress `json:"address"`
|
||||
}
|
||||
|
||||
type WireTopologyOutput struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Bandwidth int `json:"bandwidth"`
|
||||
Zone string `json:"zone"`
|
||||
Networks []NetworkTopologyOutput `json:"networks"`
|
||||
}
|
||||
|
||||
type VpcTopologyOutput struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Wires []WireTopologyOutput `json:"wires"`
|
||||
}
|
||||
|
||||
@@ -1112,7 +1112,10 @@ func (wire *SWire) purge(ctx context.Context, userCred mcclient.TokenCredential)
|
||||
}
|
||||
|
||||
func (vpc *SVpc) purgeWires(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
wires := vpc.GetWires()
|
||||
wires, err := vpc.GetWires()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetWres for vpc %s", vpc.Id)
|
||||
}
|
||||
for i := range wires {
|
||||
err := wires[i].purge(ctx, userCred)
|
||||
if err != nil {
|
||||
|
||||
+66
-10
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -259,15 +260,14 @@ func (self *SVpc) GetWireCount() (int, error) {
|
||||
return q.CountWithError()
|
||||
}
|
||||
|
||||
func (self *SVpc) GetWires() []SWire {
|
||||
func (self *SVpc) GetWires() ([]SWire, error) {
|
||||
wires := make([]SWire, 0)
|
||||
q := self.getWireQuery()
|
||||
err := db.FetchModelObjects(WireManager, q, &wires)
|
||||
if err != nil {
|
||||
log.Errorf("getWires fail %s", err)
|
||||
return nil
|
||||
return nil, errors.Wrapf(err, "db.FetchModelObjects")
|
||||
}
|
||||
return wires
|
||||
return wires, nil
|
||||
}
|
||||
|
||||
func (manager *SVpcManager) getVpcExternalIdForClassicNetwork(regionId, cloudproviderId string) string {
|
||||
@@ -616,7 +616,7 @@ func (manager *SVpcManager) newFromCloudVpc(ctx context.Context, userCred mcclie
|
||||
}
|
||||
|
||||
func (self *SVpc) markAllNetworksUnknown(userCred mcclient.TokenCredential) error {
|
||||
wires := self.GetWires()
|
||||
wires, _ := self.GetWires()
|
||||
if wires == nil || len(wires) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -1377,7 +1377,7 @@ func (vpc *SVpc) GetChangeOwnerCandidateDomainIds() []string {
|
||||
|
||||
func (vpc *SVpc) GetChangeOwnerRequiredDomainIds() []string {
|
||||
requires := stringutils2.SSortedStrings{}
|
||||
wires := vpc.GetWires()
|
||||
wires, _ := vpc.GetWires()
|
||||
for i := range wires {
|
||||
requires = stringutils2.Append(requires, wires[i].DomainId)
|
||||
}
|
||||
@@ -1385,7 +1385,7 @@ func (vpc *SVpc) GetChangeOwnerRequiredDomainIds() []string {
|
||||
}
|
||||
|
||||
func (vpc *SVpc) GetRequiredSharedDomainIds() []string {
|
||||
wires := vpc.GetWires()
|
||||
wires, _ := vpc.GetWires()
|
||||
if len(wires) == 0 {
|
||||
return vpc.SEnabledStatusInfrasResourceBase.GetRequiredSharedDomainIds()
|
||||
}
|
||||
@@ -1454,7 +1454,7 @@ func (vpc *SVpc) PerformPublic(ctx context.Context, userCred mcclient.TokenCrede
|
||||
return nil, errors.Wrap(err, "SEnabledStatusInfrasResourceBase.PerformPublic")
|
||||
}
|
||||
// perform public for all emulated wires
|
||||
wires := vpc.GetWires()
|
||||
wires, _ := vpc.GetWires()
|
||||
for i := range wires {
|
||||
if wires[i].IsEmulated {
|
||||
_, err := wires[i].PerformPublic(ctx, userCred, query, input)
|
||||
@@ -1492,7 +1492,7 @@ func (vpc *SVpc) PerformPrivate(ctx context.Context, userCred mcclient.TokenCred
|
||||
}
|
||||
// perform private for all emulated wires
|
||||
emptyNets := true
|
||||
wires := vpc.GetWires()
|
||||
wires, _ := vpc.GetWires()
|
||||
for i := range wires {
|
||||
if wires[i].DomainId == vpc.DomainId {
|
||||
nets, _ := wires[i].getNetworks(nil, rbacutils.ScopeNone)
|
||||
@@ -1549,7 +1549,7 @@ func (vpc *SVpc) PerformChangeOwner(ctx context.Context, userCred mcclient.Token
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SEnabledStatusInfrasResourceBase.PerformChangeOwner")
|
||||
}
|
||||
wires := vpc.GetWires()
|
||||
wires, _ := vpc.GetWires()
|
||||
for i := range wires {
|
||||
if wires[i].IsEmulated {
|
||||
_, err := wires[i].PerformChangeOwner(ctx, userCred, query, input)
|
||||
@@ -1721,3 +1721,59 @@ func (self *SVpc) IsSupportAssociateEip() bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SVpc) GetDetailsTopology(ctx context.Context, userCred mcclient.TokenCredential, input *api.VpcTopologyInput) (*api.VpcTopologyOutput, error) {
|
||||
ret := &api.VpcTopologyOutput{
|
||||
Name: self.Name,
|
||||
Status: self.Status,
|
||||
Wires: []api.WireTopologyOutput{},
|
||||
}
|
||||
wires, err := self.GetWires()
|
||||
if err != nil {
|
||||
return ret, errors.Wrapf(err, "GetWires")
|
||||
}
|
||||
for i := range wires {
|
||||
wire := api.WireTopologyOutput{
|
||||
Name: wires[i].Name,
|
||||
Status: wires[i].Status,
|
||||
Bandwidth: wires[i].Bandwidth,
|
||||
Networks: []api.NetworkTopologyOutput{},
|
||||
}
|
||||
if len(wires[i].ZoneId) > 0 {
|
||||
zone, _ := wires[i].GetZone()
|
||||
if zone != nil {
|
||||
wire.Zone = zone.Name
|
||||
}
|
||||
}
|
||||
networks, err := wires[i].GetNetworks(nil, rbacutils.ScopeSystem)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetNetworks")
|
||||
}
|
||||
for j := range networks {
|
||||
network := api.NetworkTopologyOutput{
|
||||
Name: networks[j].Name,
|
||||
Status: networks[j].Status,
|
||||
GuestIpStart: networks[j].GuestIpStart,
|
||||
GuestIpEnd: networks[j].GuestIpEnd,
|
||||
GuestIpMask: networks[j].GuestIpMask,
|
||||
ServerType: networks[j].ServerType,
|
||||
VlanId: networks[j].VlanId,
|
||||
Address: []api.SNetworkUsedAddress{},
|
||||
}
|
||||
|
||||
netAddrs := make([]api.SNetworkUsedAddress, 0)
|
||||
|
||||
q := networks[j].getUsedAddressQuery(userCred, rbacutils.ScopeDomain, false)
|
||||
err = q.All(&netAddrs)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "q.All")
|
||||
}
|
||||
|
||||
sort.Sort(SNetworkUsedAddressList(netAddrs))
|
||||
network.Address = netAddrs
|
||||
wire.Networks = append(wire.Networks, network)
|
||||
}
|
||||
ret.Wires = append(ret.Wires, wire)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user