nvazquez commented on a change in pull request #3240: [WIP DO NOT MERGE] api: 
instance and template details are free text
URL: https://github.com/apache/cloudstack/pull/3240#discussion_r289920549
 
 

 ##########
 File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
 ##########
 @@ -3399,6 +3407,50 @@ else if (!template.isPublicTemplate() && 
caller.getType() != Account.ACCOUNT_TYP
                 hypervisorType, true, cmd.listInReadyState(), 
permittedAccounts, caller, listProjectResourcesCriteria, tags, showRemovedISO, 
null, null);
     }
 
+    @Override
+    public DetailOptionsResponse listDetailOptions(final ListDetailOptionsCmd 
cmd) {
+        final ResourceObjectType type = cmd.getResourceType();
+        final String resourceUuid = cmd.getResourceId();
+        final Map<String, List<String>> options = new HashMap<>();
+        switch (type) {
+            case Template:
+            case UserVm:
+                HypervisorType hypervisorType = HypervisorType.None;
+                if (!Strings.isNullOrEmpty(resourceUuid) && 
ResourceObjectType.Template.equals(type)) {
+                    hypervisorType = 
_templateDao.findByUuid(resourceUuid).getHypervisorType();
+                }
+                if (!Strings.isNullOrEmpty(resourceUuid) && 
ResourceObjectType.UserVm.equals(type)) {
+                    hypervisorType = 
_vmInstanceDao.findByUuid(resourceUuid).getHypervisorType();
+                }
+                fillVMOrTemplateDetailOptions(options, hypervisorType);
+                break;
+            default:
+                throw new CloudRuntimeException("Resource type not 
supported.");
+        }
+        return new DetailOptionsResponse(options);
+    }
+
+    private void fillVMOrTemplateDetailOptions(final Map<String, List<String>> 
options, final HypervisorType hypervisorType) {
+        if (options == null) {
+            throw new CloudRuntimeException("Invalid/null detail-options 
response object passed");
+        }
+
+        options.put(VmDetailConstants.KEYBOARD, Arrays.asList("uk", "us", 
"jp", "fr"));
+        options.put(VmDetailConstants.CPU_CORE_PER_SOCKET, 
Collections.emptyList());
+
+        if (HypervisorType.KVM.equals(hypervisorType)) {
+            options.put(VmDetailConstants.ROOT_DISK_CONTROLLER, 
Arrays.asList("ide", "scsi", "virtio"));
+        }
+
+        if (HypervisorType.VMware.equals(hypervisorType)) {
+            options.put(VmDetailConstants.NIC_ADAPTER, Arrays.asList("E1000", 
"PCNet32", "Vmxnet2", "Vmxnet3"));
 
 Review comment:
   Similar as @DaanHoogland points out, what if we move these to a place in 
which we can read them and also perform validation?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to