java/code/src/com/redhat/rhn/domain/server/Server.java | 8
++
java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml | 3
java/code/src/com/redhat/rhn/frontend/xmlrpc/NoSuchNetworkInterfaceException.java | 37
++++++++++
java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java | 28
+++++++
4 files changed, 76 insertions(+)
New commits:
commit 0f97067ea0f19fe12c9130ccf74205c1d68f0df6
Author: Tomas Kasparek <tkasparek(a)redhat.com>
Date: Mon Feb 25 12:08:49 2013 +0100
API for setting primary network interface
diff --git a/java/code/src/com/redhat/rhn/domain/server/Server.java
b/java/code/src/com/redhat/rhn/domain/server/Server.java
index 418b9ff..6d752ef 100644
--- a/java/code/src/com/redhat/rhn/domain/server/Server.java
+++ b/java/code/src/com/redhat/rhn/domain/server/Server.java
@@ -1974,4 +1974,12 @@ public class Server extends BaseDomainHelper implements
Identifiable {
public void setCrashes(Set<Crash> c) {
this.crashes = c;
}
+
+ /**
+ * @param interfaceName Name of the interface to be checked
+ * @return Returns true if yes, otherwise no
+ */
+ public Boolean existsActiveInterfaceWithName(String interfaceName) {
+ return findActiveIfaceWithName(interfaceName, false) != null;
+ }
}
diff --git a/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml
b/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml
index ce1020a..0aa4550 100644
--- a/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml
+++ b/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml
@@ -6895,6 +6895,9 @@ Follow this url to see the full list of inactive systems:
<trans-unit id="api.system.crash.nosuchcrash">
<source>No such crash found.</source>
</trans-unit>
+ <trans-unit id="api.system.nosuchnetiface">
+ <source>No such network interface: {0}.</source>
+ </trans-unit>
<trans-unit id="api.errata.invalidadvisorytype">
<source>Invalid errata type, "{0}". Please use one of the
following: "Security Advisory", "Product Enhancement Advisory", or
"Bug Fix Advisory".</source>
</trans-unit>
diff --git
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/NoSuchNetworkInterfaceException.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/NoSuchNetworkInterfaceException.java
new file mode 100644
index 0000000..b7fee95
--- /dev/null
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/NoSuchNetworkInterfaceException.java
@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2013 Red Hat, Inc.
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ *
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+
+package com.redhat.rhn.frontend.xmlrpc;
+
+import com.redhat.rhn.FaultException;
+import com.redhat.rhn.common.localization.LocalizationService;
+
+/**
+ * No Crashes Exception
+ *
+ * @version $Rev$
+ */
+public class NoSuchNetworkInterfaceException extends FaultException {
+
+ /**
+ * NoSuchNetworkInterfaceException
+ * @param interfaceName Name of interface which has not been found
+ */
+ public NoSuchNetworkInterfaceException(String interfaceName) {
+ super(1072, "No Such Network Interface" ,
LocalizationService.getInstance().
+ getMessage("api.system.nosuchnetiface",
+ new Object [] {interfaceName}));
+ }
+}
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 e7ec382..cb7019e 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
@@ -99,6 +99,7 @@ import com.redhat.rhn.frontend.xmlrpc.InvalidSystemException;
import com.redhat.rhn.frontend.xmlrpc.MethodInvalidParamException;
import com.redhat.rhn.frontend.xmlrpc.NoSuchActionException;
import com.redhat.rhn.frontend.xmlrpc.NoSuchCobblerSystemRecordException;
+import com.redhat.rhn.frontend.xmlrpc.NoSuchNetworkInterfaceException;
import com.redhat.rhn.frontend.xmlrpc.NoSuchPackageException;
import com.redhat.rhn.frontend.xmlrpc.NoSuchSnapshotTagException;
import com.redhat.rhn.frontend.xmlrpc.NoSuchSystemException;
@@ -5307,4 +5308,31 @@ public class SystemHandler extends BaseHandler {
return returnList;
}
+
+ /**
+ * Sets new primary network interface
+ * @param sessionKey Session key
+ * @param serverId Server ID
+ * @param interfaceName Interface name
+ * @return 1 if success, exception thrown otherwise
+ * @throws Exception If interface does not exist Exception is thrown
+ *
+ * @xmlrpc.doc Sets new primary network interface
+ * @xmlrpc.param #param("string", "sessionKey")
+ * @xmlrpc.param #param("int", "serverId")
+ * @xmlrpc.param #param("string", "interfaceName")
+ * @xmlrpc.returntype #return_int_success()
+ */
+ public int setPrimaryInterface(String sessionKey, Integer serverId,
+ String interfaceName) throws Exception {
+ User loggedInUser = getLoggedInUser(sessionKey);
+ Server server = lookupServer(loggedInUser, serverId);
+
+ if (!server.existsActiveInterfaceWithName(interfaceName)) {
+ throw new NoSuchNetworkInterfaceException("No such network interface:
" +
+ interfaceName);
+ }
+ server.setPrimaryInterfaceWithName(interfaceName);
+ return 1;
+ }
}