diff --git a/cmd/climc/shell/compute/hosts.go b/cmd/climc/shell/compute/hosts.go index 9ba6f832af..b8f433dd6c 100644 --- a/cmd/climc/shell/compute/hosts.go +++ b/cmd/climc/shell/compute/hosts.go @@ -193,6 +193,10 @@ func init() { 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() @@ -242,6 +246,11 @@ func init() { } 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") } diff --git a/pkg/apis/compute/host.go b/pkg/apis/compute/host.go index d0500f745d..e5a8c8147c 100644 --- a/pkg/apis/compute/host.go +++ b/pkg/apis/compute/host.go @@ -296,6 +296,11 @@ type HostResourceInfo struct { // 宿主机类型 HostType string `json:"host_type"` + + // 宿主机管理IP + HostAccessIp string `json:"host_access_ip"` + // 宿主机公网IP(如果有) + HostEIP string `json:"host_eip"` } type HostFilterListInput struct { @@ -355,6 +360,9 @@ type HostAccessAttributes struct { AccessNet string `json:"access_net"` // 物理机管理口二次网络 AccessWire string `json:"access_wire"` + + // 公网IP + PublicIp *string `json:"public_ip"` } type HostSizeAttributes struct { diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 7198b39543..92205b6a46 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -188,6 +188,9 @@ type SGuest struct { PowerStates string `width:"36" charset:"ascii" nullable:"false" default:"unknown" list:"user" create:"optional"` // Used for guest rescue RescueMode bool `nullable:"false" default:"false" list:"user" create:"optional"` + + // 上次开机时间 + LastStartAt time.Time `json:"last_start_at" list:"user"` } func (manager *SGuestManager) GetPropertyStatistics(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*apis.StatusStatistic, error) { @@ -6839,3 +6842,11 @@ func (guest *SGuest) getDisksCandidateHostIds() ([]string, error) { } return ret, nil } + +func (guest *SGuest) SaveLastStartAt() error { + _, err := db.Update(guest, func() error { + guest.LastStartAt = time.Now().UTC() + return nil + }) + return errors.Wrap(err, "SaveLastStartAt") +} diff --git a/pkg/compute/models/hostresource.go b/pkg/compute/models/hostresource.go index ba43d88f2f..b7132e69d2 100644 --- a/pkg/compute/models/hostresource.go +++ b/pkg/compute/models/hostresource.go @@ -108,6 +108,8 @@ func (manager *SHostResourceBaseManager) FetchCustomizeColumns( rows[i].HostEnabled = host.Enabled.Bool() rows[i].HostServiceStatus = host.HostStatus rows[i].HostType = host.HostType + rows[i].HostAccessIp = host.AccessIp + rows[i].HostEIP = host.PublicIp rows[i].ManagerId = host.ManagerId rows[i].ZoneId = host.ZoneId } diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 4a84382b5a..486bb9daef 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -209,6 +209,9 @@ type SHost struct { // UEFI详情 UefiInfo jsonutils.JSONObject `nullable:"true" get:"domain" update:"domain" create:"domain_optional"` + + // 公网Ip地址 + PublicIp string `width:"16" charset:"ascii" nullable:"true" list:"domain" update:"domain"` } func (manager *SHostManager) GetContextManagers() [][]db.IModelManager { diff --git a/pkg/compute/tasks/guest_start_task.go b/pkg/compute/tasks/guest_start_task.go index f2a5e7954e..cb8705c26b 100644 --- a/pkg/compute/tasks/guest_start_task.go +++ b/pkg/compute/tasks/guest_start_task.go @@ -61,6 +61,8 @@ func (task *GuestStartTask) OnStartComplete(ctx context.Context, obj db.IStandal // save start mem and cpu guest.SetMetadata(ctx, api.VM_METADATA_START_VCPU_COUNT, guest.VcpuCount, task.UserCred) guest.SetMetadata(ctx, api.VM_METADATA_START_VMEM_MB, guest.VmemSize, task.UserCred) + // save start time + guest.SaveLastStartAt() // sync Vpc Topology isVpc, err := guest.IsOneCloudVpcNetwork() if err != nil {