ref: refs/heads/master
commit 3a0944e3fa291aca1eb77d6ac9a644bfafc588ff
Author: Michael Calmer
Date: Thu Feb 5 18:06:27 2009 +0100
implement SUSE_SoftwareRepository
---
mof/CMakeLists.txt | 2 +
mof/SUSE_SoftwareRepository.mof | 64 +++++++
mof/SUSE_SoftwareRepository.sfcb.reg | 5 +
mof/deploy.mof | 1 +
src/CMakeLists.txt | 2 +
src/SUSE_SoftwareRepositoryProvider.cc | 302 ++++++++++++++++++++++++++++++++
src/SUSE_SoftwareRepositoryProvider.h | 32 ++++
7 files changed, 408 insertions(+), 0 deletions(-)
diff --git a/mof/CMakeLists.txt b/mof/CMakeLists.txt
index 6c7b91b..4af9285 100644
--- a/mof/CMakeLists.txt
+++ b/mof/CMakeLists.txt
@@ -20,6 +20,8 @@ INSTALL( FILES
SUSE_ElementCapabilities.sfcb.reg
SUSE_HostedInstallationService.mof
SUSE_HostedInstallationService.sfcb.reg
+ SUSE_SoftwareRepository.mof
+ SUSE_SoftwareRepository.sfcb.reg
deploy.mof
DESTINATION ${CMPIZYPP_DATA_DIR}/
)
diff --git a/mof/SUSE_SoftwareRepository.mof b/mof/SUSE_SoftwareRepository.mof
new file mode 100644
index 0000000..b376678
--- /dev/null
+++ b/mof/SUSE_SoftwareRepository.mof
@@ -0,0 +1,64 @@
+// ==================================================================
+// SUSE_SoftwareRepository
+// ==================================================================
+ [Experimental, Version ( "2.10.0" ),
+ Description (
+ "SoftwareRepository describes the URL of a repository "
+ "containing SoftwareIdentities "
+ "for use by the SoftwareInstallationService. " )]
+class SUSE_SoftwareRepository : CIM_RemoteServiceAccessPoint {
+
+ [Override ( "InfoFormat" ),
+ Description (
+ "A SoftwareRepository will always be a URL." )]
+ uint16 InfoFormat = 200;
+
+ [Description (
+ "An enumerated integer that specifies the type of "
+ "resource referenced by the "
+ "RemoteServiceAccessPoint.AccessInfo property." ),
+ ValueMap { "0", "1", "2", "3", "4", "5", "6", "7", "9", "10",
+ "11", "12", "..", "0x8000..0xFFFF" },
+ Values { "Unknown", "Other", "Installer and Payload",
+ "Installer", "Payload", "Installability checker",
+ "Security Advisory", "Engineering Advisory",
+ "Technical release notes", "Change notification",
+ "Whitepaper", "Marketing Documentation", "DMTF Reserved",
+ "Vendor Reserved" },
+ ModelCorrespondence {
+ "CIM_SoftwareIdentityResource.OtherResourceType",
+ "CIM_SoftwareIdentityResource.ExtendedResourceType" }]
+ uint16 ResourceType = 1;
+
+ [Description (
+ "A enumerated integer that provides further information "
+ "for ResourceType. It will set to 2 (\'Not Applicable\') "
+ "if there is no extended information available." ),
+ ValueMap { "0", "2", // Binary format types
+ "3",
+ "4", "5", "6", "7", "8", "9..100", "101..200",
+ //Text formats
+ "201", "202", "203",
+ "204..0x7FFF", "0x8000..0xFFFF" },
+ Values { "Unknown", "Not Applicable",
+ // Binary format types
+ "Linux RPM",
+ "HP-UX Depot", "Windows MSI", "Solaris Package",
+ "Macintosh Disk Image", "Debian linux Package",
+ "DMTF Reserved", "Vendor Reserved",
+ //Text formats
+ "HTML", "PDF", "Text File",
+ "DMTF Reserved", "Vendor Reserved" },
+ ModelCorrespondence {
+ "CIM_SoftwareIdentityResource.ResourceType" }]
+ uint16 ExtendedResourceType;
+
+ [Description (
+ "A string describing the file type when the instance\'s "
+ "ResourceType property is 1 (\"Other\")." ),
+ ModelCorrespondence {
+ "CIM_SoftwareIdentityResource.ResourceType" }]
+ string OtherResourceType = "Software Repository";
+
+
+};
diff --git a/mof/SUSE_SoftwareRepository.sfcb.reg b/mof/SUSE_SoftwareRepository.sfcb.reg
new file mode 100644
index 0000000..1a8c53d
--- /dev/null
+++ b/mof/SUSE_SoftwareRepository.sfcb.reg
@@ -0,0 +1,5 @@
+[SUSE_SoftwareRepository]
+ provider: SUSE_SoftwareRepositoryProvider
+ location: cmpi-zypp
+ type: instance method
+ namespace: root/cimv2
diff --git a/mof/deploy.mof b/mof/deploy.mof
index dcf1632..216fd85 100644
--- a/mof/deploy.mof
+++ b/mof/deploy.mof
@@ -9,4 +9,5 @@
#pragma include ("SUSE_SoftwareInstallationServiceCapabilities.mof")
#pragma include ("SUSE_ElementCapabilities.mof")
#pragma include ("SUSE_HostedInstallationService.mof")
+#pragma include ("SUSE_SoftwareRepository.mof")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 636e441..6956fe7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -19,6 +19,7 @@ SET( CMPIZYPP_SRCS
SUSE_SoftwareInstallationServiceCapabilitiesProvider.cc
SUSE_ElementCapabilitiesProvider.cc
SUSE_HostedInstallationServiceProvider.cc
+ SUSE_SoftwareRepositoryProvider.cc
)
SET( CMPIZYPP_HEADERS
SUSE_Common.h
@@ -34,6 +35,7 @@ SET( CMPIZYPP_HEADERS
SUSE_SoftwareInstallationServiceCapabilitiesProvider.h
SUSE_ElementCapabilitiesProvider.h
SUSE_HostedInstallationServiceProvider.h
+ SUSE_SoftwareRepositoryProvider.h
)
ADD_LIBRARY(cmpi-zypp SHARED ${CMPIZYPP_SRCS})
diff --git a/src/SUSE_SoftwareRepositoryProvider.cc b/src/SUSE_SoftwareRepositoryProvider.cc
new file mode 100644
index 0000000..7b2d311
--- /dev/null
+++ b/src/SUSE_SoftwareRepositoryProvider.cc
@@ -0,0 +1,302 @@
+
+#include <iostream>
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include "SUSE_zypp.h"
+#include "SUSE_Common.h"
+#include "SUSE_SoftwareRepositoryProvider.h"
+
+using namespace zypp;
+using std::endl;
+
+namespace cmpizypp
+{
+ namespace
+ {
+ const char * _ClassName = "SUSE_SoftwareRepository";
+ } // namespace
+
+
+SUSE_SoftwareRepositoryProviderClass::SUSE_SoftwareRepositoryProviderClass( const CmpiBroker & mbp, const CmpiContext & ctx )
+ : CmpiBaseMI( mbp, ctx )
+ , CmpiInstanceMI( mbp, ctx )
+ , CmpiMethodMI( mbp, ctx )
+{
+}
+
+CmpiStatus SUSE_SoftwareRepositoryProviderClass::enumInstanceNames( const CmpiContext& ctx, CmpiResult& rslt, const CmpiObjectPath & cop )
+{
+ _CMPIZYPP_TRACE(1,("--- %s CMPI EnumInstanceNames() called",_ClassName));
+
+ CmpiObjectPath csop = get_this_computersystem(*broker, ctx, cop);
+ const char *sccn = csop.getKey("CreationClassName");
+ const char *sn = csop.getKey("Name");
+
+ // 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 list software identities: " ).c_str() );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI EnumInstanceNames() failed : %s", _ClassName, rc.msg()));
+ return rc;
+ }
+
+ RepoManager repoManager( zyppac->getSysRoot() );
+
+ RepoInfoList repos = repoManager.knownRepositories();
+ for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
+ {
+ CmpiObjectPath op( cop.getNameSpace(), _ClassName );
+ op.setKey( "SystemCreationClassName", sccn);
+ op.setKey( "SystemName", sn);
+ op.setKey( "CreationClassName", _ClassName);
+ op.setKey( "Name", it->alias().c_str() );
+ rslt.returnData( op );
+ }
+
+ rslt.returnDone();
+ _CMPIZYPP_TRACE(1,("--- %s CMPI EnumInstanceNames() exited",_ClassName));
+ return CmpiStatus(CMPI_RC_OK);
+}
+
+CmpiStatus SUSE_SoftwareRepositoryProviderClass::enumInstances( const CmpiContext & ctx, CmpiResult & rslt, const CmpiObjectPath & cop, const char** properties )
+{
+ _CMPIZYPP_TRACE(1,("--- %s CMPI EnumInstances() called",_ClassName));
+
+ CmpiObjectPath csop = get_this_computersystem(*broker, ctx, cop);
+
+ // 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 list software identities: " ).c_str() );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI EnumInstanceNames() failed : %s", _ClassName, rc.msg()));
+ return rc;
+ }
+
+ RepoManager repoManager( zyppac->getSysRoot() );
+
+ RepoInfoList repos = repoManager.knownRepositories();
+ for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
+ {
+ rslt.returnData( makeInstance( *it, cop, csop, properties ) );
+ }
+
+ rslt.returnDone();
+ _CMPIZYPP_TRACE(1,("--- %s CMPI EnumInstances() exited",_ClassName));
+ return CmpiStatus(CMPI_RC_OK);
+}
+
+
+CmpiStatus SUSE_SoftwareRepositoryProviderClass::getInstance( const CmpiContext &ctx, CmpiResult &rslt, const CmpiObjectPath &cop, const char **properties )
+{
+ _CMPIZYPP_TRACE(1,("--- %s CMPI GetInstance() called",_ClassName));
+
+ const char *lsccn = cop.getKey("SystemCreationClassName");
+ const char *lsn = cop.getKey("SystemName");
+ const char *lccn = cop.getKey("CreationClassName");
+ const char *ln = cop.getKey("Name");
+
+ CmpiObjectPath csop = get_this_computersystem(*broker, ctx, cop);
+ const char *sccn = csop.getKey("CreationClassName");
+ const char *sn = csop.getKey("Name");
+
+ if( lsccn== NULL || lsn == NULL || lccn == NULL || ln == NULL ||
+ ::strcmp(lccn, _ClassName) != 0 ||
+ ::strcmp(lsccn, sccn) != 0 || ::strcmp(lsn, sn) != 0)
+ {
+ CmpiStatus rc( CMPI_RC_ERR_FAILED, "Could not find this instance." );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI GetInstance() 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 list software identities: " ).c_str() );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI EnumInstanceNames() failed : %s", _ClassName, rc.msg()));
+ return rc;
+ }
+
+ RepoManager repoManager( zyppac->getSysRoot() );
+ if( ! repoManager.hasRepo( ln ) )
+ {
+ CmpiStatus rc( CMPI_RC_ERR_FAILED, "Could not find this instance." );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI GetInstance() failed : %s", _ClassName, rc.msg()));
+ return rc;
+ }
+ RepoInfo repo( repoManager.getRepo( ln ) );
+
+ rslt.returnData( makeInstance( repo, cop, csop, properties ) );
+
+ rslt.returnDone();
+ _CMPIZYPP_TRACE(1,("--- %s CMPI GetInstance() exited",_ClassName));
+ return CmpiStatus(CMPI_RC_OK);
+}
+
+CmpiStatus SUSE_SoftwareRepositoryProviderClass::invokeMethod (const CmpiContext &ctx, CmpiResult &rslt,
+ const CmpiObjectPath &ref, const char *methodName,
+ const CmpiArgs &in, CmpiArgs &out)
+{
+ _CMPIZYPP_TRACE(1,("--- %s CMPI invokeMethod() called with method: %s",_ClassName, methodName));
+
+ if( ::strcasecmp( ref.getClassName().charPtr(), _ClassName) != 0 )
+ {
+ return CmpiStatus(CMPI_RC_ERR_NOT_SUPPORTED, "invalid classname");
+ }
+ CmpiStatus st(CMPI_RC_ERR_NOT_SUPPORTED);
+
+ if( ::strcasecmp( methodName, "RequestStateChange" ) == 0)
+ {
+ const char *lsccn = ref.getKey("SystemCreationClassName");
+ const char *lsn = ref.getKey("SystemName");
+ const char *lccn = ref.getKey("CreationClassName");
+ const char *ln = ref.getKey("Name");
+
+ CmpiObjectPath csop = get_this_computersystem(*broker, ctx, ref);
+ const char *sccn = csop.getKey("CreationClassName");
+ const char *sn = csop.getKey("Name");
+
+ if( lsccn== NULL || lsn == NULL || lccn == NULL || ln == NULL ||
+ ::strcmp(lccn, _ClassName) != 0 ||
+ ::strcmp(lsccn, sccn) != 0 || ::strcmp(lsn, sn) != 0)
+ {
+ CmpiStatus rc( CMPI_RC_ERR_FAILED, "Could not find this instance." );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI GetInstance() failed : %s", _ClassName, rc.msg()));
+ return rc;
+ }
+
+ CMPIUint16 reqState = 0;
+ try
+ {
+ reqState = in.getArg("RequestedState");
+ }
+ catch(CmpiStatus rc)
+ {
+ CmpiStatus rc( CMPI_RC_ERR_FAILED, "Missing parameter RequestedState." );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI GetInstance() 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 list software identities: " ).c_str() );
+ _CMPIZYPP_TRACE(1,("--- %s CMPI EnumInstanceNames() failed : %s", _ClassName, rc.msg()));
+ return rc;
+ }
+ bool newStateEnabled = true;
+
+ if( reqState == 2 )
+ newStateEnabled = true;
+ else if( reqState == 3 )
+ newStateEnabled = false;
+ else
+ {
+ _CMPIZYPP_TRACE(1,("--- %s CMPI GetInstance() failed : Invalid Parameter.", _ClassName ));
+ rslt.returnData( CMPIUint32(5) ); // invalid Parameter
+ rslt.returnDone();
+ return CmpiStatus ( CMPI_RC_OK );
+ }
+
+ RepoManager repoManager( zyppac->getSysRoot() );
+ if( ! repoManager.hasRepo( ln ) )
+ {
+ _CMPIZYPP_TRACE(1,("--- %s CMPI GetInstance() failed : Could not find this instance.", _ClassName ));
+ rslt.returnData( CMPIUint32(2) ); // unknown Error
+ rslt.returnDone();
+ return CmpiStatus ( CMPI_RC_OK );
+ }
+ try
+ {
+ RepoInfo repo( repoManager.getRepo( ln ) );
+ repo.setEnabled( newStateEnabled );
+ repoManager.modifyRepository( repo );
+ }
+ catch( const zypp::Exception & err )
+ {
+ _CMPIZYPP_TRACE(1,("--- %s CMPI InvokeMethod() failed : %s ", _ClassName,
+ ZyppAC::exceptionString( err, "" ).c_str() ));
+ rslt.returnData( CMPIUint32(2) ); // unknown Error
+ rslt.returnDone();
+ return CmpiStatus ( CMPI_RC_OK );
+ }
+ rslt.returnData( CmpiData(CMPIUint32(0)) ); // Completed with No Error
+ rslt.returnDone();
+ return CmpiStatus ( CMPI_RC_OK );
+ }
+
+ _CMPIZYPP_TRACE(1,("--- %s CMPI invokeMethod() exited",_ClassName));
+ return st;
+}
+
+/* ========================= private ================================== */
+
+CmpiInstance SUSE_SoftwareRepositoryProviderClass::makeInstance( const RepoInfo &repo,
+ const CmpiObjectPath & cop,
+ const CmpiObjectPath & csop,
+ const char ** properties )
+{
+ CmpiObjectPath op( cop.getNameSpace(), _ClassName );
+ CmpiInstance ci( op );
+
+ const char *sccn = csop.getKey("CreationClassName");
+ const char *sn = csop.getKey("Name");
+
+ const char * keys[] = { "SystemCreationClassName", "SystemName", "CreationClassName", "Name" };
+ ci.setPropertyFilter( properties, keys );
+
+ ci.setProperty( "SystemCreationClassName", sccn);
+ ci.setProperty( "SystemName", sn);
+ ci.setProperty( "CreationClassName", _ClassName);
+ ci.setProperty( "Name", repo.alias().c_str() );
+
+ ci.setProperty( "AccessInfo", repo.url().asString().c_str() );
+
+ CmpiArray avReqState( 2, CMPI_uint16 );
+ avReqState[0] = CMPIUint16(2); // Enabled
+ avReqState[1] = CMPIUint16(3); // Disabled
+ ci.setProperty( "AvailableRequestedStates", avReqState );
+
+ ci.setProperty( "Caption", "Software Repository" );
+ ci.setProperty( "Description", (repo.name() + " Software Repository").c_str() );
+ ci.setProperty( "ElementName", repo.name().c_str() );
+ ci.setProperty( "EnabledDefault", CMPIUint16(7) );
+ ci.setProperty( "EnabledState", (repo.enabled())?CMPIUint16(2):CMPIUint16(3) );
+ ci.setProperty( "ExtendedResourceType", CMPIUint16(2) );
+
+ return ci;
+}
+
+} // namespace cmpizypp
+
+CMProviderBase( SUSE_SoftwareRepositoryProvider );
+
+CMInstanceMIFactory( cmpizypp::SUSE_SoftwareRepositoryProviderClass, SUSE_SoftwareRepositoryProvider );
+CMMethodMIFactory( cmpizypp::SUSE_SoftwareRepositoryProviderClass, SUSE_SoftwareRepositoryProvider );
diff --git a/src/SUSE_SoftwareRepositoryProvider.h b/src/SUSE_SoftwareRepositoryProvider.h
new file mode 100644
index 0000000..80e1985
--- /dev/null
+++ b/src/SUSE_SoftwareRepositoryProvider.h
@@ -0,0 +1,32 @@
+#ifndef SUSE_SOFTWAREREPOSITORYPROVIDER_H
+#define SUSE_SOFTWAREREPOSITORYPROVIDER_H
+
+#include
+#include
+#include
+
+namespace cmpizypp
+{
+ /**
+ */
+ class SUSE_SoftwareRepositoryProviderClass : public CmpiInstanceMI, public CmpiMethodMI
+ {
+ public:
+ SUSE_SoftwareRepositoryProviderClass( const CmpiBroker & mbp, const CmpiContext & ctx );
+
+ virtual CmpiStatus enumInstanceNames( const CmpiContext& ctx, CmpiResult& rslt, const CmpiObjectPath & cop );
+ virtual CmpiStatus enumInstances( const CmpiContext & ctx, CmpiResult & rslt, const CmpiObjectPath & cop, const char** properties );
+ virtual CmpiStatus getInstance( const CmpiContext &ctx, CmpiResult &rslt, const CmpiObjectPath &cop, const char **properties );
+
+ virtual CmpiStatus invokeMethod (const CmpiContext &ctx, CmpiResult &rslt,
+ const CmpiObjectPath &ref, const char *methodName,
+ const CmpiArgs &in, CmpiArgs &out);
+
+ private:
+ CmpiInstance makeInstance( const zypp::RepoInfo &repo, const CmpiObjectPath &cop,
+ const CmpiObjectPath &csop, const char ** properties );
+ };
+
+} // namespace cmpizypp
+
+#endif // SUSE_SOFTWAREREPOSITORYPROVIDER_H
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org