Skip to content

Commit 53ea3e2

Browse files
authored
Merge pull request #624 from jschoiRR/mold-main#2025
[Mold API] Security Group서비스가 설정된 nic를 가진 VM 일 경우 보안그룹 상세 탭 활성화 및 버그 수정
2 parents bfcc4a3 + 2dfeab0 commit 53ea3e2

4 files changed

Lines changed: 91 additions & 52 deletions

File tree

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.net.URLDecoder;
2929
import java.util.ArrayList;
3030
import java.util.Arrays;
31-
import java.util.Collections;
3231
import java.util.Date;
3332
import java.util.HashMap;
3433
import java.util.HashSet;
@@ -3205,42 +3204,6 @@ public UserVm updateVirtualMachine(long id, String displayName, String group, Bo
32053204
}
32063205
}
32073206

3208-
boolean isVMware = (vm.getHypervisorType() == HypervisorType.VMware);
3209-
3210-
if (securityGroupIdList != null && isVMware) {
3211-
throw new InvalidParameterValueException("Security group feature is not supported for vmWare hypervisor");
3212-
} else {
3213-
// Get default guest network in Basic zone
3214-
Network defaultNetwork = null;
3215-
try {
3216-
DataCenterVO zone = _dcDao.findById(vm.getDataCenterId());
3217-
if (zone.getNetworkType() == NetworkType.Basic) {
3218-
// Get default guest network in Basic zone
3219-
defaultNetwork = _networkModel.getExclusiveGuestNetwork(zone.getId());
3220-
} else if (_networkModel.checkSecurityGroupSupportForNetwork(_accountMgr.getActiveAccountById(vm.getAccountId()), zone, Collections.emptyList(), securityGroupIdList)) {
3221-
NicVO defaultNic = _nicDao.findDefaultNicForVM(vm.getId());
3222-
if (defaultNic != null) {
3223-
defaultNetwork = _networkDao.findById(defaultNic.getNetworkId());
3224-
}
3225-
}
3226-
} catch (InvalidParameterValueException e) {
3227-
if(logger.isDebugEnabled()) {
3228-
logger.debug(e.getMessage(),e);
3229-
}
3230-
defaultNetwork = _networkModel.getDefaultNetworkForVm(id);
3231-
}
3232-
3233-
if (securityGroupIdList != null && _networkModel.isSecurityGroupSupportedInNetwork(defaultNetwork) && _networkModel.canAddDefaultSecurityGroup()) {
3234-
if (vm.getState() == State.Stopped) {
3235-
// Remove instance from security groups
3236-
_securityGroupMgr.removeInstanceFromGroups(vm);
3237-
// Add instance in provided groups
3238-
_securityGroupMgr.addInstanceToGroups(vm, securityGroupIdList);
3239-
} else {
3240-
throw new InvalidParameterValueException("Virtual machine must be stopped prior to update security groups ");
3241-
}
3242-
}
3243-
}
32443207
List<? extends Nic> nics = _nicDao.listByVmId(vm.getId());
32453208
if (hostName != null) {
32463209
// Check is hostName is RFC compliant
@@ -3273,6 +3236,35 @@ public UserVm updateVirtualMachine(long id, String displayName, String group, Bo
32733236
.getUuid(), nic.getId(), extraDhcpOptionsMap);
32743237
}
32753238

3239+
boolean isVMware = (vm.getHypervisorType() == HypervisorType.VMware);
3240+
3241+
if (securityGroupIdList != null && isVMware) {
3242+
throw new InvalidParameterValueException("Security group feature is not supported for vmWare hypervisor");
3243+
} else if (securityGroupIdList != null){
3244+
DataCenterVO zone = _dcDao.findById(vm.getDataCenterId());
3245+
List<Long> networkIds = new ArrayList<>();
3246+
try {
3247+
if (zone.getNetworkType() == NetworkType.Basic) {
3248+
// Get default guest network in Basic zone
3249+
Network defaultNetwork = _networkModel.getExclusiveGuestNetwork(zone.getId());
3250+
networkIds.add(defaultNetwork.getId());
3251+
} else {
3252+
networkIds = networks.stream().map(Network::getId).collect(Collectors.toList());
3253+
}
3254+
} catch (InvalidParameterValueException e) {
3255+
if(logger.isDebugEnabled()) {
3256+
logger.debug(e.getMessage(),e);
3257+
}
3258+
}
3259+
3260+
if (_networkModel.checkSecurityGroupSupportForNetwork(
3261+
_accountMgr.getActiveAccountById(vm.getAccountId()),
3262+
zone, networkIds, securityGroupIdList)
3263+
) {
3264+
updateSecurityGroup(vm, securityGroupIdList);
3265+
}
3266+
}
3267+
32763268
_vmDao.updateVM(id, displayName, ha, osTypeId, userData, userDataId,
32773269
userDataDetails, isDisplayVmEnabled, isDynamicallyScalable,
32783270
deleteProtection, customId, hostName, instanceName);
@@ -3288,6 +3280,17 @@ public UserVm updateVirtualMachine(long id, String displayName, String group, Bo
32883280
return _vmDao.findById(id);
32893281
}
32903282

3283+
private void updateSecurityGroup(UserVmVO vm, List<Long> securityGroupIdList) {
3284+
if (vm.getState() == State.Stopped) {
3285+
// Remove instance from security groups
3286+
_securityGroupMgr.removeInstanceFromGroups(vm);
3287+
// Add instance in provided groups
3288+
_securityGroupMgr.addInstanceToGroups(vm, securityGroupIdList);
3289+
} else {
3290+
throw new InvalidParameterValueException("Virtual machine must be stopped prior to update security groups ");
3291+
}
3292+
}
3293+
32913294
protected void updateUserData(UserVm vm) throws ResourceUnavailableException, InsufficientCapacityException {
32923295
boolean result = updateUserDataInternal(vm);
32933296
if (result) {

ui/src/components/view/DetailsTab.vue

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@
2828
<a-alert type="error" :showIcon="true" v-else-if="isLicenseExpired(dataResource.licenseExpiryDate)" :message="$t('message.alert.licenseexpired') + ' : ' + dataResource.licenseExpiryDate + '(' + $t('message.license.renewal.required') + ')'" />
2929
<a-alert type="success" :showIcon="true" v-else :message="$t('message.alert.licenseexpired') + ' : ' + dataResource.licenseExpiryDate + '(' + calculateDday(dataResource.licenseExpiryDate) + $t('message.license.days.left') + ')'" />
3030
</div>
31-
<!-- <a-alert type="error" v-if="['host'].includes($route.meta.name)">
32-
<template #message>
33-
<div v-if="!dataResource.licenseExpiryDate" class="title"> {{ $t('message.license.not.found') }}</div>
34-
<div v-else-if="isLicenseExpired(dataResource.licenseExpiryDate)" class="title"> {{ $t('message.alert.licenseexpired') + ' : ' + dataResource.licenseExpiryDate + '(' + $t('message.license.renewal.required') + ')' }}</div>
35-
<div v-else class="title"> {{ $t('message.alert.licenseexpired') + ' : ' + dataResource.licenseExpiryDate + '(' + calculateDday(dataResource.licenseExpiryDate) + $t('message.license.days.left') + ')' }}</div>
36-
</template>
37-
</a-alert> -->
38-
3931
<a-alert v-if="ip4routes" type="info" :showIcon="true" :message="$t('label.add.upstream.ipv4.routes')">
4032
<template #description>
4133
<p v-html="ip4routes" />

ui/src/views/compute/EditVM.vue

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@
9191
<a-textarea v-model:value="form.userdata">
9292
</a-textarea>
9393
</a-form-item>
94-
<a-form-item ref="securitygroupids" name="securitygroupids" :label="$t('label.security.groups')" v-if="securityGroupsEnabled">
94+
<a-form-item ref="securitygroupids" name="securitygroupids" :label="$t('label.security.groups')" v-if="securityGroupNetworkProviderUseThisVM">
9595
<a-select
9696
mode="multiple"
97-
:placeholder="$t('label.select.security.groups')"
9897
v-model:value="form.securitygroupids"
9998
showSearch
10099
optionFilterProp="label"
@@ -165,7 +164,8 @@ export default {
165164
groups: {
166165
loading: false,
167166
opts: []
168-
}
167+
},
168+
securityGroupNetworkProviderUseThisVM: false
169169
}
170170
},
171171
beforeCreate () {
@@ -206,7 +206,28 @@ export default {
206206
zoneid: this.resource.zoneid
207207
}).then(response => {
208208
const zone = response?.listzonesresponse?.zone || []
209-
this.securityGroupsEnabled = zone?.[0]?.securitygroupsenabled
209+
this.securityGroupsEnabled = zone?.[0]?.securitygroupsenabled || this.$store.getters.showSecurityGroups
210+
if (this.securityGroupsEnabled) {
211+
api('listNetworks', { supportedservices: 'SecurityGroup' }).then(json => {
212+
if (json.listnetworksresponse && json.listnetworksresponse.network) {
213+
for (const net of json.listnetworksresponse.network) {
214+
if (this.securityGroupNetworkProviderUseThisVM) {
215+
break
216+
}
217+
const listVmParams = {
218+
id: this.resource.id,
219+
networkid: net.id,
220+
listall: true
221+
}
222+
api('listVirtualMachines', listVmParams).then(json => {
223+
if (json.listvirtualmachinesresponse && json.listvirtualmachinesresponse?.virtualmachine?.length > 0) {
224+
this.securityGroupNetworkProviderUseThisVM = true
225+
}
226+
})
227+
}
228+
}
229+
})
230+
}
210231
})
211232
},
212233
fetchSecurityGroups () {
@@ -337,7 +358,7 @@ export default {
337358
params.name = values.name
338359
params.displayname = values.displayname
339360
params.ostypeid = values.ostypeid
340-
if (this.securityGroupsEnabled) {
361+
if (this.securityGroupNetworkProviderUseThisVM) {
341362
if (values.securitygroupids) {
342363
params.securitygroupids = values.securitygroupids
343364
}

ui/src/views/compute/InstanceTab.vue

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
:routerlinks="(record) => { return { created: '/backup/' + record.id } }"
9595
:showSearch="false"/>
9696
</a-tab-pane>
97-
<a-tab-pane :tab="$t('label.securitygroups')" key="securitygroups" v-if="dataResource.securitygroup && dataResource.securitygroup.length > 0 || $store.getters.showSecurityGroups">
97+
<a-tab-pane :tab="$t('label.securitygroups')" key="securitygroups" v-if="(dataResource.securitygroup && dataResource.securitygroup.length > 0) || ($store.getters.showSecurityGroups && securityGroupNetworkProviderUseThisVM)">
9898
<a-button
9999
type="primary"
100100
style="width: 100%; margin-bottom: 10px"
@@ -103,6 +103,8 @@
103103
<template #icon><edit-outlined /></template> {{ $t('label.action.update.security.groups') }}
104104
</a-button>
105105
<ListResourceTable
106+
apiName="listSecurityGroups"
107+
:params="{virtualmachineid: dataResource.id}"
106108
:items="dataResource.securitygroup"
107109
:columns="['name', 'description']"
108110
:routerlinks="(record) => { return { name: '/securitygroups/' + record.id } }"
@@ -248,6 +250,7 @@ export default {
248250
totalStorage: 0,
249251
currentTab: 'details',
250252
showAddVolumeModal: false,
253+
showUpdateSecurityGroupsModal: false,
251254
diskOfferings: [],
252255
showAddMirrorVMModal: false,
253256
showDrSimulationTestModal: false,
@@ -258,7 +261,8 @@ export default {
258261
editeNic: '',
259262
editNicLinkStat: '',
260263
dataPreFill: {},
261-
securitygroupids: []
264+
securitygroupids: [],
265+
securityGroupNetworkProviderUseThisVM: false
262266
}
263267
},
264268
created () {
@@ -316,6 +320,25 @@ export default {
316320
this.annotations = json.listannotationsresponse.annotation
317321
}
318322
})
323+
api('listNetworks', { supportedservices: 'SecurityGroup' }).then(json => {
324+
if (json.listnetworksresponse && json.listnetworksresponse.network) {
325+
for (const net of json.listnetworksresponse.network) {
326+
if (this.securityGroupNetworkProviderUseThisVM) {
327+
break
328+
}
329+
const listVmParams = {
330+
id: this.resource.id,
331+
networkid: net.id,
332+
listall: true
333+
}
334+
api('listVirtualMachines', listVmParams).then(json => {
335+
if (json.listvirtualmachinesresponse && json.listvirtualmachinesresponse?.virtualmachine?.length > 0) {
336+
this.securityGroupNetworkProviderUseThisVM = true
337+
}
338+
})
339+
}
340+
}
341+
})
319342
},
320343
listDiskOfferings () {
321344
api('listDiskOfferings', {

0 commit comments

Comments
 (0)