Skip to content

Commit 490658c

Browse files
authored
display nics deviceid and order nics by deviceid on Nics tab of instances. (#4768)
1 parent 7b752c3 commit 490658c

File tree

5 files changed

+201
-1
lines changed

5 files changed

+201
-1
lines changed

api/src/main/java/org/apache/cloudstack/api/response/UserVmResponse.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.response;
1818

19+
import java.util.Comparator;
1920
import java.util.Date;
2021
import java.util.LinkedHashSet;
2122
import java.util.Map;
2223
import java.util.Set;
24+
import java.util.TreeSet;
2325

2426
import org.apache.cloudstack.acl.RoleType;
2527
import org.apache.cloudstack.affinity.AffinityGroupResponse;
@@ -316,7 +318,7 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
316318

317319
public UserVmResponse() {
318320
securityGroupList = new LinkedHashSet<SecurityGroupResponse>();
319-
nics = new LinkedHashSet<NicResponse>();
321+
nics = new TreeSet<>(Comparator.comparingInt(x -> Integer.parseInt(x.getDeviceId())));
320322
tags = new LinkedHashSet<ResourceTagResponse>();
321323
tagIds = new LinkedHashSet<Long>();
322324
affinityGroupList = new LinkedHashSet<AffinityGroupResponse>();

engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,190 @@ from
392392
`cloud`.`resource_count` secondary_storage_count ON domain.id = secondary_storage_count.domain_id
393393
and secondary_storage_count.type = 'secondary_storage';
394394

395+
396+
DROP VIEW IF EXISTS `cloud`.`user_vm_view`;
397+
CREATE
398+
VIEW `user_vm_view` AS
399+
SELECT
400+
`vm_instance`.`id` AS `id`,
401+
`vm_instance`.`name` AS `name`,
402+
`user_vm`.`display_name` AS `display_name`,
403+
`user_vm`.`user_data` AS `user_data`,
404+
`account`.`id` AS `account_id`,
405+
`account`.`uuid` AS `account_uuid`,
406+
`account`.`account_name` AS `account_name`,
407+
`account`.`type` AS `account_type`,
408+
`domain`.`id` AS `domain_id`,
409+
`domain`.`uuid` AS `domain_uuid`,
410+
`domain`.`name` AS `domain_name`,
411+
`domain`.`path` AS `domain_path`,
412+
`projects`.`id` AS `project_id`,
413+
`projects`.`uuid` AS `project_uuid`,
414+
`projects`.`name` AS `project_name`,
415+
`instance_group`.`id` AS `instance_group_id`,
416+
`instance_group`.`uuid` AS `instance_group_uuid`,
417+
`instance_group`.`name` AS `instance_group_name`,
418+
`vm_instance`.`uuid` AS `uuid`,
419+
`vm_instance`.`user_id` AS `user_id`,
420+
`vm_instance`.`last_host_id` AS `last_host_id`,
421+
`vm_instance`.`vm_type` AS `type`,
422+
`vm_instance`.`limit_cpu_use` AS `limit_cpu_use`,
423+
`vm_instance`.`created` AS `created`,
424+
`vm_instance`.`state` AS `state`,
425+
`vm_instance`.`removed` AS `removed`,
426+
`vm_instance`.`ha_enabled` AS `ha_enabled`,
427+
`vm_instance`.`hypervisor_type` AS `hypervisor_type`,
428+
`vm_instance`.`instance_name` AS `instance_name`,
429+
`vm_instance`.`guest_os_id` AS `guest_os_id`,
430+
`vm_instance`.`display_vm` AS `display_vm`,
431+
`guest_os`.`uuid` AS `guest_os_uuid`,
432+
`vm_instance`.`pod_id` AS `pod_id`,
433+
`host_pod_ref`.`uuid` AS `pod_uuid`,
434+
`vm_instance`.`private_ip_address` AS `private_ip_address`,
435+
`vm_instance`.`private_mac_address` AS `private_mac_address`,
436+
`vm_instance`.`vm_type` AS `vm_type`,
437+
`data_center`.`id` AS `data_center_id`,
438+
`data_center`.`uuid` AS `data_center_uuid`,
439+
`data_center`.`name` AS `data_center_name`,
440+
`data_center`.`is_security_group_enabled` AS `security_group_enabled`,
441+
`data_center`.`networktype` AS `data_center_type`,
442+
`host`.`id` AS `host_id`,
443+
`host`.`uuid` AS `host_uuid`,
444+
`host`.`name` AS `host_name`,
445+
`vm_template`.`id` AS `template_id`,
446+
`vm_template`.`uuid` AS `template_uuid`,
447+
`vm_template`.`name` AS `template_name`,
448+
`vm_template`.`display_text` AS `template_display_text`,
449+
`vm_template`.`enable_password` AS `password_enabled`,
450+
`iso`.`id` AS `iso_id`,
451+
`iso`.`uuid` AS `iso_uuid`,
452+
`iso`.`name` AS `iso_name`,
453+
`iso`.`display_text` AS `iso_display_text`,
454+
`service_offering`.`id` AS `service_offering_id`,
455+
`svc_disk_offering`.`uuid` AS `service_offering_uuid`,
456+
`disk_offering`.`uuid` AS `disk_offering_uuid`,
457+
`disk_offering`.`id` AS `disk_offering_id`,
458+
(CASE
459+
WHEN ISNULL(`service_offering`.`cpu`) THEN `custom_cpu`.`value`
460+
ELSE `service_offering`.`cpu`
461+
END) AS `cpu`,
462+
(CASE
463+
WHEN ISNULL(`service_offering`.`speed`) THEN `custom_speed`.`value`
464+
ELSE `service_offering`.`speed`
465+
END) AS `speed`,
466+
(CASE
467+
WHEN ISNULL(`service_offering`.`ram_size`) THEN `custom_ram_size`.`value`
468+
ELSE `service_offering`.`ram_size`
469+
END) AS `ram_size`,
470+
`backup_offering`.`uuid` AS `backup_offering_uuid`,
471+
`backup_offering`.`id` AS `backup_offering_id`,
472+
`svc_disk_offering`.`name` AS `service_offering_name`,
473+
`disk_offering`.`name` AS `disk_offering_name`,
474+
`backup_offering`.`name` AS `backup_offering_name`,
475+
`storage_pool`.`id` AS `pool_id`,
476+
`storage_pool`.`uuid` AS `pool_uuid`,
477+
`storage_pool`.`pool_type` AS `pool_type`,
478+
`volumes`.`id` AS `volume_id`,
479+
`volumes`.`uuid` AS `volume_uuid`,
480+
`volumes`.`device_id` AS `volume_device_id`,
481+
`volumes`.`volume_type` AS `volume_type`,
482+
`security_group`.`id` AS `security_group_id`,
483+
`security_group`.`uuid` AS `security_group_uuid`,
484+
`security_group`.`name` AS `security_group_name`,
485+
`security_group`.`description` AS `security_group_description`,
486+
`nics`.`id` AS `nic_id`,
487+
`nics`.`uuid` AS `nic_uuid`,
488+
`nics`.`device_id` AS `nic_device_id`,
489+
`nics`.`network_id` AS `network_id`,
490+
`nics`.`ip4_address` AS `ip_address`,
491+
`nics`.`ip6_address` AS `ip6_address`,
492+
`nics`.`ip6_gateway` AS `ip6_gateway`,
493+
`nics`.`ip6_cidr` AS `ip6_cidr`,
494+
`nics`.`default_nic` AS `is_default_nic`,
495+
`nics`.`gateway` AS `gateway`,
496+
`nics`.`netmask` AS `netmask`,
497+
`nics`.`mac_address` AS `mac_address`,
498+
`nics`.`broadcast_uri` AS `broadcast_uri`,
499+
`nics`.`isolation_uri` AS `isolation_uri`,
500+
`vpc`.`id` AS `vpc_id`,
501+
`vpc`.`uuid` AS `vpc_uuid`,
502+
`networks`.`uuid` AS `network_uuid`,
503+
`networks`.`name` AS `network_name`,
504+
`networks`.`traffic_type` AS `traffic_type`,
505+
`networks`.`guest_type` AS `guest_type`,
506+
`user_ip_address`.`id` AS `public_ip_id`,
507+
`user_ip_address`.`uuid` AS `public_ip_uuid`,
508+
`user_ip_address`.`public_ip_address` AS `public_ip_address`,
509+
`ssh_keypairs`.`keypair_name` AS `keypair_name`,
510+
`resource_tags`.`id` AS `tag_id`,
511+
`resource_tags`.`uuid` AS `tag_uuid`,
512+
`resource_tags`.`key` AS `tag_key`,
513+
`resource_tags`.`value` AS `tag_value`,
514+
`resource_tags`.`domain_id` AS `tag_domain_id`,
515+
`domain`.`uuid` AS `tag_domain_uuid`,
516+
`domain`.`name` AS `tag_domain_name`,
517+
`resource_tags`.`account_id` AS `tag_account_id`,
518+
`account`.`account_name` AS `tag_account_name`,
519+
`resource_tags`.`resource_id` AS `tag_resource_id`,
520+
`resource_tags`.`resource_uuid` AS `tag_resource_uuid`,
521+
`resource_tags`.`resource_type` AS `tag_resource_type`,
522+
`resource_tags`.`customer` AS `tag_customer`,
523+
`async_job`.`id` AS `job_id`,
524+
`async_job`.`uuid` AS `job_uuid`,
525+
`async_job`.`job_status` AS `job_status`,
526+
`async_job`.`account_id` AS `job_account_id`,
527+
`affinity_group`.`id` AS `affinity_group_id`,
528+
`affinity_group`.`uuid` AS `affinity_group_uuid`,
529+
`affinity_group`.`name` AS `affinity_group_name`,
530+
`affinity_group`.`description` AS `affinity_group_description`,
531+
`vm_instance`.`dynamically_scalable` AS `dynamically_scalable`
532+
FROM
533+
(((((((((((((((((((((((((((((((((`user_vm`
534+
JOIN `vm_instance` ON (((`vm_instance`.`id` = `user_vm`.`id`)
535+
AND ISNULL(`vm_instance`.`removed`))))
536+
JOIN `account` ON ((`vm_instance`.`account_id` = `account`.`id`)))
537+
JOIN `domain` ON ((`vm_instance`.`domain_id` = `domain`.`id`)))
538+
LEFT JOIN `guest_os` ON ((`vm_instance`.`guest_os_id` = `guest_os`.`id`)))
539+
LEFT JOIN `host_pod_ref` ON ((`vm_instance`.`pod_id` = `host_pod_ref`.`id`)))
540+
LEFT JOIN `projects` ON ((`projects`.`project_account_id` = `account`.`id`)))
541+
LEFT JOIN `instance_group_vm_map` ON ((`vm_instance`.`id` = `instance_group_vm_map`.`instance_id`)))
542+
LEFT JOIN `instance_group` ON ((`instance_group_vm_map`.`group_id` = `instance_group`.`id`)))
543+
LEFT JOIN `data_center` ON ((`vm_instance`.`data_center_id` = `data_center`.`id`)))
544+
LEFT JOIN `host` ON ((`vm_instance`.`host_id` = `host`.`id`)))
545+
LEFT JOIN `vm_template` ON ((`vm_instance`.`vm_template_id` = `vm_template`.`id`)))
546+
LEFT JOIN `vm_template` `iso` ON ((`iso`.`id` = `user_vm`.`iso_id`)))
547+
LEFT JOIN `service_offering` ON ((`vm_instance`.`service_offering_id` = `service_offering`.`id`)))
548+
LEFT JOIN `disk_offering` `svc_disk_offering` ON ((`vm_instance`.`service_offering_id` = `svc_disk_offering`.`id`)))
549+
LEFT JOIN `disk_offering` ON ((`vm_instance`.`disk_offering_id` = `disk_offering`.`id`)))
550+
LEFT JOIN `backup_offering` ON ((`vm_instance`.`backup_offering_id` = `backup_offering`.`id`)))
551+
LEFT JOIN `volumes` ON ((`vm_instance`.`id` = `volumes`.`instance_id`)))
552+
LEFT JOIN `storage_pool` ON ((`volumes`.`pool_id` = `storage_pool`.`id`)))
553+
LEFT JOIN `security_group_vm_map` ON ((`vm_instance`.`id` = `security_group_vm_map`.`instance_id`)))
554+
LEFT JOIN `security_group` ON ((`security_group_vm_map`.`security_group_id` = `security_group`.`id`)))
555+
LEFT JOIN `nics` ON (((`vm_instance`.`id` = `nics`.`instance_id`)
556+
AND ISNULL(`nics`.`removed`))))
557+
LEFT JOIN `networks` ON ((`nics`.`network_id` = `networks`.`id`)))
558+
LEFT JOIN `vpc` ON (((`networks`.`vpc_id` = `vpc`.`id`)
559+
AND ISNULL(`vpc`.`removed`))))
560+
LEFT JOIN `user_ip_address` ON ((`user_ip_address`.`vm_id` = `vm_instance`.`id`)))
561+
LEFT JOIN `user_vm_details` `ssh_details` ON (((`ssh_details`.`vm_id` = `vm_instance`.`id`)
562+
AND (`ssh_details`.`name` = 'SSH.PublicKey'))))
563+
LEFT JOIN `ssh_keypairs` ON (((`ssh_keypairs`.`public_key` = `ssh_details`.`value`)
564+
AND (`ssh_keypairs`.`account_id` = `account`.`id`))))
565+
LEFT JOIN `resource_tags` ON (((`resource_tags`.`resource_id` = `vm_instance`.`id`)
566+
AND (`resource_tags`.`resource_type` = 'UserVm'))))
567+
LEFT JOIN `async_job` ON (((`async_job`.`instance_id` = `vm_instance`.`id`)
568+
AND (`async_job`.`instance_type` = 'VirtualMachine')
569+
AND (`async_job`.`job_status` = 0))))
570+
LEFT JOIN `affinity_group_vm_map` ON ((`vm_instance`.`id` = `affinity_group_vm_map`.`instance_id`)))
571+
LEFT JOIN `affinity_group` ON ((`affinity_group_vm_map`.`affinity_group_id` = `affinity_group`.`id`)))
572+
LEFT JOIN `user_vm_details` `custom_cpu` ON (((`custom_cpu`.`vm_id` = `vm_instance`.`id`)
573+
AND (`custom_cpu`.`name` = 'CpuNumber'))))
574+
LEFT JOIN `user_vm_details` `custom_speed` ON (((`custom_speed`.`vm_id` = `vm_instance`.`id`)
575+
AND (`custom_speed`.`name` = 'CpuSpeed'))))
576+
LEFT JOIN `user_vm_details` `custom_ram_size` ON (((`custom_ram_size`.`vm_id` = `vm_instance`.`id`)
577+
AND (`custom_ram_size`.`name` = 'memory'))));
578+
395579
-- Update name for global configuration user.vm.readonly.ui.details
396580
Update configuration set name='user.vm.readonly.details' where name='user.vm.readonly.ui.details';
397581

server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
277277
nicResponse.setType(userVm.getGuestType().toString());
278278
}
279279
nicResponse.setIsDefault(userVm.isDefaultNic());
280+
nicResponse.setDeviceId(String.valueOf(userVm.getNicDeviceId()));
280281
List<NicSecondaryIpVO> secondaryIps = ApiDBUtils.findNicSecondaryIps(userVm.getNicId());
281282
if (secondaryIps != null) {
282283
List<NicSecondaryIpResponse> ipList = new ArrayList<NicSecondaryIpResponse>();
@@ -437,6 +438,7 @@ public UserVmResponse setUserVmResponse(ResponseView view, UserVmResponse userVm
437438
}
438439
/*17: default*/
439440
nicResponse.setIsDefault(uvo.isDefaultNic());
441+
nicResponse.setDeviceId(String.valueOf(uvo.getNicDeviceId()));
440442
List<NicSecondaryIpVO> secondaryIps = ApiDBUtils.findNicSecondaryIps(uvo.getNicId());
441443
if (secondaryIps != null) {
442444
List<NicSecondaryIpResponse> ipList = new ArrayList<NicSecondaryIpResponse>();

server/src/main/java/com/cloud/api/query/vo/UserVmJoinVO.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ public class UserVmJoinVO extends BaseViewWithTagInformationVO implements Contro
276276
@Column(name = "nic_uuid")
277277
private String nicUuid;
278278

279+
@Column(name = "nic_device_id")
280+
private Integer nicDeviceId = null;
281+
279282
@Column(name = "is_default_nic")
280283
private boolean isDefaultNic;
281284

@@ -668,6 +671,10 @@ public long getNicId() {
668671
return nicId;
669672
}
670673

674+
public Integer getNicDeviceId() {
675+
return nicDeviceId;
676+
}
677+
671678
public boolean isDefaultNic() {
672679
return isDefaultNic;
673680
}

ui/src/views/network/NicsTable.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ export default {
9090
data () {
9191
return {
9292
nicColumns: [
93+
{
94+
title: this.$t('label.deviceid'),
95+
dataIndex: 'deviceid',
96+
scopedSlots: { customRender: 'deviceid' }
97+
},
9398
{
9499
title: this.$t('label.networkname'),
95100
dataIndex: 'networkname',

0 commit comments

Comments
 (0)