Merge pull request #10845 from ioito/hotfix/qx-vm-account-name

fix(region): optimized vm account name code
This commit is contained in:
Zexi Li
2021-04-20 20:15:07 +08:00
committed by GitHub
13 changed files with 20 additions and 81 deletions
-8
View File
@@ -200,14 +200,6 @@ func (self *SAliyunGuestDriver) GetInstanceCapability() cloudprovider.SInstanceC
}
}
func (self *SAliyunGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
userName := "root"
if desc.OsType == "Windows" {
userName = "Administrator"
}
return userName
}
func (self *SAliyunGuestDriver) AllowReconfigGuest() bool {
return true
}
-9
View File
@@ -17,7 +17,6 @@ package guestdrivers
import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/util/billing"
@@ -61,14 +60,6 @@ func (self *SApsaraGuestDriver) GetGuestInitialStateAfterRebuild() string {
return api.VM_READY
}
func (self *SApsaraGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
userName := "root"
if desc.OsType == "Windows" {
userName = "Administrator"
}
return userName
}
func (self *SApsaraGuestDriver) AllowReconfigGuest() bool {
return true
}
+4 -4
View File
@@ -20,6 +20,7 @@ import (
"strings"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/osprofile"
"yunion.io/x/pkg/utils"
api "yunion.io/x/onecloud/pkg/apis/compute"
@@ -117,10 +118,9 @@ func (self *SAwsGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCapa
}
}
func (self *SAwsGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
// return fetchAwsUserName(desc)
if desc.OsType == "Windows" {
return api.VM_AWS_DEFAULT_WINDOWS_LOGIN_USER
func (self *SAwsGuestDriver) GetDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
if strings.ToLower(desc.OsType) == strings.ToLower(osprofile.OS_TYPE_WINDOWS) {
return api.VM_DEFAULT_WINDOWS_LOGIN_USER
}
return api.VM_AWS_DEFAULT_LOGIN_USER
+1 -1
View File
@@ -252,7 +252,7 @@ func (self *SAzureGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCa
}
}
func (self *SAzureGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
func (self *SAzureGuestDriver) GetDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
return api.VM_AZURE_DEFAULT_LOGIN_USER
}
+6 -5
View File
@@ -18,10 +18,12 @@ import (
"context"
"fmt"
"net/http"
"strings"
"time"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/osprofile"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
@@ -342,12 +344,11 @@ func (self *SBaseGuestDriver) GetUserDataType() string {
return cloudprovider.CLOUD_CONFIG
}
func (self *SBaseGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
userName := "root"
if desc.OsType == "Windows" {
userName = "Administrator"
func (self *SBaseGuestDriver) GetDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
if strings.ToLower(desc.OsType) == strings.ToLower(osprofile.OS_TYPE_WINDOWS) {
return api.VM_DEFAULT_WINDOWS_LOGIN_USER
}
return userName
return api.VM_DEFAULT_LINUX_LOGIN_USER
}
func (self *SBaseGuestDriver) OnGuestChangeCpuMemFailed(ctx context.Context, guest *models.SGuest, data *jsonutils.JSONDict, task taskman.ITask) error {
-8
View File
@@ -113,14 +113,6 @@ func (self *SCtyunGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *mo
return nil
}
func (self *SCtyunGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
if desc.OsType == "Windows" {
return "Administrator"
}
return "root"
}
func init() {
driver := SCtyunGuestDriver{}
models.RegisterGuestDriver(&driver)
-8
View File
@@ -90,14 +90,6 @@ func (self *SEcloudGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *m
return errors.ErrNotImplemented
}
func (self *SEcloudGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
if desc.OsType == "Windows" {
return "Administrator"
}
return "root"
}
func init() {
driver := SEcloudGuestDriver{}
models.RegisterGuestDriver(&driver)
-8
View File
@@ -139,14 +139,6 @@ func (self *SHuaweiGuestDriver) GetInstanceCapability() cloudprovider.SInstanceC
}
}
func (self *SHuaweiGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
userName := "root"
if desc.OsType == "Windows" {
userName = "Administrator"
}
return userName
}
func (self *SHuaweiGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCycle) bool {
months := bc.GetMonths()
if (months >= 1 && months <= 9) || (months == 12) || (months == 24) || (months == 36) {
+1 -9
View File
@@ -388,7 +388,7 @@ func (self *SManagedVirtualizedGuestDriver) RequestDeployGuestOnHost(ctx context
}
}
desc.Account = guest.GetDriver().GetLinuxDefaultAccount(desc)
desc.Account = guest.GetDriver().GetDefaultAccount(desc)
if guest.GetDriver().IsNeedInjectPasswordByCloudInit(&desc) {
err = desc.InjectPasswordByCloudInit()
@@ -475,14 +475,6 @@ func (self *SManagedVirtualizedGuestDriver) GetGuestInitialStateAfterRebuild() s
return api.VM_READY
}
func (self *SManagedVirtualizedGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
userName := "root"
if strings.ToLower(desc.OsType) == strings.ToLower(osprofile.OS_TYPE_WINDOWS) {
userName = "Administrator"
}
return userName
}
func (self *SManagedVirtualizedGuestDriver) RemoteDeployGuestForCreate(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, host *models.SHost, desc cloudprovider.SManagedVMCreateConfig) (jsonutils.JSONObject, error) {
ihost, err := host.GetIHost()
if err != nil {
+7 -4
View File
@@ -17,7 +17,9 @@ package guestdrivers
import (
"context"
"fmt"
"strings"
"yunion.io/x/pkg/util/osprofile"
"yunion.io/x/pkg/utils"
api "yunion.io/x/onecloud/pkg/apis/compute"
@@ -280,16 +282,17 @@ func (self *SQcloudGuestDriver) GetInstanceCapability() cloudprovider.SInstanceC
}
}
func (self *SQcloudGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
userName := "root"
func (self *SQcloudGuestDriver) GetDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
userName := api.VM_DEFAULT_LINUX_LOGIN_USER
if desc.ImageType == "system" {
if desc.OsDistribution == "Ubuntu" {
userName = "ubuntu"
}
}
if desc.OsType == "Windows" {
userName = "Administrator"
if strings.ToLower(desc.OsType) == strings.ToLower(osprofile.OS_TYPE_WINDOWS) {
userName = api.VM_DEFAULT_WINDOWS_LOGIN_USER
}
return userName
}
-8
View File
@@ -111,14 +111,6 @@ func (self *SUCloudGuestDriver) GetInstanceCapability() cloudprovider.SInstanceC
}
}
func (self *SUCloudGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
if desc.OsType == "Windows" {
return "Administrator"
}
return "root"
}
func init() {
driver := SUCloudGuestDriver{}
models.RegisterGuestDriver(&driver)
-8
View File
@@ -173,14 +173,6 @@ func (self *SZStackGuestDriver) GetInstanceCapability() cloudprovider.SInstanceC
}
}
func (self *SZStackGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
userName := "root"
if desc.OsType == "Windows" {
userName = "Administrator"
}
return userName
}
func (self *SZStackGuestDriver) AllowReconfigGuest() bool {
return true
}
+1 -1
View File
@@ -96,7 +96,7 @@ type IGuestDriver interface {
RemoteDeployGuestForRebuildRoot(ctx context.Context, guest *SGuest, ihost cloudprovider.ICloudHost, task taskman.ITask, desc cloudprovider.SManagedVMCreateConfig) (jsonutils.JSONObject, error)
GetGuestInitialStateAfterCreate() string
GetGuestInitialStateAfterRebuild() string
GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string
GetDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string
GetInstanceCapability() cloudprovider.SInstanceCapability
OnGuestDeployTaskDataReceived(ctx context.Context, guest *SGuest, task taskman.ITask, data jsonutils.JSONObject) error