Merge lp:~julian-edwards/gwacl/network-configuration into lp:gwacl

Proposed by Julian Edwards on 2013-07-09
Status: Merged
Approved by: Gavin Panella on 2013-07-09
Approved revision: 173
Merged at revision: 169
Proposed branch: lp:~julian-edwards/gwacl/network-configuration
Merge into: lp:gwacl
Diff against target: 197 lines (+176/-0)
2 files modified
xmlobjects.go (+70/-0)
xmlobjects_test.go (+106/-0)
To merge this branch: bzr merge lp:~julian-edwards/gwacl/network-configuration
Reviewer Review Type Date Requested Status
Gavin Panella 2013-07-09 Approve on 2013-07-09
Review via email: mp+173647@code.launchpad.net

Commit message

Add the SetNetworkConfiguration request xml

Description of the change

Add the SetNetworkConfiguration request xml.

I learned several things while getting bogged down for hours in this branch:

1. You can't put ",attr" in an xml chain like this `xml:"node>subnode,attr"` it just gets silently ignored and becomes an attr of the containing struct's node name.
2. Go will panic in its marshaller if you try and define multiple attrs on a node using an array
3. Because of (1) you need to write stupidly complex deep structs if a low-level node needs an attr
4. I need more coffee to deal with this crap
5. xml parsing in Go is utterly hideous
6. The Equals checker could do with diff output for large strings; it feels like going back to huge failing doctests
7. Kill me now.

To post a comment you must log in.
Julian Edwards (julian-edwards) wrote :

Oh one more thing I learned:

It won't marshal an empty value to <node/>, instead it always writes <node></node> so I had to take the liberty of amending the template from the Azure documentation.

Gavin Panella (allenap) wrote :

The hoops that we have to jump through keep us fit. And break our knees.

review: Approve
Julian Edwards (julian-edwards) wrote :

On 10/07/13 00:19, Gavin Panella wrote:
> The hoops that we have to jump through keep us fit. And break our knees.

