instance.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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 remotefile
  15. import (
  16. "context"
  17. "yunion.io/x/pkg/util/imagetools"
  18. api "yunion.io/x/cloudmux/pkg/apis/compute"
  19. "yunion.io/x/cloudmux/pkg/cloudprovider"
  20. )
  21. type SInstance struct {
  22. SResourceBase
  23. host *SHost
  24. osInfo *imagetools.ImageInfo
  25. HostId string
  26. Hostname string
  27. SecurityGroupIds []string
  28. VcpuCount int
  29. CpuSockets int
  30. VmemSizeMb int
  31. BootOrder string
  32. Vga string
  33. Vdi string
  34. OsArch string
  35. OsType string
  36. OsName string
  37. Bios string
  38. Machine string
  39. InstanceType string
  40. Bandwidth int
  41. Throughput int
  42. EipId string
  43. Disks []SDisk
  44. Nics []SInstanceNic
  45. }
  46. func (self *SInstance) GetSecurityGroupIds() ([]string, error) {
  47. return self.SecurityGroupIds, nil
  48. }
  49. func (self *SInstance) SetSecurityGroups(secgroupIds []string) error {
  50. return cloudprovider.ErrNotSupported
  51. }
  52. func (self *SInstance) StartVM(ctx context.Context) error {
  53. return cloudprovider.ErrNotSupported
  54. }
  55. func (self *SInstance) GetIHostId() string {
  56. return self.HostId
  57. }
  58. func (self *SInstance) GetInternetMaxBandwidthOut() int {
  59. return self.Bandwidth
  60. }
  61. func (self *SInstance) GetThroughput() int {
  62. return self.Throughput
  63. }
  64. func (self *SInstance) GetDescription() string {
  65. return ""
  66. }
  67. func (self *SInstance) GetSerialOutput(port int) (string, error) {
  68. return "", cloudprovider.ErrNotSupported
  69. }
  70. func (self *SInstance) ConvertPublicIpToEip() error {
  71. return cloudprovider.ErrNotSupported
  72. }
  73. func (self *SInstance) StopVM(ctx context.Context, opts *cloudprovider.ServerStopOptions) error {
  74. return cloudprovider.ErrNotSupported
  75. }
  76. func (self *SInstance) DeleteVM(ctx context.Context) error {
  77. return cloudprovider.ErrNotSupported
  78. }
  79. func (self *SInstance) UpdateVM(ctx context.Context, input cloudprovider.SInstanceUpdateOptions) error {
  80. return cloudprovider.ErrNotSupported
  81. }
  82. func (self *SInstance) UpdateUserData(userData string) error {
  83. return cloudprovider.ErrNotSupported
  84. }
  85. func (self *SInstance) RebuildRoot(ctx context.Context, config *cloudprovider.SManagedVMRebuildRootConfig) (string, error) {
  86. return "", cloudprovider.ErrNotSupported
  87. }
  88. func (self *SInstance) DeployVM(ctx context.Context, opts *cloudprovider.SInstanceDeployOptions) error {
  89. return cloudprovider.ErrNotSupported
  90. }
  91. func (self *SInstance) ChangeConfig(ctx context.Context, config *cloudprovider.SManagedVMChangeConfig) error {
  92. return cloudprovider.ErrNotSupported
  93. }
  94. func (self *SInstance) GetVNCInfo(input *cloudprovider.ServerVncInput) (*cloudprovider.ServerVncOutput, error) {
  95. return nil, cloudprovider.ErrNotSupported
  96. }
  97. func (self *SInstance) AttachDisk(ctx context.Context, diskId string) error {
  98. return cloudprovider.ErrNotSupported
  99. }
  100. func (self *SInstance) DetachDisk(ctx context.Context, diskId string) error {
  101. return cloudprovider.ErrNotSupported
  102. }
  103. func (self *SInstance) CreateDisk(ctx context.Context, opts *cloudprovider.GuestDiskCreateOptions) (string, error) {
  104. return "", cloudprovider.ErrNotSupported
  105. }
  106. func (self *SInstance) MigrateVM(hostid string) error {
  107. return cloudprovider.ErrNotSupported
  108. }
  109. func (self *SInstance) LiveMigrateVM(hostid string) error {
  110. return cloudprovider.ErrNotSupported
  111. }
  112. func (self *SInstance) GetError() error {
  113. return nil
  114. }
  115. func (self *SInstance) CreateInstanceSnapshot(ctx context.Context, name string, desc string) (cloudprovider.ICloudInstanceSnapshot, error) {
  116. return nil, cloudprovider.ErrNotSupported
  117. }
  118. func (self *SInstance) GetInstanceSnapshot(idStr string) (cloudprovider.ICloudInstanceSnapshot, error) {
  119. return nil, cloudprovider.ErrNotSupported
  120. }
  121. func (self *SInstance) GetInstanceSnapshots() ([]cloudprovider.ICloudInstanceSnapshot, error) {
  122. return nil, cloudprovider.ErrNotSupported
  123. }
  124. func (self *SInstance) ResetToInstanceSnapshot(ctx context.Context, idStr string) error {
  125. return cloudprovider.ErrNotSupported
  126. }
  127. func (self *SInstance) SaveImage(opts *cloudprovider.SaveImageOptions) (cloudprovider.ICloudImage, error) {
  128. return nil, cloudprovider.ErrNotSupported
  129. }
  130. func (self *SInstance) AllocatePublicIpAddress() (string, error) {
  131. return "", cloudprovider.ErrNotSupported
  132. }
  133. func (self *SInstance) GetCpuSockets() int {
  134. return self.CpuSockets
  135. }
  136. func (self *SInstance) GetVcpuCount() int {
  137. return self.VcpuCount
  138. }
  139. func (self *SInstance) GetVmemSizeMB() int {
  140. return self.VmemSizeMb
  141. }
  142. func (self *SInstance) GetBootOrder() string {
  143. return self.BootOrder
  144. }
  145. func (self *SInstance) GetVga() string {
  146. return self.Vga
  147. }
  148. func (self *SInstance) GetVdi() string {
  149. return self.Vdi
  150. }
  151. func (ins *SInstance) getNormalizedOsInfo() *imagetools.ImageInfo {
  152. if ins.osInfo == nil {
  153. osInfo := imagetools.NormalizeImageInfo(ins.OsName, ins.OsArch, ins.OsType, "", "")
  154. ins.osInfo = &osInfo
  155. }
  156. return ins.osInfo
  157. }
  158. func (ins *SInstance) GetOsArch() string {
  159. return ins.getNormalizedOsInfo().OsArch
  160. }
  161. func (ins *SInstance) GetOsType() cloudprovider.TOsType {
  162. return cloudprovider.TOsType(ins.getNormalizedOsInfo().OsType)
  163. }
  164. func (ins *SInstance) GetFullOsName() string {
  165. return ins.OsName
  166. }
  167. func (ins *SInstance) GetBios() cloudprovider.TBiosType {
  168. return cloudprovider.ToBiosType(ins.Bios)
  169. }
  170. func (ins *SInstance) GetOsLang() string {
  171. return ins.getNormalizedOsInfo().OsLang
  172. }
  173. func (ins *SInstance) GetOsDist() string {
  174. return ins.getNormalizedOsInfo().OsDistro
  175. }
  176. func (ins *SInstance) GetOsVersion() string {
  177. return ins.getNormalizedOsInfo().OsVersion
  178. }
  179. func (self *SInstance) GetMachine() string {
  180. return self.Machine
  181. }
  182. func (self *SInstance) GetInstanceType() string {
  183. return self.InstanceType
  184. }
  185. func (self *SInstance) GetHypervisor() string {
  186. return api.HYPERVISOR_REMOTEFILE
  187. }
  188. func (self *SInstance) GetHostname() string {
  189. return self.Hostname
  190. }
  191. func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
  192. ret := []cloudprovider.ICloudDisk{}
  193. storages, err := self.host.zone.region.client.GetStorages()
  194. if err != nil {
  195. return nil, err
  196. }
  197. for i := range self.Disks {
  198. for _, storage := range storages {
  199. if storage.Id == self.Disks[i].StorageId {
  200. self.Disks[i].SetStorage(storage)
  201. ret = append(ret, &self.Disks[i])
  202. }
  203. }
  204. }
  205. return ret, nil
  206. }
  207. func (self *SInstance) GetIEIP() (cloudprovider.ICloudEIP, error) {
  208. return self.host.zone.region.GetIEipById(self.EipId)
  209. }
  210. func (self *SInstance) GetIHost() cloudprovider.ICloudHost {
  211. return self.host
  212. }
  213. func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) {
  214. ret := []cloudprovider.ICloudNic{}
  215. for i := range self.Nics {
  216. ret = append(ret, &self.Nics[i])
  217. }
  218. return ret, nil
  219. }
  220. func (self *SInstance) GetPowerStates() string {
  221. if self.Status == api.VM_RUNNING {
  222. return api.VM_POWER_STATES_ON
  223. }
  224. return api.VM_POWER_STATES_OFF
  225. }
  226. func (self *SInstance) GetHealthStatus() string {
  227. return ""
  228. }
  229. func (self *SInstance) GetIsolateDeviceIds() ([]string, error) {
  230. return nil, cloudprovider.ErrNotSupported
  231. }
  232. func (self *SInstance) GetContainers() ([]cloudprovider.ICloudContainer, error) {
  233. return nil, cloudprovider.ErrNotSupported
  234. }
  235. func (self *SInstance) GetModificationTypes() ([]cloudprovider.SInstanceModificationType, error) {
  236. return nil, cloudprovider.ErrNotSupported
  237. }