This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new 41e8ad74875 api,server,ui: vr,systemvm in public ip response (#7403)
41e8ad74875 is described below
commit 41e8ad74875480e205ae1048a068a2b28ab32627
Author: Abhishek Kumar <[email protected]>
AuthorDate: Thu Jun 8 18:35:59 2023 +0530
api,server,ui: vr,systemvm in public ip response (#7403)
Signed-off-by: Abhishek Kumar <[email protected]>
Co-authored-by: Wei Zhou <[email protected]>
---
.../org/apache/cloudstack/api/ApiConstants.java | 1 +
.../cloudstack/api/response/IPAddressResponse.java | 12 ++++-
.../main/java/com/cloud/api/ApiResponseHelper.java | 53 ++++++++++++++++------
ui/src/components/view/ListView.vue | 10 +++-
ui/src/config/section/network.js | 2 +-
ui/src/views/network/IpAddressesTab.vue | 10 +++-
6 files changed, 70 insertions(+), 18 deletions(-)
diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
index 76c0830527f..9dc4e587cfa 100644
--- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
@@ -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";
diff --git
a/api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java
b/api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java
index 13497d89308..2ad0a4fad0d 100644
---
a/api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java
+++
b/api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java
@@ -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;
}
diff --git a/server/src/main/java/com/cloud/api/ApiResponseHelper.java
b/server/src/main/java/com/cloud/api/ApiResponseHelper.java
index 8fffebb3303..11db312ebdf 100644
--- a/server/src/main/java/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/main/java/com/cloud/api/ApiResponseHelper.java
@@ -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);
}
}
}
diff --git a/ui/src/components/view/ListView.vue
b/ui/src/components/view/ListView.vue
index a9163ce63cd..294087d5f7a 100644
--- a/ui/src/components/view/ListView.vue
+++ b/ui/src/components/view/ListView.vue
@@ -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/'
+ }
}
}
}
diff --git a/ui/src/config/section/network.js b/ui/src/config/section/network.js
index 281479dc73c..661a7258288 100644
--- a/ui/src/config/section/network.js
+++ b/ui/src/config/section/network.js
@@ -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')),
diff --git a/ui/src/views/network/IpAddressesTab.vue
b/ui/src/views/network/IpAddressesTab.vue
index c63458c4718..e6f75d2c626 100644
--- a/ui/src/views/network/IpAddressesTab.vue
+++ b/ui/src/views/network/IpAddressesTab.vue
@@ -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