My knees feel like they ran a marathon.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'xmlobjects.go'
2--- xmlobjects.go 2013-07-09 03:14:44 +0000
3+++ xmlobjects.go 2013-07-09 05:37:35 +0000
4@@ -561,6 +561,76 @@
5 }
6
7 //
8+// SetNetworkConfiguration request bits
9+//
10+
11+type VirtualNetDnsServer struct {
12+ XMLName string `xml:"DnsServer"`
13+ Name string `xml:"name,attr"`
14+ IPAddress string `xml:"IPAddress,attr"`
15+}
16+
17+type LocalNetworkSite struct {
18+ XMLName string `xml:"LocalNetworkSite"`
19+ Name string `xml:"name,attr"`
20+ AddressSpacePrefixes []string `xml:"AddressSpace>AddressPrefix"`
21+ VPNGatewayAddress string `xml:"VPNGatewayAddress"`
22+}
23+
24+type Subnet struct {
25+ XMLName string `xml:"Subnet"`
26+ Name string `xml:"name,attr"`
27+ AddressPrefix string `xml:"AddressPrefix"`
28+}
29+
30+type LocalNetworkSiteRefConnection struct {
31+ XMLName string `xml:"Connection"`
32+ Type string `xml:"type,attr"`
33+}
34+
35+type LocalNetworkSiteRef struct {
36+ XMLName string `xml:"LocalNetworkSiteRef"`
37+ Name string `xml:"name,attr"`
38+ Connection LocalNetworkSiteRefConnection `xml:"Connection"`
39+}
40+
41+type Gateway struct {
42+ XMLName string `xml:"Gateway"`
43+ Profile string `xml:"profile,attr"`
44+ VPNClientAddressPoolPrefixes []string `xml:"VPNClientAddressPool>AddressPrefix"`
45+ LocalNetworkSiteRef LocalNetworkSiteRef `xml:"ConnectionsToLocalNetwork>LocalNetworkSiteRef"`
46+}
47+
48+type DnsServerRef struct {
49+ XMLName string `xml:"DnsServerRef"`
50+ Name string `xml:"name,attr"`
51+}
52+
53+type VirtualNetworkSite struct {
54+ XMLName string `xml:"VirtualNetworkSite"`
55+ Name string `xml:"name,attr"`
56+ AffinityGroup string `xml:"AffinityGroup,attr"`
57+ Label string `xml:"Label"`
58+ AddressSpacePrefixes []string `xml:"AddressSpace>AddressPrefix"`
59+ Subnets *[]Subnet `xml:"Subnets>Subnet",omitempty`
60+ DnsServersRef *[]DnsServerRef `xml:"DnsServersRef>DnsServerRef",omitempty`
61+ Gateway Gateway `xml:"Gateway"`
62+}
63+
64+type SetNetworkConfiguration struct {
65+ XMLName xml.Name `xml:"NetworkConfiguration"`
66+ XMLNS string `xml:"xmlns,attr"`
67+ XMLNS_XSI string `xml:"xmlns:xsi,attr"`
68+ DNS *[]VirtualNetDnsServer `xml:"VirtualNetworkConfiguration>Dns>DnsServers>DnsServer",omitempty`
69+ LocalNetworkSites *[]LocalNetworkSite `xml:"VirtualNetworkConfiguration>LocalNetworkSites>LocalNetworkSite",omitempty`
70+ VirtualNetworkSites *[]VirtualNetworkSite `xml:"VirtualNetworkConfiguration>VirtualNetworkSites>VirtualNetworkSite",omitempty`
71+}
72+
73+func (s *SetNetworkConfiguration) Serialize() (string, error) {
74+ return toxml(s)
75+}
76+
77+//
78 // Storage Services bits
79 //
80
81
82=== modified file 'xmlobjects_test.go'
83--- xmlobjects_test.go 2013-07-04 07:23:34 +0000
84+++ xmlobjects_test.go 2013-07-09 05:37:35 +0000
85@@ -258,6 +258,112 @@
86 c.Assert(observed, DeepEquals, expected)
87 }
88
89+func (suite *xmlSuite) TestSetNetworkConfiguration(c *C) {
90+ // Template from
91+ // http://msdn.microsoft.com/en-us/library/windowsazure/jj157181.aspx
92+ expected := dedent.Dedent(`
93+ <NetworkConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
94+ <VirtualNetworkConfiguration>
95+ <Dns>
96+ <DnsServers>
97+ <DnsServer name="dns-server-name" IPAddress="IPV4-address-of-the-server"></DnsServer>
98+ </DnsServers>
99+ </Dns>
100+ <LocalNetworkSites>
101+ <LocalNetworkSite name="local-site-name">
102+ <AddressSpace>
103+ <AddressPrefix>CIDR-identifier</AddressPrefix>
104+ </AddressSpace>
105+ <VPNGatewayAddress>IPV4-address-of-the-vpn-gateway</VPNGatewayAddress>
106+ </LocalNetworkSite>
107+ </LocalNetworkSites>
108+ <VirtualNetworkSites>
109+ <VirtualNetworkSite name="virtual-network-name" AffinityGroup="affinity-group-name">
110+ <Label>label-for-the-site</Label>
111+ <AddressSpace>
112+ <AddressPrefix>CIDR-identifier</AddressPrefix>
113+ </AddressSpace>
114+ <Subnets>
115+ <Subnet name="subnet-name">
116+ <AddressPrefix>CIDR-identifier</AddressPrefix>
117+ </Subnet>
118+ </Subnets>
119+ <DnsServersRef>
120+ <DnsServerRef name="primary-DNS-name"></DnsServerRef>
121+ </DnsServersRef>
122+ <Gateway profile="Small">
123+ <VPNClientAddressPool>
124+ <AddressPrefix>CIDR-identifier</AddressPrefix>
125+ </VPNClientAddressPool>
126+ <ConnectionsToLocalNetwork>
127+ <LocalNetworkSiteRef name="local-site-name">
128+ <Connection type="connection-type"></Connection>
129+ </LocalNetworkSiteRef>
130+ </ConnectionsToLocalNetwork>
131+ </Gateway>
132+ </VirtualNetworkSite>
133+ </VirtualNetworkSites>
134+ </VirtualNetworkConfiguration>
135+ </NetworkConfiguration>`)
136+
137+ input := SetNetworkConfiguration{
138+ XMLNS: "http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration",
139+ XMLNS_XSI: "http://www.w3.org/2001/XMLSchema-instance",
140+ DNS: &[]VirtualNetDnsServer{
141+ {
142+ Name: "dns-server-name",
143+ IPAddress: "IPV4-address-of-the-server",
144+ },
145+ },
146+ LocalNetworkSites: &[]LocalNetworkSite{
147+ {
148+ Name: "local-site-name",
149+ AddressSpacePrefixes: []string{
150+ "CIDR-identifier",
151+ },
152+ VPNGatewayAddress: "IPV4-address-of-the-vpn-gateway",
153+ },
154+ },
155+ VirtualNetworkSites: &[]VirtualNetworkSite{
156+ {
157+ Name: "virtual-network-name",
158+ AffinityGroup: "affinity-group-name",
159+ Label: "label-for-the-site",
160+ AddressSpacePrefixes: []string{
161+ "CIDR-identifier",
162+ },
163+ Subnets: &[]Subnet{
164+ {
165+ Name: "subnet-name",
166+ AddressPrefix: "CIDR-identifier",
167+ },
168+ },
169+ DnsServersRef: &[]DnsServerRef{
170+ {
171+ Name: "primary-DNS-name",
172+ },
173+ },
174+ Gateway: Gateway{
175+ Profile: "Small",
176+ VPNClientAddressPoolPrefixes: []string{
177+ "CIDR-identifier",
178+ },
179+ LocalNetworkSiteRef: LocalNetworkSiteRef{
180+ Name: "local-site-name",
181+ Connection: LocalNetworkSiteRefConnection{
182+ Type: "connection-type",
183+ },
184+ },
185+ },
186+ },
187+ },
188+ }
189+
190+ observed, err := input.Serialize()
191+ c.Assert(err, IsNil)
192+ c.Assert(observed, Equals, expected)
193+}
194+
195 func (suite *xmlSuite) TestDeployment(c *C) {
196 deployment := makeDeployment()
197 dns := deployment.DNS[0]

Subscribers

People subscribed via source and target branches

to all changes: