mirror of
https://github.com/opennetworkinglab/onos.git
synced 2026-05-04 19:56:49 +02:00
Support injecting novaMetadataIp and novaMetadataPort through cfg
Change-Id: Ida449424235b70a791e8ed1d423f021f6d6726f7
This commit is contained in:
parent
4665093b0f
commit
92b6f29283
@ -392,6 +392,29 @@ public class OpenstackMetadataProxyHandler {
|
||||
return ethReply;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the metadata path.
|
||||
*
|
||||
* @param uri metadata request URI
|
||||
* @return full metadata path
|
||||
*/
|
||||
private String getMetadataPath(String uri) {
|
||||
OpenstackNode controller = osNodeService.completeNodes(CONTROLLER).
|
||||
stream().findFirst().orElse(null);
|
||||
if (controller == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String novaMetadataIpTmp = controller.neutronConfig().novaMetadataIp();
|
||||
String novaMetadataIp = novaMetadataIpTmp != null
|
||||
? novaMetadataIpTmp : controller.managementIp().toString();
|
||||
Integer novaMetadataPortTmp = controller.neutronConfig().novaMetadataPort();
|
||||
int novaMetadataPort = novaMetadataPortTmp != null
|
||||
? novaMetadataPortTmp : METADATA_SERVER_PORT;
|
||||
|
||||
return HTTP_PREFIX + novaMetadataIp + COLON + novaMetadataPort + uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxyies HTTP request.
|
||||
*
|
||||
@ -403,15 +426,7 @@ public class OpenstackMetadataProxyHandler {
|
||||
InstancePort instPort) {
|
||||
|
||||
CloseableHttpClient client = HttpClientBuilder.create().build();
|
||||
OpenstackNode controller = osNodeService.completeNodes(CONTROLLER).
|
||||
stream().findFirst().orElse(null);
|
||||
if (controller == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String path = oldRequest.getRequestLine().getUri();
|
||||
String url = HTTP_PREFIX + controller.managementIp().toString() +
|
||||
COLON + METADATA_SERVER_PORT + path;
|
||||
String url = getMetadataPath(oldRequest.getRequestLine().getUri());
|
||||
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
log.warn("The metadata endpoint is not configured!");
|
||||
|
||||
@ -29,12 +29,19 @@ public final class DefaultNeutronConfig implements NeutronConfig {
|
||||
|
||||
private final boolean useMetadataProxy;
|
||||
private final String metadataProxySecret;
|
||||
private final String novaMetadataIp;
|
||||
private final Integer novaMetadataPort;
|
||||
|
||||
private static final String NOT_NULL_MSG = "% cannot be null";
|
||||
|
||||
private DefaultNeutronConfig(boolean useMetadataProxy, String metadataProxySecret) {
|
||||
private DefaultNeutronConfig(boolean useMetadataProxy,
|
||||
String metadataProxySecret,
|
||||
String novaMetadataIp,
|
||||
Integer novaMetadataPort) {
|
||||
this.useMetadataProxy = useMetadataProxy;
|
||||
this.metadataProxySecret = metadataProxySecret;
|
||||
this.novaMetadataIp = novaMetadataIp;
|
||||
this.novaMetadataPort = novaMetadataPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,6 +54,16 @@ public final class DefaultNeutronConfig implements NeutronConfig {
|
||||
return metadataProxySecret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String novaMetadataIp() {
|
||||
return novaMetadataIp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer novaMetadataPort() {
|
||||
return novaMetadataPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
@ -56,7 +73,9 @@ public final class DefaultNeutronConfig implements NeutronConfig {
|
||||
if (o instanceof DefaultNeutronConfig) {
|
||||
DefaultNeutronConfig that = (DefaultNeutronConfig) o;
|
||||
return Objects.equals(useMetadataProxy, that.useMetadataProxy) &&
|
||||
Objects.equals(metadataProxySecret, that.metadataProxySecret);
|
||||
Objects.equals(metadataProxySecret, that.metadataProxySecret) &&
|
||||
Objects.equals(novaMetadataIp, that.novaMetadataIp) &&
|
||||
Objects.equals(novaMetadataPort, that.novaMetadataPort);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -64,7 +83,8 @@ public final class DefaultNeutronConfig implements NeutronConfig {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(useMetadataProxy, metadataProxySecret);
|
||||
return Objects.hash(useMetadataProxy, metadataProxySecret,
|
||||
novaMetadataIp, novaMetadataPort);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,6 +92,8 @@ public final class DefaultNeutronConfig implements NeutronConfig {
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("useMetadataProxy", useMetadataProxy)
|
||||
.add("metadataProxySecret", metadataProxySecret)
|
||||
.add("novaMetadataIp", novaMetadataIp)
|
||||
.add("novaMetadataPort", novaMetadataPort)
|
||||
.toString();
|
||||
}
|
||||
|
||||
@ -91,6 +113,9 @@ public final class DefaultNeutronConfig implements NeutronConfig {
|
||||
|
||||
private boolean useMetadataProxy;
|
||||
private String metadataProxySecret;
|
||||
private String novaMetadataIp;
|
||||
private Integer novaMetadataPort;
|
||||
|
||||
|
||||
// private constructor not intended to use from external
|
||||
private Builder() {
|
||||
@ -101,7 +126,8 @@ public final class DefaultNeutronConfig implements NeutronConfig {
|
||||
checkArgument(metadataProxySecret != null,
|
||||
NOT_NULL_MSG, "metadataProxySecret");
|
||||
|
||||
return new DefaultNeutronConfig(useMetadataProxy, metadataProxySecret);
|
||||
return new DefaultNeutronConfig(useMetadataProxy, metadataProxySecret,
|
||||
novaMetadataIp, novaMetadataPort);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -115,5 +141,17 @@ public final class DefaultNeutronConfig implements NeutronConfig {
|
||||
this.metadataProxySecret = metadataProxySecret;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NeutronConfig.Builder novaMetadataIp(String novaMetadataIp) {
|
||||
this.novaMetadataIp = novaMetadataIp;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NeutronConfig.Builder novaMetadataPort(Integer novaMetadataPort) {
|
||||
this.novaMetadataPort = novaMetadataPort;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,6 +36,20 @@ public interface NeutronConfig {
|
||||
*/
|
||||
String metadataProxySecret();
|
||||
|
||||
/**
|
||||
* Returns NOVA metadata IP address.
|
||||
*
|
||||
* @return NOVA metadata IP address
|
||||
*/
|
||||
String novaMetadataIp();
|
||||
|
||||
/**
|
||||
* Returns NOVA metadata port number.
|
||||
*
|
||||
* @return NOVA metadata port number
|
||||
*/
|
||||
Integer novaMetadataPort();
|
||||
|
||||
/**
|
||||
* Builder of neutron config.
|
||||
*/
|
||||
@ -63,5 +77,21 @@ public interface NeutronConfig {
|
||||
* @return neutron config builder
|
||||
*/
|
||||
Builder metadataProxySecret(String metadataProxySecret);
|
||||
|
||||
/**
|
||||
* Returns neutron config with supplied NOVA metadata IP address.
|
||||
*
|
||||
* @param novaMetadataIp NOVA metadata IP address
|
||||
* @return neutron config builder
|
||||
*/
|
||||
Builder novaMetadataIp(String novaMetadataIp);
|
||||
|
||||
/**
|
||||
* Returns neutron config with supplied NOVA metadata port number.
|
||||
*
|
||||
* @param novaMetadataPort NOVA metadata port number
|
||||
* @return neutron config builder
|
||||
*/
|
||||
Builder novaMetadataPort(Integer novaMetadataPort);
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,6 +33,12 @@ public class DefaultNeutronConfigTest {
|
||||
private static final String METADATA_PROXY_SECRET_1 = "onos";
|
||||
private static final String METADATA_PROXY_SECRET_2 = "cord";
|
||||
|
||||
private static final String NOVA_METADATA_IP_1 = "10.10.10.1";
|
||||
private static final String NOVA_METADATA_IP_2 = "20.20.20.2";
|
||||
|
||||
private static final Integer NOVA_METADATA_PORT_1 = 8775;
|
||||
private static final Integer NOVA_METADATA_PORT_2 = 8776;
|
||||
|
||||
private NeutronConfig config1;
|
||||
private NeutronConfig sameAsConfig1;
|
||||
private NeutronConfig config2;
|
||||
@ -53,16 +59,22 @@ public class DefaultNeutronConfigTest {
|
||||
config1 = DefaultNeutronConfig.builder()
|
||||
.useMetadataProxy(USE_METADATA_PROXY_1)
|
||||
.metadataProxySecret(METADATA_PROXY_SECRET_1)
|
||||
.novaMetadataIp(NOVA_METADATA_IP_1)
|
||||
.novaMetadataPort(NOVA_METADATA_PORT_1)
|
||||
.build();
|
||||
|
||||
sameAsConfig1 = DefaultNeutronConfig.builder()
|
||||
.useMetadataProxy(USE_METADATA_PROXY_1)
|
||||
.metadataProxySecret(METADATA_PROXY_SECRET_1)
|
||||
.novaMetadataIp(NOVA_METADATA_IP_1)
|
||||
.novaMetadataPort(NOVA_METADATA_PORT_1)
|
||||
.build();
|
||||
|
||||
config2 = DefaultNeutronConfig.builder()
|
||||
.useMetadataProxy(USE_METADATA_PROXY_2)
|
||||
.metadataProxySecret(METADATA_PROXY_SECRET_2)
|
||||
.novaMetadataIp(NOVA_METADATA_IP_2)
|
||||
.novaMetadataPort(NOVA_METADATA_PORT_2)
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -85,5 +97,7 @@ public class DefaultNeutronConfigTest {
|
||||
|
||||
assertEquals(config.useMetadataProxy(), USE_METADATA_PROXY_1);
|
||||
assertEquals(config.metadataProxySecret(), METADATA_PROXY_SECRET_1);
|
||||
assertEquals(config.novaMetadataIp(), NOVA_METADATA_IP_1);
|
||||
assertEquals(config.novaMetadataPort(), NOVA_METADATA_PORT_1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,11 +16,12 @@
|
||||
|
||||
package org.onosproject.openstacknode.codec;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.onosproject.codec.CodecContext;
|
||||
import org.onosproject.codec.JsonCodec;
|
||||
import org.onosproject.openstacknode.api.NeutronConfig;
|
||||
import org.onosproject.openstacknode.api.DefaultNeutronConfig;
|
||||
import org.onosproject.openstacknode.api.NeutronConfig;
|
||||
|
||||
import static org.onlab.util.Tools.nullIsIllegal;
|
||||
|
||||
@ -31,14 +32,26 @@ public final class NeutronConfigCodec extends JsonCodec<NeutronConfig> {
|
||||
|
||||
private static final String USE_METADATA_PROXY = "useMetadataProxy";
|
||||
private static final String METADATA_PROXY_SECRET = "metadataProxySecret";
|
||||
private static final String NOVA_METADATA_IP = "novaMetadataIp";
|
||||
private static final String NOVA_METADATA_PORT = "novaMetadataPort";
|
||||
|
||||
private static final String MISSING_MESSAGE = " is required in OpenstackNode";
|
||||
private static final String MISSING_MESSAGE = " is required in NeutronConfig";
|
||||
|
||||
@Override
|
||||
public ObjectNode encode(NeutronConfig entity, CodecContext context) {
|
||||
return context.mapper().createObjectNode()
|
||||
.put(USE_METADATA_PROXY, entity.useMetadataProxy())
|
||||
ObjectNode node = context.mapper().createObjectNode();
|
||||
node.put(USE_METADATA_PROXY, entity.useMetadataProxy())
|
||||
.put(METADATA_PROXY_SECRET, entity.metadataProxySecret());
|
||||
|
||||
if (entity.novaMetadataIp() != null) {
|
||||
node.put(NOVA_METADATA_IP, entity.novaMetadataIp());
|
||||
}
|
||||
|
||||
if (entity.novaMetadataPort() != null) {
|
||||
node.put(NOVA_METADATA_PORT, entity.novaMetadataPort());
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,9 +66,22 @@ public final class NeutronConfigCodec extends JsonCodec<NeutronConfig> {
|
||||
String metadataProxySecret = nullIsIllegal(json.get(METADATA_PROXY_SECRET).asText(),
|
||||
METADATA_PROXY_SECRET + MISSING_MESSAGE);
|
||||
|
||||
return DefaultNeutronConfig.builder()
|
||||
NeutronConfig.Builder builder = DefaultNeutronConfig.builder()
|
||||
.useMetadataProxy(useMetadataProxy)
|
||||
.metadataProxySecret(metadataProxySecret)
|
||||
.build();
|
||||
.metadataProxySecret(metadataProxySecret);
|
||||
|
||||
JsonNode novaMetadataIp = json.get(NOVA_METADATA_IP);
|
||||
|
||||
if (novaMetadataIp != null) {
|
||||
builder.novaMetadataIp(novaMetadataIp.asText());
|
||||
}
|
||||
|
||||
JsonNode novaMetadataPort = json.get(NOVA_METADATA_PORT);
|
||||
|
||||
if (novaMetadataPort != null) {
|
||||
builder.novaMetadataPort(novaMetadataPort.asInt());
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +29,8 @@ public final class NeutronConfigJsonMatcher extends TypeSafeDiagnosingMatcher<Js
|
||||
|
||||
private static final String USE_METADATA_PROXY = "useMetadataProxy";
|
||||
private static final String METADATA_PROXY_SECRET = "metadataProxySecret";
|
||||
private static final String NOVA_METADATA_IP = "novaMetadataIp";
|
||||
private static final String NOVA_METADATA_PORT = "novaMetadataPort";
|
||||
|
||||
private NeutronConfigJsonMatcher(NeutronConfig neutronConfig) {
|
||||
this.neutronConfig = neutronConfig;
|
||||
@ -57,6 +59,26 @@ public final class NeutronConfigJsonMatcher extends TypeSafeDiagnosingMatcher<Js
|
||||
}
|
||||
}
|
||||
|
||||
// check NOVA metadata IP
|
||||
JsonNode jsonNovaMetadataIp = jsonNode.get(NOVA_METADATA_IP);
|
||||
if (jsonNovaMetadataIp != null) {
|
||||
String novaMetadataIp = neutronConfig.novaMetadataIp();
|
||||
if (!jsonNovaMetadataIp.asText().equals(novaMetadataIp)) {
|
||||
description.appendText("novaMetadataIp was " + jsonNovaMetadataIp);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// check NOVA metadata port
|
||||
JsonNode jsonNovaMetadataPort = jsonNode.get(NOVA_METADATA_PORT);
|
||||
if (jsonNovaMetadataPort != null) {
|
||||
Integer novaMetadataPort = neutronConfig.novaMetadataPort();
|
||||
if (jsonNovaMetadataPort.asInt() != novaMetadataPort) {
|
||||
description.appendText("novaMetadataPort was " + jsonNovaMetadataIp);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -278,6 +278,8 @@ public class OpenstackNodeCodecTest {
|
||||
NeutronConfig neutronConfig = DefaultNeutronConfig.builder()
|
||||
.useMetadataProxy(true)
|
||||
.metadataProxySecret("onos")
|
||||
.novaMetadataIp("172.16.130.10")
|
||||
.novaMetadataPort(8775)
|
||||
.build();
|
||||
|
||||
OpenstackNode node = DefaultOpenstackNode.builder()
|
||||
@ -321,6 +323,8 @@ public class OpenstackNodeCodecTest {
|
||||
|
||||
assertThat(neutronConfig.useMetadataProxy(), is(true));
|
||||
assertThat(neutronConfig.metadataProxySecret(), is("onos"));
|
||||
assertThat(neutronConfig.novaMetadataIp(), is("172.16.130.10"));
|
||||
assertThat(neutronConfig.novaMetadataPort(), is(8775));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
},
|
||||
"neutronConfig": {
|
||||
"useMetadataProxy": true,
|
||||
"metadataProxySecret": "onos"
|
||||
"metadataProxySecret": "onos",
|
||||
"novaMetadataIp": "172.16.130.10",
|
||||
"novaMetadataPort": 8775
|
||||
}
|
||||
}
|
||||
@ -95,7 +95,9 @@
|
||||
},
|
||||
"neutronConfig": {
|
||||
"useMetadataProxy": true,
|
||||
"metadataProxySecret": "onos"
|
||||
"metadataProxySecret": "nova",
|
||||
"novaMetadataIp": "172.16.130.10",
|
||||
"novaMetadataPort": 8775
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user