| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- // 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 proxmox
- import (
- "context"
- "fmt"
- "net/url"
- "yunion.io/x/pkg/util/imagetools"
- api "yunion.io/x/cloudmux/pkg/apis/compute"
- "yunion.io/x/cloudmux/pkg/cloudprovider"
- "yunion.io/x/cloudmux/pkg/multicloud"
- )
- type SImage struct {
- multicloud.SImageBase
- ProxmoxTags
- cache *SStoragecache
- imageInfo *imagetools.ImageInfo
- Volid string
- Size int64
- Ctime int64
- Content string
- Format string
- }
- func (self *SImage) GetMinRamSizeMb() int {
- return 0
- }
- func (self *SImage) GetId() string {
- return self.Volid
- }
- func (self *SImage) GetName() string {
- return self.Volid
- }
- func (self *SImage) Delete(ctx context.Context) error {
- return cloudprovider.ErrNotImplemented
- }
- func (self *SImage) GetGlobalId() string {
- return self.GetId()
- }
- func (self *SImage) GetIStoragecache() cloudprovider.ICloudStoragecache {
- return self.cache
- }
- func (self *SImage) GetStatus() string {
- return api.CACHED_IMAGE_STATUS_ACTIVE
- }
- func (self *SImage) GetImageStatus() string {
- return cloudprovider.IMAGE_STATUS_ACTIVE
- }
- func (self *SImage) GetImageType() cloudprovider.TImageType {
- return cloudprovider.ImageTypeSystem
- }
- func (self *SImage) GetSizeByte() int64 {
- return self.Size
- }
- func (img *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
- if img.imageInfo == nil {
- imgInfo := imagetools.NormalizeImageInfo(img.Volid, "", "", "", "")
- img.imageInfo = &imgInfo
- }
- return img.imageInfo
- }
- func (img *SImage) GetOsType() cloudprovider.TOsType {
- return cloudprovider.TOsType(img.getNormalizedImageInfo().OsType)
- }
- func (img *SImage) GetOsDist() string {
- return img.getNormalizedImageInfo().OsDistro
- }
- func (img *SImage) GetOsVersion() string {
- return img.getNormalizedImageInfo().OsVersion
- }
- func (img *SImage) GetOsArch() string {
- return img.getNormalizedImageInfo().OsArch
- }
- func (img *SImage) GetOsLang() string {
- return img.getNormalizedImageInfo().OsLang
- }
- func (img *SImage) GetFullOsName() string {
- return ""
- }
- func (img *SImage) GetBios() cloudprovider.TBiosType {
- return cloudprovider.BIOS
- }
- func (self *SImage) GetMinOsDiskSizeGb() int {
- if self.GetOsType() == "windows" {
- return 40
- }
- return 30
- }
- func (self *SImage) GetImageFormat() string {
- return self.Format
- }
- func (self *SProxmoxClient) GetImages(node, storageName string) ([]SImage, error) {
- images := []SImage{}
- params := url.Values{}
- params.Set("content", "iso")
- path := fmt.Sprintf("/nodes/%s/storage/%s/content", node, storageName)
- err := self.get(path, params, &images)
- if err != nil {
- return nil, err
- }
- return images, nil
- }
- func (self *SRegion) GetImages(node, storageName string) ([]SImage, error) {
- return self.client.GetImages(node, storageName)
- }
|