Skip to content

Commit

Permalink
fix: host add public ip field (#20114)
Browse files Browse the repository at this point in the history
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
  • Loading branch information
swordqiu and Qiu Jian authored Apr 24, 2024
1 parent c0ae724 commit e231f14
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/climc/shell/compute/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/compute/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions pkg/compute/models/guests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
}
2 changes: 2 additions & 0 deletions pkg/compute/models/hostresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/compute/models/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/compute/tasks/guest_start_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e231f14

Please sign in to comment.