Skip to content

Commit

Permalink
Show IP addresses on node page. Fixes JENKINS-14398
Browse files Browse the repository at this point in the history
  • Loading branch information
felfert committed Nov 27, 2016
1 parent 7c13f7f commit 5a39bd8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Expand Up @@ -22,6 +22,7 @@
import jenkins.model.Jenkins;

import java.io.IOException;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -30,6 +31,11 @@
import org.kohsuke.stapler.HttpRedirect;
import org.kohsuke.stapler.HttpResponse;

import org.jclouds.compute.domain.NodeMetadata;

import shaded.com.google.common.base.Joiner;
import shaded.com.google.common.collect.ImmutableSet;

/**
* JClouds version of Jenkins {@link SlaveComputer} - responsible for terminating an instance.
*
Expand Down Expand Up @@ -128,4 +134,31 @@ public void deleteSlave(final boolean logging) {
}
}

private Set<String> getIpAddresses(final boolean wantPublic) {
final JCloudsSlave node = getNode();
if (null != node) {
final NodeMetadata md = node.getNodeMetaData();
Set<String> ret = wantPublic ? md.getPublicAddresses() : md.getPrivateAddresses();
if (!ret.isEmpty()) {
return ret;
}
}
return ImmutableSet.<String>of("None");
}

public String getPublicIpAddressHeader() {
return "Public IP-Address" + (getIpAddresses(true).size() > 1 ? "es" : "");
}

public String getPrivateIpAddressHeader() {
return "Private IP-Address" + (getIpAddresses(false).size() > 1 ? "es" : "");
}

public String getPublicIpAddresses() {
return Joiner.on(" ").join(getIpAddresses(true));
}

public String getPrivateIpAddresses() {
return Joiner.on(" ").join(getIpAddresses(false));
}
}
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2010-2016 Adrian Cole, Andrew Bayer, Fritz Elfert, Marat Mavlyutov, Monty Taylor, Vijay Kiran et. al.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout" xmlns:f="/lib/form">
<h2>${it.privateIpAddressHeader}</h2>
<p>${it.privateIpAddresses}</p>
<h2>${it.publicIpAddressHeader}</h2>
<p>${it.publicIpAddresses}</p>
</j:jelly>

0 comments on commit 5a39bd8

Please sign in to comment.