yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/classic_disk.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 azure 16 17 import ( 18 "context" 19 "net/url" 20 "strings" 21 "time" 22 23 "yunion.io/x/pkg/errors" 24 25 billing_api "yunion.io/x/cloudmux/pkg/apis/billing" 26 api "yunion.io/x/cloudmux/pkg/apis/compute" 27 "yunion.io/x/cloudmux/pkg/cloudprovider" 28 "yunion.io/x/cloudmux/pkg/multicloud" 29 ) 30 31 type ClassicProperties struct { 32 DiskName string 33 Caching string 34 OperatingSystem string 35 IoType string 36 DiskSizeGB int32 37 DiskSize int32 38 diskSizeMB int32 39 CreatedTime string 40 SourceImageName string 41 VhdUri string 42 StorageAccount SubResource 43 } 44 45 type SClassicDisk struct { 46 multicloud.SDisk 47 AzureTags 48 region *SRegion 49 50 Id string 51 Name string 52 Type string 53 Properties ClassicProperties 54 } 55 56 func (self *SClassicDisk) CreateISnapshot(ctx context.Context, name, desc string) (cloudprovider.ICloudSnapshot, error) { 57 return nil, cloudprovider.ErrNotSupported 58 } 59 60 func (self *SRegion) GetClassicDisk(id string) (*SClassicDisk, error) { 61 disk := &SClassicDisk{region: self} 62 err := self.get(id, url.Values{}, disk) 63 if err != nil { 64 return nil, errors.Wrapf(err, "get(%s)", id) 65 } 66 return disk, nil 67 } 68 69 func (self *SClassicDisk) Delete(ctx context.Context) error { 70 return cloudprovider.ErrNotImplemented 71 } 72 73 func (self *SClassicDisk) GetBillingType() string { 74 return billing_api.BILLING_TYPE_POSTPAID 75 } 76 77 func (self *SClassicDisk) GetFsFormat() string { 78 return "" 79 } 80 81 func (self *SClassicDisk) GetIsNonPersistent() bool { 82 return false 83 } 84 85 func (self *SClassicDisk) GetDriver() string { 86 return "scsi" 87 } 88 89 func (self *SClassicDisk) GetCacheMode() string { 90 return "none" 91 } 92 93 func (self *SClassicDisk) GetMountpoint() string { 94 return "" 95 } 96 97 func (self *SClassicDisk) GetDiskFormat() string { 98 return "vhd" 99 } 100 101 func (self *SClassicDisk) GetDiskSizeMB() int { 102 if self.Properties.DiskSizeGB > 0 { 103 return int(self.Properties.DiskSizeGB * 1024) 104 } 105 if self.Properties.DiskSize > 0 { 106 return int(self.Properties.DiskSize * 1024) 107 } 108 return 0 109 } 110 111 func (self *SClassicDisk) GetIsAutoDelete() bool { 112 return false 113 } 114 115 func (self *SClassicDisk) GetTemplateId() string { 116 return "" 117 } 118 119 func (self *SClassicDisk) GetDiskType() string { 120 return self.Properties.OperatingSystem 121 } 122 123 func (self *SClassicDisk) GetCreatedAt() time.Time { 124 return time.Time{} 125 } 126 127 func (self *SClassicDisk) GetExpiredAt() time.Time { 128 return time.Time{} 129 } 130 131 func (self *SClassicDisk) GetGlobalId() string { 132 return strings.ToLower(self.Id) 133 } 134 135 func (self *SClassicDisk) GetId() string { 136 return self.GetGlobalId() 137 } 138 139 func (self *SClassicDisk) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) { 140 return []cloudprovider.ICloudSnapshot{}, nil 141 } 142 143 func (self *SClassicDisk) GetIStorage() (cloudprovider.ICloudStorage, error) { 144 storage := struct { 145 Properties struct { 146 AccountType string 147 } 148 }{} 149 err := self.region.get(self.Properties.StorageAccount.ID, url.Values{}, &storage) 150 if err != nil { 151 return nil, errors.Wrapf(err, "get(%s)", self.Properties.StorageAccount.ID) 152 } 153 return &SClassicStorage{region: self.region, AccountType: storage.Properties.AccountType}, nil 154 } 155 156 func (self *SClassicDisk) GetName() string { 157 return self.Properties.DiskName 158 } 159 160 func (self *SClassicDisk) GetStatus() string { 161 return api.DISK_READY 162 } 163 164 func (self *SClassicDisk) IsEmulated() bool { 165 return false 166 } 167 168 func (self *SClassicDisk) Refresh() error { 169 return nil 170 } 171 172 func (self *SClassicDisk) Reset(ctx context.Context, snapshotId string) (string, error) { 173 return "", cloudprovider.ErrNotSupported 174 } 175 176 func (self *SClassicDisk) Resize(ctx context.Context, sizeMb int64) error { 177 return cloudprovider.ErrNotSupported 178 } 179 180 func (disk *SClassicDisk) GetAccessPath() string { 181 return "" 182 } 183 184 func (self *SClassicDisk) Rebuild(ctx context.Context) error { 185 return cloudprovider.ErrNotSupported 186 } 187 188 func (self *SClassicDisk) GetProjectId() string { 189 return "" 190 }