@@ -60,11 +60,23 @@ func (dss *HostDatastoreSystem) add(ctx *Context, ds *Datastore) *soap.Fault {
60
60
}
61
61
62
62
folder := ctx .Map .getEntityFolder (dss .Host , "datastore" )
63
- ds .Self .Type = typeName (ds )
64
- // Datastore is the only type where create methods do not include the parent (Folder in this case),
65
- // but we need the moref to be unique per DC/datastoreFolder, but not per-HostSystem.
66
- ds .Self .Value += "@" + folder .Self .Value
67
- // TODO: name should be made unique in the case of Local ds type
63
+
64
+ found := false
65
+ if e := ctx .Map .FindByName (ds .Name , folder .ChildEntity ); e != nil {
66
+ if e .Reference ().Type != "Datastore" {
67
+ return Fault (e .Reference ().Value , & types.DuplicateName {
68
+ Name : ds .Name ,
69
+ Object : e .Reference (),
70
+ })
71
+ }
72
+
73
+ // if datastore already exists, use current reference
74
+ found = true
75
+ ds .Self = e .Reference ()
76
+ } else {
77
+ // put datastore to folder and generate reference
78
+ folderPutChild (ctx , folder , ds )
79
+ }
68
80
69
81
ds .Summary .Datastore = & ds .Self
70
82
ds .Summary .Name = ds .Name
@@ -84,7 +96,8 @@ func (dss *HostDatastoreSystem) add(ctx *Context, ds *Datastore) *soap.Fault {
84
96
parent := hostParent (dss .Host )
85
97
ctx .Map .AddReference (ctx , parent , & parent .Datastore , ds .Self )
86
98
87
- if ctx .Map .Get (ds .Self ) == nil {
99
+ // NOTE: browser must be created after ds is appended to dss.Datastore
100
+ if ! found {
88
101
browser := & HostDatastoreBrowser {}
89
102
browser .Datastore = dss .Datastore
90
103
ds .Browser = ctx .Map .Put (browser ).Reference ()
@@ -95,8 +108,6 @@ func (dss *HostDatastoreSystem) add(ctx *Context, ds *Datastore) *soap.Fault {
95
108
info .FreeSpace = ds .Summary .FreeSpace
96
109
info .MaxMemoryFileSize = ds .Summary .Capacity
97
110
info .MaxFileSize = ds .Summary .Capacity
98
-
99
- folderPutChild (ctx , folder , ds )
100
111
}
101
112
102
113
return nil
@@ -107,7 +118,6 @@ func (dss *HostDatastoreSystem) CreateLocalDatastore(ctx *Context, c *types.Crea
107
118
108
119
ds := & Datastore {}
109
120
ds .Name = c .Name
110
- ds .Self .Value = c .Path
111
121
112
122
ds .Info = & types.LocalDatastoreInfo {
113
123
DatastoreInfo : types.DatastoreInfo {
@@ -147,9 +157,24 @@ func (dss *HostDatastoreSystem) CreateLocalDatastore(ctx *Context, c *types.Crea
147
157
func (dss * HostDatastoreSystem ) CreateNasDatastore (ctx * Context , c * types.CreateNasDatastore ) soap.HasFault {
148
158
r := & methods.CreateNasDatastoreBody {}
149
159
160
+ // validate RemoteHost and RemotePath are specified
161
+ if c .Spec .RemoteHost == "" {
162
+ r .Fault_ = Fault (
163
+ "A specified parameter was not correct: Spec.RemoteHost" ,
164
+ & types.InvalidArgument {InvalidProperty : "RemoteHost" },
165
+ )
166
+ return r
167
+ }
168
+ if c .Spec .RemotePath == "" {
169
+ r .Fault_ = Fault (
170
+ "A specified parameter was not correct: Spec.RemotePath" ,
171
+ & types.InvalidArgument {InvalidProperty : "RemotePath" },
172
+ )
173
+ return r
174
+ }
175
+
150
176
ds := & Datastore {}
151
177
ds .Name = path .Base (c .Spec .LocalPath )
152
- ds .Self .Value = c .Spec .RemoteHost + ":" + c .Spec .RemotePath
153
178
154
179
ds .Info = & types.NasDatastoreInfo {
155
180
DatastoreInfo : types.DatastoreInfo {
0 commit comments