From efae12b7276413006d71fdcd629f1e54b5a46d99 Mon Sep 17 00:00:00 2001 From: ioito Date: Mon, 17 Oct 2022 17:04:00 +0800 Subject: [PATCH] fix(region): incloudshpere reset password --- pkg/compute/guestdrivers/incloudsphere.go | 6 +++- pkg/multicloud/incloudsphere/disk.go | 7 ++-- pkg/multicloud/incloudsphere/host.go | 7 ++-- pkg/multicloud/incloudsphere/nic.go | 1 + pkg/multicloud/incloudsphere/shell/version.go | 33 +++++++++++++++++++ pkg/multicloud/incloudsphere/storagecache.go | 3 +- pkg/multicloud/incloudsphere/version.go | 24 ++++++++++++++ 7 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 pkg/multicloud/incloudsphere/shell/version.go create mode 100644 pkg/multicloud/incloudsphere/version.go diff --git a/pkg/compute/guestdrivers/incloudsphere.go b/pkg/compute/guestdrivers/incloudsphere.go index 6e5c36a252..285ded613d 100644 --- a/pkg/compute/guestdrivers/incloudsphere.go +++ b/pkg/compute/guestdrivers/incloudsphere.go @@ -94,6 +94,10 @@ func (self *SInCloudSphereGuestDriver) GetDefaultSysDiskBackend() string { return api.STORAGE_LOCAL } +func (self *SInCloudSphereGuestDriver) IsNeedRestartForResetLoginInfo() bool { + return false +} + func (self *SInCloudSphereGuestDriver) IsNeedInjectPasswordByCloudInit() bool { return true } @@ -116,7 +120,7 @@ func (self *SInCloudSphereGuestDriver) GetAttachDiskStatus() ([]string, error) { } func (self *SInCloudSphereGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) { - return []string{api.VM_READY}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SInCloudSphereGuestDriver) GetRebuildRootStatus() ([]string, error) { diff --git a/pkg/multicloud/incloudsphere/disk.go b/pkg/multicloud/incloudsphere/disk.go index 7dea8b2d22..b69739a1a4 100644 --- a/pkg/multicloud/incloudsphere/disk.go +++ b/pkg/multicloud/incloudsphere/disk.go @@ -212,8 +212,11 @@ func (self *SRegion) ResizeDisk(id string, sizeGb int) error { return errors.Wrapf(err, "GetDisk(%s)", id) } body := map[string]interface{}{ - "size": sizeGb, - "name": disk.Name, + "size": sizeGb, + "name": disk.Name, + "bootable": disk.Bootable, + "volumePolicy": disk.VolumePolicy, + "dataStoreType": disk.DataStoreType, } return self.put("/volumes/"+disk.Id, nil, jsonutils.Marshal(body), nil) } diff --git a/pkg/multicloud/incloudsphere/host.go b/pkg/multicloud/incloudsphere/host.go index 2c2d0bc37d..8657295867 100644 --- a/pkg/multicloud/incloudsphere/host.go +++ b/pkg/multicloud/incloudsphere/host.go @@ -228,6 +228,7 @@ func (self *SHost) CreateVM(opts *cloudprovider.SManagedVMCreateConfig) (cloudpr if strings.HasSuffix(opts.ExternalImageId, "qcow2") { format = "QCOW2" } + sizeGb := float64((image.GetSizeByte() + 1024/2) / 1024 / 1024 / 1024) disks := []Disks{} disks = append(disks, Disks{ BusModel: "IDE", @@ -237,7 +238,7 @@ func (self *SHost) CreateVM(opts *cloudprovider.SManagedVMCreateConfig) (cloudpr Bootable: true, DataStoreId: opts.SysDisk.StorageExternalId, Format: format, - Size: float64((image.GetSizeByte() + 1024/2) / 1024 / 1024 / 1024), + Size: sizeGb, VolumePolicy: "THIN", VvSourceDto: VvSourceDto{ FilePath: fmt.Sprintf("%s/%s", image.Path, image.Name), @@ -316,7 +317,9 @@ func (self *SHost) CreateVM(opts *cloudprovider.SManagedVMCreateConfig) (cloudpr DeviceType: "NETWORK", Model: "E1000", Queues: 1, - IP: opts.IpAddr, + Dhcp: true, + DhcpEnabled: true, + DhcpIP: opts.IpAddr, }, }, "panickPolicy": "NO_ACTION", diff --git a/pkg/multicloud/incloudsphere/nic.go b/pkg/multicloud/incloudsphere/nic.go index 5889d46f8f..bba4b95bee 100644 --- a/pkg/multicloud/incloudsphere/nic.go +++ b/pkg/multicloud/incloudsphere/nic.go @@ -91,6 +91,7 @@ type SInstanceNic struct { SystemVMType string `json:"systemVmType"` Dhcp bool `json:"dhcp"` DhcpIP string `json:"dhcpIp"` + DhcpEnabled bool `json:"dhcpEnabled"` UsedDpdk bool `json:"usedDpdk"` Queues int `json:"queues"` } diff --git a/pkg/multicloud/incloudsphere/shell/version.go b/pkg/multicloud/incloudsphere/shell/version.go new file mode 100644 index 0000000000..796bda1742 --- /dev/null +++ b/pkg/multicloud/incloudsphere/shell/version.go @@ -0,0 +1,33 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package shell + +import ( + "yunion.io/x/onecloud/pkg/multicloud/incloudsphere" + "yunion.io/x/onecloud/pkg/util/shellutils" +) + +func init() { + type VersionShowOptions struct { + } + shellutils.R(&VersionShowOptions{}, "version-show", "show version", func(cli *incloudsphere.SRegion, args *VersionShowOptions) error { + version, err := cli.GetClient().GetVersion() + if err != nil { + return err + } + printObject(version) + return nil + }) +} diff --git a/pkg/multicloud/incloudsphere/storagecache.go b/pkg/multicloud/incloudsphere/storagecache.go index 80563a708b..712544817f 100644 --- a/pkg/multicloud/incloudsphere/storagecache.go +++ b/pkg/multicloud/incloudsphere/storagecache.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/errors" + "yunion.io/x/pkg/utils" "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/mcclient" @@ -62,7 +63,7 @@ func (self *SStoragecache) GetICloudImages() ([]cloudprovider.ICloudImage, error return nil, err } for j := range images { - if images[j].GetImageFormat() == "iso" { + if utils.IsInStringArray(images[j].GetImageFormat(), []string{"iso", "ova"}) { continue } images[j].cache = self diff --git a/pkg/multicloud/incloudsphere/version.go b/pkg/multicloud/incloudsphere/version.go new file mode 100644 index 0000000000..63897d87bf --- /dev/null +++ b/pkg/multicloud/incloudsphere/version.go @@ -0,0 +1,24 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package incloudsphere + +type SVersion struct { + DisplayVersion string +} + +func (self *SphereClient) GetVersion() (*SVersion, error) { + ret := &SVersion{} + return ret, self.get("system/version", nil, ret) +}