|
34 | 34 |
|
35 | 35 | import javax.naming.ConfigurationException; |
36 | 36 |
|
| 37 | +import com.cloud.agent.api.routing.UpdateNetworkCommand; |
| 38 | +import com.cloud.agent.api.to.IpAddressTO; |
37 | 39 | import com.cloud.utils.PasswordGenerator; |
38 | 40 | import org.apache.cloudstack.ca.SetupCertificateAnswer; |
39 | 41 | import org.apache.cloudstack.ca.SetupCertificateCommand; |
@@ -134,6 +136,10 @@ public Answer executeRequest(final NetworkElementCommand cmd) { |
134 | 136 | return execute((AggregationControlCommand)cmd); |
135 | 137 | } |
136 | 138 |
|
| 139 | + if (cmd instanceof UpdateNetworkCommand) { |
| 140 | + return execute((UpdateNetworkCommand) cmd); |
| 141 | + } |
| 142 | + |
137 | 143 | if (_vrAggregateCommandsSet.containsKey(routerName)) { |
138 | 144 | _vrAggregateCommandsSet.get(routerName).add(cmd); |
139 | 145 | aggregated = true; |
@@ -216,6 +222,44 @@ private Answer executeQueryCommand(NetworkElementCommand cmd) { |
216 | 222 | } |
217 | 223 | } |
218 | 224 |
|
| 225 | + private static String getRouterSshControlIp(NetworkElementCommand cmd) { |
| 226 | + String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); |
| 227 | + if (s_logger.isDebugEnabled()) |
| 228 | + s_logger.debug("Use router's private IP for SSH control. IP : " + routerIp); |
| 229 | + return routerIp; |
| 230 | + } |
| 231 | + |
| 232 | + private Answer execute(UpdateNetworkCommand cmd) { |
| 233 | + IpAddressTO[] ipAddresses = cmd.getIpAddresses(); |
| 234 | + String routerIp = getRouterSshControlIp(cmd); |
| 235 | + boolean finalResult = true; |
| 236 | + for (IpAddressTO ipAddressTO : ipAddresses) { |
| 237 | + try { |
| 238 | + ExecutionResult result = _vrDeployer.executeInVR(routerIp, VRScripts.VR_UPDATE_MTU, |
| 239 | + ipAddressTO.getPublicIp() + " " + ipAddressTO.getVlanNetmask() + " " + ipAddressTO.getMtu() + " " + 15); |
| 240 | + if (s_logger.isDebugEnabled()) |
| 241 | + s_logger.debug("result: " + result.isSuccess() + ", output: " + result.getDetails()); |
| 242 | + if (!result.isSuccess()) { |
| 243 | + s_logger.warn(String.format("Failed to update interface mtu to %s on interface with ip: %s", |
| 244 | + ipAddressTO.getMtu(), ipAddressTO.getPublicIp())); |
| 245 | + finalResult = false; |
| 246 | + continue; |
| 247 | + } |
| 248 | + s_logger.info(String.format("Successfully updated mtu to %s on interface with ip: %s", |
| 249 | + ipAddressTO.getMtu(), ipAddressTO.getPublicIp())); |
| 250 | + finalResult &= true; |
| 251 | + } catch (Exception e) { |
| 252 | + String msg = "Prepare UpdateNetwork failed due to " + e.toString(); |
| 253 | + s_logger.error(msg, e); |
| 254 | + return new Answer(cmd, e); |
| 255 | + } |
| 256 | + } |
| 257 | + if (finalResult) { |
| 258 | + return new Answer(cmd, true, null); |
| 259 | + } |
| 260 | + return new Answer(cmd, new CloudRuntimeException("Failed to update interface mtu")); |
| 261 | + } |
| 262 | + |
219 | 263 | private ExecutionResult applyConfigToVR(String routerAccessIp, ConfigItem c) { |
220 | 264 | return applyConfigToVR(routerAccessIp, c, VRScripts.VR_SCRIPT_EXEC_TIMEOUT); |
221 | 265 | } |
|
0 commit comments