Skip to content

Commit bedd77f

Browse files
committed
Addition of description field for NIC's secondary IP addresses
1 parent b744824 commit bedd77f

File tree

16 files changed

+59
-10
lines changed

16 files changed

+59
-10
lines changed

api/src/main/java/com/cloud/network/NetworkService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Network createPrivateNetwork(String networkName, String displayText, long physic
232232
/**
233233
* Requests an IP address for the guest NIC
234234
*/
235-
NicSecondaryIp allocateSecondaryGuestIP(long nicId, IpAddresses requestedIpPair) throws InsufficientAddressCapacityException;
235+
NicSecondaryIp allocateSecondaryGuestIP(long nicId, IpAddresses requestedIpPair, String description) throws InsufficientAddressCapacityException;
236236

237237
boolean releaseSecondaryIpFromNic(long ipAddressId);
238238

api/src/main/java/com/cloud/vm/NicSecondaryIp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public interface NicSecondaryIp extends ControlledEntity, Identity, InternalIden
3838

3939
String getIp6Address();
4040

41+
String getDescription();
42+
4143
long getNetworkId();
4244

4345
long getVmId();

api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public class AddIpToVmNicCmd extends BaseAsyncCreateCmd {
5656
@Parameter(name = ApiConstants.IP_ADDRESS, type = CommandType.STRING, required = false, description = "Secondary IP Address")
5757
private String ipAddr;
5858

59+
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, required = false, description = "Description")
60+
private String description;
61+
5962
/////////////////////////////////////////////////////
6063
/////////////////// Accessors ///////////////////////
6164
/////////////////////////////////////////////////////
@@ -160,7 +163,7 @@ public void create() throws ResourceAllocationException {
160163
}
161164

162165
try {
163-
result = _networkService.allocateSecondaryGuestIP(getNicId(), requestedIpPair);
166+
result = _networkService.allocateSecondaryGuestIP(getNicId(), requestedIpPair, description);
164167
if (result != null) {
165168
setEntityId(result.getId());
166169
setEntityUuid(result.getUuid());

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public class NicSecondaryIpResponse extends BaseResponse {
5353
@Param(description = "The ID of the Instance")
5454
private String vmId;
5555

56+
@SerializedName(ApiConstants.DESCRIPTION)
57+
@Param(description = "description")
58+
private String description;
59+
5660
@Override
5761
public String getObjectId() {
5862
return this.getId();
@@ -98,6 +102,14 @@ public void setId(String id) {
98102
this.id = id;
99103
}
100104

105+
public String getDescription() {
106+
return description;
107+
}
108+
109+
public void setDescription(String description) {
110+
this.description = description;
111+
}
112+
101113
public List<NicSecondaryIpResponse> getSecondaryIpsList() {
102114
return secondaryIpsList;
103115
}

api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void testCreateSuccess() throws ResourceAllocationException, ResourceUnav
5959
NicSecondaryIp secIp = Mockito.mock(NicSecondaryIp.class);
6060

6161
Mockito.when(
62-
networkService.allocateSecondaryGuestIP(ArgumentMatchers.anyLong(), ArgumentMatchers.any()))
62+
networkService.allocateSecondaryGuestIP(ArgumentMatchers.anyLong(), ArgumentMatchers.any(), ArgumentMatchers.anyString()))
6363
.thenReturn(secIp);
6464

6565
ipTonicCmd._networkService = networkService;
@@ -79,7 +79,7 @@ public void testCreateFailure() throws ResourceAllocationException, ResourceUnav
7979
AddIpToVmNicCmd ipTonicCmd = Mockito.mock(AddIpToVmNicCmd.class);
8080

8181
Mockito.when(
82-
networkService.allocateSecondaryGuestIP(ArgumentMatchers.anyLong(), ArgumentMatchers.any()))
82+
networkService.allocateSecondaryGuestIP(ArgumentMatchers.anyLong(), ArgumentMatchers.any(), ArgumentMatchers.anyString()))
8383
.thenReturn(null);
8484

8585
ipTonicCmd._networkService = networkService;

engine/schema/src/main/java/com/cloud/vm/dao/NicSecondaryIpVO.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ public NicSecondaryIpVO(long nicId, String ipaddr, long vmId, long accountId, lo
4343
this.networkId = networkId;
4444
}
4545

46-
public NicSecondaryIpVO(long nicId, String ip4Address, String ip6Address, long vmId, long accountId, long domainId, long networkId) {
46+
public NicSecondaryIpVO(long nicId, String ip4Address, String ip6Address, long vmId, long accountId, long domainId, long networkId, String description) {
4747
this.nicId = nicId;
4848
this.vmId = vmId;
4949
this.ip4Address = ip4Address;
5050
this.ip6Address = ip6Address;
5151
this.accountId = accountId;
5252
this.domainId = domainId;
5353
this.networkId = networkId;
54+
this.description = description;
5455
}
5556

5657
protected NicSecondaryIpVO() {
@@ -88,6 +89,18 @@ protected NicSecondaryIpVO() {
8889
@Column(name = "vmId")
8990
long vmId;
9091

92+
@Column(name = "description")
93+
String description;
94+
95+
@Override
96+
public String getDescription() {
97+
return description;
98+
}
99+
100+
public void setDescription(String description) {
101+
this.description = description;
102+
}
103+
91104
@Override
92105
public String toString() {
93106
return String.format("NicSecondaryIp %s",

engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,6 @@ CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Resource Admin', 'deleteUserKey
114114

115115
-- Add conserve mode for VPC offerings
116116
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc_offerings','conserve_mode', 'tinyint(1) unsigned NULL DEFAULT 0 COMMENT ''True if the VPC offering is IP conserve mode enabled, allowing public IP services to be used across multiple VPC tiers'' ');
117+
118+
-- Add description for secondary IP addresses
119+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.nic_secondary_ips','description', 'varchar(2048) DEFAULT NULL');

server/src/main/java/com/cloud/api/ApiResponseHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4729,6 +4729,7 @@ public NicSecondaryIpResponse createSecondaryIPToNicResponse(NicSecondaryIp resu
47294729
setResponseIpAddress(result, response);
47304730
response.setNicId(nic.getUuid());
47314731
response.setNwId(network.getUuid());
4732+
response.setDescription(result.getDescription());
47324733
response.setObjectName("nicsecondaryip");
47334734
return response;
47344735
}
@@ -4815,6 +4816,7 @@ public NicResponse createNicResponse(Nic result) {
48154816
for (NicSecondaryIpVO ip : secondaryIps) {
48164817
NicSecondaryIpResponse ipRes = new NicSecondaryIpResponse();
48174818
ipRes.setId(ip.getUuid());
4819+
ipRes.setDescription(ip.getDescription());
48184820
setResponseIpAddress(ip, ipRes);
48194821
ipList.add(ipRes);
48204822
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
384384
for (NicSecondaryIpVO ip : secondaryIps) {
385385
NicSecondaryIpResponse ipRes = new NicSecondaryIpResponse();
386386
ipRes.setId(ip.getUuid());
387+
ipRes.setDescription(ip.getDescription());
387388
ApiResponseHelper.setResponseIpAddress(ip, ipRes);
388389
ipList.add(ipRes);
389390
}

server/src/main/java/com/cloud/network/NetworkServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ public boolean configureNicSecondaryIp(NicSecondaryIp secIp, boolean isZoneSgEna
887887
*/
888888
@Override
889889
@ActionEvent(eventType = EventTypes.EVENT_NIC_SECONDARY_IP_ASSIGN, eventDescription = "Assigning secondary IP to NIC", create = true)
890-
public NicSecondaryIp allocateSecondaryGuestIP(final long nicId, IpAddresses requestedIpPair) throws InsufficientAddressCapacityException {
890+
public NicSecondaryIp allocateSecondaryGuestIP(final long nicId, IpAddresses requestedIpPair, String description) throws InsufficientAddressCapacityException {
891891

892892
Account caller = CallContext.current().getCallingAccount();
893893
String ipv4Address = requestedIpPair.getIp4Address();
@@ -985,7 +985,7 @@ public Long doInTransaction(TransactionStatus status) {
985985

986986
logger.debug("Setting nic_secondary_ip table ...");
987987
Long vmId = nicVO.getInstanceId();
988-
NicSecondaryIpVO secondaryIpVO = new NicSecondaryIpVO(nicId, ip4AddrFinal, ip6AddrFinal, vmId, ipOwner.getId(), ipOwner.getDomainId(), networkId);
988+
NicSecondaryIpVO secondaryIpVO = new NicSecondaryIpVO(nicId, ip4AddrFinal, ip6AddrFinal, vmId, ipOwner.getId(), ipOwner.getDomainId(), networkId, description);
989989
_nicSecondaryIpDao.persist(secondaryIpVO);
990990
return secondaryIpVO.getId();
991991
}

0 commit comments

Comments
 (0)