@@ -425,21 +425,23 @@ func (a *InstanceAdmin) Reinstall(ctx context.Context, instance *model.Instance,
425
425
}
426
426
427
427
// rebuild metadata
428
- metadata , err := a .getMetadata (instance )
429
- if err != nil {
430
- logger .Error ("Failed to get instance metadata" , err )
431
- return
428
+ instancePasswd := rootPasswd
429
+ if rootPasswd != "" && image .OSCode != "windows" {
430
+ instancePasswd , err = encrpt .Mkpasswd (rootPasswd , "sha512" )
431
+ if err != nil {
432
+ logger .Errorf ("Failed to encrypt admin password, %v" , err )
433
+ return
434
+ }
432
435
}
433
- metadata .RootPasswd = rootPasswd
434
- jsonData , err := json .Marshal (metadata )
436
+ metadata , err := a .getMetadata (instance , instancePasswd )
435
437
if err != nil {
436
- logger .Errorf ("Failed to marshal instance json data, %v " , err )
438
+ logger .Error ("Failed to get instance metadata " , err )
437
439
return
438
440
}
439
441
440
442
snapshot := total / MaxmumSnapshot + 1 // Same snapshot reference can not be over 128, so use 96 here
441
443
control := fmt .Sprintf ("inter=%d" , instance .Hyper )
442
- command := fmt .Sprintf ("/opt/cloudland/scripts/backend/reinstall_vm.sh '%d' '%s.%s' '%d' '%d' '%s' '%d' '%d' '%d' '%s'<<EOF\n %s\n EOF" , instance .ID , imagePrefix , image .Format , snapshot , bootVolume .ID , bootVolume .GetOriginVolumeID (), flavor .Cpu , flavor .Memory , flavor .Disk , instance .Hostname , base64 .StdEncoding .EncodeToString (jsonData ))
444
+ command := fmt .Sprintf ("/opt/cloudland/scripts/backend/reinstall_vm.sh '%d' '%s.%s' '%d' '%d' '%s' '%d' '%d' '%d' '%s'<<EOF\n %s\n EOF" , instance .ID , imagePrefix , image .Format , snapshot , bootVolume .ID , bootVolume .GetOriginVolumeID (), flavor .Cpu , flavor .Memory , flavor .Disk , instance .Hostname , base64 .StdEncoding .EncodeToString ([] byte ( metadata ) ))
443
445
err = HyperExecute (ctx , control , command )
444
446
if err != nil {
445
447
logger .Error ("Reinstall remote exec failed" , err )
@@ -642,7 +644,7 @@ func (a *InstanceAdmin) buildMetadata(ctx context.Context, primaryIface *Interfa
642
644
return interfaces , string (jsonData ), nil
643
645
}
644
646
645
- func (a * InstanceAdmin ) getMetadata (instance * model.Instance ) (metadata * InstanceData , err error ) {
647
+ func (a * InstanceAdmin ) getMetadata (instance * model.Instance , rootPasswd string ) (metadata string , err error ) {
646
648
vlans := []* VlanInfo {}
647
649
instNetworks := []* InstanceNetwork {}
648
650
instLinks := []* NetworkLink {}
@@ -677,17 +679,23 @@ func (a *InstanceAdmin) getMetadata(instance *model.Instance) (metadata *Instanc
677
679
vlans = append (vlans , & VlanInfo {Device : iface .Name , Vlan : subnet .Vlan , Inbound : iface .Inbound , Outbound : iface .Outbound , AllowSpoofing : iface .AllowSpoofing , Gateway : subnet .Gateway , Router : subnet .RouterID , IpAddr : iface .Address .Address , MacAddr : iface .MacAddr })
678
680
}
679
681
instData := & InstanceData {
680
- Userdata : instance .Userdata ,
681
- VirtType : virtType ,
682
- DNS : dns ,
683
- Vlans : vlans ,
684
- Networks : instNetworks ,
685
- Links : instLinks ,
686
- Keys : instKeys ,
687
- LoginPort : int (instance .LoginPort ),
688
- OSCode : instance .Image .OSCode ,
689
- }
690
- return instData , nil
682
+ Userdata : instance .Userdata ,
683
+ VirtType : virtType ,
684
+ DNS : dns ,
685
+ Vlans : vlans ,
686
+ Networks : instNetworks ,
687
+ Links : instLinks ,
688
+ Keys : instKeys ,
689
+ RootPasswd : rootPasswd ,
690
+ LoginPort : int (instance .LoginPort ),
691
+ OSCode : instance .Image .OSCode ,
692
+ }
693
+ jsonData , err := json .Marshal (instData )
694
+ if err != nil {
695
+ logger .Errorf ("Failed to marshal instance json data, %v" , err )
696
+ return
697
+ }
698
+ return string (jsonData ), nil
691
699
}
692
700
693
701
func (a * InstanceAdmin ) Delete (ctx context.Context , instance * model.Instance ) (err error ) {
0 commit comments