Author: rhafer Date: Thu Jun 16 13:23:46 2011 New Revision: 64407 URL: http://svn.opensuse.org/viewcvs/yast?rev=64407&view=rev Log: Automatically find the next unassinged ServerId Modified: branches/SuSE-Code-11-SP2-Branch/ldap-server/src/LdapServer.pm branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.cc branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.h Modified: branches/SuSE-Code-11-SP2-Branch/ldap-server/src/LdapServer.pm URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/ldap-server/src/LdapServer.pm?rev=64407&r1=64406&r2=64407&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/ldap-server/src/LdapServer.pm (original) +++ branches/SuSE-Code-11-SP2-Branch/ldap-server/src/LdapServer.pm Thu Jun 16 13:23:46 2011 @@ -1395,6 +1395,24 @@ return 1; } +BEGIN { $TYPEINFO {AssignServerId} = ["function", "boolean" ]; } +sub AssignServerId +{ + my ( $self, $fqdn ) = @_; + if ( ! $fqdn ) + { + $fqdn = $self->ReadHostnameFQ(); + } + if ( $fqdn eq "" ) + { + y2error("Unable to determine full-qualified hostname"); + return 0; + } + + SCR->Execute('.ldapserver.assignServerId', "ldap://".$fqdn ); + return 1; +} + BEGIN { $TYPEINFO {ReadAllowFeatures} = ["function", [ "list", "string" ] ]; } sub ReadAllowFeatures { Modified: branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.cc?rev=64407&r1=64406&r2=64407&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.cc (original) +++ branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.cc Thu Jun 16 13:23:46 2011 @@ -433,6 +433,11 @@ return YCPBoolean(false); } } + else if ( path->component_str(0) == "assignServerId" ) + { + std::string url( arg->asString()->value_cstr() ); + this->assignServerId( url ); + } else if ( path->component_str(0) == "waitForBackgroundTasks" ) { olc.waitForBackgroundTasks(); @@ -2285,3 +2290,56 @@ throw; } } + +class CompareUri +{ + private: + const std::string &theUri; + + public: + CompareUri( const std::string &val ) : theUri(val) {} + + bool operator() ( const OlcServerId &id ) const + { + return theUri == id.getServerUri(); + } +}; + +class CompareId +{ + private: + int theId; + + public: + CompareId( int val ) : theId(val) {} + + bool operator() ( const OlcServerId &id ) const + { + return theId == id.getServerId(); + } +}; + +void SlapdConfigAgent::assignServerId( const std::string &uri ) +{ + // check if uri has already a Id assigned + std::vector<OlcServerId> serverIds = globals->getServerIds(); + + std::vector<OlcServerId>::const_iterator found; + found = find_if(serverIds.begin(), serverIds.end(), CompareUri(uri) ); + if ( found != serverIds.end() ) + { + y2milestone("Found ServerId %s", found->toStringVal().c_str() ); + return; + } + + for ( int j=1; j < 999; j++ ) + { + found = find_if(serverIds.begin(), serverIds.end(), CompareId(j) ); + if ( found == serverIds.end() ) + { + y2milestone( "Free ServerId %d", j); + globals->addServerId( OlcServerId( j, uri ) ); + return; + } + } +} Modified: branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.h URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.h?rev=64407&r1=64406&r2=64407&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.h (original) +++ branches/SuSE-Code-11-SP2-Branch/ldap-server/src/agent/SlapdConfigAgent.h Thu Jun 16 13:23:46 2011 @@ -76,6 +76,7 @@ const std::string &bindpw); void syncCheck( LDAPConnection &c, const std::string &basedn ); + void assignServerId( const std::string &uri ); private: YCPMap lastError; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org