yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/remotefile/resource.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  	"time"
    19  
    20  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    21  	"yunion.io/x/cloudmux/pkg/multicloud"
    22  )
    23  
    24  type SResourceBase struct {
    25  	RemoteFileTags
    26  	multicloud.SBillingBase
    27  	Id        string
    28  	Name      string
    29  	Emulated  bool
    30  	Status    string
    31  	CreatedAt time.Time
    32  	ProjectId string
    33  }
    34  
    35  func (self *SResourceBase) GetId() string {
    36  	return self.Id
    37  }
    38  
    39  func (self *SResourceBase) GetName() string {
    40  	return self.Name
    41  }
    42  
    43  func (self *SResourceBase) Refresh() error {
    44  	return nil
    45  }
    46  
    47  func (self *SResourceBase) GetStatus() string {
    48  	if len(self.Status) == 0 {
    49  		return "unknown"
    50  	}
    51  	return self.Status
    52  }
    53  
    54  func (self *SResourceBase) GetProjectId() string {
    55  	return self.ProjectId
    56  }
    57  
    58  func (self *SResourceBase) GetI18n() cloudprovider.SModelI18nTable {
    59  	table := cloudprovider.SModelI18nTable{}
    60  	table["name"] = cloudprovider.NewSModelI18nEntry(self.GetName()).CN(self.GetName()).EN(self.GetName())
    61  	return table
    62  }
    63  
    64  func (self *SResourceBase) GetGlobalId() string {
    65  	if len(self.Id) == 0 {
    66  		panic("empty id")
    67  	}
    68  	return self.Id
    69  }
    70  
    71  func (self *SResourceBase) IsEmulated() bool {
    72  	return self.Emulated
    73  }
    74  
    75  func (self *SResourceBase) GetCreatedAt() time.Time {
    76  	return self.CreatedAt
    77  }
    78  
    79  func (self *SResourceBase) GetSysTags() map[string]string {
    80  	return self.RemoteFileTags.GetSysTags()
    81  }
    82  
    83  func (self *SResourceBase) GetTags() (map[string]string, error) {
    84  	return self.RemoteFileTags.GetTags()
    85  }
    86  
    87  func (self *SResourceBase) SetTags(tags map[string]string, replace bool) error {
    88  	return self.RemoteFileTags.SetTags(tags, replace)
    89  }