client/tools/spacewalk-koan/spacewalkkoan/spacewalkkoan.py | 37 ++- java/code/src/com/redhat/rhn/frontend/action/kickstart/ScheduleKickstartWizardAction.java | 4 java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml | 8 java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java | 97 ++++++++-- java/code/src/com/redhat/rhn/manager/kickstart/KickstartFormatter.java | 63 +++++- java/code/src/com/redhat/rhn/manager/kickstart/KickstartScheduleCommand.java | 24 ++ java/code/webapp/WEB-INF/pages/common/fragments/kickstart/schedule/network-options.jspf | 10 - java/code/webapp/WEB-INF/struts-config.xml | 1 web/conf/rhn_web.conf | 2 9 files changed, 212 insertions(+), 34 deletions(-)
New commits: commit 5b2e12d2cbda9d1cbc100210d6e45e35140a36fe Author: Milan Zazrivec mzazrivec@redhat.com Date: Fri Dec 2 15:44:48 2011 +0100
IPv6: reprovisioning with static network interface
diff --git a/client/tools/spacewalk-koan/spacewalkkoan/spacewalkkoan.py b/client/tools/spacewalk-koan/spacewalkkoan/spacewalkkoan.py index 1420580..3b5ffdf 100644 --- a/client/tools/spacewalk-koan/spacewalkkoan/spacewalkkoan.py +++ b/client/tools/spacewalk-koan/spacewalkkoan/spacewalkkoan.py @@ -83,7 +83,17 @@ def find_name_servers():
def find_gateway(): response = execute("route -n | awk '/^0.0.0.0/ {print $2}'") - return response[0] + if response: + return response[0] + else: + return "" + +def find_gateway6(device): + response = execute("ip -f inet6 route list dev eth0|awk '/^default/ {print $3}'") + if response: + return response[0] + else: + return ""
def getSystemId(): path = "/etc/sysconfig/rhn/systemid" @@ -93,18 +103,25 @@ def getSystemId():
def update_static_device_records(kickstart_host, static_device): client = xmlrpclib.Server("https://" + kickstart_host + "/rpc/api") - data = {"gateway": find_gateway(),\ + data = {"gateway" : find_gateway(),\ "nameservers": find_name_servers(),\ - "hostname": find_host_name(),\ + "hostname" : find_host_name(),\ "device" : static_device,\ "ip": find_ip(static_device),\ - "netmask": find_netmask(static_device)} - msg = """Unable to retrieve the '%s' information needed to update static network configuration information. - Details:\n %s""" - for key, value in data.items(): - if not value: - raise Exception(msg % (key, pprint.pformat(data))) - client.system.setup_static_network(getSystemId(), data) + "netmask" : find_netmask(static_device)} + + data6 = {"gateway" : find_gateway6(static_device), \ + "device" : static_device, \ + "ip" : find_ip6(static_device), \ + "netmask" : find_netmask6(static_device)} + + api_version = client.api.get_version() + + # Since api_version >= 11.1 we support setup_static_network with IPv6 data + if float(api_version) <= 11.00: + client.system.setup_static_network(getSystemId(), data) + else: + client.system.setup_static_network(getSystemId(), data, data6)
def initiate(kickstart_host, base, extra_append, static_device=None, system_record="", preserve_files=[]):
diff --git a/java/code/src/com/redhat/rhn/frontend/action/kickstart/ScheduleKickstartWizardAction.java b/java/code/src/com/redhat/rhn/frontend/action/kickstart/ScheduleKickstartWizardAction.java index 4d4bd04..8de8247 100644 --- a/java/code/src/com/redhat/rhn/frontend/action/kickstart/ScheduleKickstartWizardAction.java +++ b/java/code/src/com/redhat/rhn/frontend/action/kickstart/ScheduleKickstartWizardAction.java @@ -104,6 +104,7 @@ public class ScheduleKickstartWizardAction extends RhnWizardAction { public static final String NETWORK_TYPE = "networkType"; public static final String NETWORK_INTERFACE = "networkInterface"; public static final String NETWORK_INTERFACES = "networkInterfaces"; + public static final String USE_IPV6_GATEWAY = "useIpv6Gateway"; /** * {@inheritDoc} */ @@ -449,6 +450,9 @@ public class ScheduleKickstartWizardAction extends RhnWizardAction {
cmd.setNetworkDevice(form.getString(NETWORK_TYPE), form.getString(NETWORK_INTERFACE)); + if (form.getString(USE_IPV6_GATEWAY).equals("1")) { + cmd.setIpv6Gateway(); + } cmd.setKernelOptions(parseKernelOptions(form, ctx.getRequest(), form.getString(RequestContext.COBBLER_ID), false)); cmd.setPostKernelOptions(parseKernelOptions(form, ctx.getRequest(), diff --git a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml index cd768de..d96b4db 100644 --- a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml +++ b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml @@ -11015,6 +11015,14 @@ Please note that some manual configuration of these scripts may still be require </context-group> </trans-unit>
+ <trans-unit id="kickstart.netconn.static.useipv6gw.jsp.label"> + <source>Use IPv6 gateway</source> + <context-group name="ctx"> + <context context-type="sourcefile">/rhn/kickstart/KickstartSystemDetailsEdit</context> + </context-group> + </trans-unit> + + <trans-unit id="kickstart.netconn.dhcp.jsp.link"> <source>DHCP using first available interface</source> <context-group name="ctx"> diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java index e80f1b5..c0b8329 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java @@ -4395,22 +4395,11 @@ public class SystemHandler extends BaseHandler { }
/** - * Method to setup the static network configuration for a given server - * This is used by spacewalkkoan if the user selects static networking option - * in the advanced configuration section during provisioning. - * It basically adds $static_network variable to the cobbler system record - * which gets rendered during the kickstart. - * @param clientcert the client certificate or the system id file - * @param data a map holding the network details like ip, gateway, - * name servers, ip, netmask and hostname. - * - * @return 1 on success exception otherwise. - * - * @xmlrpc.ignore Since this API is for internal integration between services and - * is not useful to external users of the API, the typical XMLRPC API documentation - * is not being included. + * Authenticates the client system by the client cert and looks up system record. + * @param clientcert Client certificate. + * @return SystemRecord. */ - public int setupStaticNetwork(String clientcert, Map<String, Object> data) { + private SystemRecord getSystemRecordFromClientCert(String clientcert) { StringReader rdr = new StringReader(clientcert); Server server = null;
@@ -4438,6 +4427,27 @@ public class SystemHandler extends BaseHandler { throw new MethodInvalidParamException(); } SystemRecord rec = server.getCobblerObject(null); + return rec; + } + + /** + * Method to setup the static network configuration for a given server + * This is used by spacewalkkoan if the user selects static networking option + * in the advanced configuration section during provisioning. + * It basically adds $static_network variable to the cobbler system record + * which gets rendered during the kickstart. + * @param clientcert the client certificate or the system id file + * @param data a map holding the network details like ip, gateway, + * name servers, ip, netmask and hostname. + * + * @return 1 on success exception otherwise. + * + * @xmlrpc.ignore Since this API is for internal integration between services and + * is not useful to external users of the API, the typical XMLRPC API documentation + * is not being included. + */ + public int setupStaticNetwork(String clientcert, Map<String, Object> data) { + SystemRecord rec = getSystemRecordFromClientCert(clientcert); if (rec == null) { throw new NoSuchSystemException(); } @@ -4460,6 +4470,63 @@ public class SystemHandler extends BaseHandler { return 1; }
+ /** + * Method to setup the static network IPv4 and IPv6 configuration for a given server + * This is used by spacewalkkoan if the user selects static networking option + * in the advanced configuration section during provisioning. + * It basically adds $static_network variable to the cobbler system record + * which gets rendered during the kickstart. + * @param clientcert the client certificate or the system id file + * @param data a map holding the IPv4 network details like ip, gateway, + * name servers, ip, netmask and hostname. + * + * @param data6 a map holding the IPv6 network details like ip, netmask, gateway + * and device. + * @return 1 on success exception otherwise. + * + * @xmlrpc.ignore Since this API is for internal integration between services and + * is not useful to external users of the API, the typical XMLRPC API documentation + * is not being included. + */ + public int setupStaticNetwork(String clientcert, Map<String, Object> data, + Map<String, Object> data6) { + SystemRecord rec = getSystemRecordFromClientCert(clientcert); + if (rec == null) { + throw new NoSuchSystemException(); + } + + String device = (String)data.get("device"); + // General network info + String hostName = (String)data.get("hostname"); + List<String> nameservers = (List<String>)data.get("nameservers"); + // IPv4 network info + String ip4 = (String)data.get("ip"); + String nm4 = (String)data.get("netmask"); + String gw4 = (String)data.get("gateway"); + // IPv6 network info + String ip6 = (String) data6.get("ip"); + String nm6 = (String) data6.get("netmask"); + String gw6 = (String) data6.get("gateway"); + + Map<String, Object> meta = rec.getKsMeta(); + String ipv6GatewayMeta = (String) meta.get(KickstartFormatter.USE_IPV6_GATEWAY); + boolean preferIpv6Gateway = false; + if (ipv6GatewayMeta != null && ipv6GatewayMeta.equals("true")) { + preferIpv6Gateway = true; + } + + String command = KickstartFormatter.makeStaticNetworkCommand(device, hostName, + nameservers.get(0), ip4, nm4, gw4, ip6, nm6, gw6, preferIpv6Gateway); + + rec.setHostName(hostName); + rec.setGateway((preferIpv6Gateway) ? gw6 : gw4); + rec.setNameServers(nameservers); + meta.put(KickstartFormatter.STATIC_NETWORK_VAR, command); + rec.setKsMeta(meta); + rec.save(); + return 1; + } + private KickstartData lookupKsData(String label, Org org) { return XmlRpcKickstartHelper.getInstance().lookupKsData(label, org); } diff --git a/java/code/src/com/redhat/rhn/manager/kickstart/KickstartFormatter.java b/java/code/src/com/redhat/rhn/manager/kickstart/KickstartFormatter.java index 8f170f0..7f346ce 100644 --- a/java/code/src/com/redhat/rhn/manager/kickstart/KickstartFormatter.java +++ b/java/code/src/com/redhat/rhn/manager/kickstart/KickstartFormatter.java @@ -149,12 +149,17 @@ public class KickstartFormatter { private static final String CHDIR_RPMS = "cd /tmp/rhn_rpms"; private static final String REDHAT_MGMT_SERVER = "$redhat_management_server"; public static final String STATIC_NETWORK_VAR = "static_network"; + public static final String USE_IPV6_GATEWAY = "use_ipv6_gateway"; private static final String STATIC_NETWORK_COMMAND = "network --bootproto static" + - " " + "--device %s --ip %s" + + " " + "--device %s" + " " + "--gateway %s" + " " + "--nameserver %s" + - " " + "--netmask %s" + " " + "--hostname %s"; + private static final String STATIC_NETWORK_COMMAND1 = " " + "--ip %s" + + " " + "--netmask %s"; + private static final String STATIC_NETWORK_COMMAND2 = " " + "--ipv6 %s"; + private static final String STATIC_NETWORK_COMMAND3 = " " + "--ipv6 %s/%s"; + private static final String NETWORK_STRING = "#if $varExists('%s')" + NEWLINE + "$%s" + NEWLINE + @@ -364,13 +369,61 @@ public class KickstartFormatter { * @param nameServer the nameserver information * @param netmask the netmask information * @param hostName the host name information - * @return the network* lne for a static host + * @return the network* line for a static host */ public static String makeStaticNetworkCommand(String device, String ip, String gateway, String nameServer, String netmask, String hostName) { - return String.format(STATIC_NETWORK_COMMAND, device, ip, - gateway, nameServer, netmask, hostName); + return String.format(STATIC_NETWORK_COMMAND + STATIC_NETWORK_COMMAND1, device, + gateway, nameServer, hostName, ip, netmask); + } + + /** + * Returns the network line for static networks + * network --bootproto static --device $DEVICE --ip $IPADDR --ipv6 $IP6ADDR + * --gateway $GATEWAY --nameserver $NAMESERVER + * --netmask $NETMASK --hostname $HOSTNAME + * @param device the network interface name (eth0) + * @param hostName the host name info + * @param nameServer the nameserver info + * @param ip4 the ipv4 address of the interface + * @param nm4 the ipv4 netmask of the interface + * @param gw4 the ipv4 gateway + * @param ip6 the ipv6 address of the interface + * @param nm6 the ipv6 netmask of the interface + * @param gw6 the ipv6 gateway + * @param preferIpv6Gateway whether or not should ipv6 gateway be prefered + * @return the network* line for a static host + */ + public static String makeStaticNetworkCommand(String device, String hostName, + String nameServer, String ip4, String nm4, String gw4, + String ip6, String nm6, String gw6, boolean preferIpv6Gateway) { + + String gateway; + if (preferIpv6Gateway && gw6 != null && gw6.length() != 0) { + gateway = gw6; + } + else { + gateway = gw4; + } + + String command = String.format(STATIC_NETWORK_COMMAND, device, gateway, + nameServer, hostName); + + if (ip4 != null && ip4.length() > 0 && nm4 != null && nm4.length() > 0) { + command += String.format(STATIC_NETWORK_COMMAND1, ip4, nm4); + } + + if (ip6 != null && ip6.length() > 0) { + if (nm6 == null || nm6.length() == 0) { + command += String.format(STATIC_NETWORK_COMMAND2, ip6); + } + else { + command += String.format(STATIC_NETWORK_COMMAND3, ip6, nm6); + } + } + + return command; }
/** diff --git a/java/code/src/com/redhat/rhn/manager/kickstart/KickstartScheduleCommand.java b/java/code/src/com/redhat/rhn/manager/kickstart/KickstartScheduleCommand.java index 5ccd2ab..29c4ec6 100644 --- a/java/code/src/com/redhat/rhn/manager/kickstart/KickstartScheduleCommand.java +++ b/java/code/src/com/redhat/rhn/manager/kickstart/KickstartScheduleCommand.java @@ -143,6 +143,7 @@ public class KickstartScheduleCommand extends BaseSystemOperation { private Profile createdProfile; // Static device private String networkInterface; + private boolean useIpv6Gateway = false; private boolean isDhcp;
private String kernelOptions; @@ -770,6 +771,14 @@ public class KickstartScheduleCommand extends BaseSystemOperation { if (!isDhcp) { ksAction.getKickstartActionDetails().setStaticDevice(networkInterface); } + + SystemRecord rec = this.getHostServer().getCobblerObject(null); + Map<String, Object> meta = rec.getKsMeta(); + meta.put(KickstartFormatter.USE_IPV6_GATEWAY, + this.useIpv6Gateway() ? "true" : "false"); + rec.setKsMeta(meta); + rec.save(); + return ksAction; }
@@ -1355,6 +1364,21 @@ public class KickstartScheduleCommand extends BaseSystemOperation { }
/** + * Sets to use IPv6 gateway. + */ + public void setIpv6Gateway() { + useIpv6Gateway = true; + } + + /** + * Indicate whether an IPv6 gateway is to be used for re-provisioning. + * @return true if IPv6 gateway is to be used, false otherwise. + */ + public boolean useIpv6Gateway() { + return useIpv6Gateway; + } + + /** * @return Returns the user. */ @Override diff --git a/java/code/webapp/WEB-INF/pages/common/fragments/kickstart/schedule/network-options.jspf b/java/code/webapp/WEB-INF/pages/common/fragments/kickstart/schedule/network-options.jspf index e23a9ae..590ccd7 100644 --- a/java/code/webapp/WEB-INF/pages/common/fragments/kickstart/schedule/network-options.jspf +++ b/java/code/webapp/WEB-INF/pages/common/fragments/kickstart/schedule/network-options.jspf @@ -6,7 +6,7 @@ <th><bean:message key="kickstart.netconn.jsp.label" />:</th> <td> <input type="radio" name="networkType" value="dhcp" - onclick="form.dhcpNetworkId.disabled = false; form.staticNetworkId.disabled = true;" + onclick="form.dhcpNetworkId.disabled = false; form.staticNetworkId.disabled = true; form.useIpv6Gateway.disabled = true;" <c:if test="${form.networkType == 'dhcp'}">checked="checked"</c:if> /> <bean:message key="kickstart.netconn.dhcp.jsp.label"/> @@ -31,7 +31,7 @@ <br /> <c:if test="${empty noStatic}"> <input type="radio" name="networkType" value="static" - onclick="form.staticNetworkId.disabled = false;form.dhcpNetworkId.disabled = true;" + onclick="form.staticNetworkId.disabled = false; form.dhcpNetworkId.disabled = true; form.useIpv6Gateway.disabled = false;" <c:if test="${not form.networkType}">checked="checked"</c:if> /> <bean:message key="kickstart.netconn.static.jsp.label"/> @@ -54,9 +54,13 @@ </c:otherwise> </c:choose> <br /> + <input type="checkbox" name="useIpv6Gateway" value="1" + <c:if test="${form.networkType ne 'static'}">disabled="true"</c:if>/> + <bean:message key="kickstart.netconn.static.useipv6gw.jsp.label"/> + <br /> </c:if> <input type="radio" name="networkType" value="link" - onclick="form.staticNetworkId.disabled = true;form.dhcpNetworkId.disabled = true;" + onclick="form.staticNetworkId.disabled = true;form.dhcpNetworkId.disabled = true; form.useIpv6Gateway.disabled = true;" <c:if test="${form.networkType == 'link' or empty form.networkType}">checked="checked"</c:if> /> <bean:message key="kickstart.netconn.dhcp.jsp.link"/> diff --git a/java/code/webapp/WEB-INF/struts-config.xml b/java/code/webapp/WEB-INF/struts-config.xml index 5a17a64..942b5cb 100644 --- a/java/code/webapp/WEB-INF/struts-config.xml +++ b/java/code/webapp/WEB-INF/struts-config.xml @@ -797,6 +797,7 @@ <!-- Advanced Options Page --> <form-property name="networkType" type="java.lang.String" /> <form-property name="networkInterface" type="java.lang.String" /> + <form-property name="useIpv6Gateway" type="java.lang.String"/> <form-property name="kernelParamsType" type="java.lang.String" /> <form-property name="kernelParams" type="java.lang.String" /> <form-property name="postKernelParamsType" type="java.lang.String" /> diff --git a/web/conf/rhn_web.conf b/web/conf/rhn_web.conf index dad786e..271c7e0 100644 --- a/web/conf/rhn_web.conf +++ b/web/conf/rhn_web.conf @@ -225,7 +225,7 @@ web.config_delim_end = |} web.version = 1.6 nightly
# the version of API -web.apiversion = 11.00 +web.apiversion = 11.1
# maximum size for a config file web.maximum_config_file_size = 131072
spacewalk-commits@lists.fedorahosted.org