Merge lp:~axwalk/gwacl/gwacl-disks into lp:gwacl

Proposed by Andrew Wilkins
Status: Merged
Approved by: Ian Booth
Approved revision: 245
Merged at revision: 245
Proposed branch: lp:~axwalk/gwacl/gwacl-disks
Merge into: lp:gwacl
Diff against target: 279 lines (+186/-15)
4 files modified
management_base.go (+45/-0)
management_base_test.go (+96/-0)
xmlobjects.go (+35/-5)
xmlobjects_test.go (+10/-10)
To merge this branch: bzr merge lp:~axwalk/gwacl/gwacl-disks
Reviewer Review Type Date Requested Status
Ian Booth Approve
Review via email: mp+267477@code.launchpad.net

Description of the change

Add "AddDataDisks" and "ListDisks" APIs

These APIs are needed for adding data disks to
VM roles, and for listing disks in the account.

To post a comment you must log in.
Revision history for this message
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 2015-07-28 09:58:11 +0000
3+++ management_base.go 2015-08-10 08:06:54 +0000
4@@ -7,6 +7,7 @@
5 "encoding/xml"
6 "fmt"
7 "net/http"
8+ "path"
9 "strings"
10 "time"
11
12@@ -435,6 +436,50 @@
13 return api.blockUntilCompleted(response)
14 }
15
16+type AddDataDiskRequest struct {
17+ ServiceName string
18+ DeploymentName string
19+ RoleName string
20+ DataVirtualHardDisk DataVirtualHardDisk
21+}
22+
23+// AddDataDisk requests the addition of a data disk to a VM role.
24+// See https://msdn.microsoft.com/en-us/library/azure/jj157199.aspx
25+func (api *ManagementAPI) AddDataDisk(req *AddDataDiskRequest) error {
26+ url := path.Join(
27+ "services", "hostedservices", req.ServiceName,
28+ "deployments", req.DeploymentName,
29+ "roles", req.RoleName,
30+ "DataDisks",
31+ )
32+ disk := req.DataVirtualHardDisk
33+ disk.XMLNS = XMLNS
34+ disk.XMLNS_I = XMLNS_I
35+ body, err := marshalXML(&disk)
36+ if err != nil {
37+ return err
38+ }
39+ response, err := api.session.post(url, baseAPIVersion, []byte(body), "application/xml")
40+ if err != nil {
41+ return err
42+ }
43+ return api.blockUntilCompleted(response)
44+}
45+
46+// ListDisks requests a list of disks in the account's image repository.
47+// See https://msdn.microsoft.com/en-us/library/azure/jj157176.aspx
48+func (api *ManagementAPI) ListDisks() ([]Disk, error) {
49+ var disks struct {
50+ Disks []Disk `xml:"Disk"`
51+ }
52+ response, err := api.session.get("services/disks", baseAPIVersion)
53+ if err != nil {
54+ return nil, err
55+ }
56+ err = xml.Unmarshal(response.Body, &disks)
57+ return disks.Disks, err
58+}
59+
60 // Perform an operation on the specified role (as defined by serviceName,
61 // deploymentName and roleName) This is an asynchronous operation on Azure, but
62 // the call blocks until the operation is completed.
63
64=== modified file 'management_base_test.go'
65--- management_base_test.go 2015-07-28 13:09:12 +0000
66+++ management_base_test.go 2015-08-10 08:06:54 +0000
67@@ -968,6 +968,102 @@
68 c.Check(values["comp"], DeepEquals, []string{"media"})
69 }
70
71+func (suite *managementBaseAPISuite) TestAddDataDisk(c *C) {
72+ api := makeAPI(c)
73+ serviceName := "serviceName"
74+ deploymentName := "deploymentName"
75+ roleName := "roleName"
76+
77+ recordedRequests := setUpDispatcher("operationID")
78+ err := api.AddDataDisk(&AddDataDiskRequest{
79+ ServiceName: serviceName,
80+ DeploymentName: deploymentName,
81+ RoleName: roleName,
82+ DataVirtualHardDisk: DataVirtualHardDisk{
83+ DiskLabel: "abcdef",
84+ LUN: 31,
85+ LogicalDiskSizeInGB: 42,
86+ MediaLink: "http://example.blob.core.windows.net/disks/mydisk.vhd",
87+ },
88+ })
89+ c.Assert(err, IsNil)
90+ c.Assert(*recordedRequests, HasLen, 1)
91+
92+ expectedURL := fmt.Sprintf(
93+ "%s%s/services/hostedservices/%s/deployments/%s/roles/%s/DataDisks",
94+ defaultManagement,
95+ api.session.subscriptionId,
96+ serviceName,
97+ deploymentName,
98+ roleName,
99+ )
100+
101+ expectedPayload := []byte(strings.TrimSpace(`
102+<DataVirtualHardDisk xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
103+ <DiskLabel>abcdef</DiskLabel>
104+ <Lun>31</Lun>
105+ <LogicalDiskSizeInGB>42</LogicalDiskSizeInGB>
106+ <MediaLink>http://example.blob.core.windows.net/disks/mydisk.vhd</MediaLink>
107+</DataVirtualHardDisk>
108+ `))
109+ checkOneRequest(c, recordedRequests, expectedURL, baseAPIVersion, expectedPayload, "POST")
110+}
111+
112+func (suite *managementBaseAPISuite) TestListDisks(c *C) {
113+ api := makeAPI(c)
114+
115+ fixedResponse := x509Response{
116+ StatusCode: http.StatusOK,
117+ Body: []byte(strings.TrimSpace(`
118+<Disks xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
119+ <Disk>
120+ <AffinityGroup>name-of-affinity-group</AffinityGroup>
121+ <AttachedTo>
122+ <HostedServiceName>name-of-cloud-service</HostedServiceName>
123+ <DeploymentName>name-of-deployment</DeploymentName>
124+ <RoleName>name-of-virtual-machine</RoleName>
125+ </AttachedTo>
126+ <OS>operating-system-type</OS>
127+ <Location>geo-location-of-disk</Location>
128+ <LogicalSizeInGB>123</LogicalSizeInGB>
129+ <MediaLink>uri-of-vhd</MediaLink>
130+ <Name>name-of-disk</Name>
131+ <SourceImageName>name-of-source-image</SourceImageName>
132+ <CreatedTime>creation-time-of-disk</CreatedTime>
133+ <IOType>IO-Type</IOType>
134+ </Disk>
135+</Disks>
136+`)),
137+ }
138+ rigFixedResponseDispatcher(&fixedResponse)
139+ recordedRequests := make([]*X509Request, 0)
140+ rigRecordingDispatcher(&recordedRequests)
141+
142+ disks, err := api.ListDisks()
143+ c.Assert(err, IsNil)
144+ c.Assert(disks, HasLen, 1)
145+
146+ expectedURL := fmt.Sprintf("%s%s/services/disks", defaultManagement, api.session.subscriptionId)
147+ checkOneRequest(c, &recordedRequests, expectedURL, baseAPIVersion, nil, "GET")
148+
149+ c.Assert(disks[0], DeepEquals, Disk{
150+ AffinityGroup: "name-of-affinity-group",
151+ AttachedTo: &DiskAttachment{
152+ HostedServiceName: "name-of-cloud-service",
153+ DeploymentName: "name-of-deployment",
154+ RoleName: "name-of-virtual-machine",
155+ },
156+ OS: "operating-system-type",
157+ Location: "geo-location-of-disk",
158+ LogicalSizeInGB: 123,
159+ MediaLink: "uri-of-vhd",
160+ Name: "name-of-disk",
161+ SourceImageName: "name-of-source-image",
162+ CreatedTime: "creation-time-of-disk",
163+ IOType: "IO-Type",
164+ })
165+}
166+
167 func (suite *managementBaseAPISuite) TestPerformNodeOperation(c *C) {
168 api := makeAPI(c)
169 recordedRequests := setUpDispatcher("operationID")
170
171=== modified file 'xmlobjects.go'
172--- xmlobjects.go 2015-07-28 13:09:12 +0000
173+++ xmlobjects.go 2015-08-10 08:06:54 +0000
174@@ -329,11 +329,41 @@
175 //
176
177 type DataVirtualHardDisk struct {
178- HostCaching string `xml:"HostCaching"`
179- DiskName string `xml:"DiskName"`
180- LUN string `xml:"Lun"`
181- LogicalDiskSizeInGB string `xml:"LogicalDiskSizeInGB"`
182- MediaLink string `xml:"MediaLink"`
183+ XMLNS string `xml:"xmlns,attr,omitempty"`
184+ XMLNS_I string `xml:"xmlns:i,attr,omitempty"`
185+ HostCaching string `xml:"HostCaching,omitempty"`
186+ DiskLabel string `xml:"DiskLabel,omitempty"`
187+ DiskName string `xml:"DiskName,omitempty"`
188+ LUN int `xml:"Lun,omitempty"`
189+ LogicalDiskSizeInGB int `xml:"LogicalDiskSizeInGB,omitempty"`
190+ MediaLink string `xml:"MediaLink,omitempty"`
191+ SourceMediaLink string `xml:"SourceMediaLink,omitempty"`
192+}
193+
194+//
195+// Disk
196+//
197+
198+type Disk struct {
199+ XMLNS string `xml:"xmlns,attr,omitempty"`
200+ XMLNS_I string `xml:"xmlns:i,attr,omitempty"`
201+ AffinityGroup string `xml:"AffinityGroup,omitempty"`
202+ AttachedTo *DiskAttachment `xml:"AttachedTo,omitempty"`
203+ OS string `xml:"OS"`
204+ Location string `xml:"Location,omitempty"`
205+ LogicalSizeInGB int `xml:"LogicalSizeInGB,omitempty"`
206+ MediaLink string `xml:"MediaLink"`
207+ Label string `xml:"Label,omitempty"`
208+ Name string `xml:"Name"`
209+ SourceImageName string `xml:"SourceImageName,omitempty"`
210+ CreatedTime string `xml:"CreatedTime,omitempty"`
211+ IOType string `xml:"IOType,omitempty"`
212+}
213+
214+type DiskAttachment struct {
215+ HostedServiceName string `xml:"HostedServiceName"`
216+ DeploymentName string `xml:"DeploymentName"`
217+ RoleName string `xml:"RoleName"`
218 }
219
220 //
221
222=== modified file 'xmlobjects_test.go'
223--- xmlobjects_test.go 2015-07-28 13:09:12 +0000
224+++ xmlobjects_test.go 2015-08-10 08:06:54 +0000
225@@ -348,8 +348,8 @@
226 <DataVirtualHardDisk>
227 <HostCaching>host-caching-mode-of-data-disk</HostCaching>
228 <DiskName>new-or-existing-disk-name</DiskName>
229- <Lun>logical-unit-number-of-data-disk</Lun>
230- <LogicalDiskSizeInGB>size-of-data-disk</LogicalDiskSizeInGB>
231+ <Lun>31</Lun>
232+ <LogicalDiskSizeInGB>42</LogicalDiskSizeInGB>
233 <MediaLink>path-to-vhd</MediaLink>
234 </DataVirtualHardDisk>
235 </DataVirtualHardDisks>
236@@ -410,8 +410,8 @@
237 {
238 HostCaching: "host-caching-mode-of-data-disk",
239 DiskName: "new-or-existing-disk-name",
240- LUN: "logical-unit-number-of-data-disk",
241- LogicalDiskSizeInGB: "size-of-data-disk",
242+ LUN: 31,
243+ LogicalDiskSizeInGB: 42,
244 MediaLink: "path-to-vhd",
245 },
246 },
247@@ -478,8 +478,8 @@
248 {
249 HostCaching: "host-caching-mode-of-data-disk",
250 DiskName: "new-or-existing-disk-name",
251- LUN: "logical-unit-number-of-data-disk",
252- LogicalDiskSizeInGB: "size-of-data-disk",
253+ LUN: 31,
254+ LogicalDiskSizeInGB: 42,
255 MediaLink: "path-to-vhd",
256 },
257 },
258@@ -940,8 +940,8 @@
259 <DataVirtualHardDisk>
260 <HostCaching>host-caching-mode-of-data-disk</HostCaching>
261 <DiskName>name-of-data-disk</DiskName>
262- <Lun>logical-unit-number-of-data-disk</Lun>
263- <LogicalDiskSizeInGB>size-of-data-disk</LogicalDiskSizeInGB>
264+ <Lun>31</Lun>
265+ <LogicalDiskSizeInGB>42</LogicalDiskSizeInGB>
266 <MediaLink>path-to-vhd</MediaLink>
267 </DataVirtualHardDisk>
268 </DataVirtualHardDisks>
269@@ -1073,8 +1073,8 @@
270 {
271 HostCaching: "host-caching-mode-of-data-disk",
272 DiskName: "name-of-data-disk",
273- LUN: "logical-unit-number-of-data-disk",
274- LogicalDiskSizeInGB: "size-of-data-disk",
275+ LUN: 31,
276+ LogicalDiskSizeInGB: 42,
277 MediaLink: "path-to-vhd",
278 },
279 },

Subscribers

People subscribed via source and target branches

to all changes: