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
=== modified file 'management_base.go'
--- management_base.go 2014-12-02 00:36:45 +0000
+++ management_base.go 2014-12-03 07:39:03 +0000
@@ -6,10 +6,11 @@
6import (6import (
7 "encoding/xml"7 "encoding/xml"
8 "fmt"8 "fmt"
9 "launchpad.net/gwacl/fork/tls"
10 "net/http"9 "net/http"
11 "strings"10 "strings"
12 "time"11 "time"
12
13 "launchpad.net/gwacl/fork/tls"
13)14)
1415
15// Note: each API call is required to include a version string in the request header.16// Note: each API call is required to include a version string in the request header.
@@ -151,6 +152,20 @@
151 return nil152 return nil
152}153}
153154
155// ListLocations lists the Azure data centre locations, and details
156// about each location (e.g. role sizes available).
157func (api *ManagementAPI) ListLocations() ([]Location, error) {
158 var locations struct {
159 Locations []Location `xml:"Location"`
160 }
161 response, err := api.session.get("locations", "2014-05-01")
162 if err != nil {
163 return nil, err
164 }
165 err = xml.Unmarshal(response.Body, &locations)
166 return locations.Locations, err
167}
168
154// ListOSImages retrieves the list of available operating system disk images169// ListOSImages retrieves the list of available operating system disk images
155// from the Azure management API.170// from the Azure management API.
156// Images are returned in the order in which Azure lists them.171// Images are returned in the order in which Azure lists them.
157172
=== modified file 'management_base_test.go'
--- management_base_test.go 2014-12-02 00:36:45 +0000
+++ management_base_test.go 2014-12-03 07:39:03 +0000
@@ -1388,3 +1388,59 @@
1388 c.Assert(recordedRequests, HasLen, 1)1388 c.Assert(recordedRequests, HasLen, 1)
1389 assertSetNetworkConfigurationRequest(c, api, requestPayload, recordedRequests[0])1389 assertSetNetworkConfigurationRequest(c, api, requestPayload, recordedRequests[0])
1390}1390}
1391
1392func (suite *managementBaseAPISuite) TestListLocationsRequestsListing(c *C) {
1393 api := makeAPI(c)
1394 rigFixedResponseDispatcher(&x509Response{StatusCode: http.StatusOK, Body: []byte("<Locations></Locations>")})
1395 requests := make([]*X509Request, 0)
1396 rigRecordingDispatcher(&requests)
1397
1398 _, err := api.ListLocations()
1399 c.Assert(err, IsNil)
1400
1401 c.Assert(len(requests), Equals, 1)
1402 c.Check(requests[0].URL, Equals, api.session.composeURL("locations"))
1403}
1404
1405func (suite *managementBaseAPISuite) TestListLocationsReturnsLocations(c *C) {
1406 expectedLocations := []Location{{
1407 Name: "West US",
1408 }, {
1409 Name: "East US",
1410 ComputeCapabilities: &ComputeCapabilities{
1411 VirtualMachineRoleSizes: []string{"ExtraSmall", "ExtraLarge"},
1412 WebWorkerRoleSizes: []string{"Small", "Large"},
1413 },
1414 }}
1415 body := `
1416<Locations>
1417 <Location>
1418 <Name>West US</Name>
1419 </Location>
1420 <Location>
1421 <Name>East US</Name>
1422 <ComputeCapabilities>
1423 <VirtualMachinesRoleSizes>
1424 <RoleSize>ExtraSmall</RoleSize>
1425 <RoleSize>ExtraLarge</RoleSize>
1426 </VirtualMachinesRoleSizes>
1427 <WebWorkerRoleSizes>
1428 <RoleSize>Small</RoleSize>
1429 <RoleSize>Large</RoleSize>
1430 </WebWorkerRoleSizes>
1431 </ComputeCapabilities>
1432 </Location>
1433</Locations>
1434`
1435 api := makeAPI(c)
1436 rigFixedResponseDispatcher(&x509Response{
1437 StatusCode: http.StatusOK,
1438 Body: []byte(body),
1439 })
1440
1441 locations, err := api.ListLocations()
1442 c.Assert(err, IsNil)
1443
1444 c.Assert(len(locations), Equals, 2)
1445 c.Assert(locations, DeepEquals, expectedLocations)
1446}
13911447
=== modified file 'xmlobjects.go'
--- xmlobjects.go 2014-12-02 00:36:45 +0000
+++ xmlobjects.go 2014-12-03 07:39:03 +0000
@@ -251,6 +251,23 @@
251}251}
252252
253//253//
254// Location
255//
256
257type Location struct {
258 Name string `xml:"Name"`
259 DisplayName string `xml:"DisplayName"`
260 AvailableServices []string `xml:"AvailableServices>AvailableService,omitempty"`
261 ComputeCapabilities *ComputeCapabilities `xml:"ComputeCapabilities,omitempty"`
262}
263
264type ComputeCapabilities struct {
265 // The tag name is plural VirtualMachines, contrary to the online documentation.
266 VirtualMachineRoleSizes []string `xml:"VirtualMachinesRoleSizes>RoleSize"`
267 WebWorkerRoleSizes []string `xml:"WebWorkerRoleSizes>RoleSize"`
268}
269
270//
254// DataVirtualHardDisk271// DataVirtualHardDisk
255//272//
256273

Subscribers

People subscribed via source and target branches

to all changes: