api,server,ui: vr,systemvm in public ip response (#7403)

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
Co-authored-by: Wei Zhou <weizhou@apache.org>
This commit is contained in:
Abhishek Kumar 2023-06-08 18:35:59 +05:30 committed by GitHub
parent c00a1ba532
commit 41e8ad7487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 18 deletions

View File

@ -460,6 +460,7 @@ public class ApiConstants {
public static final String VIRTUAL_MACHINE_NAME = "virtualmachinename";
public static final String VIRTUAL_MACHINE_ID_IP = "vmidipmap";
public static final String VIRTUAL_MACHINE_COUNT = "virtualmachinecount";
public static final String VIRTUAL_MACHINE_TYPE = "virtualmachinetype";
public static final String VIRTUAL_MACHINES = "virtualmachines";
public static final String USAGE_ID = "usageid";
public static final String USAGE_TYPE = "usagetype";

View File

@ -96,15 +96,19 @@ public class IPAddressResponse extends BaseResponseWithAnnotations implements Co
private Boolean isSystem;
@SerializedName(ApiConstants.VIRTUAL_MACHINE_ID)
@Param(description = "virtual machine id the ip address is assigned to (not null only for static nat Ip)")
@Param(description = "virtual machine id the ip address is assigned to")
private String virtualMachineId;
@SerializedName(ApiConstants.VIRTUAL_MACHINE_TYPE)
@Param(description = "virtual machine type the ip address is assigned to", since = "4.19.0")
private String virtualMachineType;
@SerializedName("vmipaddress")
@Param(description = "virtual machine (dnat) ip address (not null only for static nat Ip)")
private String virtualMachineIp;
@SerializedName("virtualmachinename")
@Param(description = "virtual machine name the ip address is assigned to (not null only for static nat Ip)")
@Param(description = "virtual machine name the ip address is assigned to")
private String virtualMachineName;
@SerializedName("virtualmachinedisplayname")
@ -232,6 +236,10 @@ public class IPAddressResponse extends BaseResponseWithAnnotations implements Co
this.virtualMachineId = virtualMachineId;
}
public void setVirtualMachineType(String virtualMachineType) {
this.virtualMachineType = virtualMachineType;
}
public void setVirtualMachineIp(String virtualMachineIp) {
this.virtualMachineIp = virtualMachineIp;
}

View File

@ -199,6 +199,7 @@ import org.apache.cloudstack.usage.Usage;
import org.apache.cloudstack.usage.UsageService;
import org.apache.cloudstack.usage.UsageTypes;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
@ -935,6 +936,42 @@ public class ApiResponseHelper implements ResponseGenerator {
return userIpAddresVO != null ? userIpAddresVO.isForSystemVms() : false;
}
private void addVmDetailsInIpResponse(IPAddressResponse response, IpAddress ipAddress) {
if (ipAddress.getAllocatedToAccountId() != null && ipAddress.getAllocatedToAccountId() == Account.ACCOUNT_ID_SYSTEM) {
NicVO nic = ApiDBUtils.findByIp4AddressAndNetworkId(ipAddress.getAddress().toString(), ipAddress.getNetworkId());
if (nic != null) {
addSystemVmInfoToIpResponse(nic, response);
}
}
if (ipAddress.getAssociatedWithVmId() != null) {
addUserVmDetailsInIpResponse(response, ipAddress);
}
}
private void addSystemVmInfoToIpResponse(NicVO nic, IPAddressResponse ipResponse) {
final boolean isAdmin = Account.Type.ADMIN.equals(CallContext.current().getCallingAccount().getType());
if (!isAdmin) {
return;
}
VirtualMachine vm = ApiDBUtils.findVMInstanceById(nic.getInstanceId());
if (vm == null) {
return;
}
ipResponse.setVirtualMachineId(vm.getUuid());
ipResponse.setVirtualMachineName(vm.getHostName());
ipResponse.setVirtualMachineType(vm.getType().toString());
}
private void addUserVmDetailsInIpResponse(IPAddressResponse response, IpAddress ipAddress) {
UserVm userVm = ApiDBUtils.findUserVmById(ipAddress.getAssociatedWithVmId());
if (userVm != null) {
response.setVirtualMachineId(userVm.getUuid());
response.setVirtualMachineName(userVm.getHostName());
response.setVirtualMachineType(userVm.getType().toString());
response.setVirtualMachineDisplayName(ObjectUtils.firstNonNull(userVm.getDisplayName(), userVm.getHostName()));
}
}
@Override
public IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ipAddr) {
VlanVO vlan = ApiDBUtils.findVlanById(ipAddr.getVlanId());
@ -963,18 +1000,7 @@ public class ApiResponseHelper implements ResponseGenerator {
ipResponse.setForVirtualNetwork(forVirtualNetworks);
ipResponse.setStaticNat(ipAddr.isOneToOneNat());
if (ipAddr.getAssociatedWithVmId() != null) {
UserVm vm = ApiDBUtils.findUserVmById(ipAddr.getAssociatedWithVmId());
if (vm != null) {
ipResponse.setVirtualMachineId(vm.getUuid());
ipResponse.setVirtualMachineName(vm.getHostName());
if (vm.getDisplayName() != null) {
ipResponse.setVirtualMachineDisplayName(vm.getDisplayName());
} else {
ipResponse.setVirtualMachineDisplayName(vm.getHostName());
}
}
}
addVmDetailsInIpResponse(ipResponse, ipAddr);
if (ipAddr.getVmIp() != null) {
ipResponse.setVirtualMachineIp(ipAddr.getVmIp());
}
@ -1092,8 +1118,9 @@ public class ApiResponseHelper implements ResponseGenerator {
ipResponse.setVirtualMachineDisplayName(vm.getHostName());
}
}
} else if (nic.getVmType() == VirtualMachine.Type.DomainRouter) {
} else if (nic.getVmType().isUsedBySystem()) {
ipResponse.setIsSystem(true);
addSystemVmInfoToIpResponse(nic, ipResponse);
}
}
}

View File

@ -153,7 +153,7 @@
<router-link :to="{ path: createPathBasedOnVmType(record.vmtype, record.virtualmachineid) }">{{ text }}</router-link>
</template>
<template v-if="column.key === 'virtualmachinename'">
<router-link :to="{ path: '/vm/' + record.virtualmachineid }">{{ text }}</router-link>
<router-link :to="{ path: getVmRouteUsingType(record) + record.virtualmachineid }">{{ text }}</router-link>
</template>
<template v-if="column.key === 'hypervisor'">
<span v-if="$route.name === 'hypervisorcapability'">
@ -792,6 +792,14 @@ export default {
},
updateSelectedColumns (name) {
this.$emit('update-selected-columns', name)
},
getVmRouteUsingType (record) {
switch (record.virtualmachinetype) {
case 'DomainRouter' : return '/router/'
case 'ConsoleProxy' :
case 'SecondaryStorageVm': return '/systemvm/'
default: return '/vm/'
}
}
}
}

View File

@ -323,7 +323,7 @@ export default {
docHelp: 'adminguide/networking_and_traffic.html#reserving-public-ip-addresses-and-vlans-for-accounts',
permission: ['listPublicIpAddresses'],
resourceType: 'PublicIpAddress',
columns: ['ipaddress', 'state', 'associatednetworkname', 'virtualmachinename', 'allocated', 'account', 'zonename'],
columns: ['ipaddress', 'state', 'associatednetworkname', 'vpcname', 'virtualmachinename', 'allocated', 'account', 'zonename'],
details: ['ipaddress', 'id', 'associatednetworkname', 'virtualmachinename', 'networkid', 'issourcenat', 'isstaticnat', 'virtualmachinename', 'vmipaddress', 'vlan', 'allocated', 'account', 'zonename'],
filters: ['allocated', 'reserved', 'free'],
component: shallowRef(() => import('@/views/network/PublicIpResource.vue')),

View File

@ -78,7 +78,7 @@
<template v-if="column.key === 'virtualmachineid'">
<desktop-outlined v-if="record.virtualmachineid" />
<router-link :to="{ path: '/vm/' + record.virtualmachineid }" > {{ record.virtualmachinename || record.virtualmachineid }} </router-link>
<router-link :to="{ path: getVmRouteUsingType(record) + record.virtualmachineid }" > {{ record.virtualmachinename || record.virtualmachineid }} </router-link>
</template>
<template v-if="column.key === 'associatednetworkname'">
@ -442,6 +442,14 @@ export default {
})
})
},
getVmRouteUsingType (record) {
switch (record.virtualmachinetype) {
case 'DomainRouter' : return '/router/'
case 'ConsoleProxy' :
case 'SecondaryStorageVm': return '/systemvm/'
default: return '/vm/'
}
},
async onShowAcquireIp () {
this.showAcquireIp = true
this.acquireLoading = true