interface.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package diskutils
  15. import (
  16. comapi "yunion.io/x/onecloud/pkg/apis/compute"
  17. "yunion.io/x/onecloud/pkg/hostman/guestfs/fsdriver"
  18. "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
  19. "yunion.io/x/onecloud/pkg/util/qemuimg"
  20. )
  21. type IDisk interface {
  22. Connect(desc *apis.GuestDesc) error
  23. ConnectWithDiskId(desc *apis.GuestDesc, diskId string) error
  24. Disconnect() error
  25. MountRootfs() (fsdriver.IRootFsDriver, error)
  26. UmountRootfs(driver fsdriver.IRootFsDriver) error
  27. Cleanup()
  28. DeployGuestfs(req *apis.DeployParams) (res *apis.DeployGuestFsResponse, err error)
  29. ResizeFs(req *apis.ResizeFsParams) (res *apis.Empty, err error)
  30. FormatFs(req *apis.FormatFsParams) (*apis.Empty, error)
  31. SaveToGlance(req *apis.SaveToGlanceParams) (*apis.SaveToGlanceResponse, error)
  32. ProbeImageInfo(req *apis.ProbeImageInfoPramas) (*apis.ImageInfo, error)
  33. }
  34. type DiskParams struct {
  35. Hypervisor string
  36. DiskInfo qemuimg.SImageInfo
  37. VddkInfo *apis.VDDKConInfo
  38. }
  39. func GetIDisk(params DiskParams, driver string, readOnly bool) (IDisk, error) {
  40. hypervisor := params.Hypervisor
  41. switch hypervisor {
  42. case comapi.HYPERVISOR_KVM:
  43. return NewKVMGuestDisk(params.DiskInfo, driver, readOnly)
  44. case comapi.HYPERVISOR_ESXI:
  45. // ESXI does not support encrypted disk
  46. return NewVDDKDisk(params.VddkInfo, params.DiskInfo.Path, driver, readOnly)
  47. default:
  48. return NewKVMGuestDisk(params.DiskInfo, driver, readOnly)
  49. }
  50. }