Skip to content

Commit 4488238

Browse files
committed
NE: add network guest_type to payload
1 parent 80e4cd3 commit 4488238

3 files changed

Lines changed: 72 additions & 33 deletions

File tree

framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/network/NetworkExtensionElement.java

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm
445445
}
446446
addExtensionIpToPayload(payload, network);
447447

448-
logger.debug("Preparing NIC via extension script: network={} nicMac={} nicIp={}", network, nic != null ? nic.getMacAddress() : null, nic != null ? nic.getIPv4Address() : null);
448+
logger.debug("Preparing NIC via extension script: network={} nicMac={} nicIp={}", network, nic.getMacAddress(), nic.getIPv4Address());
449449

450450
return executeScript(network, CMD_PREPARE_NIC, payload);
451451
} catch (Exception e) {
@@ -968,6 +968,9 @@ private void addNetworkToPayload(JsonObject payload, Network network) {
968968
payload.addProperty("network_id", String.valueOf(network.getId()));
969969
payload.addProperty("vlan", safeStr(getVlanId(network)));
970970
payload.addProperty("zone_id", String.valueOf(network.getDataCenterId()));
971+
if (network.getGuestType() != null) {
972+
payload.addProperty("guest_type", network.getGuestType().toString().toLowerCase());
973+
}
971974
if (StringUtils.isNotBlank(network.getGateway())) {
972975
payload.addProperty("gateway", safeStr(network.getGateway()));
973976
}
@@ -1718,16 +1721,7 @@ public boolean applyLBRules(Network network, List<LoadBalancingRule> rules)
17181721
ruleObj.addProperty("protocol", safeStr(rule.getProtocol()));
17191722
ruleObj.addProperty("algorithm", safeStr(rule.getAlgorithm()));
17201723
ruleObj.addProperty("revoke", revoke);
1721-
JsonArray backendsArray = new JsonArray();
1722-
if (rule.getDestinations() != null) {
1723-
for (LoadBalancingRule.LbDestination dest : rule.getDestinations()) {
1724-
JsonObject destObj = new JsonObject();
1725-
destObj.addProperty("ip", dest.getIpAddress());
1726-
destObj.addProperty("port", dest.getDestinationPortStart());
1727-
destObj.addProperty("revoked", dest.isRevoked());
1728-
backendsArray.add(destObj);
1729-
}
1730-
}
1724+
JsonArray backendsArray = buildLBRuleBackendArray(rule);
17311725
ruleObj.add("backends", backendsArray);
17321726
lbRulesArray.add(ruleObj);
17331727
}
@@ -1743,6 +1737,20 @@ public boolean applyLBRules(Network network, List<LoadBalancingRule> rules)
17431737
return true;
17441738
}
17451739

1740+
private static JsonArray buildLBRuleBackendArray(LoadBalancingRule rule) {
1741+
JsonArray backendsArray = new JsonArray();
1742+
if (rule.getDestinations() != null) {
1743+
for (LoadBalancingRule.LbDestination dest : rule.getDestinations()) {
1744+
JsonObject destObj = new JsonObject();
1745+
destObj.addProperty("ip", dest.getIpAddress());
1746+
destObj.addProperty("port", dest.getDestinationPortStart());
1747+
destObj.addProperty("revoked", dest.isRevoked());
1748+
backendsArray.add(destObj);
1749+
}
1750+
}
1751+
return backendsArray;
1752+
}
1753+
17461754
@Override
17471755
public boolean validateLBRule(Network network, LoadBalancingRule rule) {
17481756
// Delegate validation to the external script; accept by default
@@ -2015,7 +2023,7 @@ private JsonObject buildRestoreNetworkData(Network network, List<NicVO> nics,
20152023
continue;
20162024
}
20172025

2018-
Long instanceId = nic.getInstanceId();
2026+
long instanceId = nic.getInstanceId();
20192027

20202028
UserVmVO userVm = userVmDao.findById(instanceId);
20212029
if (userVm == null) {
@@ -2513,15 +2521,7 @@ private JsonArray buildAclRulesArray(List<? extends NetworkACLItem> rules) {
25132521
.sorted(java.util.Comparator.comparingInt(NetworkACLItem::getNumber))
25142522
.collect(Collectors.toList());
25152523
for (NetworkACLItem rule : sorted) {
2516-
JsonObject ruleObj = new JsonObject();
2517-
ruleObj.addProperty("number", rule.getNumber());
2518-
ruleObj.addProperty("action", rule.getAction().name().toLowerCase());
2519-
ruleObj.addProperty("trafficType", rule.getTrafficType().name().toLowerCase());
2520-
ruleObj.addProperty("protocol", safeStr(rule.getProtocol()));
2521-
if (rule.getSourcePortStart() != null) ruleObj.addProperty("portStart", rule.getSourcePortStart());
2522-
if (rule.getSourcePortEnd() != null) ruleObj.addProperty("portEnd", rule.getSourcePortEnd());
2523-
if (rule.getIcmpType() != null) ruleObj.addProperty("icmpType", rule.getIcmpType());
2524-
if (rule.getIcmpCode() != null) ruleObj.addProperty("icmpCode", rule.getIcmpCode());
2524+
JsonObject ruleObj = buildAclRuleObject(rule);
25252525
JsonArray sourceCidrsArray = new JsonArray();
25262526
List<String> sourceCidrs = rule.getSourceCidrList();
25272527
if (CollectionUtils.isNotEmpty(sourceCidrs)) {
@@ -2532,4 +2532,17 @@ private JsonArray buildAclRulesArray(List<? extends NetworkACLItem> rules) {
25322532
}
25332533
return array;
25342534
}
2535+
2536+
private JsonObject buildAclRuleObject(NetworkACLItem rule) {
2537+
JsonObject ruleObj = new JsonObject();
2538+
ruleObj.addProperty("number", rule.getNumber());
2539+
ruleObj.addProperty("action", rule.getAction().name().toLowerCase());
2540+
ruleObj.addProperty("trafficType", rule.getTrafficType().name().toLowerCase());
2541+
ruleObj.addProperty("protocol", safeStr(rule.getProtocol()));
2542+
if (rule.getSourcePortStart() != null) ruleObj.addProperty("portStart", rule.getSourcePortStart());
2543+
if (rule.getSourcePortEnd() != null) ruleObj.addProperty("portEnd", rule.getSourcePortEnd());
2544+
if (rule.getIcmpType() != null) ruleObj.addProperty("icmpType", rule.getIcmpType());
2545+
if (rule.getIcmpCode() != null) ruleObj.addProperty("icmpCode", rule.getIcmpCode());
2546+
return ruleObj;
2547+
}
25352548
}

framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/network/README.md

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,26 +254,52 @@ For all standard network / VPC commands, CloudStack now executes the script as:
254254

255255
The following names appear repeatedly inside the nested `payload` object.
256256

257+
### Network-level fields (added by `addNetworkToPayload`)
258+
257259
| Field | Description |
258260
|---|---|
259261
| `network_id` | CloudStack numeric network ID. |
260-
| `vpc_id` | CloudStack numeric VPC ID. Present for VPC tier networks and VPC-scoped commands. |
261262
| `vlan` | Guest VLAN tag (for example `100`). Extracted from the broadcast URI. May be empty for flat networks. |
262-
| `gateway` | Guest network gateway (for example `10.0.0.1`). |
263-
| `cidr` | Guest network CIDR (for example `10.0.0.0/24`). |
263+
| `zone_id` | CloudStack zone ID. |
264+
| `guest_type` | Guest network type: `"isolated"`, `"shared"`, or `"l2"`. Scripts should use this to skip NAT/firewall operations that are not applicable to Shared or L2 networks. |
265+
| `gateway` | Guest network gateway (for example `10.0.0.1`). Omitted when blank. |
266+
| `cidr` | Guest network CIDR (for example `10.0.0.0/24`). Omitted when blank. |
267+
| `vpc_id` | CloudStack numeric VPC ID. Present for VPC tier networks and VPC-scoped commands. |
264268
| `network_ip6_gateway` | Guest network IPv6 gateway, when the network has IPv6 configured. |
265269
| `network_ip6_cidr` | Guest network IPv6 CIDR, when the network has IPv6 configured. |
266-
| `extension_ip` | The IP the extension device uses on the guest side. Equals the gateway when SourceNat/Gateway is provided; otherwise it is a dedicated IP from the guest subnet. |
267-
| `public_ip` | A public IP address. |
268-
| `public_cidr` | CIDR of the public IP (for example `203.0.113.5/24`). |
269-
| `public_vlan` | VLAN tag of the public IP segment. |
270-
| `public_gateway` | Gateway of the public IP segment. |
271-
| `private_ip` | A VM's private guest-network IP address. |
270+
271+
### NIC-level fields (added by `addNicToPayload`)
272+
273+
| Field | Description |
274+
|---|---|
275+
| `nic_id` | CloudStack numeric NIC ID. |
276+
| `nic_uuid` | NIC UUID — matches `external_ids:iface-id` written by the KVM agent for OVN port binding. |
277+
| `mac` | VM NIC MAC address. |
278+
| `ip` | VM NIC IPv4 address. |
279+
| `gateway` | VM NIC IPv4 gateway (NIC-level; equals the network gateway for normal guest networks). |
280+
| `netmask` | VM NIC IPv4 netmask (for example `255.255.255.0`). |
281+
| `default_nic` | Stringified boolean — `"false"` for secondary NICs. |
282+
| `device_id` | NIC device index in the VM (slot number). |
272283
| `nic_ip6_address` | VM NIC IPv6 address, when the NIC has IPv6 configured. |
273284
| `nic_ip6_gateway` | VM NIC IPv6 gateway, when available. |
274285
| `nic_ip6_cidr` | VM NIC IPv6 CIDR, when available. |
275-
| `source_nat` | Stringified boolean (`"true"` / `"false"`) indicating whether the public IP is a source-NAT IP. |
276-
| `nic_uuid` | NIC UUID when the current API path has a `NicProfile` available. |
286+
287+
### Public-IP fields (added by `addPublicIpToPayload`)
288+
289+
| Field | Description |
290+
|---|---|
291+
| `public_ip` | A public IP address. |
292+
| `public_vlan` | VLAN tag of the public IP segment. |
293+
| `public_gateway` | Gateway of the public IP segment. |
294+
| `public_cidr` | CIDR of the public IP (for example `203.0.113.0/24`). |
295+
| `source_nat` | Stringified boolean (`"true"` / `"false"`) indicating whether the public IP is the source-NAT IP. |
296+
| `private_ip` | A VM's private guest-network IP address (NAT target). |
297+
298+
### DNS / extension-IP fields
299+
300+
| Field | Description |
301+
|---|---|
302+
| `extension_ip` | The IP the extension device uses on the guest side. Equals the gateway when SourceNat/Gateway is provided; otherwise it is a dedicated IP from the guest subnet. |
277303
| `dns` | Comma-separated DNS server list. |
278304
| `domain` | Network domain suffix. |
279305

test/integration/smoke/test_network_extension_namespace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ def test_07_vpc_network_acl(self):
21932193
self.cleanup = [o for o in self.cleanup if o != tier2]
21942194

21952195
vpc.delete(self.apiclient)
2196-
self.cleanup = [o for o in self.cleanup if o != vpc]
2196+
self.cleanup = [o for o in self.cleanup if o != vpc and o != acl1 and o != acl2]
21972197

21982198
self._teardown_extension()
21992199
self.logger.info("test_07 PASSED")

0 commit comments

Comments
 (0)