[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/ricci docs/rpm_api.html modules/rpm/Pack ...



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	kupcevic sourceware org	2006-10-12 19:13:11

Modified files:
	ricci/docs     : rpm_api.html 
	ricci/modules/rpm: PackageHandler.cpp PackageHandler.h 
	                   RpmModule.cpp 

Log message:
	rpm module: enable upgrade of packages, but only if requested

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/docs/rpm_api.html.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/rpm/PackageHandler.cpp.diff?cvsroot=cluster&r1=1.8&r2=1.9
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/rpm/PackageHandler.h.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/rpm/RpmModule.cpp.diff?cvsroot=cluster&r1=1.2&r2=1.3

--- conga/ricci/docs/rpm_api.html	2006/04/12 15:47:09	1.1
+++ conga/ricci/docs/rpm_api.html	2006/10/12 19:13:11	1.2
@@ -93,10 +93,11 @@
 	</P>
 	<UL>
 		<P ALIGN=LEFT>Install/upgrade rpms and sets from repository.</P>
-		<P>Input variables: <BR>- “rpms” (list_xml) – list of rpms to
+		<P>Input variables: <BR>- “rpms” (list_xml) – optional, list of rpms to
 		install/upgrade. Rpm format &lt;rpm name=”rpm name”/&gt;. <BR>-
-		“sets” (list_xml) – list of sets to install/upgrade. Set
-		format &lt;set name=”set name”/&gt;. 
+		“sets” (list_xml) – optional, list of sets to install/upgrade. Set
+		format &lt;set name=”set name”/&gt;. <BR>-
+		“upgrade” (boolean) – optional (defaults to true), upgrade already installed packages/sets. 
 		</P>
 		<P>No output variables. 
 		</P>
@@ -121,4 +122,4 @@
 <P><BR><BR>
 </P>
 </BODY>
-</HTML>
\ No newline at end of file
+</HTML>
--- conga/ricci/modules/rpm/PackageHandler.cpp	2006/10/11 22:33:43	1.8
+++ conga/ricci/modules/rpm/PackageHandler.cpp	2006/10/12 19:13:11	1.9
@@ -155,10 +155,11 @@
   if (rpms.empty())
     return true;
   
-  //if (!available())
-  //  return rpms.empty();
-  
   if (RHEL4) {
+    // TODO: fix up2date handling
+    
+    throw String("RHEL4 not supported, yet");
+    
     String out, err;
     int status;
     vector<String> args;
@@ -171,8 +172,7 @@
     return true;
     
   } else if (FC5 || FC6 || RHEL5) {
-    // install
-    vector<String> rpms_to_install;
+    vector<String> rpms_to_install, rpms_to_upgrade;
     String out, err;
     int status;
     vector<String> args;
@@ -198,6 +198,8 @@
       }
       if (install)
 	rpms_to_install.push_back(*rpm);
+      else
+	rpms_to_upgrade.push_back(*rpm);
     }
     if (!rpms_to_install.empty()) {
       out = err = "";
@@ -213,21 +215,21 @@
       if (status)
 	return false;
     }
+    if (!rpms_to_upgrade.empty()) {
+      out = err = "";
+      args.clear();
+      args.push_back("-y");
+      args.push_back("update");
+      for (vector<String>::const_iterator rpm = rpms_to_upgrade.begin();
+	   rpm != rpms_to_upgrade.end();
+	   rpm++)
+	args.push_back(*rpm);
+      if (utils::execute(YUM_PATH, args, out, err, status, false))
+	throw command_not_found_error_msg(YUM_PATH);
+      if (status)
+	return false;
+    }
     return true;
-    /*
-    // update
-    out = err = "";
-    args.clear();
-    args.push_back("-y");
-    args.push_back("update");
-    for (vector<String>::const_iterator rpm = rpms.begin();
-	 rpm != rpms.end();
-	 rpm++)
-      args.push_back(*rpm);
-    if (utils::execute(YUM_PATH, args, out, err, status, false))
-      throw command_not_found_error_msg(YUM_PATH);
-    return !status;
-    */
   } else 
     return false;
 }
