Skip to content

Commit

Permalink
use host to list vms
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanHoogland committed Jan 13, 2025
1 parent cd6d42c commit 11ca518
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ private HostResponse createHostResponse(HostMO hostInstance) throws InvalidPrope
HostResponse response = new HostResponse();
response.setHypervisor(Hypervisor.HypervisorType.VMware.toString());
response.setName(hostInstance.getHostName());
response.setObjectName("host");
return response;
}


private void checkParameters() {
if ((existingVcenterId == null && vcenter == null) || (existingVcenterId != null && vcenter != null)) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
Expand Down
1 change: 1 addition & 0 deletions ui/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3004,6 +3004,7 @@
"message.license.agreements.not.accepted": "License agreements not accepted.",
"message.linstor.resourcegroup.description": "Linstor resource group to use for primary storage.",
"message.list.zone.vmware.datacenter.empty": "No VMware Datacenter exists in the selected Zone",
"message.list.zone.vmware.hosts.empty": "No VMware hosts were found in the selected Datacenter",
"message.listnsp.not.return.providerid": "error: listNetworkServiceProviders API doesn't return VirtualRouter provider ID.",
"message.load.host.failed": "Failed to load hosts.",
"message.loadbalancer.stickypolicy.configuration": "Customize the load balancer stickiness policy:",
Expand Down
53 changes: 50 additions & 3 deletions ui/src/views/tools/SelectVmwareVcenter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,31 @@
/>
</a-form-item>
</div>
<div v-if="selectedExistingVcenterId">
<a-form-item ref="host" name="host" v-if="hosts.length > 0">
<a-select
v-model:value="form.host"
:loading="loading"
optionFilterProp="label"
:filterOption="(input, option) => {
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
}"
:placeholder="$t('label.vcenter.host')"
@change="onSelectExistingVmwareHost">
<a-select-option v-for="opt in hosts" :key="opt.id">
{{ 'ESXi: ' + opt.host + ' - DC: ' + opt.name }}
</a-select-option>
</a-select>
</a-form-item>
<div v-else>
{{ $t('message.list.zone.vmware.hosts.empty') }}
</div>
</div>
<div class="card-footer">
<a-button
v-if="vcenterSelectedOption == 'existing' || vcenterSelectedOption == 'new'"
:disabled="(vcenterSelectedOption === 'new' && (vcenter === '' || datacentername === '' || username === '' || password === '')) ||
(vcenterSelectedOption === 'existing' && selectedExistingVcenterId === '')"
:disabled="(vcenterSelectedOption === 'new' && ((vcenter === '' || datacentername === '' || username === '' || password === '')) ||
(vcenterSelectedOption === 'existing' && selectedExistingVcenterId === '')) && selectedHost === ''"
:loading="loading"
type="primary"
@click="listVmwareDatacenterVms">{{ $t('label.list.vmware.vcenter.vms') }}</a-button>
Expand Down Expand Up @@ -154,6 +174,8 @@ export default {
zones: {},
vcenterSelectedOption: '',
existingvcenter: [],
hosts: [],
selectedHost: '',
selectedExistingVcenterId: '',
selectedPoweredOnVm: false,
vmwareDcVms: [],
Expand Down Expand Up @@ -217,7 +239,7 @@ export default {
} else {
params.existingvcenterid = this.selectedExistingVcenterId
}
params.batchsize = 2
params.host = this.selectedhost
api('listVmwareDcVms', params).then(json => {
const obj = {
params: params,
Expand Down Expand Up @@ -256,8 +278,33 @@ export default {
this.loading = false
})
},
listZoneVmwareDcHosts () {
this.loading = true
const params = {}
if (this.vcenterSelectedOption === 'new') {
params.datacentername = this.datacenter
params.vcenter = this.vcenter
params.username = this.username
params.password = this.password
} else {
params.existingvcenterid = this.selectedExistingVcenterId
}
api('listVmwareDcHosts', params).then(response => {
if (response.listvmwaredchostsresponse.VMwareDC && response.listvmwaredchostsresponse.VMwareDC.length > 0) {
this.hosts = response.listvmwaredchostsresponse.hosts
}
}).catch(error => {
this.$notifyError(error)
}).finally(() => {
this.loading = false
})
},
onSelectExistingVmwareDatacenter (value) {
this.selectedExistingVcenterId = value
this.listZoneVmwareDcHosts()
},
onSelectExistingVmwareHost (value) {
this.selectedHost = value
},
onVcenterTypeChange () {
this.$emit('onVcenterTypeChanged', this.vcenterSelectedOption)
Expand Down

0 comments on commit 11ca518

Please sign in to comment.