mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-30 18:23:35 +08:00
fix baremetal online prepare!
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
@@ -49,19 +50,25 @@ func getBmAgentUrl(ctx context.Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
n, _ := models.NetworkManager.GetOnPremiseNetworkOfIP(ipAddr, "baremetal", tristate.None)
|
||||
n, _ := models.NetworkManager.GetOnPremiseNetworkOfIP(
|
||||
ipAddr, compute.NETWORK_TYPE_IPMI, tristate.None)
|
||||
if n == nil {
|
||||
n, _ = models.NetworkManager.GetOnPremiseNetworkOfIP(
|
||||
ipAddr, compute.NETWORK_TYPE_BAREMETAL, tristate.None)
|
||||
}
|
||||
if n == nil {
|
||||
httperrors.NotFoundError(w, "Network not found")
|
||||
return
|
||||
}
|
||||
|
||||
zoneId := n.GetWire().ZoneId
|
||||
bmAgentUrl, err := auth.GetServiceURL("baremetal", options.Options.Region, zoneId, "")
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
httperrors.InternalServerError(w, err.Error())
|
||||
bmAgent := models.BaremetalagentManager.GetAgent(compute.AgentTypeBaremetal, zoneId)
|
||||
if bmAgent == nil {
|
||||
httperrors.InternalServerError(w, "Baremetal agent not found")
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, bmAgentUrl)
|
||||
|
||||
fmt.Fprintf(w, bmAgent.ManagerUri)
|
||||
}
|
||||
|
||||
func getBmPrepareScript(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -2919,6 +2919,56 @@ func (self *SHost) StartPrepareTask(ctx context.Context, userCred mcclient.Token
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SHost) AllowPerformInitialize(
|
||||
ctx context.Context, userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject, data jsonutils.JSONObject,
|
||||
) bool {
|
||||
return db.IsAdminAllowPerform(userCred, self, "initialize")
|
||||
}
|
||||
|
||||
func (self *SHost) PerformInitialize(
|
||||
ctx context.Context, userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject, data jsonutils.JSONObject,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
if !utils.IsInStringArray(
|
||||
self.Status, []string{api.BAREMETAL_INIT, api.BAREMETAL_PREPARE_FAIL}) {
|
||||
return nil, httperrors.NewBadRequestError(
|
||||
"Cannot do initialization in status %s", self.Status)
|
||||
}
|
||||
|
||||
name, err := data.GetString("name")
|
||||
if err != nil || self.GetBaremetalServer() != nil {
|
||||
return nil, nil
|
||||
}
|
||||
err = db.NewNameValidator(GuestManager, userCred.GetProjectId(), name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if self.IpmiInfo == nil || !self.IpmiInfo.Contains("ip_addr") ||
|
||||
!self.IpmiInfo.Contains("password") {
|
||||
return nil, httperrors.NewBadRequestError("IPMI infomation not configured")
|
||||
}
|
||||
guest := &SGuest{}
|
||||
guest.Name = name
|
||||
guest.VmemSize = self.MemSize
|
||||
guest.VcpuCount = self.CpuCount
|
||||
guest.DisableDelete = tristate.True
|
||||
guest.Hypervisor = api.HYPERVISOR_BAREMETAL
|
||||
guest.HostId = self.Id
|
||||
guest.ProjectId = userCred.GetProjectId()
|
||||
guest.Status = api.VM_RUNNING
|
||||
guest.OsType = "Linux"
|
||||
guest.SetModelManager(GuestManager)
|
||||
err = GuestManager.TableSpec().Insert(guest)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInternalServerError("Guest Insert error: %s", err)
|
||||
}
|
||||
guest.SetAllMetadata(ctx, map[string]interface{}{
|
||||
"is_fake_baremetal_server": true, "host_ip": self.AccessIp}, userCred)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SHost) AllowPerformAddNetif(ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
|
||||
Reference in New Issue
Block a user