use of org.onosproject.kubevirtnode.api.KubevirtPhyInterface in project onos by opennetworkinglab.
the class DefaultKubevirtNodeHandler method isDeviceCreatedStateDone.
private boolean isDeviceCreatedStateDone(KubevirtNode node) {
try {
// we need to wait a while, in case tunneling ports
// creation requires some time
sleep(SLEEP_MID_MS);
} catch (InterruptedException e) {
log.error("Exception caused during init state checking...");
}
if (node.dataIp() != null && !isIntfEnabled(node, VXLAN)) {
log.warn("VXLAN interface is not enabled!");
return false;
}
if (node.dataIp() != null && !isIntfEnabled(node, GRE)) {
log.warn("GRE interface is not enabled!");
return false;
}
if (node.dataIp() != null && !isIntfEnabled(node, GENEVE)) {
log.warn("GENEVE interface is not enabled!");
return false;
}
for (KubevirtPhyInterface phyIntf : node.phyIntfs()) {
if (phyIntf == null) {
log.warn("Physnet interface is invalid");
return false;
}
try {
// we need to wait a while, in case tunneling ports
// creation requires some time
sleep(SLEEP_LONG_MS);
} catch (InterruptedException e) {
log.error("Exception caused during init state checking...");
}
String bridgeName = BRIDGE_PREFIX + phyIntf.network();
String patchPortName = structurePortName(INTEGRATION_TO_PHYSICAL_PREFIX + phyIntf.network());
if (!(hasPhyBridge(node, bridgeName) && hasPhyPatchPort(node, patchPortName) && hasPhyIntf(node, phyIntf.intf()))) {
log.warn("PhyBridge {}", hasPhyBridge(node, bridgeName));
log.warn("hasPhyPatchPort {}", hasPhyPatchPort(node, patchPortName));
log.warn("hasPhyIntf {}", hasPhyIntf(node, phyIntf.intf()));
return false;
}
}
if (node.type() == GATEWAY) {
if (!(hasPhyIntf(node, INTEGRATION_TO_TUNNEL) && hasPhyIntf(node, TUNNEL_TO_INTEGRATION))) {
log.warn("IntToTunPort {}", hasPhyIntf(node, INTEGRATION_TO_TUNNEL));
log.warn("TunToIntPort {}", hasPhyIntf(node, TUNNEL_TO_INTEGRATION));
return false;
}
}
return true;
}
use of org.onosproject.kubevirtnode.api.KubevirtPhyInterface in project onos by opennetworkinglab.
the class KubevirtShowNodeCommand method printNode.
private void printNode(KubevirtNode node) {
print("Name: %s", node.hostname());
print(" Type: %s", node.type());
print(" State: %s", node.state());
print(" Management IP: %s", node.managementIp().toString());
print(" Data IP: %s", node.dataIp().toString());
print(" Integration Bridge: %s", node.intgBridge());
print(" Tunneling Bridge: %s", node.tunBridge());
int counter = 1;
for (KubevirtPhyInterface intf : node.phyIntfs()) {
print(" Physical interfaces #%d:", counter);
print(" Network: %s", intf.network());
print(" Interface: %s", intf.intf());
counter++;
}
}
use of org.onosproject.kubevirtnode.api.KubevirtPhyInterface in project onos by opennetworkinglab.
the class KubevirtNodeJsonMatcher method matchesSafely.
@Override
protected boolean matchesSafely(JsonNode jsonNode, Description description) {
// check hostname
String jsonHostname = jsonNode.get(Constants.HOST_NAME).asText();
String hostname = node.hostname();
if (!jsonHostname.equals(hostname)) {
description.appendText("hostname was " + jsonHostname);
return false;
}
// check type
String jsonType = jsonNode.get(Constants.TYPE).asText();
String type = node.type().name();
if (!jsonType.equals(type)) {
description.appendText("type was " + jsonType);
return false;
}
// check management IP
String jsonMgmtIp = jsonNode.get(Constants.MANAGEMENT_IP).asText();
String mgmtIp = node.managementIp().toString();
if (!jsonMgmtIp.equals(mgmtIp)) {
description.appendText("management IP was " + jsonMgmtIp);
return false;
}
// check integration bridge
JsonNode jsonIntgBridge = jsonNode.get(INTEGRATION_BRIDGE);
if (jsonIntgBridge != null) {
String intgBridge = node.intgBridge().toString();
if (!jsonIntgBridge.asText().equals(intgBridge)) {
description.appendText("integration bridge was " + jsonIntgBridge);
return false;
}
}
// check tunnel bridge
JsonNode jsonTunBridge = jsonNode.get(TUNNEL_BRIDGE);
if (jsonTunBridge != null) {
String tunBridge = node.tunBridge().toString();
if (!jsonTunBridge.asText().equals(tunBridge)) {
description.appendText("tunnel bridge was " + jsonTunBridge);
return false;
}
}
// check state
String jsonState = jsonNode.get(STATE).asText();
String state = node.state().name();
if (!jsonState.equals(state)) {
description.appendText("state was " + jsonState);
return false;
}
// check data IP
JsonNode jsonDataIp = jsonNode.get(Constants.DATA_IP);
if (jsonDataIp != null) {
String dataIp = node.dataIp().toString();
if (!jsonDataIp.asText().equals(dataIp)) {
description.appendText("Data IP was " + jsonDataIp.asText());
return false;
}
}
// check physical interfaces
JsonNode jsonPhyIntfs = jsonNode.get(PHYSICAL_INTERFACES);
if (jsonPhyIntfs != null) {
if (jsonPhyIntfs.size() != node.phyIntfs().size()) {
description.appendText("physical interface size was " + jsonPhyIntfs.size());
return false;
}
for (KubevirtPhyInterface phyIntf : node.phyIntfs()) {
boolean intfFound = false;
for (int intfIndex = 0; intfIndex < jsonPhyIntfs.size(); intfIndex++) {
KubevirtPhyInterfaceJsonMatcher intfMatcher = KubevirtPhyInterfaceJsonMatcher.matchesKubevirtPhyInterface(phyIntf);
if (intfMatcher.matches(jsonPhyIntfs.get(intfIndex))) {
intfFound = true;
break;
}
}
if (!intfFound) {
description.appendText("PhyIntf not found " + phyIntf.toString());
return false;
}
}
}
return true;
}
use of org.onosproject.kubevirtnode.api.KubevirtPhyInterface in project onos by opennetworkinglab.
the class KubevirtNodeCodec method decode.
@Override
public KubevirtNode decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
String hostname = nullIsIllegal(json.get(HOST_NAME).asText(), HOST_NAME + MISSING_MESSAGE);
String type = nullIsIllegal(json.get(TYPE).asText(), TYPE + MISSING_MESSAGE);
String mIp = nullIsIllegal(json.get(MANAGEMENT_IP).asText(), MANAGEMENT_IP + MISSING_MESSAGE);
KubevirtNode.Builder nodeBuilder = DefaultKubevirtNode.builder().hostname(hostname).type(KubevirtNode.Type.valueOf(type)).state(KubevirtNodeState.INIT).managementIp(IpAddress.valueOf(mIp));
if (json.get(DATA_IP) != null) {
nodeBuilder.dataIp(IpAddress.valueOf(json.get(DATA_IP).asText()));
}
JsonNode intBridgeJson = json.get(INTEGRATION_BRIDGE);
if (intBridgeJson != null) {
nodeBuilder.intgBridge(DeviceId.deviceId(intBridgeJson.asText()));
}
JsonNode tunBridgeJson = json.get(TUNNEL_BRIDGE);
if (tunBridgeJson != null) {
nodeBuilder.tunBridge(DeviceId.deviceId(tunBridgeJson.asText()));
}
// parse physical interfaces
List<KubevirtPhyInterface> phyIntfs = new ArrayList<>();
JsonNode phyIntfsJson = json.get(PHYSICAL_INTERFACES);
if (phyIntfsJson != null) {
final JsonCodec<KubevirtPhyInterface> phyIntfCodec = context.codec(KubevirtPhyInterface.class);
IntStream.range(0, phyIntfsJson.size()).forEach(i -> {
ObjectNode intfJson = get(phyIntfsJson, i);
phyIntfs.add(phyIntfCodec.decode(intfJson, context));
});
}
nodeBuilder.phyIntfs(phyIntfs);
JsonNode externalBridgeJson = json.get(GATEWAY_BRIDGE_NAME);
if (externalBridgeJson != null) {
nodeBuilder.gatewayBridgeName(externalBridgeJson.asText());
}
log.trace("node is {}", nodeBuilder.build().toString());
return nodeBuilder.build();
}
use of org.onosproject.kubevirtnode.api.KubevirtPhyInterface in project onos by opennetworkinglab.
the class KubevirtNodeUtil method buildKubevirtNode.
/**
* Returns the kubevirt node from the node.
*
* @param node a raw node object returned from a k8s client
* @return kubevirt node
*/
public static KubevirtNode buildKubevirtNode(Node node) {
String hostname = node.getMetadata().getName();
IpAddress managementIp = null;
IpAddress dataIp = null;
for (NodeAddress nodeAddress : node.getStatus().getAddresses()) {
if (nodeAddress.getType().equals(INTERNAL_IP)) {
managementIp = IpAddress.valueOf(nodeAddress.getAddress());
dataIp = IpAddress.valueOf(nodeAddress.getAddress());
}
}
Set<String> rolesFull = node.getMetadata().getLabels().keySet().stream().filter(l -> l.contains(K8S_ROLE)).collect(Collectors.toSet());
KubevirtNode.Type nodeType = WORKER;
for (String roleStr : rolesFull) {
String role = roleStr.split("/")[1];
if (MASTER.name().equalsIgnoreCase(role)) {
nodeType = MASTER;
break;
}
}
// start to parse kubernetes annotation
Map<String, String> annots = node.getMetadata().getAnnotations();
String physnetConfig = annots.get(PHYSNET_CONFIG_KEY);
String gatewayConfig = annots.get(GATEWAY_CONFIG_KEY);
String dataIpStr = annots.get(DATA_IP_KEY);
Set<KubevirtPhyInterface> phys = new HashSet<>();
String gatewayBridgeName = null;
try {
if (physnetConfig != null) {
JSONArray configJson = new JSONArray(physnetConfig);
for (int i = 0; i < configJson.length(); i++) {
JSONObject object = configJson.getJSONObject(i);
String network = object.getString(NETWORK_KEY);
String intf = object.getString(INTERFACE_KEY);
if (network != null && intf != null) {
phys.add(DefaultKubevirtPhyInterface.builder().network(network).intf(intf).build());
}
}
}
if (dataIpStr != null) {
dataIp = IpAddress.valueOf(dataIpStr);
}
if (gatewayConfig != null) {
JsonNode jsonNode = new ObjectMapper().readTree(gatewayConfig);
nodeType = GATEWAY;
gatewayBridgeName = jsonNode.get(GATEWAY_BRIDGE_NAME).asText();
}
} catch (JSONException | JsonProcessingException e) {
log.error("Failed to parse physnet config or gateway config object", e);
}
// if the node is taint with kubevirt.io key configured,
// we mark this node as OTHER type, and do not add it into the cluster
NodeSpec spec = node.getSpec();
if (spec.getTaints() != null) {
for (Taint taint : spec.getTaints()) {
String effect = taint.getEffect();
String key = taint.getKey();
String value = taint.getValue();
if (StringUtils.equals(effect, NO_SCHEDULE_EFFECT) && StringUtils.equals(key, KUBEVIRT_IO_KEY) && StringUtils.equals(value, DRAINING_VALUE)) {
nodeType = OTHER;
}
}
}
return DefaultKubevirtNode.builder().hostname(hostname).managementIp(managementIp).dataIp(dataIp).type(nodeType).state(KubevirtNodeState.ON_BOARDED).phyIntfs(phys).gatewayBridgeName(gatewayBridgeName).build();
}
Aggregations