@@ -551,11 +553,9 @@
 
 void 
 PackageHandler::install(const std::list<Package>& packages, 
-			const std::list<PackageSet>& sets)
+			const std::list<PackageSet>& sets,
+			bool upgrade)
 {
-  if (!repo_available())
-    throw String("System not configured to use repositories");
-  
   vector<String> rpms;
   
   PackageHandler h_pre;
@@ -565,12 +565,25 @@
     String name(iter->name);
     map<String, Package>::iterator pack_iter = h_pre.packages().find(name);
     if (pack_iter == h_pre.packages().end())
-      throw String("package ") + name + " not present in repository";
+      throw String("package ") + name + " present neither locally nor in repository";
     else {
-      if (pack_iter->second.repo_version.empty())
-	throw String("package ") + name + " not present in repository";
-      else
-	rpms.push_back(name);
+      String curr_ver(pack_iter->second.version);
+      String repo_ver(pack_iter->second.repo_version);
+      if (curr_ver.empty()) {
+	// not installed
+	if (repo_ver.empty())
+	  throw String("package ") + name + " not present in repository";
+	else
+	  rpms.push_back(name);
+      } else {
+	// already installed
+	if (upgrade) {
+	  if (repo_ver.empty())
+	    throw String("package ") + name + " not present in repository";
+	  else if (repo_ver > curr_ver)
+	    rpms.push_back(name);
+	}
+      }
     }
   }
   
@@ -580,21 +593,40 @@
     String name(iter->name);
     map<String, PackageSet>::iterator set_iter = h_pre.sets().find(name);
     if (set_iter == h_pre.sets().end())
-      throw String("set ") + name + " not present in repository";
+      throw String("set ") + name + " present neither locally nor in repository";
     else {
       PackageSet& p_set = set_iter->second;
-      if (p_set.in_repo)
-	for (list<String>::const_iterator name_iter = p_set.packages.begin();
-	     name_iter != p_set.packages.end();
-	     name_iter++)
-	  rpms.push_back(*name_iter);
-      else
-	throw String("packages of set ") + name + " not present in repository";
+      if (p_set.installed) {
+	// already installed
+	if (upgrade) {
+	  if (p_set.in_repo) {
+	    if (p_set.upgradeable)
+	      for (list<String>::const_iterator name_iter = p_set.packages.begin();
+		   name_iter != p_set.packages.end();
+		   name_iter++)
+		rpms.push_back(*name_iter);
+	  } else
+	    throw String("packages of set ") + name + " not present in repository";
+	}
+      } else {
+	// not installed
+	if (p_set.in_repo)
+	  for (list<String>::const_iterator name_iter = p_set.packages.begin();
+	       name_iter != p_set.packages.end();
+	       name_iter++)
+	    rpms.push_back(*name_iter);
+	else
+	  throw String("packages of set ") + name + " not present in repository";
+      }
     }
   }
   
-  if (!_pi.install(rpms))
-    throw String("unable to install packages");
+  if (!_pi.install(rpms)) {
+    String msg("Failed to install packages");
+    if (!repo_available())
+      msg += ": System not configured to use repositories";
+    throw msg;
+  }
 }
 
 
--- conga/ricci/modules/rpm/PackageHandler.h	2006/08/15 00:06:48	1.4
+++ conga/ricci/modules/rpm/PackageHandler.h	2006/10/12 19:13:11	1.5
@@ -108,7 +108,8 @@
   static PackageSet build_linux_virtual_server_set();
   
   static void install(const std::list<Package>& packages,
-		      const std::list<PackageSet>& sets);
+		      const std::list<PackageSet>& sets,
+		      bool upgrade=true);
   
  private:
   
--- conga/ricci/modules/rpm/RpmModule.cpp	2006/08/10 22:53:08	1.2
+++ conga/ricci/modules/rpm/RpmModule.cpp	2006/10/12 19:13:11	1.3
@@ -64,6 +64,7 @@
 install(const VarMap& args)
 {
   list<XMLObject> rpms_list, sets_list;
+  bool upgrade;
   try{
     VarMap::const_iterator iter = args.find("rpms");
     if (iter != args.end())
@@ -72,8 +73,13 @@
     iter = args.find("sets");
     if (iter != args.end())
       sets_list = iter->second.get_list_XML();
+    
+    upgrade = true;
+    iter = args.find("upgrade");
+    if (iter != args.end())
+      upgrade = iter->second.get_bool();
   } catch ( String e ) {
-	throw APIerror(e);
+    throw APIerror(e);
   }
   
   // command 
@@ -101,7 +107,7 @@
       }
     }
   
-  PackageHandler::install(rpms, sets);
+  PackageHandler::install(rpms, sets, upgrade);
   return VarMap();
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]