Puppet: System Administration Automated

Support

Ticket #219: locking.patch

File locking.patch, 3.6 kB (added by jamtur01, 10 months ago)
  • a/lib/puppet/provider/nameservice.rb

    old new  
    186186        self.ensure = :absent 
    187187    end 
    188188 
    189     def locked 
    190         self.ensure = :locked 
    191     end 
    192  
    193     def unlocked 
    194         self.ensure = :unlocked 
    195     end 
    196  
    197189    def ensure 
    198190        if exists? 
    199191            :present 
     
    202194        end 
    203195    end 
    204196 
     197    def locked 
     198        self.status = :locked 
     199    end 
     200 
     201    def unlocked 
     202        self.status = :unlocked 
     203    end 
     204 
     205    #def status 
     206    #    if exists? 
     207    #        :unlocked 
     208    #    else 
     209    #        :locked 
     210    #    end 
     211    #end 
     212 
     213    def status=(value) 
     214        cmd = nil 
     215        event = nil 
     216        case value 
     217        when :unlocked 
     218            unless exists? 
     219                info "absent - cannot unlock" 
     220                return nil 
     221            end 
     222 
     223            cmd = self.unlockcmd 
     224            type = "unlock" 
     225        when :locked 
     226            # FIXME - what happens when already locked? 
     227             
     228            cmd = self.lockcmd    
     229            type = "lock" 
     230        end 
     231 
     232        begin 
     233            execute(cmd) 
     234        rescue Puppet::ExecutionFailure => detail 
     235            raise Puppet::Error, "Could not %s %s %s: %s" % 
     236                [type, @resource.class.name, @resource.name, detail] 
     237        end 
     238    end 
     239  
    205240    # This is only used when creating or destroying the object. 
    206241    def ensure=(value) 
    207242        cmd = nil 
     
    229264            # blah blah, define elsewhere, blah blah 
    230265            cmd = self.addcmd 
    231266            type = "create" 
    232         when :locked 
    233             unless exists? 
    234             #the object doesn't exist - can't lock it 
    235                     info "is absent - cannot lock" 
    236                     return nil 
    237             end 
    238  
    239             cmd = self.lockcmd 
    240             type = "locked" 
    241         when :unlocked 
    242             unless exists? 
    243             #the object doesn't exist - can't unlock it 
    244                     info "is absent - cannot unlock" 
    245                     return nil 
    246             end 
    247    
    248             cmd = self.unlockcmd 
    249             type = "unlocked" 
    250267        end 
    251268                    
    252269        begin 
  • a/lib/puppet/type/user.rb

    old new  
    3333                provider.delete 
    3434            end 
    3535 
    36             newvalue(:locked, :event => :user_locked) do 
    37                 provider.locked 
    38             end 
    39  
    40             newvalue(:unlocked, :event => :user_unlocked) do 
    41                 provider.unlocked 
    42             end 
    43  
    4436            desc "The basic state that the object should be in." 
    4537 
    4638            # If they're talking about the thing at all, they generally want to 
     
    8173 
    8274        end 
    8375 
     76        newproperty(:status) do 
     77            desc "The status of the user.  Can be specified as locked or  
     78                  unlocked.  Status defaults to unlocked." 
     79 
     80            newvalue(:locked, :event => :user_locked) do 
     81                provider.locked 
     82            end 
     83 
     84            newvalue(:unlocked, :event => :user_unlocked) do 
     85                provider.unlocked 
     86            end 
     87       
     88        end 
     89 
    8490        newproperty(:uid) do 
    8591            desc "The user ID.  Must be specified numerically.  For new users 
    8692                being created, if no user ID is specified then one will be