We still only store addresses in the config,
so we lose some metadata. We make use of the
scope metadata before storing, though, to
prune the addresses to the internal ones.
+ "launchpad.net/juju-core/instance"
"launchpad.net/juju-core/state"
"launchpad.net/juju-core/state/api"
"launchpad.net/juju-core/state/api/params"
@@ -133,6 +134,9 @@
// the agent has successfully upgraded to.
SetUpgradedToVersion(newVersion version.Number)
+ // SetAPIHostPorts sets the API host/port addresses to connect to.
+ SetAPIHostPorts(servers [][]instance.HostPort)
+
// Migrate takes an existing agent config and applies the given
// parameters to change it.
//
@@ -423,6 +427,20 @@
c.upgradedToVersion = newVersion
}
+func (c *configInternal) SetAPIHostPorts(servers [][]instance.HostPort) {
+ if c.apiDetails == nil {
+ return
+ }
+ var addrs []string
+ for _, serverHostPorts := range servers {
+ addr := instance.SelectInternalHostPort(serverHostPorts, false)
+ if addr != "" {
+ addrs = append(addrs, addr)
+ }
+ }
+ c.apiDetails.addresses = addrs
+}
+
func (c *configInternal) SetValue(key, value string) {
if value == "" {
delete(c.values, key)
Reviewers: mp+213409_ code.launchpad. net,
Message:
Please take a look.
Description: y.SetAPIHostPor ts
agent: add ConfigSetterOnl
We still only store addresses in the config,
so we lose some metadata. We make use of the
scope metadata before storing, though, to
prune the addresses to the internal ones.
https:/ /code.launchpad .net/~axwalk/ juju-core/ agent-setapihos tports/ +merge/ 213409
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/82520043/
Affected files (+54, -0 lines):
A [revision details]
M agent/agent.go
M agent/agent_test.go
Index: [revision details] 20140330221944- tt65zj7hl6967aa d
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: agent/agent.go com/errgo/ errgo" com/juju/ loggo"
=== modified file 'agent/agent.go'
--- agent/agent.go 2014-03-28 08:55:45 +0000
+++ agent/agent.go 2014-03-31 06:30:43 +0000
@@ -16,6 +16,7 @@
"github.
"github.
+ "launchpad. net/juju- core/instance" net/juju- core/state" net/juju- core/state/ api" net/juju- core/state/ api/params" oVersion( newVersion version.Number)
"launchpad.
"launchpad.
"launchpad.
@@ -133,6 +134,9 @@
// the agent has successfully upgraded to.
SetUpgradedT
+ // SetAPIHostPorts sets the API host/port addresses to connect to. (servers [][]instance. HostPort) Version = newVersion
+ SetAPIHostPorts
+
// Migrate takes an existing agent config and applies the given
// parameters to change it.
//
@@ -423,6 +427,20 @@
c.upgradedTo
}
+func (c *configInternal) SetAPIHostPorts (servers [][]instance. HostPort) { SelectInternalH ostPort( serverHostPorts , false) addresses = addrs c.values, key)
+ if c.apiDetails == nil {
+ return
+ }
+ var addrs []string
+ for _, serverHostPorts := range servers {
+ addr := instance.
+ if addr != "" {
+ addrs = append(addrs, addr)
+ }
+ }
+ c.apiDetails.
+}
+
func (c *configInternal) SetValue(key, value string) {
if value == "" {
delete(
Index: agent/agent_test.go agent_test. go' net/gocheck"
=== modified file 'agent/
--- agent/agent_test.go 2014-03-28 08:28:04 +0000
+++ agent/agent_test.go 2014-03-31 06:30:43 +0000
@@ -10,6 +10,7 @@
gc "launchpad.
"launchpad. net/juju- core/agent" net/juju- core/instance" net/juju- core/state" net/juju- core/state/ api" net/juju- core/state/ api/params" SetUpgradedToVe rsion(expectVer s) conf.UpgradedTo Version( ), gc.Equals, expectVers) orts(c *gc.C) { onfig(attribute Params) .APIAddresses) NewAddresses( "0.1.2. 3", "0.1.2.4", "zeroonetwothree") 0].NetworkScope = instance. NetworkCloudLoc al 1].NetworkScope = instance. NetworkCloudLoc al 2].NetworkScope = instance. NetworkPublic NewAddresses( "127.0. 0.1") 0].NetworkScope = instance. NetworkMachineL ocal NewAddresses( "0.1.2. 5", "zeroonetwofive") 0].NetworkScope = instance. NetworkUnknown 1].NetworkScope = instance. NetworkUnknown Ports([ ][]instance. HostPort{ AddressesWithPo rt(server1, 123), AddressesWithPo rt(server2, 124), AddressesWithPo rt(server3, 125), "0.1.2. 3:123", "0.1.2.5:125"})
+ "launchpad.
"launchpad.
"launchpad.
"launchpad.
@@ -430,3 +431,36 @@
conf.
c.Assert(
}
+
+func (*suite) TestSetAPIHostP
+ conf, err := agent.NewAgentC
+ c.Assert(err, gc.IsNil)
+
+ addrs, err := conf.APIAddresses()
+ c.Assert(err, gc.IsNil)
+ c.Assert(addrs, gc.DeepEquals, attributeParams
+
+ // The first cloud-local address for each server is used,
+ // else if there are none then the first public- or unknown-
+ // scope address.
+ //
+ // If a server has only machine-local addresses, or none
+ // at all, then it will be excluded.
+ server1 := instance.
+ server1[
+ server1[
+ server1[
+ server2 := instance.
+ server2[
+ server3 := instance.
+ server3[
+ server3[
+ conf.SetAPIHost
+ instance.
+ instance.
+ instance.
+ })
+ addrs, err = conf.APIAddresses()
+ c.Assert(err, gc.IsNil)
+ c.Assert(addrs, gc.DeepEquals, []string{
+}