Skip to content

Commit

Permalink
Add provisionSystem API with proxy option
Browse files Browse the repository at this point in the history
Using web ui it is possible to schedule system provisioning through
specific proxy. This is not possible using any API call.
This commit adds this missing provisionSystem API call and related unit
tests.
Automatic proxy detection based on request headers is preserved.
  • Loading branch information
aaannz committed Nov 14, 2024
1 parent 9104e77 commit ef605e3
Show file tree
Hide file tree
Showing 4 changed files with 403 additions and 5 deletions.
129 changes: 124 additions & 5 deletions java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024 SUSE LLC
* Copyright (c) 2009--2017 Red Hat, Inc.
*
* This software is licensed to you under the GNU General Public License,
Expand Down Expand Up @@ -2859,7 +2860,7 @@ public int provisionVirtualGuest(User loggedInUser, Integer sid, String guestNam
* @param loggedInUser The current user
* @param sid of the system to be provisioned
* @param profileName of Profile to be used.
* @return Returns 1 if successful, exception otherwise
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
Expand All @@ -2883,7 +2884,7 @@ public int provisionSystem(User loggedInUser, Integer sid, String profileName)
* @param request the spark request
* @param sid of the system to be provisioned
* @param profileName of Profile to be used.
* @return Returns 1 if successful, exception otherwise
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
Expand All @@ -2900,14 +2901,66 @@ public int provisionSystem(User loggedInUser, HttpServletRequest request, Intege
return provisionSystem(loggedInUser, request, sid, profileName, new Date());
}

/**
* Provision a system using the specified kickstart/autoinstallation profile.
*
* @param loggedInUser The current user
* @param sid of the system to be provisioned
* @param proxy ID of the proxy to use
* @param profileName of Profile to be used
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
* @apidoc.doc Provision a system using the specified kickstart/autoinstallation profile.
* @apidoc.param #session_key()
* @apidoc.param #param_desc("int", "sid", "ID of the system to be provisioned.")
* @apidoc.param #param_desc("int", "proxy", "ID of the proxy to use.")
* @apidoc.param #param_desc("string", "profileName", "Profile to use.")
* @apidoc.returntype #param_desc("int", "id", "ID of the action scheduled, otherwise exception thrown
* on error")
*/
@ApiIgnore(ApiType.HTTP)
public int provisionSystem(User loggedInUser, Integer sid, Integer proxy, String profileName)
throws FaultException {
return provisionSystem(loggedInUser, RhnXmlRpcServer.getRequest(), sid, proxy, profileName, new Date());
}

/**
* Provision a system using the specified kickstart/autoinstallation profile.
*
* @param loggedInUser The current user
* @param request the spark request
* @param sid of the system to be provisioned
* @param proxy ID of the proxy to use
* @param profileName of Profile to be used.
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
* @apidoc.doc Provision a system using the specified kickstart/autoinstallation profile.
* @apidoc.param #session_key()
* @apidoc.param #param_desc("int", "sid", "ID of the system to be provisioned.")
* @apidoc.param #param_desc("int", "proxy", "ID of the proxy to use.")
* @apidoc.param #param_desc("string", "profileName", "Profile to use.")
* @apidoc.returntype #param_desc("int", "id", "ID of the action scheduled, otherwise exception thrown
* on error")
*/
@ApiIgnore(ApiType.XMLRPC)
public int provisionSystem(User loggedInUser, HttpServletRequest request, Integer sid, Integer proxy,
String profileName)
throws FaultException {
return provisionSystem(loggedInUser, request, sid, proxy, profileName, new Date());
}

/**
* Provision a system using the specified kickstart/autoinstallation profile at specified time.
*
* @param loggedInUser The current user
* @param sid of the system to be provisioned
* @param profileName of Profile to be used.
* @param earliestDate when the autoinstallation needs to be scheduled
* @return Returns 1 if successful, exception otherwise
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
Expand All @@ -2934,7 +2987,7 @@ public int provisionSystem(User loggedInUser, Integer sid,
* @param sid of the system to be provisioned
* @param profileName of Profile to be used.
* @param earliestDate when the autoinstallation needs to be scheduled
* @return Returns 1 if successful, exception otherwise
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
Expand All @@ -2950,6 +3003,63 @@ public int provisionSystem(User loggedInUser, Integer sid,
public int provisionSystem(User loggedInUser, HttpServletRequest request, Integer sid,
String profileName, Date earliestDate)
throws FaultException {
return provisionSystem(loggedInUser, request , sid, null, profileName, earliestDate);
}

/**
* Provision a system using the specified kickstart/autoinstallation profile at specified time.
*
* @param loggedInUser The current user
* @param sid of the system to be provisioned
* @param proxy ID of the proxy to use
* @param profileName of Profile to be used.
* @param earliestDate when the autoinstallation needs to be scheduled
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
* @apidoc.doc Provision a system using the specified kickstart/autoinstallation profile.
* @apidoc.param #session_key()
* @apidoc.param #param_desc("int", "sid", "ID of the system to be provisioned.")
* @apidoc.param #param_desc("int", "proxy", "ID of the proxy to use.")
* @apidoc.param #param_desc("string", "profileName", "Profile to use.")
* @apidoc.param #param("$date", "earliestDate")
* @apidoc.returntype #param_desc("int", "id", "ID of the action scheduled, otherwise exception thrown
* on error")
*/
@ApiIgnore(ApiType.HTTP)
public int provisionSystem(User loggedInUser, Integer sid,
Integer proxy, String profileName, Date earliestDate)
throws FaultException {
HttpServletRequest request = RhnXmlRpcServer.getRequest();
return provisionSystem(loggedInUser, request, sid, proxy, profileName, earliestDate);
}
/**
* Provision a system using the specified kickstart/autoinstallation profile at specified time.
*
* @param loggedInUser The current user
* @param request the request
* @param sid of the system to be provisioned
* @param proxy ID of the proxy to use
* @param profileName of Profile to be used.
* @param earliestDate when the autoinstallation needs to be scheduled
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
* @apidoc.doc Provision a system using the specified kickstart/autoinstallation profile.
* @apidoc.param #session_key()
* @apidoc.param #param_desc("int", "sid", "ID of the system to be provisioned.")
* @apidoc.param #param_desc("int", "proxy", "ID of the proxy to use.")
* @apidoc.param #param_desc("string", "profileName", "Profile to use.")
* @apidoc.param #param("$date", "earliestDate")
* @apidoc.returntype #param_desc("int", "id", "ID of the action scheduled, otherwise exception thrown
* on error")
*/
@ApiIgnore(ApiType.XMLRPC)
public int provisionSystem(User loggedInUser, HttpServletRequest request, Integer sid,
Integer proxy, String profileName, Date earliestDate)
throws FaultException {
log.debug("provisionSystem called.");

// Lookup the server so we can validate it exists and throw error if not.
Expand All @@ -2970,10 +3080,19 @@ public int provisionSystem(User loggedInUser, HttpServletRequest request, Intege
KickstartHelper helper = new KickstartHelper(request);
String host = helper.getKickstartHost();


KickstartScheduleCommand cmd = new KickstartScheduleCommand(
Long.valueOf(sid),
ksdata.getId(), loggedInUser, earliestDate, host);
if (proxy != null) {
Server proxyServer = SystemManager.lookupByIdAndOrg(Long.valueOf(proxy), loggedInUser.getOrg());
if (proxyServer == null) {
throw new FaultException(-2, "provisionError", "Requested proxy is not available");
}
if (!proxyServer.isProxy()) {
throw new FaultException(-2, "provisionError", "Requested proxy is not registered proxy");
}
cmd.setProxy(proxyServer);
}
ValidatorError ve = cmd.store();
if (ve != null) {
throw new FaultException(-2, "provisionError",
Expand Down
Loading

0 comments on commit ef605e3

Please sign in to comment.