[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-9542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16299929#comment-16299929
 ] 

ASF GitHub Bot commented on CLOUDSTACK-9542:
--------------------------------------------

rhtyd closed pull request #2208: CLOUDSTACK-9542 make listNics and ListUserVms 
return uniform NIC data
URL: https://github.com/apache/cloudstack/pull/2208
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/server/src/com/cloud/api/ApiResponseHelper.java 
b/server/src/com/cloud/api/ApiResponseHelper.java
index b0898baa2da..098814c47ef 100644
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -3592,6 +3592,10 @@ public NicSecondaryIpResponse 
createSecondaryIPToNicResponse(NicSecondaryIp resu
         return response;
     }
 
+    /**
+     * The resulting Response attempts to be in line with what is returned from
+     * @see 
com.cloud.api.query.dao.UserVmJoinDaoImpl#setUserVmResponse(ResponseView, 
UserVmResponse, UserVmJoinVO)
+     */
     @Override
     public NicResponse createNicResponse(Nic result) {
         NicResponse response = new NicResponse();
@@ -3600,30 +3604,63 @@ public NicResponse createNicResponse(Nic result) {
         UserVmJoinVO userVm = _entityMgr.findById(UserVmJoinVO.class, 
result.getInstanceId());
         List<NicExtraDhcpOptionVO> nicExtraDhcpOptionVOs = 
_nicExtraDhcpOptionDao.listByNicId(result.getId());
 
+        // The numbered comments are to keep track of the data returned from 
here and UserVmJoinDaoImpl.setUserVmResponse()
+        // the data can't be identical but some tidying up/unifying might be 
possible
+        /*1: nicUuid*/
         response.setId(result.getUuid());
+        /*2: networkUuid*/
         response.setNetworkid(network.getUuid());
-
+        /*3: vmId*/
         if (vm != null) {
             response.setVmId(vm.getUuid());
         }
 
         if (userVm != null){
             if (userVm.getTrafficType() != null) {
+                /*4: trafficType*/
                 response.setTrafficType(userVm.getTrafficType().toString());
             }
             if (userVm.getGuestType() != null) {
+                /*5: guestType*/
                 response.setType(userVm.getGuestType().toString());
             }
         }
+        /*6: ipAddress*/
         response.setIpaddress(result.getIPv4Address());
-
-        List<NicExtraDhcpOptionResponse> nicExtraDhcpOptionResponses = 
nicExtraDhcpOptionVOs
-                .stream()
-                .map(vo -> new 
NicExtraDhcpOptionResponse(Dhcp.DhcpOptionCode.valueOfInt(vo.getCode()).getName(),
 vo.getCode(), vo.getValue()))
-                .collect(Collectors.toList());
-
-        response.setExtraDhcpOptions(nicExtraDhcpOptionResponses);
-
+        /*7: gateway*/
+        response.setGateway(result.getIPv4Gateway());
+        /*8: netmask*/
+        response.setNetmask(result.getIPv4Netmask());
+        /*9: networkName*/
+        if(userVm != null && userVm.getNetworkName() != null) {
+            response.setNetworkName(userVm.getNetworkName());
+        }
+        /*10: macAddress*/
+        response.setMacAddress(result.getMacAddress());
+        /*11: IPv6Address*/
+        if (result.getIPv6Address() != null) {
+            response.setIp6Address(result.getIPv6Address());
+        }
+        /*12: IPv6Gateway*/
+        if (result.getIPv6Gateway() != null) {
+            response.setIp6Gateway(result.getIPv6Gateway());
+        }
+        /*13: IPv6Cidr*/
+        if (result.getIPv6Cidr() != null) {
+            response.setIp6Cidr(result.getIPv6Cidr());
+        }
+        /*14: deviceId*/
+        response.setDeviceId(String.valueOf(result.getDeviceId()));
+        /*15: broadcastURI*/
+        if (result.getBroadcastUri() != null) {
+            response.setBroadcastUri(result.getBroadcastUri().toString());
+        }
+        /*16: isolationURI*/
+        if (result.getIsolationUri() != null) {
+            response.setIsolationUri(result.getIsolationUri().toString());
+        }
+        /*17: default*/
+        response.setIsDefault(result.isDefaultNic());
         if (result.getSecondaryIp()) {
             List<NicSecondaryIpVO> secondaryIps = 
ApiDBUtils.findNicSecondaryIps(result.getId());
             if (secondaryIps != null) {
@@ -3637,22 +3674,13 @@ public NicResponse createNicResponse(Nic result) {
                 response.setSecondaryIps(ipList);
             }
         }
+        /*18: extra dhcp options */
+        List<NicExtraDhcpOptionResponse> nicExtraDhcpOptionResponses = 
nicExtraDhcpOptionVOs
+                .stream()
+                .map(vo -> new 
NicExtraDhcpOptionResponse(Dhcp.DhcpOptionCode.valueOfInt(vo.getCode()).getName(),
 vo.getCode(), vo.getValue()))
+                .collect(Collectors.toList());
 
-        response.setGateway(result.getIPv4Gateway());
-        response.setNetmask(result.getIPv4Netmask());
-        response.setMacAddress(result.getMacAddress());
-
-        if (result.getIPv6Address() != null) {
-            response.setIp6Address(result.getIPv6Address());
-        }
-
-        if (result.getIPv6Cidr() != null) {
-            response.setIp6Cidr(result.getIPv6Cidr());
-        }
-
-        response.setDeviceId(String.valueOf(result.getDeviceId()));
-
-        response.setIsDefault(result.isDefaultNic());
+        response.setExtraDhcpOptions(nicExtraDhcpOptionResponses);
 
         if (result instanceof NicVO){
             if (((NicVO)result).getNsxLogicalSwitchUuid() != null){
diff --git a/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java 
b/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
index c0eb222be16..f0a0a56e3c6 100644
--- a/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
@@ -324,6 +324,10 @@ public UserVmResponse newUserVmResponse(ResponseView view, 
String objectName, Us
         return userVmResponse;
     }
 
+    /**
+     * The resulting Response attempts to be in line with what is returned from
+     * @see com.cloud.api.ApiResponseHelper#createNicResponse(Nic)
+     */
     @Override
     public UserVmResponse setUserVmResponse(ResponseView view, UserVmResponse 
userVmData, UserVmJoinVO uvo) {
         Long securityGroupId = uvo.getSecurityGroupId();
@@ -345,28 +349,50 @@ public UserVmResponse setUserVmResponse(ResponseView 
view, UserVmResponse userVm
         long nic_id = uvo.getNicId();
         if (nic_id > 0) {
             NicResponse nicResponse = new NicResponse();
+            // The numbered comments are to keep track of the data returned 
from here and ApiResponseHelper.createNicResponse()
+            // the data can't be identical but some tidying up/unifying might 
be possible
+            /*1: nicUuid*/
             nicResponse.setId(uvo.getNicUuid());
+            /*2: networkUuid*/
+            nicResponse.setNetworkid(uvo.getNetworkUuid());
+            /*3: vmId makes no sense on a nested nic object so it is ommited 
here */
+
+            if (uvo.getTrafficType() != null) {
+            /*4: trafficType*/
+                nicResponse.setTrafficType(uvo.getTrafficType().toString());
+            }
+            if (uvo.getGuestType() != null) {
+                /*5: guestType*/
+                nicResponse.setType(uvo.getGuestType().toString());
+            }
+            /*6: ipAddress*/
             nicResponse.setIpaddress(uvo.getIpAddress());
+            /*7: gateway*/
             nicResponse.setGateway(uvo.getGateway());
+            /*8: netmask*/
             nicResponse.setNetmask(uvo.getNetmask());
-            nicResponse.setNetworkid(uvo.getNetworkUuid());
+            /*9: networkName*/
             nicResponse.setNetworkName(uvo.getNetworkName());
+            /*10: macAddress*/
             nicResponse.setMacAddress(uvo.getMacAddress());
+            /*11: IPv6Address*/
             nicResponse.setIp6Address(uvo.getIp6Address());
+            /*12: IPv6Gateway*/
             nicResponse.setIp6Gateway(uvo.getIp6Gateway());
+            /*13: IPv6Cidr*/
             nicResponse.setIp6Cidr(uvo.getIp6Cidr());
+            /*14: deviceId*/
+// where do we find           nicResponse.setDeviceId(
+// this is probably not String.valueOf(uvo.getNicId())); as this is a db-id
+            /*15: broadcastURI*/
             if (uvo.getBroadcastUri() != null) {
                 nicResponse.setBroadcastUri(uvo.getBroadcastUri().toString());
             }
+            /*16: isolationURI*/
             if (uvo.getIsolationUri() != null) {
                 nicResponse.setIsolationUri(uvo.getIsolationUri().toString());
             }
-            if (uvo.getTrafficType() != null) {
-                nicResponse.setTrafficType(uvo.getTrafficType().toString());
-            }
-            if (uvo.getGuestType() != null) {
-                nicResponse.setType(uvo.getGuestType().toString());
-            }
+            /*17: default*/
             nicResponse.setIsDefault(uvo.isDefaultNic());
             List<NicSecondaryIpVO> secondaryIps = 
ApiDBUtils.findNicSecondaryIps(uvo.getNicId());
             if (secondaryIps != null) {
@@ -380,6 +406,7 @@ public UserVmResponse setUserVmResponse(ResponseView view, 
UserVmResponse userVm
                 nicResponse.setSecondaryIps(ipList);
             }
 
+            /* 18: extra dhcp options */
             nicResponse.setObjectName("nic");
             List<NicExtraDhcpOptionResponse> nicExtraDhcpOptionResponses = 
_nicExtraDhcpOptionDao.listByNicId(nic_id)
                     .stream()


 

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


> listNics API does not return data as per API documentation
> ----------------------------------------------------------
>
>                 Key: CLOUDSTACK-9542
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-9542
>             Project: CloudStack
>          Issue Type: Bug
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>          Components: API
>    Affects Versions: 4.5.2, 4.6.2
>         Environment: ACS
>            Reporter: Paul Angus
>            Assignee: Daan Hoogland
>             Fix For: 4.9.2.0, 4.9.1.0, 4.10.1.0
>
>
> Using both Chrome developer tools ans Cloudmonkey to confirm API responses, 
> listNics returns a subset of the NIC information. (as specified in the API 
> documentation)
> {"listnicsresponse":{"count":1,"nic":[{"id":"fbbe345b-6cbd-495f-8e27-d180d782ccbe","networkid":"30002db2-be52-489f-8307-5c2fbcbea374","netmask":"255.255.255.0","gateway":"10.5.1.254","ipaddress":"10.5.1.107","isdefault":true,"macaddress":"06:39:9c:01:0a:5b","deviceid":"0","virtualmachineid":"c65e6c6a-1d9e-4812-89c7-2af2858af76b"}]}}
> However listVirtualMachines does return the full detail.
> {"listvirtualmachinesresponse":{"count":1,"virtualmachine":[{"id":"c65e6c6a-1d9e-4812-89c7-2af2858af76b","name":"sbjenkins-cattle1","displayname":"sbjenkins-cattle1","account":"ryadav","domainid":"5dfaa086-6a9c-11e6-8ec0-0050568ef122","domain":"ROOT","created":"2016-09-09T01:44:25+0100","state":"Running","haenable":false,"zoneid":"c852110c-e1b5-4c8c-9e3d-f2a6e76b8fc0","zonename":"SBLAB-SW19-1","hostid":"fff7cdce-9d1d-408c-a37a-68e19113c092","hostname":"10.2.0.22","guestosid":"0372db46-6a9d-11e6-8ec0-0050568ef122","securitygroup":[],-->>
> "nic":[{"id":"fbbe345b-6cbd-495f-8e27-d180d782ccbe","networkid":"30002db2-be52-489f-8307-5c2fbcbea374","networkname":"JenkinsNet","netmask":"255.255.255.0","gateway":"10.5.1.254","ipaddress":"10.5.1.107","isolationuri":"vlan://12","broadcasturi":"vlan://12","traffictype":"Guest","type":"Shared","isdefault":true,"macaddress":"06:39:9c:01:0a:5b"}],
> <<--"hypervisor":"VMware","instancename":"i-15-93-VM","tags":[],"affinitygroup":[],"displayvm":true,"isdynamicallyscalable":false,"ostypeid":254}]}}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to