Skip to content

Commit

Permalink
fix(region): support skip sync host and storage info (#21918)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Jan 2, 2025
1 parent 8c51743 commit e133b83
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 110 deletions.
83 changes: 1 addition & 82 deletions cmd/climc/shell/compute/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func init() {
cmd.List(&compute.HostListOptions{})
cmd.GetMetadata(&options.BaseIdOptions{})
cmd.GetProperty(&compute.HostStatusStatisticsOptions{})
cmd.Update(&compute.HostUpdateOptions{})

cmd.Perform("ping", &options.BaseIdOptions{})
cmd.Perform("purge", &options.BaseIdOptions{})
Expand Down Expand Up @@ -201,88 +202,6 @@ func init() {
return nil
})

type HostUpdateOptions struct {
ID string `help:"ID or Name of Host"`
Name string `help:"New name of the host"`
Desc string `help:"New Description of the host"`
MemoryReserved string `help:"Memory reserved"`
CpuReserved int64 `help:"CPU reserved"`
HostType string `help:"Change host type, CAUTION!!!!" choices:"hypervisor|kubelet|esxi|baremetal"`
// AccessIp string `help:"Change access ip, CAUTION!!!!"`
AccessMac string `help:"Change baremetal access MAC, CAUTION!!!!"`
Uuid string `help:"Change baremetal UUID, CAUTION!!!!"`
EnableNumaAllocate string `help:"Host enable numa allocate" choices:"True|False"`

IpmiUsername string `help:"IPMI user"`
IpmiPassword string `help:"IPMI password"`
IpmiIpAddr string `help:"IPMI ip_addr"`

Sn string `help:"serial number"`

Hostname string `help:"update host name"`

PublicIp string `help:"public_ip"`

NoPublicIp bool `help:"clear public ip"`
}
R(&HostUpdateOptions{}, "host-update", "Update information of a host", func(s *mcclient.ClientSession, args *HostUpdateOptions) error {
params := jsonutils.NewDict()
if len(args.Name) > 0 {
params.Add(jsonutils.NewString(args.Name), "name")
}
if len(args.Desc) > 0 {
params.Add(jsonutils.NewString(args.Desc), "description")
}
if len(args.MemoryReserved) > 0 {
params.Add(jsonutils.NewString(args.MemoryReserved), "mem_reserved")
}
if args.CpuReserved > 0 {
params.Add(jsonutils.NewInt(args.CpuReserved), "cpu_reserved")
}
if len(args.HostType) > 0 {
params.Add(jsonutils.NewString(args.HostType), "host_type")
}
if len(args.AccessMac) > 0 {
params.Add(jsonutils.NewString(args.AccessMac), "access_mac")
}
if len(args.Uuid) > 0 {
params.Add(jsonutils.NewString(args.Uuid), "uuid")
}
if len(args.IpmiUsername) > 0 {
params.Add(jsonutils.NewString(args.IpmiUsername), "ipmi_username")
}
if len(args.IpmiPassword) > 0 {
params.Add(jsonutils.NewString(args.IpmiPassword), "ipmi_password")
}
if len(args.IpmiIpAddr) > 0 {
params.Add(jsonutils.NewString(args.IpmiIpAddr), "ipmi_ip_addr")
}
if len(args.Sn) > 0 {
params.Add(jsonutils.NewString(args.Sn), "sn")
}
if len(args.EnableNumaAllocate) > 0 {
enableNumaAllocate := false
if args.EnableNumaAllocate == "True" {
enableNumaAllocate = true
}
params.Add(jsonutils.NewBool(enableNumaAllocate), "enable_numa_allocate")
}
if len(args.PublicIp) > 0 {
params.Add(jsonutils.NewString(args.PublicIp), "public_ip")
} else if args.NoPublicIp {
params.Add(jsonutils.NewString(""), "public_ip")
}
if params.Size() == 0 {
return fmt.Errorf("Not data to update")
}
result, err := modules.Hosts.Update(s, args.ID, params)
if err != nil {
return err
}
printObject(result)
return nil
})

type HostConvertOptions struct {
ID string `help:"Host ID or Name"`
Name string `help:"New name of the converted host"`
Expand Down
47 changes: 25 additions & 22 deletions pkg/compute/models/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,7 @@ func (hh *SHost) syncRemoveCloudHost(ctx context.Context, userCred mcclient.Toke
}

func (hh *SHost) SyncWithCloudHost(ctx context.Context, userCred mcclient.TokenCredential, extHost cloudprovider.ICloudHost) error {
provider := hh.GetCloudprovider()
diff, err := db.UpdateWithLock(ctx, hh, func() error {
// hh.Name = extHost.GetName()

Expand All @@ -2091,16 +2092,6 @@ func (hh *SHost) SyncWithCloudHost(ctx context.Context, userCred mcclient.TokenC
hh.AccessMac = extHost.GetAccessMac()
hh.SN = extHost.GetSN()
hh.SysInfo = extHost.GetSysInfo()
hh.CpuCount = extHost.GetCpuCount()
hh.NodeCount = extHost.GetNodeCount()
cpuDesc := extHost.GetCpuDesc()
if len(cpuDesc) > 128 {
cpuDesc = cpuDesc[:128]
}
hh.CpuDesc = cpuDesc
hh.CpuMhz = extHost.GetCpuMhz()
hh.MemSize = extHost.GetMemSizeMB()
hh.StorageSize = extHost.GetStorageSizeMB()
hh.StorageType = extHost.GetStorageType()
hh.HostType = extHost.GetHostType()
if hh.HostType == api.HOST_TYPE_BAREMETAL {
Expand All @@ -2112,20 +2103,33 @@ func (hh *SHost) SyncWithCloudHost(ctx context.Context, userCred mcclient.TokenC
}
hh.OvnVersion = extHost.GetOvnVersion()

if cpuCmt := extHost.GetCpuCmtbound(); cpuCmt > 0 {
hh.CpuCmtbound = cpuCmt
}
if provider != nil && !utils.IsInStringArray(provider.Provider, strings.Split(options.Options.SkipSyncHostConfigInfoProviders, ",")) {
hh.CpuCount = extHost.GetCpuCount()
hh.NodeCount = extHost.GetNodeCount()
cpuDesc := extHost.GetCpuDesc()
if len(cpuDesc) > 128 {
cpuDesc = cpuDesc[:128]
}
hh.CpuDesc = cpuDesc
hh.CpuMhz = extHost.GetCpuMhz()
hh.MemSize = extHost.GetMemSizeMB()
hh.StorageSize = extHost.GetStorageSizeMB()

if memCmt := extHost.GetMemCmtbound(); memCmt > 0 {
hh.MemCmtbound = memCmt
}
if cpuCmt := extHost.GetCpuCmtbound(); cpuCmt > 0 {
hh.CpuCmtbound = cpuCmt
}

if arch := extHost.GetCpuArchitecture(); len(arch) > 0 {
hh.CpuArchitecture = arch
}
if memCmt := extHost.GetMemCmtbound(); memCmt > 0 {
hh.MemCmtbound = memCmt
}

if arch := extHost.GetCpuArchitecture(); len(arch) > 0 {
hh.CpuArchitecture = arch
}

if reservedMem := extHost.GetReservedMemoryMb(); reservedMem > 0 {
hh.MemReserved = reservedMem
if reservedMem := extHost.GetReservedMemoryMb(); reservedMem > 0 {
hh.MemReserved = reservedMem
}
}

hh.IsEmulated = extHost.IsEmulated()
Expand All @@ -2142,7 +2146,6 @@ func (hh *SHost) SyncWithCloudHost(ctx context.Context, userCred mcclient.TokenC

db.OpsLog.LogSyncUpdate(hh, diff, userCred)

provider := hh.GetCloudprovider()
if provider != nil {
SyncCloudDomain(userCred, hh, provider.GetOwnerId())
hh.SyncShareState(ctx, userCred, provider.getAccountShareInfo())
Expand Down
17 changes: 11 additions & 6 deletions pkg/compute/models/storages.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"path"
"strconv"
"strings"

"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/jsonutils"
Expand Down Expand Up @@ -1103,13 +1104,17 @@ func (self *SStorage) syncWithCloudStorage(ctx context.Context, userCred mcclien
// self.Name = extStorage.GetName()
self.Status = ext.GetStatus()
self.StorageType = ext.GetStorageType()
self.MediumType = ext.GetMediumType()
if capacity := ext.GetCapacityMB(); capacity != 0 {
self.Capacity = capacity
}
if capacity := ext.GetCapacityUsedMB(); capacity != 0 {
self.ActualCapacityUsed = capacity

if provider != nil && !utils.IsInStringArray(provider.Provider, strings.Split(options.Options.SkipSyncStorageConfigInfoProviders, ",")) {
self.MediumType = ext.GetMediumType()
if capacity := ext.GetCapacityMB(); capacity != 0 {
self.Capacity = capacity
}
if capacity := ext.GetCapacityUsedMB(); capacity != 0 {
self.ActualCapacityUsed = capacity
}
}

self.StorageConf = ext.GetStorageConf()

self.Enabled = tristate.NewFromBool(ext.GetEnabled())
Expand Down
3 changes: 3 additions & 0 deletions pkg/compute/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ type ComputeOptions struct {

ResourceExpiredNotifyDays []int `help:"The notify of resource expired" default:"1,3,30"`

SkipSyncHostConfigInfoProviders string `help:"Skip sync host cpu and mem config by provider"`
SkipSyncStorageConfigInfoProviders string `help:"Skip sync storage capacity and media type config by provider"`

esxi.EsxiOptions

NetworkAlwaysManualConfig bool `help:"always manually configure network settings" default:"false"`
Expand Down
47 changes: 47 additions & 0 deletions pkg/mcclient/options/compute/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,50 @@ func (h HostValidateIPMI) Params() (jsonutils.JSONObject, error) {
Password: h.PASSWORD,
}), nil
}

type HostUpdateOptions struct {
options.BaseIdOptions
Name string `help:"New name of the host"`
Description *string `help:"New Description of the host"`
MemReserved *string `help:"Memory reserved"`
CpuReserved *int64 `help:"CPU reserved"`
HostType *string `help:"Change host type, CAUTION!!!!" choices:"hypervisor|kubelet|esxi|baremetal"`
CpuCount *int
NodeCount *int8
CpuDesc *string
MemSize *int
StorageSize *int64
// AccessIp string `help:"Change access ip, CAUTION!!!!"`
AccessMac *string `help:"Change baremetal access MAC, CAUTION!!!!"`
Uuid *string `help:"Change baremetal UUID, CAUTION!!!!"`
EnableNumaAllocate string `help:"Host enable numa allocate" choices:"True|False"`

IpmiUsername *string `help:"IPMI user"`
IpmiPassword *string `help:"IPMI password"`
IpmiIpAddr *string `help:"IPMI ip_addr"`

Sn *string `help:"serial number"`

Hostname *string `help:"update host name"`

PublicIp *string `help:"public_ip"`

NoPublicIp *bool `help:"clear public ip"`
}

func (opts *HostUpdateOptions) Params() (jsonutils.JSONObject, error) {
v := jsonutils.Marshal(opts).(*jsonutils.JSONDict)
if opts.NoPublicIp != nil && *opts.NoPublicIp {
v.Set("public_ip", jsonutils.NewString(""))
v.Remove("no_public_ip")
}
if len(opts.EnableNumaAllocate) > 0 {
enableNumaAllocate := false
if opts.EnableNumaAllocate == "True" {
enableNumaAllocate = true
}
v.Set("enable_numa_allocate", jsonutils.NewBool(enableNumaAllocate))
}
v.Remove("id")
return v, nil
}

0 comments on commit e133b83

Please sign in to comment.