resource.go 2.1 KB

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