mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-17 11:04:00 +01:00
Merge pull request #2126 from Accelerite/CLOUDSTACK-9740
CLOUDSTACK-9740 : Search for secondary IP of NIC that is attached to an instance is not working
This commit is contained in:
commit
9fd0965087
@ -180,4 +180,6 @@ public interface NetworkService {
|
|||||||
IpAddress updateIP(Long id, String customId, Boolean displayIp);
|
IpAddress updateIP(Long id, String customId, Boolean displayIp);
|
||||||
|
|
||||||
boolean configureNicSecondaryIp(NicSecondaryIp secIp, boolean isZoneSgEnabled);
|
boolean configureNicSecondaryIp(NicSecondaryIp secIp, boolean isZoneSgEnabled);
|
||||||
|
|
||||||
|
List<? extends NicSecondaryIp> listVmNicSecondaryIps(ListNicsCmd listNicsCmd);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,8 @@ package org.apache.cloudstack.api.command.user.vm;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import com.cloud.vm.NicSecondaryIp;
|
||||||
|
import org.apache.cloudstack.api.response.NicSecondaryIpResponse;
|
||||||
import org.apache.cloudstack.acl.RoleType;
|
import org.apache.cloudstack.acl.RoleType;
|
||||||
import org.apache.cloudstack.api.APICommand;
|
import org.apache.cloudstack.api.APICommand;
|
||||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||||
@ -122,22 +123,45 @@ public class ListNicsCmd extends BaseListCmd {
|
|||||||
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
|
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<? extends Nic> results = _networkService.listNics(this);
|
if (this.getKeyword() != null && !this.getKeyword().isEmpty() && this.getNicId() != null) {
|
||||||
ListResponse<NicResponse> response = new ListResponse<NicResponse>();
|
List<? extends NicSecondaryIp> results = _networkService.listVmNicSecondaryIps(this);
|
||||||
List<NicResponse> resList = null;
|
ListResponse<NicSecondaryIpResponse> response = new ListResponse<NicSecondaryIpResponse>();
|
||||||
if (results != null) {
|
List<NicSecondaryIpResponse> resList = new ArrayList<NicSecondaryIpResponse>();
|
||||||
resList = new ArrayList<NicResponse>(results.size());
|
NicSecondaryIpResponse res = new NicSecondaryIpResponse();
|
||||||
for (Nic r : results) {
|
List<NicSecondaryIpResponse> res_List = new ArrayList<NicSecondaryIpResponse>();
|
||||||
NicResponse resp = _responseGenerator.createNicResponse(r);
|
if (results != null) {
|
||||||
resp.setObjectName("nic");
|
for (NicSecondaryIp r : results) {
|
||||||
resList.add(resp);
|
NicSecondaryIpResponse ipRes = _responseGenerator.createSecondaryIPToNicResponse(r);
|
||||||
}
|
resList.add(ipRes);
|
||||||
response.setResponses(resList);
|
res.setSecondaryIpsList(resList);
|
||||||
}
|
res.setObjectName("nic");
|
||||||
response.setResponses(resList);
|
}
|
||||||
response.setResponseName(getCommandName());
|
|
||||||
this.setResponseObject(response);
|
|
||||||
|
|
||||||
|
res_List.add(res);
|
||||||
|
response.setResponses(res_List);
|
||||||
|
}
|
||||||
|
response.setResponses(res_List);
|
||||||
|
response.setResponseName(getCommandName());
|
||||||
|
this.setResponseObject(response);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
List<? extends Nic> results = _networkService.listNics(this);
|
||||||
|
ListResponse<NicResponse> response = new ListResponse<NicResponse>();
|
||||||
|
List<NicResponse> resList = null;
|
||||||
|
if (results != null) {
|
||||||
|
resList = new ArrayList<NicResponse>(results.size());
|
||||||
|
for (Nic r : results) {
|
||||||
|
NicResponse resp = _responseGenerator.createNicResponse(r);
|
||||||
|
resp.setObjectName("nic");
|
||||||
|
resList.add(resp);
|
||||||
|
}
|
||||||
|
response.setResponses(resList);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.setResponses(resList);
|
||||||
|
response.setResponseName(getCommandName());
|
||||||
|
this.setResponseObject(response);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
s_logger.warn("Failed to list secondary ip address per nic ");
|
s_logger.warn("Failed to list secondary ip address per nic ");
|
||||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
|
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
package org.apache.cloudstack.api.response;
|
package org.apache.cloudstack.api.response;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import java.util.List;
|
||||||
import org.apache.cloudstack.api.ApiConstants;
|
import org.apache.cloudstack.api.ApiConstants;
|
||||||
import org.apache.cloudstack.api.BaseResponse;
|
import org.apache.cloudstack.api.BaseResponse;
|
||||||
import org.apache.cloudstack.api.EntityReference;
|
import org.apache.cloudstack.api.EntityReference;
|
||||||
@ -33,6 +33,10 @@ public class NicSecondaryIpResponse extends BaseResponse {
|
|||||||
@Param(description = "the ID of the secondary private IP addr")
|
@Param(description = "the ID of the secondary private IP addr")
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
@SerializedName("secondaryip")
|
||||||
|
@Param(description = "the list of Secondary ipv4 addr of nic")
|
||||||
|
private List<NicSecondaryIpResponse> secondaryIpsList;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.IP_ADDRESS)
|
@SerializedName(ApiConstants.IP_ADDRESS)
|
||||||
@Param(description = "Secondary IP address")
|
@Param(description = "Secondary IP address")
|
||||||
private String ipAddr;
|
private String ipAddr;
|
||||||
@ -94,4 +98,11 @@ public class NicSecondaryIpResponse extends BaseResponse {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<NicSecondaryIpResponse> getSecondaryIpsList() {
|
||||||
|
return secondaryIpsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecondaryIpsList(List<NicSecondaryIpResponse> secondaryIpsList) {
|
||||||
|
this.secondaryIpsList = secondaryIpsList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -213,7 +213,7 @@ public interface NetworkOrchestrationService {
|
|||||||
|
|
||||||
boolean isSecondaryIpSetForNic(long nicId);
|
boolean isSecondaryIpSetForNic(long nicId);
|
||||||
|
|
||||||
List<? extends Nic> listVmNics(long vmId, Long nicId, Long networkId);
|
List<? extends Nic> listVmNics(long vmId, Long nicId, Long networkId, String keyword);
|
||||||
|
|
||||||
Nic savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType);
|
Nic savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType);
|
||||||
|
|
||||||
|
|||||||
@ -2894,12 +2894,17 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends Nic> listVmNics(final long vmId, final Long nicId, final Long networkId) {
|
public List<? extends Nic> listVmNics(final long vmId, final Long nicId, final Long networkId, String keyword) {
|
||||||
List<NicVO> result = null;
|
List<NicVO> result = null;
|
||||||
if (nicId == null && networkId == null) {
|
|
||||||
result = _nicDao.listByVmId(vmId);
|
if (keyword == null || keyword.isEmpty()) {
|
||||||
|
if (nicId == null && networkId == null) {
|
||||||
|
result = _nicDao.listByVmId(vmId);
|
||||||
|
} else {
|
||||||
|
result = _nicDao.listByVmIdAndNicIdAndNtwkId(vmId, nicId, networkId);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result = _nicDao.listByVmIdAndNicIdAndNtwkId(vmId, nicId, networkId);
|
result = _nicDao.listByVmIdAndKeyword(vmId, keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final NicVO nic : result) {
|
for (final NicVO nic : result) {
|
||||||
|
|||||||
@ -76,4 +76,6 @@ public interface NicDao extends GenericDao<NicVO, Long> {
|
|||||||
int countNicsForStartingVms(long networkId);
|
int countNicsForStartingVms(long networkId);
|
||||||
|
|
||||||
NicVO getControlNicForVM(long vmId);
|
NicVO getControlNicForVM(long vmId);
|
||||||
|
|
||||||
|
List<NicVO> listByVmIdAndKeyword(long instanceId, String keyword);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,7 +60,7 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
|
|||||||
AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
|
AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
|
||||||
AllFieldsSearch.and("gateway", AllFieldsSearch.entity().getIPv4Gateway(), Op.EQ);
|
AllFieldsSearch.and("gateway", AllFieldsSearch.entity().getIPv4Gateway(), Op.EQ);
|
||||||
AllFieldsSearch.and("vmType", AllFieldsSearch.entity().getVmType(), Op.EQ);
|
AllFieldsSearch.and("vmType", AllFieldsSearch.entity().getVmType(), Op.EQ);
|
||||||
AllFieldsSearch.and("address", AllFieldsSearch.entity().getIPv4Address(), Op.EQ);
|
AllFieldsSearch.and("address", AllFieldsSearch.entity().getIPv4Address(), Op.LIKE);
|
||||||
AllFieldsSearch.and("isDefault", AllFieldsSearch.entity().isDefaultNic(), Op.EQ);
|
AllFieldsSearch.and("isDefault", AllFieldsSearch.entity().isDefaultNic(), Op.EQ);
|
||||||
AllFieldsSearch.and("broadcastUri", AllFieldsSearch.entity().getBroadcastUri(), Op.EQ);
|
AllFieldsSearch.and("broadcastUri", AllFieldsSearch.entity().getBroadcastUri(), Op.EQ);
|
||||||
AllFieldsSearch.and("secondaryip", AllFieldsSearch.entity().getSecondaryIp(), Op.EQ);
|
AllFieldsSearch.and("secondaryip", AllFieldsSearch.entity().getSecondaryIp(), Op.EQ);
|
||||||
@ -311,4 +311,12 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
|
|||||||
List<Integer> results = customSearch(sc, null);
|
List<Integer> results = customSearch(sc, null);
|
||||||
return results.get(0);
|
return results.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<NicVO> listByVmIdAndKeyword(long instanceId, String keyword) {
|
||||||
|
SearchCriteria<NicVO> sc = AllFieldsSearch.create();
|
||||||
|
sc.setParameters("instance", instanceId);
|
||||||
|
sc.setParameters("address", "%" + keyword + "%");
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,4 +53,6 @@ public interface NicSecondaryIpDao extends GenericDao<NicSecondaryIpVO, Long> {
|
|||||||
List<String> getSecondaryIpAddressesForNic(long nicId);
|
List<String> getSecondaryIpAddressesForNic(long nicId);
|
||||||
|
|
||||||
Long countByNicId(long nicId);
|
Long countByNicId(long nicId);
|
||||||
|
|
||||||
|
List<NicSecondaryIpVO> listSecondaryIpUsingKeyword(long nicId, String keyword);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public class NicSecondaryIpDaoImpl extends GenericDaoBase<NicSecondaryIpVO, Long
|
|||||||
AllFieldsSearch = createSearchBuilder();
|
AllFieldsSearch = createSearchBuilder();
|
||||||
AllFieldsSearch.and("instanceId", AllFieldsSearch.entity().getVmId(), Op.EQ);
|
AllFieldsSearch.and("instanceId", AllFieldsSearch.entity().getVmId(), Op.EQ);
|
||||||
AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
|
AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
|
||||||
AllFieldsSearch.and("address", AllFieldsSearch.entity().getIp4Address(), Op.EQ);
|
AllFieldsSearch.and("address", AllFieldsSearch.entity().getIp4Address(), Op.LIKE);
|
||||||
AllFieldsSearch.and("nicId", AllFieldsSearch.entity().getNicId(), Op.EQ);
|
AllFieldsSearch.and("nicId", AllFieldsSearch.entity().getNicId(), Op.EQ);
|
||||||
AllFieldsSearch.done();
|
AllFieldsSearch.done();
|
||||||
|
|
||||||
@ -146,4 +146,13 @@ public class NicSecondaryIpDaoImpl extends GenericDaoBase<NicSecondaryIpVO, Long
|
|||||||
sc.setParameters("nic", nicId);
|
sc.setParameters("nic", nicId);
|
||||||
return customSearch(sc, null).get(0);
|
return customSearch(sc, null).get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<NicSecondaryIpVO> listSecondaryIpUsingKeyword(long nicId, String keyword)
|
||||||
|
{
|
||||||
|
SearchCriteria<NicSecondaryIpVO> sc = AllFieldsSearch.create();
|
||||||
|
sc.setParameters("nicId", nicId);
|
||||||
|
sc.setParameters("address", "%" + keyword + "%");
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4140,6 +4140,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||||||
Account caller = CallContext.current().getCallingAccount();
|
Account caller = CallContext.current().getCallingAccount();
|
||||||
Long nicId = cmd.getNicId();
|
Long nicId = cmd.getNicId();
|
||||||
long vmId = cmd.getVmId();
|
long vmId = cmd.getVmId();
|
||||||
|
String keyword = cmd.getKeyword();
|
||||||
Long networkId = cmd.getNetworkId();
|
Long networkId = cmd.getNetworkId();
|
||||||
UserVmVO userVm = _userVmDao.findById(vmId);
|
UserVmVO userVm = _userVmDao.findById(vmId);
|
||||||
|
|
||||||
@ -4150,7 +4151,26 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_accountMgr.checkAccess(caller, null, true, userVm);
|
_accountMgr.checkAccess(caller, null, true, userVm);
|
||||||
return _networkMgr.listVmNics(vmId, nicId, networkId);
|
return _networkMgr.listVmNics(vmId, nicId, networkId, keyword);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends NicSecondaryIp> listVmNicSecondaryIps(ListNicsCmd cmd)
|
||||||
|
{
|
||||||
|
Account caller = CallContext.current().getCallingAccount();
|
||||||
|
Long nicId = cmd.getNicId();
|
||||||
|
long vmId = cmd.getVmId();
|
||||||
|
String keyword = cmd.getKeyword();
|
||||||
|
UserVmVO userVm = _userVmDao.findById(vmId);
|
||||||
|
|
||||||
|
if (userVm == null || (!userVm.isDisplayVm() && caller.getType() == Account.ACCOUNT_TYPE_NORMAL)) {
|
||||||
|
InvalidParameterValueException ex = new InvalidParameterValueException("Virtual mahine id does not exist");
|
||||||
|
ex.addProxyObject(Long.valueOf(vmId).toString(), "vmId");
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
_accountMgr.checkAccess(caller, null, true, userVm);
|
||||||
|
return _nicSecondaryIpDao.listSecondaryIpUsingKeyword(nicId, keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<NetworkGuru> getNetworkGurus() {
|
public List<NetworkGuru> getNetworkGurus() {
|
||||||
|
|||||||
@ -800,7 +800,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkOrches
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends Nic> listVmNics(long vmId, Long nicId, Long networkId) {
|
public List<? extends Nic> listVmNics(long vmId, Long nicId, Long networkId, String keyword) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -906,4 +906,9 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkOrches
|
|||||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends NicSecondaryIp> listVmNicSecondaryIps(ListNicsCmd listNicsCmd) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1710,11 +1710,16 @@
|
|||||||
dataProvider: function(args) {
|
dataProvider: function(args) {
|
||||||
var data = {};
|
var data = {};
|
||||||
|
|
||||||
|
if (args.filterBy.search.value != null) {
|
||||||
|
data.keyword = args.filterBy.search.value;
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: createURL('listNics'),
|
url: createURL('listNics'),
|
||||||
data: {
|
data: {
|
||||||
nicId: args.context.nics[0].id,
|
nicId: args.context.nics[0].id,
|
||||||
virtualmachineid: args.context.instances[0].id
|
virtualmachineid: args.context.instances[0].id,
|
||||||
|
keyword: args.filterBy.search.value
|
||||||
},
|
},
|
||||||
success: function(json) {
|
success: function(json) {
|
||||||
var ips = json.listnicsresponse.nic ? json.listnicsresponse.nic[0].secondaryip : [];
|
var ips = json.listnicsresponse.nic ? json.listnicsresponse.nic[0].secondaryip : [];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user