Skip to content

Commit

Permalink
VNF: add management property to VNF template nics
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhouapache committed Oct 2, 2023
1 parent 82aa44c commit 047b5da
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 34 deletions.
8 changes: 7 additions & 1 deletion api/src/main/java/com/cloud/network/VNF.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ class VnfNic {
int deviceId;
String name;
boolean required;
boolean management;
String description;

public VnfNic(int deviceId, String nicName, boolean required, String nicDescription) {
public VnfNic(int deviceId, String nicName, boolean required, boolean management, String nicDescription) {
this.deviceId = deviceId;
this.name = nicName;
this.required = required;
this.management = management;
this.description = nicDescription;
}

Expand All @@ -99,6 +101,10 @@ public boolean isRequired() {
return required;
}

public boolean isManagement() {
return management;
}

public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ public class ApiConstants {
public static final String SOURCE_NAT_IP_ID = "sourcenatipaddressid";
public static final String HAS_RULES = "hasrules";

public static final String MANAGEMENT = "management";
public static final String IS_VNF = "isvnf";
public static final String VNF_NICS = "vnfnics";
public static final String VNF_DETAILS = "vnfdetails";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public class VnfNicResponse {
@Param(description = "True if the NIC is required. False if optional")
private Boolean required;

@SerializedName(ApiConstants.MANAGEMENT)
@Param(description = "True if the NIC is a management interface. False otherwise")
private Boolean management;

@SerializedName(ApiConstants.DESCRIPTION)
@Param(description = "Description of the NIC")
private String description;
Expand All @@ -58,6 +62,10 @@ public void setRequired(Boolean required) {
this.required = required;
}

public void setManagement(Boolean management) {
this.management = management;
}

public void setDescription(String description) {
this.description = description;
}
Expand All @@ -73,10 +81,11 @@ public void setNetworkName(String networkName) {
public VnfNicResponse() {
}

public VnfNicResponse(long deviceId, String name, Boolean required, String description) {
public VnfNicResponse(long deviceId, String name, Boolean required, Boolean management, String description) {
this.deviceId = deviceId;
this.name = name;
this.required = required;
this.management = management;
this.description = description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static List<VNF.VnfNic> getVnfNicsList(Map vnfNics) {
String deviceIdString = nicDetails.get("deviceid");
String name = nicDetails.get("name");
String requiredString = nicDetails.get("required");
String managementString = nicDetails.get("management");
String description = nicDetails.get("description");
Integer deviceId = null;
if (StringUtils.isAnyBlank(name, deviceIdString)) {
Expand All @@ -75,7 +76,8 @@ static List<VNF.VnfNic> getVnfNicsList(Map vnfNics) {
throw new InvalidParameterValueException("Unable to parse VNF nic deviceId to Integer: " + deviceId);
}
boolean required = StringUtils.isBlank(requiredString) || Boolean.parseBoolean(requiredString);
nicsList.add(new VNF.VnfNic(deviceId, name, required, description));
boolean management = StringUtils.isBlank(managementString) || Boolean.parseBoolean(managementString);
nicsList.add(new VNF.VnfNic(deviceId, name, required, management, description));
}
}
Collections.sort(nicsList, Comparator.comparing(VNF.VnfNic::getDeviceId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,36 +108,36 @@ public void testGetVnfNicsListWithInvalidDeviceId() {
@Test
public void testValidateVnfNicsAllGood() {
List<VnfNic> nicsList = new ArrayList<>();
nicsList.add(new VnfNic(0, "eth0", true, "first NIC"));
nicsList.add(new VnfNic(1, "eth1", true, "second NIC"));
nicsList.add(new VnfNic(2, "eth2", false, "third NIC"));
nicsList.add(new VnfNic(0, "eth0", true, true, "first NIC"));
nicsList.add(new VnfNic(1, "eth1", true, true, "second NIC"));
nicsList.add(new VnfNic(2, "eth2", false, true, "third NIC"));
VnfTemplateManager.validateVnfNics(nicsList);
}

@Test(expected = InvalidParameterValueException.class)
public void testValidateVnfNicsStartWithNonzero() {
List<VnfNic> nicsList = new ArrayList<>();
nicsList.add(new VnfNic(1, "eth0", true, "first NIC"));
nicsList.add(new VnfNic(2, "eth1", true, "second NIC"));
nicsList.add(new VnfNic(3, "eth2", false, "third NIC"));
nicsList.add(new VnfNic(1, "eth0", true, true, "first NIC"));
nicsList.add(new VnfNic(2, "eth1", true, true, "second NIC"));
nicsList.add(new VnfNic(3, "eth2", false, true, "third NIC"));
VnfTemplateManager.validateVnfNics(nicsList);
}

@Test(expected = InvalidParameterValueException.class)
public void testValidateVnfNicsWithNonConstantDeviceIds() {
List<VnfNic> nicsList = new ArrayList<>();
nicsList.add(new VnfNic(0, "eth0", true, "first NIC"));
nicsList.add(new VnfNic(2, "eth1", true, "second NIC"));
nicsList.add(new VnfNic(4, "eth2", false, "third NIC"));
nicsList.add(new VnfNic(0, "eth0", true, true, "first NIC"));
nicsList.add(new VnfNic(2, "eth1", true, true, "second NIC"));
nicsList.add(new VnfNic(4, "eth2", false, true, "third NIC"));
VnfTemplateManager.validateVnfNics(nicsList);
}

@Test(expected = InvalidParameterValueException.class)
public void testValidateVnfNicsWithInvalidRequired() {
List<VnfNic> nicsList = new ArrayList<>();
nicsList.add(new VnfNic(0, "eth0", true, "first NIC"));
nicsList.add(new VnfNic(1, "eth1", false, "second NIC"));
nicsList.add(new VnfNic(2, "eth2", true, "third NIC"));
nicsList.add(new VnfNic(0, "eth0", true, true, "first NIC"));
nicsList.add(new VnfNic(1, "eth1", false, true, "second NIC"));
nicsList.add(new VnfNic(2, "eth2", true, true, "third NIC"));
VnfTemplateManager.validateVnfNics(nicsList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,21 @@ public class VnfTemplateNicVO implements InternalIdentity {
@Column(name = "required")
private boolean required = true;

@Column(name = "management")
private boolean management = true;

@Column(name = "description")
private String description;

public VnfTemplateNicVO() {
}

public VnfTemplateNicVO(long templateId, long deviceId, String deviceName, boolean required, String description) {
public VnfTemplateNicVO(long templateId, long deviceId, String deviceName, boolean required, boolean management, String description) {
this.templateId = templateId;
this.deviceId = deviceId;
this.deviceName = deviceName;
this.required = required;
this.management = management;
this.description = description;
}

Expand All @@ -83,10 +87,14 @@ public String getDeviceName() {
return deviceName;
}

public boolean getRequired() {
public boolean isRequired() {
return required;
}

public boolean isManagement() {
return management;
}

public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ CREATE TABLE IF NOT EXISTS `cloud`.`vnf_template_nics` (
`device_id` bigint unsigned NOT NULL COMMENT 'Device id of the NIC when plugged into the VNF appliances',
`device_name` varchar(1024) NOT NULL COMMENT 'Name of the NIC',
`required` tinyint NOT NULL DEFAULT '1' COMMENT 'True if the NIC is required. False if optional',
`management` tinyint NOT NULL DEFAULT '1' COMMENT 'True if the NIC is a management interface',
`description` varchar(1024) COMMENT 'Description of the NIC',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_template_id_device_id` (`template_id`, `device_id`),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private TemplateResponse initTemplateResponse(TemplateJoinVO template) {
VnfTemplateResponse vnfTemplateResponse = new VnfTemplateResponse();
List<VnfTemplateNicVO> nics = vnfTemplateNicDao.listByTemplateId(template.getId());
for (VnfTemplateNicVO nic : nics) {
vnfTemplateResponse.addVnfNic(new VnfNicResponse(nic.getDeviceId(), nic.getDeviceName(), nic.getRequired(), nic.getDescription()));
vnfTemplateResponse.addVnfNic(new VnfNicResponse(nic.getDeviceId(), nic.getDeviceName(), nic.isRequired(), nic.isManagement(), nic.getDescription()));
}
List<VnfTemplateDetailVO> details = vnfTemplateDetailsDao.listDetails(template.getId());
Collections.sort(details, (v1, v2) -> v1.getName().compareToIgnoreCase(v2.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
if (TemplateType.VNF.equals(userVm.getTemplateType()) && (details.contains(VMDetails.all) || details.contains(VMDetails.vnfnics))) {
List<VnfTemplateNicVO> vnfNics = vnfTemplateNicDao.listByTemplateId(userVm.getTemplateId());
for (VnfTemplateNicVO nic : vnfNics) {
userVmResponse.addVnfNic(new VnfNicResponse(nic.getDeviceId(), nic.getDeviceName(), nic.getRequired(), nic.getDescription()));
userVmResponse.addVnfNic(new VnfNicResponse(nic.getDeviceId(), nic.getDeviceName(), nic.isRequired(), nic.isManagement(), nic.getDescription()));
}
List<VnfTemplateDetailVO> vnfDetails = vnfTemplateDetailsDao.listDetails(userVm.getTemplateId());
Collections.sort(vnfDetails, (v1, v2) -> v1.getName().compareToIgnoreCase(v2.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void persistVnfTemplate(long templateId, RegisterVnfTemplateCmd cmd) {

private void persistVnfTemplateNics(long templateId, List<VNF.VnfNic> nics) {
for (VNF.VnfNic nic : nics) {
VnfTemplateNicVO vnfTemplateNicVO = new VnfTemplateNicVO(templateId, nic.getDeviceId(), nic.getName(), nic.isRequired(), nic.getDescription());
VnfTemplateNicVO vnfTemplateNicVO = new VnfTemplateNicVO(templateId, nic.getDeviceId(), nic.getName(), nic.isRequired(), nic.isManagement(), nic.getDescription());
vnfTemplateNicDao.persist(vnfTemplateNicVO);
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ public void validateVnfApplianceNics(VirtualMachineTemplate template, List<Long>
}
List<VnfTemplateNicVO> vnfNics = vnfTemplateNicDao.listByTemplateId(template.getId());
for (VnfTemplateNicVO vnfNic : vnfNics) {
if (vnfNic.getRequired() && networkIds.size() <= vnfNic.getDeviceId()) {
if (vnfNic.isRequired() && networkIds.size() <= vnfNic.getDeviceId()) {
throw new InvalidParameterValueException("VNF nic is required but not found: " + vnfNic);
}
}
Expand Down
1 change: 0 additions & 1 deletion tools/marvin/marvin/lib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6817,4 +6817,3 @@ def list(cls, apiclient, **kwargs):
if 'account' in list(kwargs.keys()) and 'domainid' in list(kwargs.keys()):
cmd.listall = True
return (apiclient.listVnfTemplates(cmd))

6 changes: 4 additions & 2 deletions ui/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,7 @@
"label.vmwarenetworklabel": "VMware traffic label",
"label.vnf.appliance": "VNF Appliance",
"label.vnf.appliance.add": "Add VNF Appliance",
"label.vnf.appliance.access.methods": "Access information of VNF appliance",
"label.vnf.appliance.access.methods": "Access information of this VNF appliance",
"label.vnf.detail.add": "Add VNF detail",
"label.vnf.detail.remove": "Remove VNF detail",
"label.vnf.details": "VNF details",
Expand All @@ -2186,9 +2186,11 @@
"label.vnf.nic.description": "Description of VNF nic",
"label.vnf.nic.deviceid": "Device ID of VNF nic. It starts with 0",
"label.vnf.nic.edit": "Edit VNF nic",
"label.vnf.nic.management": "Management NIC",
"label.vnf.nic.management.description": "True if the VNF nic is a management interface. False otherwise",
"label.vnf.nic.name": "Name of VNF nic",
"label.vnf.nic.remove": "Remove VNF nic",
"label.vnf.nic.required": "True of VNF nic is required. Otherwise optional",
"label.vnf.nic.required": "True if VNF nic is required. Otherwise optional",
"label.vnf.nics": "VNF nics",
"label.vnf.settings": "VNF settings",
"label.vnf.templates": "VNF templates",
Expand Down
35 changes: 25 additions & 10 deletions ui/src/components/view/DetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,35 @@ export default {
if (password) {
credentials.push(this.$t('label.password') + ' : ' + password)
}
if (webUsername) {
credentials.push('Web ' + this.$t('label.username') + ' : ' + webUsername)
}
if (webPassword) {
credentials.push('Web ' + this.$t('label.password') + ' : ' + webPassword)
}
if (sshUsername) {
credentials.push('SSH ' + this.$t('label.username') + ' : ' + sshUsername)
}
if (sshPassword) {
credentials.push('SSH ' + this.$t('label.password') + ' : ' + sshPassword)
}
if (webUsername) {
credentials.push('Web ' + this.$t('label.username') + ' : ' + webUsername)
const managementDeviceIds = []
for (const vnfnic of this.resource.vnfnics) {
if (vnfnic.management) {
managementDeviceIds.push(vnfnic.deviceid)
}
}
if (webPassword) {
credentials.push('Web ' + this.$t('label.password') + ' : ' + webPassword)
const managementIps = []
for (const nic of this.resource.nic) {
if (managementDeviceIds.includes(parseInt(nic.deviceid)) && nic.ipaddress) {
managementIps.push(nic.ipaddress)
}
}
if (this.resource.publicip && managementDeviceIds.includes(0)) {
managementIps.push(this.resource.publicip)
}
console.log('managementIps = ' + managementIps)
if (accessMethods) {
const accessMethodsArray = accessMethods.split(',')
Expand All @@ -210,14 +227,12 @@ export default {
} else if (accessMethod === 'ssh-key') {
accessMethodsDescription.push('- SSH with key' + (sshPort ? ' (SSH port is ' + sshPort + ').' : '.'))
} else if (accessMethod === 'http') {
accessMethodsDescription.push('- Webpage: http://' + this.resource.ipaddress + (httpPort ? ':' + httpPort : '') + (httpPath ? '/' + httpPath : ''))
if (this.resource.publicip) {
accessMethodsDescription.push('- Webpage: http://' + this.resource.publicip + (httpPort ? ':' + httpPort : '') + (httpPath ? '/' + httpPath : ''))
for (const managementIp of managementIps) {
accessMethodsDescription.push('- Webpage: http://' + managementIp + (httpPort ? ':' + httpPort : '') + (httpPath ? '/' + httpPath : ''))
}
} else if (accessMethod === 'https') {
accessMethodsDescription.push('- Webpage: https://' + this.resource.ipaddress + (httpsPort ? ':' + httpsPort : '') + (httpsPath ? '/' + httpsPath : ''))
if (this.resource.publicip) {
accessMethodsDescription.push('- Webpage: https://' + this.resource.publicip + (httpsPort ? ':' + httpsPort : '') + (httpsPath ? '/' + httpsPath : ''))
for (const managementIp of managementIps) {
accessMethodsDescription.push('- Webpage: https://' + managementIp + (httpsPort ? ':' + httpsPort : '') + (httpsPath ? '/' + httpsPath : ''))
}
}
}
Expand Down
Loading

0 comments on commit 047b5da

Please sign in to comment.