Merge lp:~axwalk/gwacl/listlocations into lp:gwacl

Proposed by Andrew Wilkins on 2014-12-03
Status: Merged
Approved by: Ian Booth on 2014-12-03
Approved revision: 242
Merged at revision: 242
Proposed branch: lp:~axwalk/gwacl/listlocations
Merge into: lp:gwacl
Diff against target: 128 lines (+89/-1)
3 files modified
management_base.go (+16/-1)
management_base_test.go (+56/-0)
xmlobjects.go (+17/-0)
To merge this branch: bzr merge lp:~axwalk/gwacl/listlocations
Reviewer Review Type Date Requested Status
Ian Booth 2014-12-03 Approve on 2014-12-03
Review via email: mp+243495@code.launchpad.net

Commit message

Add ListLocations API

ListLocations returns role sizes available in
each data centre location, as well as other
information about the locations.

Description of the change

Add ListLocations API

ListLocations returns role sizes available in
each data centre location, as well as other
information about the locations.

To post a comment you must log in.
Ian Booth (wallyworld) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'management_base.go'
2--- management_base.go 2014-12-02 00:36:45 +0000
3+++ management_base.go 2014-12-03 07:39:03 +0000
4@@ -6,10 +6,11 @@
5 import (
6 "encoding/xml"
7 "fmt"
8- "launchpad.net/gwacl/fork/tls"
9 "net/http"
10 "strings"
11 "time"
12+
13+ "launchpad.net/gwacl/fork/tls"
14 )
15
16 // Note: each API call is required to include a version string in the request header.
17@@ -151,6 +152,20 @@
18 return nil
19 }
20
21+// ListLocations lists the Azure data centre locations, and details
22+// about each location (e.g. role sizes available).
23+func (api *ManagementAPI) ListLocations() ([]Location, error) {
24+ var locations struct {
25+ Locations []Location `xml:"Location"`
26+ }
27+ response, err := api.session.get("locations", "2014-05-01")
28+ if err != nil {
29+ return nil, err
30+ }
31+ err = xml.Unmarshal(response.Body, &locations)
32+ return locations.Locations, err
33+}
34+
35 // ListOSImages retrieves the list of available operating system disk images
36 // from the Azure management API.
37 // Images are returned in the order in which Azure lists them.
38
39=== modified file 'management_base_test.go'
40--- management_base_test.go 2014-12-02 00:36:45 +0000
41+++ management_base_test.go 2014-12-03 07:39:03 +0000
42@@ -1388,3 +1388,59 @@
43 c.Assert(recordedRequests, HasLen, 1)
44 assertSetNetworkConfigurationRequest(c, api, requestPayload, recordedRequests[0])
45 }
46+
47+func (suite *managementBaseAPISuite) TestListLocationsRequestsListing(c *C) {
48+ api := makeAPI(c)
49+ rigFixedResponseDispatcher(&x509Response{StatusCode: http.StatusOK, Body: []byte("<Locations></Locations>")})
50+ requests := make([]*X509Request, 0)
51+ rigRecordingDispatcher(&requests)
52+
53+ _, err := api.ListLocations()
54+ c.Assert(err, IsNil)
55+
56+ c.Assert(len(requests), Equals, 1)
57+ c.Check(requests[0].URL, Equals, api.session.composeURL("locations"))
58+}
59+
60+func (suite *managementBaseAPISuite) TestListLocationsReturnsLocations(c *C) {
61+ expectedLocations := []Location{{
62+ Name: "West US",
63+ }, {
64+ Name: "East US",
65+ ComputeCapabilities: &ComputeCapabilities{
66+ VirtualMachineRoleSizes: []string{"ExtraSmall", "ExtraLarge"},
67+ WebWorkerRoleSizes: []string{"Small", "Large"},
68+ },
69+ }}
70+ body := `
71+<Locations>
72+ <Location>
73+ <Name>West US</Name>
74+ </Location>
75+ <Location>
76+ <Name>East US</Name>
77+ <ComputeCapabilities>
78+ <VirtualMachinesRoleSizes>
79+ <RoleSize>ExtraSmall</RoleSize>
80+ <RoleSize>ExtraLarge</RoleSize>
81+ </VirtualMachinesRoleSizes>
82+ <WebWorkerRoleSizes>
83+ <RoleSize>Small</RoleSize>
84+ <RoleSize>Large</RoleSize>
85+ </WebWorkerRoleSizes>
86+ </ComputeCapabilities>
87+ </Location>
88+</Locations>
89+`
90+ api := makeAPI(c)
91+ rigFixedResponseDispatcher(&x509Response{
92+ StatusCode: http.StatusOK,
93+ Body: []byte(body),
94+ })
95+
96+ locations, err := api.ListLocations()
97+ c.Assert(err, IsNil)
98+
99+ c.Assert(len(locations), Equals, 2)
100+ c.Assert(locations, DeepEquals, expectedLocations)
101+}
102
103=== modified file 'xmlobjects.go'
104--- xmlobjects.go 2014-12-02 00:36:45 +0000
105+++ xmlobjects.go 2014-12-03 07:39:03 +0000
106@@ -251,6 +251,23 @@
107 }
108
109 //
110+// Location
111+//
112+
113+type Location struct {
114+ Name string `xml:"Name"`
115+ DisplayName string `xml:"DisplayName"`
116+ AvailableServices []string `xml:"AvailableServices>AvailableService,omitempty"`
117+ ComputeCapabilities *ComputeCapabilities `xml:"ComputeCapabilities,omitempty"`
118+}
119+
120+type ComputeCapabilities struct {
121+ // The tag name is plural VirtualMachines, contrary to the online documentation.
122+ VirtualMachineRoleSizes []string `xml:"VirtualMachinesRoleSizes>RoleSize"`
123+ WebWorkerRoleSizes []string `xml:"WebWorkerRoleSizes>RoleSize"`
124+}
125+
126+//
127 // DataVirtualHardDisk
128 //
129

Subscribers

People subscribed via source and target branches

to all changes: