|
31 | 31 |
|
32 | 32 | import com.vmware.nsx.model.TransportZone; |
33 | 33 | import com.vmware.nsx.model.TransportZoneListResult; |
| 34 | +import com.vmware.nsx_policy.infra.DhcpRelayConfigs; |
34 | 35 | import com.vmware.nsx_policy.infra.Segments; |
35 | 36 | import com.vmware.nsx_policy.infra.Sites; |
36 | 37 | import com.vmware.nsx_policy.infra.Tier1s; |
37 | 38 | import com.vmware.nsx_policy.infra.sites.EnforcementPoints; |
38 | 39 | import com.vmware.nsx_policy.infra.tier_0s.LocaleServices; |
39 | 40 | import com.vmware.nsx_policy.model.ApiError; |
| 41 | +import com.vmware.nsx_policy.model.DhcpRelayConfig; |
40 | 42 | import com.vmware.nsx_policy.model.EnforcementPointListResult; |
41 | 43 | import com.vmware.nsx_policy.model.LocaleServicesListResult; |
42 | 44 | import com.vmware.nsx_policy.model.Segment; |
|
47 | 49 | import com.vmware.vapi.std.errors.Error; |
48 | 50 | import org.apache.cloudstack.NsxAnswer; |
49 | 51 | import org.apache.cloudstack.StartupNsxCommand; |
| 52 | +import org.apache.cloudstack.agent.api.CreateDhcpRelayCommand; |
50 | 53 | import org.apache.cloudstack.agent.api.CreateNsxSegmentCommand; |
51 | 54 | import org.apache.cloudstack.agent.api.CreateNsxTier1GatewayCommand; |
52 | 55 | import org.apache.cloudstack.agent.api.DeleteNsxSegmentCommand; |
@@ -128,6 +131,8 @@ public Answer executeRequest(Command cmd) { |
128 | 131 | return executeRequest((CreateNsxSegmentCommand) cmd); |
129 | 132 | } else if (cmd instanceof CreateNsxTier1GatewayCommand) { |
130 | 133 | return executeRequest((CreateNsxTier1GatewayCommand) cmd); |
| 134 | + } else if (cmd instanceof CreateDhcpRelayCommand) { |
| 135 | + return executeRequest((CreateDhcpRelayCommand) cmd); |
131 | 136 | } else { |
132 | 137 | return Answer.createUnsupportedCommandAnswer(cmd); |
133 | 138 | } |
@@ -235,6 +240,29 @@ public boolean configure(String name, Map<String, Object> params) throws Configu |
235 | 240 | return true; |
236 | 241 | } |
237 | 242 |
|
| 243 | + private Answer executeRequest(CreateDhcpRelayCommand cmd) { |
| 244 | + String dhcpRelayName = cmd.getDhcpRelayName(); |
| 245 | + List<String> addresses = cmd.getServerAddresses(); |
| 246 | + String msg = String.format("Creating DHCP relay with name %s for addresses %s", dhcpRelayName, addresses); |
| 247 | + LOGGER.debug(msg); |
| 248 | + |
| 249 | + try { |
| 250 | + DhcpRelayConfigs service = (DhcpRelayConfigs) nsxService.apply(DhcpRelayConfigs.class); |
| 251 | + DhcpRelayConfig config = new DhcpRelayConfig.Builder() |
| 252 | + .setServerAddresses(addresses) |
| 253 | + .setId(dhcpRelayName) |
| 254 | + .setDisplayName(dhcpRelayName) |
| 255 | + .build(); |
| 256 | + service.patch(dhcpRelayName, config); |
| 257 | + } catch (Error error) { |
| 258 | + ApiError ae = error.getData()._convertTo(ApiError.class); |
| 259 | + msg = String.format("Error creating the DHCP relay with name %s: %s", dhcpRelayName, ae.getErrorMessage()); |
| 260 | + LOGGER.error(msg); |
| 261 | + return new NsxAnswer(cmd, new CloudRuntimeException(ae.getErrorMessage())); |
| 262 | + } |
| 263 | + return new NsxAnswer(cmd, true, ""); |
| 264 | + } |
| 265 | + |
238 | 266 | private Answer executeRequest(ReadyCommand cmd) { |
239 | 267 | return new ReadyAnswer(cmd); |
240 | 268 | } |
|
0 commit comments