Merge lp:~gz/juju-core/add_state_address into lp:~go-bot/juju-core/trunk

Proposed by Martin Packman
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
Merged at revision: 1488
Proposed branch: lp:~gz/juju-core/add_state_address
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 68 lines (+59/-0)
2 files modified
state/address.go (+36/-0)
state/address_test.go (+23/-0)
To merge this branch: bzr merge lp:~gz/juju-core/add_state_address
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+174823@code.launchpad.net

Commit message

Add state/address.go for machine location data

Add data structure for describing machine addresses. This is the
first step towards deprecating PublicAddress and PrivateAddress
in unitDoc and storing a list of addresses in machineDoc instead.

The structure uses a single field that may contain either a hostname
or an address. The plan is for a New constructor to correctly flag
the type of location.

https://codereview.appspot.com/11284044/

R=fwereade, jameinel

Description of the change

Add state/address.go for machine location data

Add data structure for describing machine addresses. This is the
first step towards deprecating PublicAddress and PrivateAddress
in unitDoc and storing a list of addresses in machineDoc instead.

The structure uses a single field that may contain either a hostname
or an address. The plan is for a New constructor to correctly flag
the type of location.

Suggestions on naming of things welcome.

https://codereview.appspot.com/11284044/

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Reviewers: mp+174823_code.launchpad.net,

Message:
Please take a look.

Description:
Add state/address.go for machine location data

Add data structure for describing machine addresses. This is the
first step towards deprecating PublicAddress and PrivateAddress
in unitDoc and storing a list of addresses in machineDoc instead.

The structure uses a single field that may contain either a hostname
or an address. The plan is for a New constructor to correctly flag
the type of location.

Suggestions on naming of things welcome.

https://code.launchpad.net/~gz/juju-core/add_state_address/+merge/174823

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/11284044/

Affected files:
   A [revision details]
   A state/address.go

Index: [revision details]
=== 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-20130715152550-v4p859yzf8o5a3ca
+New revision: <email address hidden>

Index: state/address.go
=== added file 'state/address.go'
--- state/address.go 1970-01-01 00:00:00 +0000
+++ state/address.go 2013-07-15 16:45:38 +0000
@@ -0,0 +1,36 @@
+// Copyright 2013 Canonical Ltd.
+// Licensed under the AGPLv3, see LICENCE file for details.
+
+package state
+
+// AddressType represents the possible ways of specifying a machine
location by
+// either a hostname resolvable by dns lookup, or ipv4 or ipv6 address.
+type AddressType string
+
+const (
+ HostName AddressType = "hostname"
+ Ipv4Address AddressType = "ipv4"
+ Ipv6Address AddressType = "ipv6"
+)
+
+// NetworkScope denotes the context a location may apply to. If a name or
+// address can be reached from the wider internet, it is considered
public. A
+// private network address is either specific to the cloud or cloud subnet
a
+// machine belongs to, or to the machine itself for containers.
+type NetworkScope string
+
+const (
+ NetworkUnknown NetworkScope = ""
+ NetworkPublic NetworkScope = "public"
+ NetworkCloudLocal NetworkScope = "local-cloud"
+ NetworkMachineLocal NetworkScope = "local-machine"
+)
+
+// Address represents the location of a machine, including metadata about
what
+// kind of location the address describes.
+type Address struct {
+ Name string
+ Type AddressType
+ NetworkName string `bson:",omitempty"`
+ NetworkScope string `bson:",omitempty"`
+}

Revision history for this message
William Reade (fwereade) wrote :

Looks sane to me. If this is intended for merging, LGTM :).

https://codereview.appspot.com/11284044/diff/1/state/address.go
File state/address.go (right):

https://codereview.appspot.com/11284044/diff/1/state/address.go#newcode32
state/address.go:32: Name string
Wondering if this is more "Value" than "Name"?

https://codereview.appspot.com/11284044/

Revision history for this message
John A Meinel (jameinel) wrote :

How is this linked with the other data structures?

Is it intended that machine will grow an array of Address objects?

I want us to be aware of what happened with adding the container field
(be ready to handle fields that don't exist, as well as ones that have
empty content).

Otherwise LGTM.

I like the Address.Value change proposed by William.

https://codereview.appspot.com/11284044/

Revision history for this message
Tim Penhey (thumper) wrote :

