mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
解决冲突
This commit is contained in:
@@ -101,7 +101,7 @@ func (host *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, erro
|
||||
}
|
||||
|
||||
func (host *SHost) GetIVMs() ([]cloudprovider.ICloudVM, error) {
|
||||
instances, err := host.zone.region.GetInstances(host.zone.ZoneName, host.GetName())
|
||||
instances, err := host.zone.region.GetInstances(host.GetName())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -125,9 +125,9 @@ func (region *SRegion) GetSecurityGroupsByInstance(instanceId string) ([]Securit
|
||||
return secgroups, resp.Unmarshal(&secgroups, "security_groups")
|
||||
}
|
||||
|
||||
func (region *SRegion) GetInstances(zoneName string, hostName string) ([]SInstance, error) {
|
||||
func (region *SRegion) GetInstances(hostName string) ([]SInstance, error) {
|
||||
_, maxVersion, _ := region.GetVersion("compute")
|
||||
_, resp, err := region.List("compute", "/servers/detail", maxVersion, nil)
|
||||
_, resp, err := region.List("compute", "/servers/detail?all_tenants=True", maxVersion, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -136,10 +136,8 @@ func (region *SRegion) GetInstances(zoneName string, hostName string) ([]SInstan
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(instances); i++ {
|
||||
if len(zoneName) == 0 || instances[i].AvailabilityZone == zoneName {
|
||||
if len(hostName) == 0 || hostName == instances[i].Host {
|
||||
result = append(result, instances[i])
|
||||
}
|
||||
if len(hostName) == 0 || hostName == instances[i].Host {
|
||||
result = append(result, instances[i])
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
|
||||
@@ -193,7 +193,8 @@ func (region *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error)
|
||||
}
|
||||
|
||||
func (region *SRegion) fetchZones() error {
|
||||
_, resp, err := region.List("compute", "/os-availability-zone", "", jsonutils.NewDict())
|
||||
zone := &SZone{region: region, ZoneName: region.Name, cachedHosts: map[string][]string{}}
|
||||
_, resp, err := region.List("compute", "/os-availability-zone/detail", "", jsonutils.NewDict())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -201,14 +202,20 @@ func (region *SRegion) fetchZones() error {
|
||||
if err := resp.Unmarshal(&zones, "availabilityZoneInfo"); err != nil {
|
||||
return err
|
||||
}
|
||||
region.izones = []cloudprovider.ICloudZone{}
|
||||
for i := 0; i < len(zones); i++ {
|
||||
if zones[i].ZoneName == "internal" {
|
||||
continue
|
||||
}
|
||||
zones[i].region = region
|
||||
region.izones = append(region.izones, &zones[i])
|
||||
zone.cachedHosts[zones[i].ZoneName] = []string{}
|
||||
for hostname, hostInfo := range zones[i].Hosts {
|
||||
for k := range hostInfo {
|
||||
if k == "nova-compute" {
|
||||
zone.cachedHosts[zones[i].ZoneName] = append(zone.cachedHosts[zones[i].ZoneName], hostname)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
region.izones = []cloudprovider.ICloudZone{zone}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,10 @@ import (
|
||||
|
||||
func init() {
|
||||
type InstanceListOptions struct {
|
||||
ZoneID string `help:"Zone ID for filter instance list"`
|
||||
Host string `help:"Host name for filter instance list"`
|
||||
Host string `help:"Host name for filter instance list"`
|
||||
}
|
||||
shellutils.R(&InstanceListOptions{}, "instance-list", "List instances", func(cli *openstack.SRegion, args *InstanceListOptions) error {
|
||||
instances, err := cli.GetInstances(args.ZoneID, args.Host)
|
||||
instances, err := cli.GetInstances(args.Host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package openstack
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -20,14 +21,23 @@ const (
|
||||
HYPERVISORS_VERSION = "2.28"
|
||||
)
|
||||
|
||||
type HostState struct {
|
||||
Available bool
|
||||
Active bool
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type SZone struct {
|
||||
region *SRegion
|
||||
|
||||
iwires []cloudprovider.ICloudWire
|
||||
istorages []cloudprovider.ICloudStorage
|
||||
|
||||
ZoneName string
|
||||
ZoneState ZoneState
|
||||
ZoneName string
|
||||
|
||||
cachedHosts map[string][]string
|
||||
|
||||
Hosts map[string]map[string]HostState
|
||||
}
|
||||
|
||||
func (zone *SZone) GetMetadata() *jsonutils.JSONDict {
|
||||
@@ -47,14 +57,11 @@ func (zone *SZone) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (zone *SZone) IsEmulated() bool {
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
||||
func (zone *SZone) GetStatus() string {
|
||||
if zone.ZoneState.Available {
|
||||
return models.ZONE_ENABLE
|
||||
}
|
||||
return models.ZONE_SOLDOUT
|
||||
return models.ZONE_ENABLE
|
||||
}
|
||||
|
||||
func (zone *SZone) Refresh() error {
|
||||
@@ -151,6 +158,11 @@ func (zone *SZone) GetIHosts() ([]cloudprovider.ICloudHost, error) {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(hosts); i++ {
|
||||
// 过滤vmware的机器
|
||||
hypervisor := strings.ToLower(hosts[i].HypervisorType)
|
||||
if strings.Index(hypervisor, "vmware") != -1 {
|
||||
continue
|
||||
}
|
||||
hosts[i].zone = zone
|
||||
ihosts = append(ihosts, &hosts[i])
|
||||
}
|
||||
@@ -168,7 +180,7 @@ func (zone *SZone) GetIHosts() ([]cloudprovider.ICloudHost, error) {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(_hosts); i++ {
|
||||
if _hosts[i].Zone == zone.ZoneName && _hosts[i].Service == "compute" {
|
||||
if _hosts[i].Service == "compute" {
|
||||
host := SHost{HostName: _hosts[i].HostName, Zone: _hosts[i].Zone, zone: zone}
|
||||
ihosts = append(ihosts, &host)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user