Skip to content

Commit 02bb5de

Browse files
erikbocksDaanHooglandbernardodemarco
authored
Addition of description field for NIC's secondary IP addresses (#12864)
* Addition of description field for NIC's secondary IP addresses * Address copilot's review * Add newline at the end of file Co-authored-by: dahn <daan.hoogland@gmail.com> * Address Wei's label changes * Remove colon from label * Apply suggestions from code review Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com> * Fix missing newline at end of SQL file --------- Co-authored-by: dahn <daan.hoogland@gmail.com> Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com>
1 parent ce9793c commit 02bb5de

15 files changed

Lines changed: 57 additions & 9 deletions

File tree

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 of the secondary IP address", length = 2048)
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 of the secondary IP address")
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
@@ -208,3 +208,6 @@ INSERT INTO cloud.role_permissions (uuid, role_id, rule, permission, sort_order)
208208
SELECT uuid(), role_id, 'quotaResourceStatement', permission, sort_order
209209
FROM cloud.role_permissions rp
210210
WHERE rule = 'quotaStatement' AND NOT EXISTS(SELECT 1 FROM cloud.role_permissions rp_ WHERE rp.role_id = rp_.role_id AND rp_.rule = 'quotaResourceStatement');
211+
212+
-- Add description for secondary IP addresses
213+
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
@@ -4759,6 +4759,7 @@ public NicSecondaryIpResponse createSecondaryIPToNicResponse(NicSecondaryIp resu
47594759
setResponseIpAddress(result, response);
47604760
response.setNicId(nic.getUuid());
47614761
response.setNwId(network.getUuid());
4762+
response.setDescription(result.getDescription());
47624763
response.setObjectName("nicsecondaryip");
47634764
return response;
47644765
}
@@ -4845,6 +4846,7 @@ public NicResponse createNicResponse(Nic result) {
48454846
for (NicSecondaryIpVO ip : secondaryIps) {
48464847
NicSecondaryIpResponse ipRes = new NicSecondaryIpResponse();
48474848
ipRes.setId(ip.getUuid());
4849+
ipRes.setDescription(ip.getDescription());
48484850
setResponseIpAddress(ip, ipRes);
48494851
ipList.add(ipRes);
48504852
}

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
@@ -388,6 +388,7 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
388388
for (NicSecondaryIpVO ip : secondaryIps) {
389389
NicSecondaryIpResponse ipRes = new NicSecondaryIpResponse();
390390
ipRes.setId(ip.getUuid());
391+
ipRes.setDescription(ip.getDescription());
391392
ApiResponseHelper.setResponseIpAddress(ip, ipRes);
392393
ipList.add(ipRes);
393394
}

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

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

896896
Account caller = CallContext.current().getCallingAccount();
897897
String ipv4Address = requestedIpPair.getIp4Address();
@@ -989,7 +989,7 @@ public Long doInTransaction(TransactionStatus status) {
989989

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

0 commit comments

Comments
 (0)