service_instance.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. Copyright (c) 2017 VMware, Inc. All Rights Reserved.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package simulator
  14. import (
  15. "time"
  16. "github.com/google/uuid"
  17. "github.com/vmware/govmomi/object"
  18. "github.com/vmware/govmomi/simulator/vpx"
  19. "github.com/vmware/govmomi/vim25"
  20. "github.com/vmware/govmomi/vim25/methods"
  21. "github.com/vmware/govmomi/vim25/mo"
  22. "github.com/vmware/govmomi/vim25/soap"
  23. "github.com/vmware/govmomi/vim25/types"
  24. )
  25. type ServiceInstance struct {
  26. mo.ServiceInstance
  27. }
  28. func NewServiceInstance(content types.ServiceContent, folder mo.Folder) *ServiceInstance {
  29. Map = NewRegistry()
  30. s := &ServiceInstance{}
  31. s.Self = vim25.ServiceInstance
  32. s.Content = content
  33. Map.Put(s)
  34. f := &Folder{Folder: folder}
  35. Map.Put(f)
  36. var setting []types.BaseOptionValue
  37. if content.About.ApiType == "HostAgent" {
  38. CreateDefaultESX(f)
  39. } else {
  40. content.About.InstanceUuid = uuid.New().String()
  41. setting = vpx.Setting
  42. }
  43. objects := []object.Reference{
  44. NewSessionManager(*s.Content.SessionManager),
  45. NewAuthorizationManager(*s.Content.AuthorizationManager),
  46. NewPerformanceManager(*s.Content.PerfManager),
  47. NewPropertyCollector(s.Content.PropertyCollector),
  48. NewFileManager(*s.Content.FileManager),
  49. NewVirtualDiskManager(*s.Content.VirtualDiskManager),
  50. NewLicenseManager(*s.Content.LicenseManager),
  51. NewSearchIndex(*s.Content.SearchIndex),
  52. NewViewManager(*s.Content.ViewManager),
  53. NewEventManager(*s.Content.EventManager),
  54. NewTaskManager(*s.Content.TaskManager),
  55. NewUserDirectory(*s.Content.UserDirectory),
  56. NewOptionManager(s.Content.Setting, setting),
  57. NewStorageResourceManager(*s.Content.StorageResourceManager),
  58. }
  59. switch content.VStorageObjectManager.Type {
  60. case "HostVStorageObjectManager":
  61. // TODO: NewHostVStorageObjectManager(*content.VStorageObjectManager)
  62. case "VcenterVStorageObjectManager":
  63. objects = append(objects, NewVcenterVStorageObjectManager(*content.VStorageObjectManager))
  64. }
  65. if s.Content.CustomFieldsManager != nil {
  66. objects = append(objects, NewCustomFieldsManager(*s.Content.CustomFieldsManager))
  67. }
  68. if s.Content.IpPoolManager != nil {
  69. objects = append(objects, NewIpPoolManager(*s.Content.IpPoolManager))
  70. }
  71. if s.Content.AccountManager != nil {
  72. objects = append(objects, NewHostLocalAccountManager(*s.Content.AccountManager))
  73. }
  74. for _, o := range objects {
  75. Map.Put(o)
  76. }
  77. return s
  78. }
  79. func (s *ServiceInstance) RetrieveServiceContent(*types.RetrieveServiceContent) soap.HasFault {
  80. return &methods.RetrieveServiceContentBody{
  81. Res: &types.RetrieveServiceContentResponse{
  82. Returnval: s.Content,
  83. },
  84. }
  85. }
  86. func (*ServiceInstance) CurrentTime(*types.CurrentTime) soap.HasFault {
  87. return &methods.CurrentTimeBody{
  88. Res: &types.CurrentTimeResponse{
  89. Returnval: time.Now(),
  90. },
  91. }
  92. }