Skip to content

Commit 9b3d635

Browse files
author
Michael Gasch
committed
vcsim: Fix distribute VMs across resource pools
This fix aligns the behavior of vcsim with the documentation for the `pool` and `machine` model flags for cluster configurations. When no child pools are created, i.e. `pool` is not specified, VMs will be deployed in the root resource pool of a cluster, i.e. `RP0`. The VMs will also be prefixed with the corresponding resource pool. In order to not break standalone host behavior, VMs deployed on a standalone host will not carry a resource pool identifier in their name. See the linked issue for deployment examples and naming. The total number of VMs deployed in a VPX model is the result of the number of datacenters, clusters and resource pools. BREAKING: The name of virtual machines deployed in `vcsim` in a cluster (and optionally child resource pools) has changed to include the corresponding resource pool name. VM names deployed to standalone hosts in `vcsim` are not changed. Closes: #2047 Signed-off-by: Michael Gasch <[email protected]>
1 parent 7f41531 commit 9b3d635

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

simulator/finder_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ func TestFinderVPX(t *testing.T) {
7474
{"DatacenterList", "/F0/*", 1},
7575
{"DatacenterList", "/DC0", 1},
7676
{"VirtualMachineList", "/DC0/vm/*", (m.Host + m.Cluster) * m.Machine},
77-
{"VirtualMachineList", "F0/DC1_C0_RP0_VM0", 1},
78-
{"VirtualMachineList", "./DC1_C0_RP0_VM0", 0},
79-
{"VirtualMachineList", "DC1_C0_RP0_VM0", 1}, // find . -type VirtualMachine -name DC1_C0_RP0_VM0
77+
{"VirtualMachineList", "F0/DC1_C0_RP1_VM0", 1},
78+
{"VirtualMachineList", "./DC1_C0_RP1_VM0", 0},
79+
{"VirtualMachineList", "DC1_C0_RP1_VM0", 1}, // find . -type VirtualMachine -name DC1_C0_RP0_VM0
8080
{"VirtualAppList", "/DC0/vm/*", 0},
8181
{"DatastoreList", "/DC0/datastore/*", m.Datastore},
8282
{"DatastoreList", "./*", 0},
@@ -123,7 +123,7 @@ func TestFinderVPX(t *testing.T) {
123123
{"DatacenterList", "/*", m.Datacenter - m.Folder},
124124
{"DatacenterList", "/*/*", m.Folder},
125125
{"DatastoreList", "/F1/DC2/datastore/F1/LocalDS_0", 1},
126-
{"VirtualMachineList", "DC1_C0_RP0_VM0", 0}, // TODO: recurse all Datacenters?
126+
{"VirtualMachineList", "DC1_C0_RP1_VM0", 0}, // TODO: recurse all Datacenters?
127127
}
128128

129129
f := reflect.ValueOf(finder)

simulator/model.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ type Model struct {
107107
// For example: /DC0/host/DC0_C0/Resources
108108
// The root ResourcePool is named "RP0" within other object names.
109109
// When Model.Pool is set to 1 or higher, this creates child ResourcePools under the root pool.
110+
// Note that this flag is not effective on standalone hosts.
110111
// For example: /DC0/host/DC0_C0/Resources/DC0_C0_RP1
111112
// Name prefix: RP, vcsim flag: -pool
112113
Pool int
@@ -117,7 +118,12 @@ type Model struct {
117118
// Name prefix: LocalDS, vcsim flag: -ds
118119
Datastore int
119120

120-
// Machine specifies the number of VirtualMachine entities to create per ResourcePool
121+
// Machine specifies the number of VirtualMachine entities to create per
122+
// ResourcePool. If the pool flag is specified, the specified number of virtual
123+
// machines will be deployed to each child pool and prefixed with the child
124+
// resource pool name. Otherwise they are deployed into the root resource pool,
125+
// prefixed with RP0. On standalone hosts, machines are always deployed into the
126+
// root resource pool without any prefix.
121127
// Name prefix: VM, vcsim flag: -vm
122128
Machine int
123129

@@ -731,19 +737,24 @@ func (m *Model) Create() error {
731737
}
732738
}
733739

734-
pool, err := cluster.ResourcePool(ctx)
740+
rootRP, err := cluster.ResourcePool(ctx)
735741
if err != nil {
736742
return err
737743
}
738744

739745
prefix := clusterName + "_RP"
740746

741-
addMachine(prefix+"0", nil, pool, folders)
747+
// put VMs in cluster RP if no child RP(s) configured
748+
if m.Pool == 0 {
749+
addMachine(prefix+"0", nil, rootRP, folders)
750+
}
742751

743-
for npool := 1; npool <= m.Pool; npool++ {
752+
// create child RP(s) with VMs
753+
for childRP := 1; childRP <= m.Pool; childRP++ {
744754
spec := types.DefaultResourceConfigSpec()
745755

746-
_, err = pool.Create(ctx, m.fmtName(prefix, npool), spec)
756+
p, err := rootRP.Create(ctx, m.fmtName(prefix, childRP), spec)
757+
addMachine(m.fmtName(prefix, childRP), nil, p, folders)
747758
if err != nil {
748759
return err
749760
}
@@ -756,7 +767,7 @@ func (m *Model) Create() error {
756767
vspec := NewVAppConfigSpec()
757768
name := m.fmtName(prefix, napp)
758769

759-
vapp, err := pool.CreateVApp(ctx, name, rspec, vspec, nil)
770+
vapp, err := rootRP.CreateVApp(ctx, name, rspec, vspec, nil)
760771
if err != nil {
761772
return err
762773
}

simulator/model_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func compareModel(t *testing.T, m *Model) {
2626
count := m.Count()
2727

2828
hosts := (m.Host + (m.ClusterHost * m.Cluster)) * m.Datacenter
29-
vms := ((m.Host + m.Cluster) * m.Datacenter) * m.Machine
29+
vms := ((m.Host + m.Cluster + m.Pool) * m.Datacenter) * m.Machine
3030
// child pools + root pools
3131
pools := (m.Pool * m.Cluster * m.Datacenter) + (m.Host+m.Cluster)*m.Datacenter
3232
// root folder + Datacenter folders {host,vm,datastore,network} + top-level folders

simulator/search_index_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ func TestSearchIndexFindChild(t *testing.T) {
160160
// Datacenter -> host Folder -> Cluster -> ResourcePool -> ResourcePool
161161
{"DC0", "host", "DC0_C0", "Resources", "DC0_C0_RP1"},
162162
// Datacenter -> host Folder -> Cluster -> ResourcePool -> VirtualMachine
163-
{"DC0", "host", "DC0_C0", "Resources", "DC0_C0_RP0_VM0"},
163+
{"DC0", "host", "DC0_C0", "Resources", "DC0_C0_RP1", "DC0_C0_RP1_VM0"},
164164
// Datacenter -> vm Folder -> VirtualMachine
165-
{"DC0", "vm", "DC0_C0_RP0_VM0"},
165+
{"DC0", "vm", "DC0_C0_RP1_VM0"},
166166
}
167167

168168
root := c.ServiceContent.RootFolder

0 commit comments

Comments
 (0)