ref: refs/heads/master
commit d3b4a9d14c6d5bfa544e3f8a1389cdf3696cdbc9
Author: Michael Calmer
Date: Mon Feb 9 15:07:24 2009 +0100
Add method RefreshAllRepositories to InstallationService
It refreshes all "enabled" repositories and load the objects into the pool.
---
mof/SUSE_SoftwareInstallationService.mof | 12 +++-
src/SUSE_SoftwareInstallationServiceProvider.cc | 87 ++++++++++++++++++++++-
src/SUSE_SoftwareInstallationServiceProvider.h | 2 +
3 files changed, 99 insertions(+), 2 deletions(-)
diff --git a/mof/SUSE_SoftwareInstallationService.mof b/mof/SUSE_SoftwareInstallationService.mof
index 4e7f5b9..bb8c7ee 100644
--- a/mof/SUSE_SoftwareInstallationService.mof
+++ b/mof/SUSE_SoftwareInstallationService.mof
@@ -17,7 +17,17 @@
Description ("A Class which provide a SoftwareInstallationService.")
]
class SUSE_SoftwareInstallationService : CIM_SoftwareInstallationService
-{
+{
+ [Description (
+ "Refresh all enabled repositories and load the new metadata into the pool."),
+ ValueMap { "0", "1", ".." },
+ Values { "Completed with no Errors", "Error", "Vendor Specific" }]
+ uint32 RefreshAllRepositories(
+ [IN, Description (
+ "Refresh Policy"),
+ ValueMap { "0", "1", "2" },
+ Values { "RefreshIfNeeded", "RefreshForced", "RefreshIfNeededIgnoreDelay" }]
+ uint16 RefreshPolicy);
};
diff --git a/src/SUSE_SoftwareInstallationServiceProvider.cc b/src/SUSE_SoftwareInstallationServiceProvider.cc
index a70e461..4014e4c 100644
--- a/src/SUSE_SoftwareInstallationServiceProvider.cc
+++ b/src/SUSE_SoftwareInstallationServiceProvider.cc
@@ -137,7 +137,10 @@ CmpiStatus SUSE_SoftwareInstallationServiceProviderClass::invokeMethod (const Cm
{
st = this->installFromSoftwareIdentity(ctx, rslt, ref, in, out);
}
-
+ else if( ::strcasecmp( methodName, "RefreshAllRepositories" ) == 0)
+ {
+ st = this->refreshAllRepositories(ctx, rslt, ref, in, out);
+ }
_CMPIZYPP_TRACE(1,("--- %s CMPI invokeMethod() exited",_ClassName));
return st;
}
@@ -156,6 +159,88 @@ CmpiStatus SUSE_SoftwareInstallationServiceProviderClass::installFromSoftwareIde
return st;
}
+CmpiStatus SUSE_SoftwareInstallationServiceProviderClass::refreshAllRepositories(const CmpiContext &ctx, CmpiResult &rslt,
+ const CmpiObjectPath &ref,
+ const CmpiArgs &in, CmpiArgs &out)
+{
+ CmpiStatus st(CMPI_RC_ERR_NOT_SUPPORTED);
+ _CMPIZYPP_TRACE(1,("--- %s CMPI refreshAllRepositories() called.",_ClassName));
+
+ CMPIUint16 policy = 0;
+ try
+ {
+ policy = in.getArg("RefreshPolicy");
+ }
+ catch(CmpiStatus rc)
+ {
+ CmpiStatus rc( CMPI_RC_ERR_FAILED, "Missing parameter RefreshPolicy." );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI refreshAllRepositories() failed : %s", _ClassName, rc.msg()));
+ return rc;
+ }
+ // zypp init
+ zypp::scoped_ptr<ZyppAC> zyppac;
+ try
+ {
+ zyppac.reset( new ZyppAC() );
+ }
+ catch ( const zypp::Exception & err )
+ {
+ CmpiStatus rc( CMPI_RC_ERR_FAILED, ZyppAC::exceptionString( err, "Could not initialize zypp: " ).c_str() );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI refreshAllRepositories() failed : %s", _ClassName, rc.msg()));
+ return rc;
+ }
+ RepoManager::RawMetadataRefreshPolicy pol = RepoManager::RefreshIfNeeded;
+
+ switch( policy )
+ {
+ case 0:
+ pol = RepoManager::RefreshIfNeeded;
+ break;
+ case 1:
+ pol = RepoManager::RefreshForced;
+ break;
+ case 2:
+ pol = RepoManager::RefreshIfNeededIgnoreDelay;
+ break;
+ }
+ RepoManager repoManager( zyppac->getSysRoot() );
+
+ try
+ {
+ // Load all enabled repos in repos.d to pool.
+ RepoInfoList repos = repoManager.knownRepositories();
+ for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
+ {
+
+ RepoInfo & repo( *it );
+
+ if ( ! repo.enabled() )
+ continue;
+
+ if ( repoManager.isCached( repo ) )
+ {
+ repoManager.cleanCache( repo );
+ }
+ repoManager.refreshMetadata( repo, pol );
+ repoManager.buildCache( repo );
+ repoManager.loadFromCache( repo );
+ }
+ }
+ catch( const zypp::Exception & err )
+ {
+ _CMPIZYPP_TRACE(1,("--- %s CMPI refreshAllRepositories() failed : %s ", _ClassName,
+ ZyppAC::exceptionString( err, "" ).c_str() ));
+ rslt.returnData( CMPIUint32(1) ); // Error
+ rslt.returnDone();
+ return CmpiStatus ( CMPI_RC_OK );
+ }
+ rslt.returnData( CmpiData(CMPIUint32(0)) ); // Completed with No Error
+ rslt.returnDone();
+ st = CmpiStatus ( CMPI_RC_OK );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI refreshAllRepositories() exited.",_ClassName));
+ return st;
+}
+
} // namespace cmpizypp
CMProviderBase( SUSE_SoftwareInstallationServiceProvider );
diff --git a/src/SUSE_SoftwareInstallationServiceProvider.h b/src/SUSE_SoftwareInstallationServiceProvider.h
index ced16da..16b873a 100644
--- a/src/SUSE_SoftwareInstallationServiceProvider.h
+++ b/src/SUSE_SoftwareInstallationServiceProvider.h
@@ -24,6 +24,8 @@ namespace cmpizypp
private:
CmpiStatus installFromSoftwareIdentity(const CmpiContext &ctx, CmpiResult &rslt,
const CmpiObjectPath &ref, const CmpiArgs &in, CmpiArgs &out);
+ CmpiStatus refreshAllRepositories(const CmpiContext &ctx, CmpiResult &rslt,
+ const CmpiObjectPath &ref, const CmpiArgs &in, CmpiArgs &out);
};
} // namespace cmpizypp
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org