From 1ac8507521bfdb284ddc8d619d1231c14888a70d Mon Sep 17 00:00:00 2001 From: Nathan Anderson Date: Sun, 11 Jan 2015 19:06:37 -0800 Subject: [PATCH] Fix update() for Port (AllowedAddressPair) and Router (HostRoutes) to send in payload. --- .../networking/internal/PortServiceImpl.java | 3 ++- .../networking/internal/RouterServiceImpl.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/openstack4j/openstack/networking/internal/PortServiceImpl.java b/core/src/main/java/org/openstack4j/openstack/networking/internal/PortServiceImpl.java index 684321bb8..4fb75ad34 100644 --- a/core/src/main/java/org/openstack4j/openstack/networking/internal/PortServiceImpl.java +++ b/core/src/main/java/org/openstack4j/openstack/networking/internal/PortServiceImpl.java @@ -59,7 +59,8 @@ public Port create(Port port) { public Port update(Port port) { checkNotNull(port); checkNotNull(port.getId()); - return put(NeutronPort.class, uri("/ports/%s", getAndClearIdentifier(port))).entity(port).execute(); + Port p = port.toBuilder().networkId(null).state(null).tenantId(null).macAddress(null).build(); + return put(NeutronPort.class, uri("/ports/%s", getAndClearIdentifier(p))).entity(p).execute(); } private String getAndClearIdentifier(Port port) { diff --git a/core/src/main/java/org/openstack4j/openstack/networking/internal/RouterServiceImpl.java b/core/src/main/java/org/openstack4j/openstack/networking/internal/RouterServiceImpl.java index a0e09d49b..f96403393 100644 --- a/core/src/main/java/org/openstack4j/openstack/networking/internal/RouterServiceImpl.java +++ b/core/src/main/java/org/openstack4j/openstack/networking/internal/RouterServiceImpl.java @@ -10,7 +10,9 @@ import org.openstack4j.model.network.AttachInterfaceType; import org.openstack4j.model.network.Router; import org.openstack4j.model.network.RouterInterface; +import org.openstack4j.model.network.builder.RouterBuilder; import org.openstack4j.openstack.networking.domain.AddRouterInterfaceAction; +import org.openstack4j.openstack.networking.domain.NeutronHostRoute; import org.openstack4j.openstack.networking.domain.NeutronRouter; import org.openstack4j.openstack.networking.domain.NeutronRouter.Routers; import org.openstack4j.openstack.networking.domain.NeutronRouterInterface; @@ -73,8 +75,18 @@ public Router create(Router router) { public Router update(Router router) { checkNotNull(router); checkNotNull(router.getId()); + + RouterBuilder rb = NeutronRouter.builder().name(router.getName()).adminStateUp(router.isAdminStateUp()).externalGateway(router.getExternalGatewayInfo()); + List routes = (List) router.getRoutes(); + + if (routes != null) { + for (NeutronHostRoute route : routes) { + rb.route(route.getDestination(), route.getNexthop()); + } + } + return put(NeutronRouter.class, uri("/routers/%s", router.getId())) - .entity(NeutronRouter.builder().name(router.getName()).adminStateUp(router.isAdminStateUp()).externalGateway(router.getExternalGatewayInfo()).build()) + .entity(rb.build()) .execute(); }