mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #15358 from swordqiu/hotfix/qj-not-detect-vm-ips-when-manage-vmware
fix: do not detect vm ips when managing vmware
This commit is contained in:
@@ -83,7 +83,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221111025915-ff307c592d7d
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221112124251-e086cfa622dd
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
|
||||
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
|
||||
yunion.io/x/log v1.0.0
|
||||
|
||||
@@ -1162,8 +1162,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221111025915-ff307c592d7d h1:4+xSygGpc2iehPhHjz3WRYnPt0ZrQIAlDTk44iVjJuk=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221111025915-ff307c592d7d/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221112124251-e086cfa622dd h1:zcUjAzwGTPaAxQUrE/uUPY3u3baqPMJMcAW3lnyzHaE=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221112124251-e086cfa622dd/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -376,9 +376,9 @@ type CloudaccountPerformPrepareNetsInput struct {
|
||||
type CloudaccountPerformPrepareNetsOutput struct {
|
||||
CAWireNets []CAWireNet `json:"wire_networks"`
|
||||
Hosts []CAGuestNet `json:"hosts"`
|
||||
Guests []CAGuestNet `json:"guests"`
|
||||
Wires []CAPWire `json:"wires"`
|
||||
VSwitchs []VSwitch `json:"vswitchs"`
|
||||
// Guests []CAGuestNet `json:"guests"`
|
||||
Wires []CAPWire `json:"wires"`
|
||||
VSwitchs []VSwitch `json:"vswitchs"`
|
||||
}
|
||||
|
||||
type CloudaccountSyncVMwareNetworkInput struct {
|
||||
@@ -413,10 +413,10 @@ type CAWireNet struct {
|
||||
SuitableWire string `json:"suitable_wire,allowempty"`
|
||||
Hosts []CAHostNet `json:"hosts"`
|
||||
// description: 没有合适的已有网络,推荐的网络配置
|
||||
HostSuggestedNetworks []CANetConf `json:"host_suggested_networks"`
|
||||
Guests []CAGuestNet `json:"guests"`
|
||||
HostSuggestedNetworks []CANetConf `json:"host_suggested_networks"`
|
||||
// Guests []CAGuestNet `json:"guests"`
|
||||
// description: 没有合适的已有网络,推荐的网络配置
|
||||
GuestSuggestedNetworks []CANetConf `json:"guest_suggested_networks"`
|
||||
// GuestSuggestedNetworks []CANetConf `json:"guest_suggested_networks"`
|
||||
}
|
||||
|
||||
type CAWireConf struct {
|
||||
|
||||
@@ -577,7 +577,7 @@ func (self *SCloudaccount) PostCreate(ctx context.Context, userCred mcclient.Tok
|
||||
if self.Enabled.IsTrue() {
|
||||
if self.Provider == api.CLOUD_PROVIDER_VMWARE {
|
||||
zone, _ := data.GetString("zone")
|
||||
self.StartSyncVmwareNetworkTask(ctx, userCred, "", zone)
|
||||
self.StartSyncVMwareNetworkTask(ctx, userCred, "", zone)
|
||||
} else {
|
||||
self.StartSyncCloudProviderInfoTask(ctx, userCred, nil, "")
|
||||
}
|
||||
@@ -788,19 +788,6 @@ func (self *SCloudaccount) PerformUpdateCredential(ctx context.Context, userCred
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) StartSyncVmwareNetworkTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string, zone string) error {
|
||||
params := jsonutils.NewDict()
|
||||
if len(zone) != 0 {
|
||||
params.Set("zone", jsonutils.NewString(zone))
|
||||
}
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "CloudAccountSyncVMwareNetworkTask", self, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to create task CloudAccountSyncVMwareNetworkTask")
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) StartSyncCloudProviderInfoTask(ctx context.Context, userCred mcclient.TokenCredential, syncRange *SSyncRange, parentTaskId string) error {
|
||||
params := jsonutils.NewDict()
|
||||
if syncRange != nil {
|
||||
|
||||
@@ -262,7 +262,7 @@ func (cam *SCloudaccountManager) prepareNets(ctx context.Context, userCred mccli
|
||||
IPNets: ipNets,
|
||||
})
|
||||
}
|
||||
output.Guests = cam.parseSimpleVms(nInfo.VMs, existedIpPool)
|
||||
// output.Guests = cam.parseSimpleVms(nInfo.VMs, existedIpPool)
|
||||
|
||||
vsList := nInfo.VsMap.List()
|
||||
for i := range vsList {
|
||||
@@ -298,7 +298,7 @@ func (cam *SCloudaccountManager) prepareNets(ctx context.Context, userCred mccli
|
||||
ipWithSameNet = append(ipWithSameNet, ips[k])
|
||||
}
|
||||
ipLimitLow, ipLimitUp := ips[0], ips[len(ips)-1]
|
||||
simNetConfs := cam.expandIPRnage(ips, ipLimitLow, ipLimitUp, func(proc esxi.SIPProc) bool {
|
||||
simNetConfs := cam.expandIPRange(ips, ipLimitLow, ipLimitUp, func(proc esxi.SIPProc) bool {
|
||||
return proc.IsHost
|
||||
}, nInfo.IPPool, existedIpPool)
|
||||
for k := range simNetConfs {
|
||||
@@ -309,8 +309,8 @@ func (cam *SCloudaccountManager) prepareNets(ctx context.Context, userCred mccli
|
||||
}
|
||||
}
|
||||
}
|
||||
for vlan, ips := range vs.Vlans {
|
||||
simNetConfs := cam.expandIPRnage(ips, 0, 0, func(proc esxi.SIPProc) bool {
|
||||
/*for vlan, ips := range vs.Vlans {
|
||||
simNetConfs := cam.expandIPRange(ips, 0, 0, func(proc esxi.SIPProc) bool {
|
||||
return proc.VlanId == vlan
|
||||
}, nInfo.IPPool, existedIpPool)
|
||||
for j := range simNetConfs {
|
||||
@@ -320,7 +320,7 @@ func (cam *SCloudaccountManager) prepareNets(ctx context.Context, userCred mccli
|
||||
CASimpleNetConf: simNetConfs[j],
|
||||
})
|
||||
}
|
||||
}
|
||||
}*/
|
||||
output.Wires = append(output.Wires, wire)
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ func (cam *SCloudaccountManager) parseSimpleVms(vms []esxi.SSimpleVM, existedIpP
|
||||
return guests
|
||||
}
|
||||
|
||||
func (cam *SCloudaccountManager) expandIPRnage(ips []netutils.IPV4Addr, limitLow, limitUp netutils.IPV4Addr,
|
||||
func (cam *SCloudaccountManager) expandIPRange(ips []netutils.IPV4Addr, limitLow, limitUp netutils.IPV4Addr,
|
||||
expand func(esxi.SIPProc) bool, ipPool esxi.SIPPool, existedIpPool *sIPPool) []api.CASimpleNetConf {
|
||||
ret := make([]api.CASimpleNetConf, 0)
|
||||
for i := 0; i < len(ips); i++ {
|
||||
@@ -562,10 +562,10 @@ func (scm *SCloudaccountManager) parseAndSuggestSingleWire(params sParseAndSugge
|
||||
})
|
||||
}
|
||||
|
||||
wireNet.Guests = scm.parseSimpleVms(ni.VMs, params.ExistedIpPool)
|
||||
/* wireNet.Guests = scm.parseSimpleVms(ni.VMs, params.ExistedIpPool)
|
||||
|
||||
for vlan, ips := range ni.VlanIps {
|
||||
simNetConfs := scm.expandIPRnage(ips, 0, 0, func(proc esxi.SIPProc) bool {
|
||||
simNetConfs := scm.expandIPRange(ips, 0, 0, func(proc esxi.SIPProc) bool {
|
||||
return proc.VlanId == vlan
|
||||
}, ni.IPPool, params.ExistedIpPool)
|
||||
for i := range simNetConfs {
|
||||
@@ -575,7 +575,7 @@ func (scm *SCloudaccountManager) parseAndSuggestSingleWire(params sParseAndSugge
|
||||
CASimpleNetConf: simNetConfs[i],
|
||||
})
|
||||
}
|
||||
}
|
||||
}*/
|
||||
output.CAWireNets = append(output.CAWireNets, wireNet)
|
||||
}
|
||||
return output
|
||||
@@ -673,17 +673,19 @@ func (manager *SCloudaccountManager) suggestHostNetworks(ips []netutils.IPV4Addr
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) StartSyncVMwareNetworkTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string, networkZone string) error {
|
||||
if self.Provider != api.CLOUD_PROVIDER_VMWARE {
|
||||
func (ca *SCloudaccount) StartSyncVMwareNetworkTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string, networkZone string) error {
|
||||
if ca.Provider != api.CLOUD_PROVIDER_VMWARE {
|
||||
return errors.ErrNotSupported
|
||||
}
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("zone", jsonutils.NewString(networkZone))
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "CloudAccountSyncVMwareNetworkTask", self, userCred, params, parentTaskId, "", nil)
|
||||
if len(networkZone) != 0 {
|
||||
params.Set("zone", jsonutils.NewString(networkZone))
|
||||
}
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "CloudAccountSyncVMwareNetworkTask", ca, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
self.SetStatus(userCred, api.CLOUD_PROVIDER_SYNC_NETWORK, "StartSyncVMwareNetworkTask")
|
||||
ca.SetStatus(userCred, api.CLOUD_PROVIDER_SYNC_NETWORK, "StartSyncVMwareNetworkTask")
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
@@ -26,11 +25,11 @@ import (
|
||||
)
|
||||
|
||||
func TestParseAndSuggest(t *testing.T) {
|
||||
param, err := structureTestData()
|
||||
_, err := structureTestData()
|
||||
if err != nil {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
out := CloudaccountManager.parseAndSuggestSingleWire(param)
|
||||
/*out := CloudaccountManager.parseAndSuggestSingleWire(param)
|
||||
for _, net := range out.CAWireNets[0].GuestSuggestedNetworks {
|
||||
ips, _ := netutils.NewIPV4Addr(net.GuestIpStart)
|
||||
ipe, _ := netutils.NewIPV4Addr(net.GuestIpEnd)
|
||||
@@ -38,7 +37,7 @@ func TestParseAndSuggest(t *testing.T) {
|
||||
if ips-ipn != 1 || ipe-ipn != 254 {
|
||||
t.Fatalf("wrong ip range '%s-%s' of suggest networks", net.GuestIpStart, net.GuestIpEnd)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
func structureTestData() (sParseAndSuggest, error) {
|
||||
@@ -67,7 +66,7 @@ func structureTestData() (sParseAndSuggest, error) {
|
||||
ninfo.IPPool.Insert(ip, esxi.SIPProc{
|
||||
VlanId: vlan.Id,
|
||||
})
|
||||
ninfo.VMs = append(ninfo.VMs, esxi.SSimpleVM{
|
||||
/*ninfo.VMs = append(ninfo.VMs, esxi.SSimpleVM{
|
||||
Name: fmt.Sprintf("%s%d", "vm", len(ninfo.VMs)),
|
||||
IPVlans: []esxi.SIPVlan{
|
||||
{
|
||||
@@ -75,7 +74,7 @@ func structureTestData() (sParseAndSuggest, error) {
|
||||
VlanId: vlan.Id,
|
||||
},
|
||||
},
|
||||
})
|
||||
})*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3418,6 +3418,7 @@ func (self *SGuest) SyncVMNics(ctx context.Context, userCred mcclient.TokenCrede
|
||||
for i := 0; i < len(added); i += 1 {
|
||||
localNet, err := getCloudNicNetwork(ctx, added[i], host, ipList, i)
|
||||
if err != nil {
|
||||
log.Errorf("SyncVMNics getCloudNicNetwork add fail: %s", err)
|
||||
if ip := added[i].GetIP(); len(ip) > 0 {
|
||||
syncIps = append(syncIps, ip)
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ func (self *CloudAccountSyncVMwareNetworkTask) OnInit(ctx context.Context, obj d
|
||||
}
|
||||
}
|
||||
}
|
||||
for vlan, ips := range vs.Vlans {
|
||||
/* for vlan, ips := range vs.Vlans {
|
||||
simNetConfs := self.expandIPRnage(ips, 0, 0, func(proc esxi.SIPProc) bool {
|
||||
return proc.VlanId == vlan && proc.VSId == vs.Id && !proc.IsHost
|
||||
}, nInfo.IPPool, excludedIPPool, func(net sSimpleNet) {
|
||||
@@ -180,7 +180,7 @@ func (self *CloudAccountSyncVMwareNetworkTask) OnInit(ctx context.Context, obj d
|
||||
CASimpleNetConf: simNetConfs[j],
|
||||
})
|
||||
}
|
||||
}
|
||||
}*/
|
||||
// make sure wire
|
||||
suitableWire := ""
|
||||
maxScore := 1
|
||||
@@ -230,7 +230,8 @@ func (self *CloudAccountSyncVMwareNetworkTask) createNetworks(ctx context.Contex
|
||||
var err error
|
||||
ret := make(map[string][]models.SVs2Wire)
|
||||
for i := range capWires {
|
||||
if len(capWires[i].GuestNetworks)+len(capWires[i].HostNetworks) == 0 {
|
||||
// if len(capWires[i].GuestNetworks)+len(capWires[i].HostNetworks) == 0 {
|
||||
if len(capWires[i].HostNetworks) == 0 {
|
||||
continue
|
||||
}
|
||||
var wireId = capWires[i].WireId
|
||||
@@ -247,12 +248,12 @@ func (self *CloudAccountSyncVMwareNetworkTask) createNetworks(ctx context.Contex
|
||||
return nil, errors.Wrapf(err, "can't create network %v", net)
|
||||
}
|
||||
}
|
||||
for _, net := range capWires[i].GuestNetworks {
|
||||
/* for _, net := range capWires[i].GuestNetworks {
|
||||
err := self.createNetwork(ctx, cloudaccount, wireId, api.NETWORK_TYPE_GUEST, net)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "can't create network %v", net)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
for _, host := range capWires[i].Hosts {
|
||||
ret[host.Id] = append(ret[host.Id], models.SVs2Wire{
|
||||
VsId: capWires[i].VsId,
|
||||
@@ -529,14 +530,14 @@ func (pl *sIPPool) Get(ip netutils.IPV4Addr) (sSimpleNet, bool) {
|
||||
}
|
||||
|
||||
type CAPWire struct {
|
||||
VsId string
|
||||
WireId string
|
||||
Name string
|
||||
Distributed bool
|
||||
Description string
|
||||
Hosts []esxi.SSimpleHostDev
|
||||
HostNetworks []CANetConf
|
||||
GuestNetworks []CANetConf
|
||||
VsId string
|
||||
WireId string
|
||||
Name string
|
||||
Distributed bool
|
||||
Description string
|
||||
Hosts []esxi.SSimpleHostDev
|
||||
HostNetworks []CANetConf
|
||||
// GuestNetworks []CANetConf
|
||||
}
|
||||
|
||||
type CASimpleNetConf struct {
|
||||
|
||||
Vendored
+1
-1
@@ -1428,7 +1428,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221111025915-ff307c592d7d
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221112124251-e086cfa622dd
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+3
@@ -45,6 +45,9 @@ const (
|
||||
|
||||
VM_SYNC_CONFIG = "sync_config"
|
||||
|
||||
VM_POWER_STATES_OFF = "off"
|
||||
VM_POWER_STATES_ON = "on"
|
||||
|
||||
HYPERVISOR_ESXI = "esxi"
|
||||
|
||||
HYPERVISOR_ALIYUN = "aliyun"
|
||||
|
||||
+11
-2
@@ -15,6 +15,15 @@
|
||||
package compute
|
||||
|
||||
const (
|
||||
MODELARTS_POOL_STATUS_RUNNING = "running"
|
||||
MODELARTS_POOL_STATUS_CREATING = "creating"
|
||||
MODELARTS_POOL_STATUS_RUNNING = "running"
|
||||
MODELARTS_POOL_STATUS_ABNORMAL = "abnormal"
|
||||
MODELARTS_POOL_STATUS_CREATING = "creating"
|
||||
MODELARTS_POOL_STATUS_CREATE_FAILED = "create_failed"
|
||||
MODELARTS_POOL_STATUS_DELETING = "deleting"
|
||||
MODELARTS_POOL_STATUS_DELETE_FAILED = "delete_failed"
|
||||
MODELARTS_POOL_STATUS_CHANGE_CONFIG = "change_config"
|
||||
MODELARTS_POOL_STATUS_CHANGE_CONFIG_FAILED = "change_config_failed"
|
||||
MODELARTS_POOL_STATUS_ERROR = "error"
|
||||
MODELARTS_POOL_STATUS_UNKNOWN = "unknown"
|
||||
MODELARTS_POOL_STATUS_TIMEOUT = "timeout"
|
||||
)
|
||||
|
||||
+12
@@ -372,6 +372,18 @@ func (self *SInstance) GetStatus() string {
|
||||
return api.VM_UNKNOWN
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetPowerStates() string {
|
||||
status := ins.GetStatus()
|
||||
switch status {
|
||||
case api.VM_READY:
|
||||
return api.VM_POWER_STATES_OFF
|
||||
case api.VM_UNKNOWN:
|
||||
return api.VM_POWER_STATES_OFF
|
||||
default:
|
||||
return api.VM_POWER_STATES_ON
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SInstance) GetIHost() cloudprovider.ICloudHost {
|
||||
return self.host
|
||||
}
|
||||
|
||||
+16
-15
@@ -16,14 +16,11 @@ package esxi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
)
|
||||
|
||||
func (cli *SESXiClient) HostVmIPsInDc(ctx context.Context, dc *SDatacenter) (SNetworkInfo, error) {
|
||||
@@ -58,7 +55,7 @@ func (s *SNetworkInfo) Insert(proc SIPProc, ip netutils.IPV4Addr) {
|
||||
|
||||
func (cli *SESXiClient) hostVMIPs(ctx context.Context, hosts []mo.HostSystem) (SNetworkInfo, error) {
|
||||
ret := SNetworkInfo{}
|
||||
dvpgMap, err := cli.getDVPGMap()
|
||||
/*dvpgMap, err := cli.getDVPGMap()
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "unable to get dvpgKeyVlanMap")
|
||||
}
|
||||
@@ -75,6 +72,10 @@ func (cli *SESXiClient) hostVMIPs(ctx context.Context, hosts []mo.HostSystem) (S
|
||||
return nil
|
||||
})
|
||||
}
|
||||
err = group.Wait()
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}*/
|
||||
|
||||
hostIps := make(map[string]netutils.IPV4Addr, len(hosts))
|
||||
for i := range hosts {
|
||||
@@ -87,22 +88,22 @@ func (cli *SESXiClient) hostVMIPs(ctx context.Context, hosts []mo.HostSystem) (S
|
||||
}
|
||||
hostIps[host.GetName()] = ip
|
||||
}
|
||||
err = group.Wait()
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// length
|
||||
if len(collection) == 0 {
|
||||
/* if len(collection) == 0 {
|
||||
ret.HostIps = hostIps
|
||||
return ret, nil
|
||||
}
|
||||
ni := cli.mergeNetworInfo(collection)
|
||||
ni.HostIps = hostIps
|
||||
return ni, nil
|
||||
return ni, nil*/
|
||||
|
||||
ret.HostIps = hostIps
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (cli *SESXiClient) mergeNetworInfo(nInfos []*SNetworkInfo) SNetworkInfo {
|
||||
var vmsLen, vlanIpLen, ipPoolLen int
|
||||
/* func (cli *SESXiClient) mergeNetworInfo(nInfos []*SNetworkInfo) SNetworkInfo {
|
||||
var vlanIpLen, ipPoolLen int
|
||||
for i := range nInfos {
|
||||
vmsLen += len(nInfos[i].VMs)
|
||||
vlanIpLen += len(nInfos[i].VlanIps)
|
||||
@@ -128,7 +129,7 @@ func (cli *SESXiClient) mergeNetworInfo(nInfos []*SNetworkInfo) SNetworkInfo {
|
||||
})
|
||||
}
|
||||
return ret
|
||||
}
|
||||
} */
|
||||
|
||||
func (cli *SESXiClient) HostVmIPs(ctx context.Context) (SNetworkInfo, error) {
|
||||
var hosts []mo.HostSystem
|
||||
@@ -139,7 +140,7 @@ func (cli *SESXiClient) HostVmIPs(ctx context.Context) (SNetworkInfo, error) {
|
||||
return cli.hostVMIPs(ctx, hosts)
|
||||
}
|
||||
|
||||
func (cli *SESXiClient) vmIPs(host *mo.HostSystem, vpgMap sVPGMap) (INetworkInfo, error) {
|
||||
/*func (cli *SESXiClient) vmIPs(host *mo.HostSystem, vpgMap sVPGMap) (INetworkInfo, error) {
|
||||
nInfo := NewNetworkInfo(false, len(host.Vm))
|
||||
if len(host.Vm) == 0 {
|
||||
return nInfo, nil
|
||||
@@ -190,4 +191,4 @@ func (cli *SESXiClient) vmIPs(host *mo.HostSystem, vpgMap sVPGMap) (INetworkInfo
|
||||
nInfo.AppendVMs(vm.Name, guestIps)
|
||||
}
|
||||
return nInfo, nil
|
||||
}
|
||||
}*/
|
||||
|
||||
+29
-29
@@ -22,9 +22,7 @@ import (
|
||||
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
@@ -98,7 +96,7 @@ func (cli *SESXiClient) networkName(refV string) (string, error) {
|
||||
func (cli *SESXiClient) hostVMIPsPro(ctx context.Context, hosts []mo.HostSystem) (SNetworkInfoPro, error) {
|
||||
ret := SNetworkInfoPro{
|
||||
SNetworkInfoBase: SNetworkInfoBase{
|
||||
VMs: []SSimpleVM{},
|
||||
// VMs: []SSimpleVM{},
|
||||
IPPool: SIPPool{},
|
||||
},
|
||||
HostIps: make(map[string][]netutils.IPV4Addr),
|
||||
@@ -108,7 +106,7 @@ func (cli *SESXiClient) hostVMIPsPro(ctx context.Context, hosts []mo.HostSystem)
|
||||
return ret, errors.Wrap(err, "unable to getVirtualSwitchs")
|
||||
}
|
||||
ret.VsMap = vsMap
|
||||
dvpgMap, err := cli.getDVPGMap()
|
||||
/* dvpgMap, err := cli.getDVPGMap()
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "unable to get dvpgKeyVlanMap")
|
||||
}
|
||||
@@ -131,6 +129,8 @@ func (cli *SESXiClient) hostVMIPsPro(ctx context.Context, hosts []mo.HostSystem)
|
||||
return ret, err
|
||||
}
|
||||
cli.mergeNetworInfoPro(&ret, collection)
|
||||
*/
|
||||
ret.IPPool = NewIPPool(0)
|
||||
vsList := vsMap.List()
|
||||
for i := range vsList {
|
||||
vs := vsList[i]
|
||||
@@ -151,7 +151,7 @@ func (cli *SESXiClient) hostVMIPsPro(ctx context.Context, hosts []mo.HostSystem)
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (cli *SESXiClient) mergeNetworInfoPro(ret *SNetworkInfoPro, nInfos []*SNetworkInfoPro) {
|
||||
/*func (cli *SESXiClient) mergeNetworInfoPro(ret *SNetworkInfoPro, nInfos []*SNetworkInfoPro) {
|
||||
log.Infof("nInfos before mergeNetworInfoPro: %s", jsonutils.Marshal(nInfos))
|
||||
var vmsLen, ipPoolLen int
|
||||
for i := range nInfos {
|
||||
@@ -165,7 +165,7 @@ func (cli *SESXiClient) mergeNetworInfoPro(ret *SNetworkInfoPro, nInfos []*SNetw
|
||||
ret.IPPool.Merge(&nInfos[i].IPPool)
|
||||
ret.VsMap.Merge(&nInfos[i].VsMap)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
func (cli *SESXiClient) HostVmIPsPro(ctx context.Context) (SNetworkInfoPro, error) {
|
||||
var hosts []mo.HostSystem
|
||||
@@ -233,13 +233,13 @@ type SNetworkInfoPro struct {
|
||||
VsMap SVirtualSwitchMap
|
||||
}
|
||||
|
||||
func (s *SNetworkInfoPro) Insert(proc SIPProc, ip netutils.IPV4Addr) {
|
||||
/*func (s *SNetworkInfoPro) Insert(proc SIPProc, ip netutils.IPV4Addr) {
|
||||
s.SNetworkInfoBase.Insert(proc, ip)
|
||||
s.VsMap.AddVlanIp(proc.VSId, proc.VlanId, ip)
|
||||
}
|
||||
}*/
|
||||
|
||||
type SNetworkInfoBase struct {
|
||||
VMs []SSimpleVM
|
||||
// VMs []SSimpleVM
|
||||
IPPool SIPPool
|
||||
}
|
||||
|
||||
@@ -247,18 +247,18 @@ func (s *SNetworkInfoBase) Insert(proc SIPProc, ip netutils.IPV4Addr) {
|
||||
s.IPPool.Insert(ip, proc)
|
||||
}
|
||||
|
||||
func (s *SNetworkInfoBase) AppendVMs(name string, IpVlans []SIPVlan) {
|
||||
/* func (s *SNetworkInfoBase) AppendVMs(name string, IpVlans []SIPVlan) {
|
||||
s.VMs = append(s.VMs, SSimpleVM{name, IpVlans})
|
||||
}
|
||||
}*/
|
||||
|
||||
type INetworkInfo interface {
|
||||
Insert(SIPProc, netutils.IPV4Addr)
|
||||
AppendVMs(name string, IpVlans []SIPVlan)
|
||||
// AppendVMs(name string, IpVlans []SIPVlan)
|
||||
}
|
||||
|
||||
func NewNetworkInfo(dvs bool, size int) INetworkInfo {
|
||||
base := SNetworkInfoBase{
|
||||
VMs: make([]SSimpleVM, 0, size),
|
||||
// VMs: make([]SSimpleVM, 0, size),
|
||||
IPPool: NewIPPool(int(size)),
|
||||
}
|
||||
if dvs {
|
||||
@@ -268,14 +268,14 @@ func NewNetworkInfo(dvs bool, size int) INetworkInfo {
|
||||
}
|
||||
}
|
||||
return &SNetworkInfo{
|
||||
SNetworkInfoBase: base,
|
||||
HostIps: make(map[string]netutils.IPV4Addr),
|
||||
VlanIps: make(map[int32][]netutils.IPV4Addr),
|
||||
// SNetworkInfoBase: base,
|
||||
HostIps: make(map[string]netutils.IPV4Addr),
|
||||
VlanIps: make(map[int32][]netutils.IPV4Addr),
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *SESXiClient) vmIPsPro(host *mo.HostSystem, vpgMap sVPGMap) (INetworkInfo, error) {
|
||||
nInfo := NewNetworkInfo(true, len(host.Vm))
|
||||
/*func (cli *SESXiClient) vmIPsPro(host *mo.HostSystem, vpgMap sVPGMap) (INetworkInfo, error) {
|
||||
nInfo := NewNetworkInfo(true, 0)
|
||||
if len(host.Vm) == 0 {
|
||||
return nInfo, nil
|
||||
}
|
||||
@@ -325,7 +325,7 @@ func (cli *SESXiClient) vmIPsPro(host *mo.HostSystem, vpgMap sVPGMap) (INetworkI
|
||||
nInfo.AppendVMs(vm.Name, guestIps)
|
||||
}
|
||||
return nInfo, nil
|
||||
}
|
||||
}*/
|
||||
|
||||
type SVirtualSwitchSpec struct {
|
||||
Name string
|
||||
@@ -333,21 +333,21 @@ type SVirtualSwitchSpec struct {
|
||||
Distributed bool
|
||||
Hosts []SSimpleHostDev
|
||||
HostIps map[string][]netutils.IPV4Addr
|
||||
Vlans map[int32][]netutils.IPV4Addr
|
||||
// Vlans map[int32][]netutils.IPV4Addr
|
||||
}
|
||||
|
||||
func NewVirtualSwitch() *SVirtualSwitchSpec {
|
||||
return &SVirtualSwitchSpec{
|
||||
HostIps: make(map[string][]netutils.IPV4Addr),
|
||||
Vlans: make(map[int32][]netutils.IPV4Addr),
|
||||
// Vlans: make(map[int32][]netutils.IPV4Addr),
|
||||
}
|
||||
}
|
||||
|
||||
func (vs *SVirtualSwitchSpec) Merge(vsc *SVirtualSwitchSpec) {
|
||||
/*func (vs *SVirtualSwitchSpec) Merge(vsc *SVirtualSwitchSpec) {
|
||||
for vlan, ips := range vsc.Vlans {
|
||||
vs.Vlans[vlan] = insert(vs.Vlans[vlan], ips)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
func insert(base []netutils.IPV4Addr, add []netutils.IPV4Addr) []netutils.IPV4Addr {
|
||||
for _, ip := range add {
|
||||
@@ -378,9 +378,9 @@ func NewVirtualSwitchMap(length ...int) SVirtualSwitchMap {
|
||||
}
|
||||
|
||||
func (vsm *SVirtualSwitchMap) Insert(id string, vs SVirtualSwitchSpec) {
|
||||
ovs, ok := vsm.vsMap[id]
|
||||
_, ok := vsm.vsMap[id]
|
||||
if ok {
|
||||
ovs.Merge(&vs)
|
||||
// ovs.Merge(&vs)
|
||||
return
|
||||
}
|
||||
vsm.vsList = append(vsm.vsList, vs)
|
||||
@@ -394,7 +394,7 @@ func (vms *SVirtualSwitchMap) Merge(ovsm *SVirtualSwitchMap) {
|
||||
}
|
||||
}
|
||||
|
||||
func (vsm *SVirtualSwitchMap) AddVlanIp(id string, vlanId int32, ip netutils.IPV4Addr) bool {
|
||||
/*func (vsm *SVirtualSwitchMap) AddVlanIp(id string, vlanId int32, ip netutils.IPV4Addr) bool {
|
||||
vs, ok := vsm.vsMap[id]
|
||||
if !ok {
|
||||
vs = NewVirtualSwitch()
|
||||
@@ -404,7 +404,7 @@ func (vsm *SVirtualSwitchMap) AddVlanIp(id string, vlanId int32, ip netutils.IPV
|
||||
}
|
||||
vs.Vlans[vlanId] = append(vs.Vlans[vlanId], ip)
|
||||
return true
|
||||
}
|
||||
}*/
|
||||
|
||||
func (vsm *SVirtualSwitchMap) List() []SVirtualSwitchSpec {
|
||||
return vsm.vsList
|
||||
@@ -511,7 +511,7 @@ func (cli *SESXiClient) getVirtualSwitchs(hss []mo.HostSystem) (SVirtualSwitchMa
|
||||
Id: vsId,
|
||||
Distributed: true,
|
||||
HostIps: make(map[string][]netutils.IPV4Addr, len(hosts)),
|
||||
Vlans: make(map[int32][]netutils.IPV4Addr),
|
||||
// Vlans: make(map[int32][]netutils.IPV4Addr),
|
||||
}
|
||||
for _, host := range hosts {
|
||||
hostName := value2name[host.Config.Host.Value]
|
||||
@@ -552,7 +552,7 @@ func (cli *SESXiClient) getVirtualSwitchs(hss []mo.HostSystem) (SVirtualSwitchMa
|
||||
Id: vsId,
|
||||
Distributed: false,
|
||||
HostIps: make(map[string][]netutils.IPV4Addr),
|
||||
Vlans: make(map[int32][]netutils.IPV4Addr),
|
||||
// Vlans: make(map[int32][]netutils.IPV4Addr),
|
||||
}
|
||||
hostDev := SSimpleHostDev{
|
||||
Id: hs.Self.Value,
|
||||
|
||||
+12
@@ -188,6 +188,18 @@ func (instance *SInstance) GetStatus() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetPowerStates() string {
|
||||
status := ins.GetStatus()
|
||||
switch status {
|
||||
case api.VM_READY:
|
||||
return api.VM_POWER_STATES_OFF
|
||||
case api.VM_UNKNOWN:
|
||||
return api.VM_POWER_STATES_OFF
|
||||
default:
|
||||
return api.VM_POWER_STATES_ON
|
||||
}
|
||||
}
|
||||
|
||||
func (instance *SInstance) GetBillingType() string {
|
||||
return billing_api.BILLING_TYPE_POSTPAID
|
||||
}
|
||||
|
||||
+9
@@ -231,6 +231,15 @@ func (self *SInstance) GetStatus() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetPowerStates() string {
|
||||
switch ins.OSEXTSTSPowerState {
|
||||
case 1:
|
||||
return api.VM_POWER_STATES_ON
|
||||
default:
|
||||
return api.VM_POWER_STATES_OFF
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SInstance) Refresh() error {
|
||||
ret, err := self.host.zone.region.GetInstance(self.GetId())
|
||||
if err != nil {
|
||||
|
||||
+9
@@ -230,6 +230,15 @@ func (self *SInstance) GetStatus() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetPowerStates() string {
|
||||
switch ins.OSEXTSTSPowerState {
|
||||
case 1:
|
||||
return api.VM_POWER_STATES_ON
|
||||
default:
|
||||
return api.VM_POWER_STATES_OFF
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SInstance) Refresh() error {
|
||||
new, err := self.host.zone.region.GetInstanceByID(self.GetId())
|
||||
new.host = self.host
|
||||
|
||||
+4
@@ -290,6 +290,10 @@ func (self *SModelartsPool) GetStatus() string {
|
||||
switch {
|
||||
case res == compute.MODELARTS_POOL_STATUS_RUNNING && len(self.Status.Resource.Creating) != 0:
|
||||
res = compute.MODELARTS_POOL_STATUS_CREATING
|
||||
case self.Status.Phase == "CreationFailed":
|
||||
res = compute.MODELARTS_POOL_STATUS_CREATE_FAILED
|
||||
case self.Status.Phase == "SeclingFailed":
|
||||
res = compute.MODELARTS_POOL_STATUS_CHANGE_CONFIG_FAILED
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
+9
@@ -230,6 +230,15 @@ func (self *SInstance) GetStatus() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetPowerStates() string {
|
||||
switch ins.OSEXTSTSPowerState {
|
||||
case 1:
|
||||
return api.VM_POWER_STATES_ON
|
||||
default:
|
||||
return api.VM_POWER_STATES_OFF
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SInstance) Refresh() error {
|
||||
new, err := self.host.zone.region.GetInstanceByID(self.GetId())
|
||||
new.host = self.host
|
||||
|
||||
+4
@@ -289,6 +289,10 @@ func (self *SModelartsPool) GetStatus() string {
|
||||
switch {
|
||||
case res == compute.MODELARTS_POOL_STATUS_RUNNING && len(self.Status.Resource.Creating) != 0:
|
||||
res = compute.MODELARTS_POOL_STATUS_CREATING
|
||||
case self.Status.Phase == "CreationFailed":
|
||||
res = compute.MODELARTS_POOL_STATUS_CREATE_FAILED
|
||||
case self.Status.Phase == "SeclingFailed":
|
||||
res = compute.MODELARTS_POOL_STATUS_CHANGE_CONFIG_FAILED
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
+4
@@ -82,3 +82,7 @@ func (self *SInstanceBase) GetThroughput() int {
|
||||
func (self *SInstanceBase) GetInternetMaxBandwidthOut() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (ins *SInstanceBase) GetPowerStates() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user