mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
bm register use domain token
This commit is contained in:
@@ -231,7 +231,7 @@ func handleServerStatus(ctx *Context, bm *baremetal.SBaremetalInstance, _ bareme
|
||||
|
||||
func handleBaremetalRegister(ctx *Context, input *baremetal.BmRegisterInput) {
|
||||
ctx.DelayProcess(func(data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
baremetal.GetBaremetalManager().RegisterBaremetal(ctx, input)
|
||||
baremetal.GetBaremetalManager().RegisterBaremetal(ctx, ctx.userCred, input)
|
||||
return nil, nil
|
||||
}, nil)
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ func (i *BmRegisterInput) isTimeout() bool {
|
||||
}
|
||||
|
||||
// delay task
|
||||
func (m *SBaremetalManager) RegisterBaremetal(ctx context.Context, input *BmRegisterInput) {
|
||||
func (m *SBaremetalManager) RegisterBaremetal(ctx context.Context, userCred mcclient.TokenCredential, input *BmRegisterInput) {
|
||||
adminWire, err := m.checkNetworkFromIp(input.RemoteIp)
|
||||
if input.isTimeout() {
|
||||
return
|
||||
@@ -341,7 +341,7 @@ func (m *SBaremetalManager) RegisterBaremetal(ctx context.Context, input *BmRegi
|
||||
}
|
||||
|
||||
registerTask := tasks.NewBaremetalRegisterTask(
|
||||
m, sshCli, input.Hostname, input.RemoteIp,
|
||||
userCred, m, sshCli, input.Hostname, input.RemoteIp,
|
||||
input.Username, input.Password, input.IpAddr,
|
||||
ipmiMac, ipmiLanChannel, adminWire, ipmiWire,
|
||||
)
|
||||
@@ -750,11 +750,10 @@ func (b *SBaremetalInstance) SyncStatusBackground() {
|
||||
}()
|
||||
}
|
||||
|
||||
func (b *SBaremetalInstance) InitializeServer(name string) error {
|
||||
func (b *SBaremetalInstance) InitializeServer(s *mcclient.ClientSession, name string) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("name", jsonutils.NewString(name))
|
||||
_, err := modules.Hosts.PerformAction(
|
||||
b.manager.GetClientSession(), b.GetId(), "initialize", params)
|
||||
_, err := modules.Hosts.PerformAction(s, b.GetId(), "initialize", params)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ import (
|
||||
o "yunion.io/x/onecloud/pkg/baremetal/options"
|
||||
"yunion.io/x/onecloud/pkg/baremetal/utils/ipmitool"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/types"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/util/redfish"
|
||||
"yunion.io/x/onecloud/pkg/util/ssh"
|
||||
@@ -55,24 +57,30 @@ type sBaremetalRegisterTask struct {
|
||||
accessNic *types.SNicDevInfo
|
||||
}
|
||||
|
||||
func NewBaremetalRegisterTask(bmManager IBmManager, sshCli *ssh.Client,
|
||||
func NewBaremetalRegisterTask(
|
||||
userCred mcclient.TokenCredential, bmManager IBmManager, sshCli *ssh.Client,
|
||||
hostname, remoteIp, ipmiUsername, ipmiPassword, ipmiIpAddr string,
|
||||
ipmiMac net.HardwareAddr, ipmiLanChannel int, adminWire, ipmiWire string) *sBaremetalRegisterTask {
|
||||
return &sBaremetalRegisterTask{
|
||||
BmManager: bmManager,
|
||||
SshCli: sshCli,
|
||||
Hostname: hostname,
|
||||
RemoteIp: remoteIp,
|
||||
IpmiUsername: ipmiUsername,
|
||||
IpmiPassword: ipmiPassword,
|
||||
IpmiIpAddr: ipmiIpAddr,
|
||||
IpmiMac: ipmiMac,
|
||||
IpmiLanChannel: ipmiLanChannel,
|
||||
AdminWire: adminWire,
|
||||
IpmiWire: ipmiWire,
|
||||
sBaremetalPrepareTask: sBaremetalPrepareTask{userCred: userCred},
|
||||
BmManager: bmManager,
|
||||
SshCli: sshCli,
|
||||
Hostname: hostname,
|
||||
RemoteIp: remoteIp,
|
||||
IpmiUsername: ipmiUsername,
|
||||
IpmiPassword: ipmiPassword,
|
||||
IpmiIpAddr: ipmiIpAddr,
|
||||
IpmiMac: ipmiMac,
|
||||
IpmiLanChannel: ipmiLanChannel,
|
||||
AdminWire: adminWire,
|
||||
IpmiWire: ipmiWire,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *sBaremetalRegisterTask) getSession() *mcclient.ClientSession {
|
||||
return auth.GetSession(context.Background(), s.userCred, o.Options.Region, "v2")
|
||||
}
|
||||
|
||||
func (s *sBaremetalRegisterTask) getAccessDevMacAddr(ip string) (string, error) {
|
||||
nicsRet, err := s.SshCli.Run("/sbin/ip -o -4 addr show")
|
||||
if err != nil {
|
||||
@@ -136,7 +144,7 @@ func (s *sBaremetalRegisterTask) CreateBaremetal() (string, error) {
|
||||
params.Set("host_type", jsonutils.NewString("baremetal"))
|
||||
params.Set("is_baremetal", jsonutils.JSONTrue)
|
||||
params.Set("is_import", jsonutils.JSONTrue)
|
||||
res, err := modules.Hosts.CreateInContext(s.BmManager.GetClientSession(), params, &modules.Zones, zoneId)
|
||||
res, err := modules.Hosts.CreateInContext(s.getSession(), params, &modules.Zones, zoneId)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Create baremetal failed: %s", err)
|
||||
}
|
||||
@@ -295,7 +303,7 @@ func (s *sBaremetalRegisterTask) updateBmInfo(cli *ssh.Client, i *baremetalPrepa
|
||||
}
|
||||
|
||||
func (s *sBaremetalRegisterTask) initBaremetalServer() error {
|
||||
if err := s.baremetal.InitializeServer(s.Hostname); err != nil {
|
||||
if err := s.baremetal.InitializeServer(s.getSession(), s.Hostname); err != nil {
|
||||
return fmt.Errorf("Baremteal Create Server Failed %s", err)
|
||||
}
|
||||
// if err := s.baremetal.SaveSSHConfig("", ""); err != nil {
|
||||
|
||||
@@ -64,7 +64,7 @@ type IBaremetal interface {
|
||||
GetImageCacheUrl() string
|
||||
|
||||
RemoveServer()
|
||||
InitializeServer(name string) error
|
||||
InitializeServer(session *mcclient.ClientSession, name string) error
|
||||
SaveSSHConfig(remoteAddr string, key string) error
|
||||
ServerLoadDesc() error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user