mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: baremetal pxeboot fail to find record of preregistered baremetal
This commit is contained in:
@@ -306,12 +306,9 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&HostDetailOptions{}, "host-delete", "Delete host record", func(s *mcclient.ClientSession, args *HostDetailOptions) error {
|
||||
result, err := modules.Hosts.Delete(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
R(&HostOpsOptions{}, "host-delete", "Delete host record", func(s *mcclient.ClientSession, args *HostOpsOptions) error {
|
||||
results := modules.Hosts.BatchDelete(s, args.ID, nil)
|
||||
printBatchResults(results, modules.Hosts.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -211,16 +211,30 @@ func (h *DHCPHandler) findNetworkConf(filterUseIp bool) (*types.SNetworkConfig,
|
||||
return &network, err
|
||||
}
|
||||
|
||||
// createOrUpdateBaremetal create or update baremetal by client MAC
|
||||
func (h *DHCPHandler) createOrUpdateBaremetal() (jsonutils.JSONObject, error) {
|
||||
func (h *DHCPHandler) findBaremetalsOfAnyMac(isBaremetal bool) (*modules.ListResult, error) {
|
||||
session := h.baremetalManager.GetClientSession()
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(h.ClientMac.String()), "any_mac")
|
||||
params.Add(jsonutils.JSONTrue, "is_baremetal")
|
||||
ret, err := modules.Hosts.List(session, params)
|
||||
if isBaremetal {
|
||||
params.Add(jsonutils.JSONTrue, "is_baremetal")
|
||||
} else {
|
||||
params.Add(jsonutils.NewString("baremetal"), "host_type")
|
||||
}
|
||||
return modules.Hosts.List(session, params)
|
||||
}
|
||||
|
||||
// createOrUpdateBaremetal create or update baremetal by client MAC
|
||||
func (h *DHCPHandler) createOrUpdateBaremetal() (jsonutils.JSONObject, error) {
|
||||
ret, err := h.findBaremetalsOfAnyMac(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(ret.Data) == 0 {
|
||||
ret, err = h.findBaremetalsOfAnyMac(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
switch len(ret.Data) {
|
||||
case 0:
|
||||
// found new baremetal, create it if auto register
|
||||
|
||||
Reference in New Issue
Block a user