https://codereview.appspot.com/11284044/diff/1/state/address.go
File state/address.go (right):

https://codereview.appspot.com/11284044/diff/1/state/address.go#newcode25
state/address.go:25: NetworkCloudLocal NetworkScope = "local-cloud"
So a "local-cloud" address is what we currently call a private address?

https://codereview.appspot.com/11284044/diff/1/state/address.go#newcode32
state/address.go:32: Name string
On 2013/07/15 21:50:43, fwereade wrote:
> Wondering if this is more "Value" than "Name"?

I agree here, "Name" seems a bit weird for an IPv4 address.
Seems ok with a hostname, but should really make sense for all.

https://codereview.appspot.com/11284044/

Revision history for this message
Martin Packman (gz) wrote :

Please take a look.

https://codereview.appspot.com/11284044/diff/1/state/address.go
File state/address.go (right):

https://codereview.appspot.com/11284044/diff/1/state/address.go#newcode25
state/address.go:25: NetworkCloudLocal NetworkScope = "local-cloud"
On 2013/07/18 02:38:57, thumper wrote:
> So a "local-cloud" address is what we currently call a private
address?

Yes. Thee public interfaces will still be in terms of "private address"
I just wanted to keep the distinction between a 10. address routed
across a cloud region and a 10. address set up by lxc say.

https://codereview.appspot.com/11284044/diff/1/state/address.go#newcode32
state/address.go:32: Name string
On 2013/07/15 21:50:43, fwereade wrote:
> Wondering if this is more "Value" than "Name"?

Changed.

https://codereview.appspot.com/11284044/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'state/address.go'
2--- state/address.go 1970-01-01 00:00:00 +0000
3+++ state/address.go 2013-07-18 12:40:32 +0000
4@@ -0,0 +1,36 @@
5+// Copyright 2013 Canonical Ltd.
6+// Licensed under the AGPLv3, see LICENCE file for details.
7+
8+package state
9+
10+// AddressType represents the possible ways of specifying a machine location by
11+// either a hostname resolvable by dns lookup, or ipv4 or ipv6 address.
12+type AddressType string
13+
14+const (
15+ HostName AddressType = "hostname"
16+ Ipv4Address AddressType = "ipv4"
17+ Ipv6Address AddressType = "ipv6"
18+)
19+
20+// NetworkScope denotes the context a location may apply to. If a name or
21+// address can be reached from the wider internet, it is considered public. A
22+// private network address is either specific to the cloud or cloud subnet a
23+// machine belongs to, or to the machine itself for containers.
24+type NetworkScope string
25+
26+const (
27+ NetworkUnknown NetworkScope = ""
28+ NetworkPublic NetworkScope = "public"
29+ NetworkCloudLocal NetworkScope = "local-cloud"
30+ NetworkMachineLocal NetworkScope = "local-machine"
31+)
32+
33+// Address represents the location of a machine, including metadata about what
34+// kind of location the address describes.
35+type Address struct {
36+ Value string
37+ Type AddressType
38+ NetworkName string `bson:",omitempty"`
39+ NetworkScope `bson:",omitempty"`
40+}
41
42=== added file 'state/address_test.go'
43--- state/address_test.go 1970-01-01 00:00:00 +0000
44+++ state/address_test.go 2013-07-18 12:40:32 +0000
45@@ -0,0 +1,23 @@
46+// Copyright 2013 Canonical Ltd.
47+// Licensed under the AGPLv3, see LICENCE file for details.
48+
49+package state_test
50+
51+import (
52+ . "launchpad.net/gocheck"
53+
54+ "launchpad.net/juju-core/state"
55+)
56+
57+type AddressSuite struct{}
58+
59+var _ = Suite(&AddressSuite{})
60+
61+func (s *AddressSuite) TestMakeAddress(c *C) {
62+ addr := state.Address{"0.0.0.0", state.Ipv4Address, "net",
63+ state.NetworkUnknown}
64+ c.Check(addr.Value, Equals, "0.0.0.0")
65+ c.Check(addr.Type, Equals, state.Ipv4Address)
66+ c.Check(addr.NetworkName, Equals, "net")
67+ c.Check(addr.NetworkScope, Equals, state.NetworkUnknown)
68+}

Subscribers

People subscribed via source and target branches

to status/vote changes: