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