yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/cloudprovider/images.go (about)

     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  
    15  package cloudprovider
    16  
    17  import (
    18  	"fmt"
    19  	"time"
    20  )
    21  
    22  type TImageType string
    23  
    24  const (
    25  	IMAGE_STATUS_ACTIVE  = "active"
    26  	IMAGE_STATUS_QUEUED  = "queued"
    27  	IMAGE_STATUS_SAVING  = "saving"
    28  	IMAGE_STATUS_KILLED  = "killed"
    29  	IMAGE_STATUS_DELETED = "deleted"
    30  
    31  	ImageTypeSystem     = TImageType("system")
    32  	ImageTypeCustomized = TImageType("customized")
    33  	ImageTypeShared     = TImageType("shared")
    34  	ImageTypeMarket     = TImageType("market")
    35  )
    36  
    37  type SImage struct {
    38  	Checksum string
    39  	// ContainerFormat string
    40  	CreatedAt  time.Time
    41  	Deleted    bool
    42  	DiskFormat string
    43  	Id         string
    44  	IsPublic   bool
    45  	MinDiskMB  int `json:"min_disk"`
    46  	MinRamMB   int `json:"min_ram"`
    47  	Name       string
    48  	Owner      string
    49  	Properties map[string]string
    50  	Protected  bool
    51  	SizeBytes  int64 `json:"size"`
    52  	Status     string
    53  	// UpdatedAt       time.Time
    54  	PublicScope string
    55  	ExternalId  string
    56  
    57  	// SubImages record the subImages of the guest image.
    58  	// For normal image, it's nil.
    59  	SubImages []SSubImage
    60  
    61  	// EncryptKeyId
    62  	EncryptKeyId string
    63  }
    64  
    65  type SSubImage struct {
    66  	Index     int
    67  	MinDiskMB int
    68  	MinRamMb  int
    69  	SizeBytes int64
    70  }
    71  
    72  type SaveImageOptions struct {
    73  	Name  string
    74  	Notes string
    75  }
    76  
    77  func CloudImage2Image(image ICloudImage) SImage {
    78  	uefiSupport := false
    79  	if image.GetBios() == BIOS {
    80  		uefiSupport = true
    81  	}
    82  	return SImage{
    83  		CreatedAt:  image.GetCreatedAt(),
    84  		Deleted:    false,
    85  		DiskFormat: image.GetImageFormat(),
    86  		Id:         image.GetId(),
    87  		IsPublic:   image.GetImageType() != ImageTypeCustomized,
    88  		MinDiskMB:  image.GetMinOsDiskSizeGb() * 1024,
    89  		MinRamMB:   image.GetMinRamSizeMb(),
    90  		Name:       image.GetName(),
    91  		Properties: map[string]string{
    92  			"os_full_name":    image.GetFullOsName(),
    93  			"os_type":         string(image.GetOsType()),
    94  			"os_distribution": image.GetOsDist(),
    95  			"os_version":      image.GetOsVersion(),
    96  			"os_arch":         image.GetOsArch(),
    97  			"os_language":     image.GetOsLang(),
    98  			"uefi_support":    fmt.Sprintf("%v", uefiSupport),
    99  		},
   100  		Protected: true,
   101  		SizeBytes: image.GetSizeByte(),
   102  		Status:    image.GetImageStatus(),
   103  		SubImages: image.GetSubImages(),
   104  	}
   105  }
   106  
   107  type SImageCreateOption struct {
   108  	ImageId        string
   109  	ExternalId     string
   110  	ImageName      string
   111  	OsType         string
   112  	OsArch         string
   113  	OsDistribution string
   114  	OsVersion      string
   115  	OsFullVersion  string
   116  }