github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/upgrades/rsyslogport.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package upgrades
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/juju/juju/environs/config"
    10  	"github.com/juju/juju/state"
    11  )
    12  
    13  func updateRsyslogPort(context Context) error {
    14  	agentConfig := context.AgentConfig()
    15  	info, ok := agentConfig.StateInfo()
    16  	if !ok {
    17  		return fmt.Errorf("Failed to get StateInfo")
    18  	}
    19  	// we need to re-open state with a nil policay so we can bypass
    20  	// validation, as the syslog-port is normally immutable
    21  	st, err := state.Open(info, state.DefaultDialOpts(), nil)
    22  	if err != nil {
    23  		return err
    24  	}
    25  	defer st.Close()
    26  	attrs := map[string]interface{}{
    27  		"syslog-port": config.DefaultSyslogPort,
    28  	}
    29  	return st.UpdateEnvironConfig(attrs, nil, nil)
    30  }