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
=== modified file 'management_base.go'
--- management_base.go 2015-07-28 09:58:11 +0000
+++ management_base.go 2015-08-10 08:06:54 +0000
@@ -7,6 +7,7 @@
7 "encoding/xml"7 "encoding/xml"
8 "fmt"8 "fmt"
9 "net/http"9 "net/http"
10 "path"
10 "strings"11 "strings"
11 "time"12 "time"
1213
@@ -435,6 +436,50 @@
435 return api.blockUntilCompleted(response)436 return api.blockUntilCompleted(response)
436}437}
437438
439type AddDataDiskRequest struct {
440 ServiceName string
441 DeploymentName string
442 RoleName string
443 DataVirtualHardDisk DataVirtualHardDisk
444}
445
446// AddDataDisk requests the addition of a data disk to a VM role.
447// See https://msdn.microsoft.com/en-us/library/azure/jj157199.aspx
448func (api *ManagementAPI) AddDataDisk(req *AddDataDiskRequest) error {
449 url := path.Join(
450 "services", "hostedservices", req.ServiceName,
451 "deployments", req.DeploymentName,
452 "roles", req.RoleName,
453 "DataDisks",
454 )
455 disk := req.DataVirtualHardDisk
456 disk.XMLNS = XMLNS
457 disk.XMLNS_I = XMLNS_I
458 body, err := marshalXML(&disk)
459 if err != nil {
460 return err
461 }
462 response, err := api.session.post(url, baseAPIVersion, []byte(body), "application/xml")
463 if err != nil {
464 return err
465 }
466 return api.blockUntilCompleted(response)
467}
468
469// ListDisks requests a list of disks in the account's image repository.
470// See https://msdn.microsoft.com/en-us/library/azure/jj157176.aspx
471func (api *ManagementAPI) ListDisks() ([]Disk, error) {
472 var disks struct {
473 Disks []Disk `xml:"Disk"`
474 }
475 response, err := api.session.get("services/disks", baseAPIVersion)
476 if err != nil {
477 return nil, err
478 }
479 err = xml.Unmarshal(response.Body, &disks)
480 return disks.Disks, err
481}
482
438// Perform an operation on the specified role (as defined by serviceName,483// Perform an operation on the specified role (as defined by serviceName,
439// deploymentName and roleName) This is an asynchronous operation on Azure, but484// deploymentName and roleName) This is an asynchronous operation on Azure, but
440// the call blocks until the operation is completed.485// the call blocks until the operation is completed.
441486
=== modified file 'management_base_test.go'
--- management_base_test.go 2015-07-28 13:09:12 +0000
+++ management_base_test.go 2015-08-10 08:06:54 +0000
@@ -968,6 +968,102 @@
968 c.Check(values["comp"], DeepEquals, []string{"media"})968 c.Check(values["comp"], DeepEquals, []string{"media"})
969}969}
970970
971func (suite *managementBaseAPISuite) TestAddDataDisk(c *C) {
972 api := makeAPI(c)
973 serviceName := "serviceName"
974 deploymentName := "deploymentName"
975 roleName := "roleName"
976
977 recordedRequests := setUpDispatcher("operationID")
978 err := api.AddDataDisk(&AddDataDiskRequest{
979 ServiceName: serviceName,
980 DeploymentName: deploymentName,
981 RoleName: roleName,
982 DataVirtualHardDisk: DataVirtualHardDisk{
983 DiskLabel: "abcdef",
984 LUN: 31,
985 LogicalDiskSizeInGB: 42,
986 MediaLink: "http://example.blob.core.windows.net/disks/mydisk.vhd",
987 },
988 })
989 c.Assert(err, IsNil)
990 c.Assert(*recordedRequests, HasLen, 1)
991
992 expectedURL := fmt.Sprintf(
993 "%s%s/services/hostedservices/%s/deployments/%s/roles/%s/DataDisks",
994 defaultManagement,
995 api.session.subscriptionId,
996 serviceName,
997 deploymentName,
998 roleName,
999 )
1000
1001 expectedPayload := []byte(strings.TrimSpace(`
1002<DataVirtualHardDisk xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
1003 <DiskLabel>abcdef</DiskLabel>
1004 <Lun>31</Lun>
1005 <LogicalDiskSizeInGB>42</LogicalDiskSizeInGB>
1006 <MediaLink>http://example.blob.core.windows.net/disks/mydisk.vhd</MediaLink>
1007</DataVirtualHardDisk>
1008 `))
1009 checkOneRequest(c, recordedRequests, expectedURL, baseAPIVersion, expectedPayload, "POST")
1010}
1011
1012func (suite *managementBaseAPISuite) TestListDisks(c *C) {
1013 api := makeAPI(c)
1014
1015 fixedResponse := x509Response{
1016 StatusCode: http.StatusOK,
1017 Body: []byte(strings.TrimSpace(`
1018<Disks xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
1019 <Disk>
1020 <AffinityGroup>name-of-affinity-group</AffinityGroup>
1021 <AttachedTo>
1022 <HostedServiceName>name-of-cloud-service</HostedServiceName>
1023 <DeploymentName>name-of-deployment</DeploymentName>
1024 <RoleName>name-of-virtual-machine</RoleName>
1025 </AttachedTo>
1026 <OS>operating-system-type</OS>
1027 <Location>geo-location-of-disk</Location>
1028 <LogicalSizeInGB>123</LogicalSizeInGB>
1029 <MediaLink>uri-of-vhd</MediaLink>
1030 <Name>name-of-disk</Name>
1031 <SourceImageName>name-of-source-image</SourceImageName>
1032 <CreatedTime>creation-time-of-disk</CreatedTime>
1033 <IOType>IO-Type</IOType>
1034 </Disk>
1035</Disks>
1036`)),
1037 }
1038 rigFixedResponseDispatcher(&fixedResponse)
1039 recordedRequests := make([]*X509Request, 0)
1040 rigRecordingDispatcher(&recordedRequests)
1041
1042 disks, err := api.ListDisks()
1043 c.Assert(err, IsNil)
1044 c.Assert(disks, HasLen, 1)
1045
1046 expectedURL := fmt.Sprintf("%s%s/services/disks", defaultManagement, api.session.subscriptionId)
1047 checkOneRequest(c, &recordedRequests, expectedURL, baseAPIVersion, nil, "GET")
1048
1049 c.Assert(disks[0], DeepEquals, Disk{
1050 AffinityGroup: "name-of-affinity-group",
1051 AttachedTo: &DiskAttachment{
1052 HostedServiceName: "name-of-cloud-service",
1053 DeploymentName: "name-of-deployment",
1054 RoleName: "name-of-virtual-machine",
1055 },
1056 OS: "operating-system-type",
1057 Location: "geo-location-of-disk",
1058 LogicalSizeInGB: 123,
1059 MediaLink: "uri-of-vhd",
1060 Name: "name-of-disk",
1061 SourceImageName: "name-of-source-image",
1062 CreatedTime: "creation-time-of-disk",
1063 IOType: "IO-Type",
1064 })
1065}
1066
971func (suite *managementBaseAPISuite) TestPerformNodeOperation(c *C) {1067func (suite *managementBaseAPISuite) TestPerformNodeOperation(c *C) {
972 api := makeAPI(c)1068 api := makeAPI(c)
973 recordedRequests := setUpDispatcher("operationID")1069 recordedRequests := setUpDispatcher("operationID")
9741070
=== modified file 'xmlobjects.go'
--- xmlobjects.go 2015-07-28 13:09:12 +0000
+++ xmlobjects.go 2015-08-10 08:06:54 +0000
@@ -329,11 +329,41 @@
329//329//
330330
331type DataVirtualHardDisk struct {331type DataVirtualHardDisk struct {
332 HostCaching string `xml:"HostCaching"`332 XMLNS string `xml:"xmlns,attr,omitempty"`
333 DiskName string `xml:"DiskName"`333 XMLNS_I string `xml:"xmlns:i,attr,omitempty"`
334 LUN string `xml:"Lun"`334 HostCaching string `xml:"HostCaching,omitempty"`
335 LogicalDiskSizeInGB string `xml:"LogicalDiskSizeInGB"`335 DiskLabel string `xml:"DiskLabel,omitempty"`
336 MediaLink string `xml:"MediaLink"`336 DiskName string `xml:"DiskName,omitempty"`
337 LUN int `xml:"Lun,omitempty"`
338 LogicalDiskSizeInGB int `xml:"LogicalDiskSizeInGB,omitempty"`
339 MediaLink string `xml:"MediaLink,omitempty"`
340 SourceMediaLink string `xml:"SourceMediaLink,omitempty"`
341}
342
343//
344// Disk
345//
346
347type Disk struct {
348 XMLNS string `xml:"xmlns,attr,omitempty"`
349 XMLNS_I string `xml:"xmlns:i,attr,omitempty"`
350 AffinityGroup string `xml:"AffinityGroup,omitempty"`
351 AttachedTo *DiskAttachment `xml:"AttachedTo,omitempty"`
352 OS string `xml:"OS"`
353 Location string `xml:"Location,omitempty"`
354 LogicalSizeInGB int `xml:"LogicalSizeInGB,omitempty"`
355 MediaLink string `xml:"MediaLink"`
356 Label string `xml:"Label,omitempty"`
357 Name string `xml:"Name"`
358 SourceImageName string `xml:"SourceImageName,omitempty"`
359 CreatedTime string `xml:"CreatedTime,omitempty"`
360 IOType string `xml:"IOType,omitempty"`
361}
362
363type DiskAttachment struct {
364 HostedServiceName string `xml:"HostedServiceName"`
365 DeploymentName string `xml:"DeploymentName"`
366 RoleName string `xml:"RoleName"`
337}367}
338368
339//369//
340370
=== modified file 'xmlobjects_test.go'
--- xmlobjects_test.go 2015-07-28 13:09:12 +0000
+++ xmlobjects_test.go 2015-08-10 08:06:54 +0000
@@ -348,8 +348,8 @@
348 <DataVirtualHardDisk>348 <DataVirtualHardDisk>
349 <HostCaching>host-caching-mode-of-data-disk</HostCaching>349 <HostCaching>host-caching-mode-of-data-disk</HostCaching>
350 <DiskName>new-or-existing-disk-name</DiskName>350 <DiskName>new-or-existing-disk-name</DiskName>
351 <Lun>logical-unit-number-of-data-disk</Lun>351 <Lun>31</Lun>
352 <LogicalDiskSizeInGB>size-of-data-disk</LogicalDiskSizeInGB>352 <LogicalDiskSizeInGB>42</LogicalDiskSizeInGB>
353 <MediaLink>path-to-vhd</MediaLink>353 <MediaLink>path-to-vhd</MediaLink>
354 </DataVirtualHardDisk>354 </DataVirtualHardDisk>
355 </DataVirtualHardDisks>355 </DataVirtualHardDisks>
@@ -410,8 +410,8 @@
410 {410 {
411 HostCaching: "host-caching-mode-of-data-disk",411 HostCaching: "host-caching-mode-of-data-disk",
412 DiskName: "new-or-existing-disk-name",412 DiskName: "new-or-existing-disk-name",
413 LUN: "logical-unit-number-of-data-disk",413 LUN: 31,
414 LogicalDiskSizeInGB: "size-of-data-disk",414 LogicalDiskSizeInGB: 42,
415 MediaLink: "path-to-vhd",415 MediaLink: "path-to-vhd",
416 },416 },
417 },417 },
@@ -478,8 +478,8 @@
478 {478 {
479 HostCaching: "host-caching-mode-of-data-disk",479 HostCaching: "host-caching-mode-of-data-disk",
480 DiskName: "new-or-existing-disk-name",480 DiskName: "new-or-existing-disk-name",
481 LUN: "logical-unit-number-of-data-disk",481 LUN: 31,
482 LogicalDiskSizeInGB: "size-of-data-disk",482 LogicalDiskSizeInGB: 42,
483 MediaLink: "path-to-vhd",483 MediaLink: "path-to-vhd",
484 },484 },
485 },485 },
@@ -940,8 +940,8 @@
940 <DataVirtualHardDisk>940 <DataVirtualHardDisk>
941 <HostCaching>host-caching-mode-of-data-disk</HostCaching>941 <HostCaching>host-caching-mode-of-data-disk</HostCaching>
942 <DiskName>name-of-data-disk</DiskName>942 <DiskName>name-of-data-disk</DiskName>
943 <Lun>logical-unit-number-of-data-disk</Lun>943 <Lun>31</Lun>
944 <LogicalDiskSizeInGB>size-of-data-disk</LogicalDiskSizeInGB>944 <LogicalDiskSizeInGB>42</LogicalDiskSizeInGB>
945 <MediaLink>path-to-vhd</MediaLink>945 <MediaLink>path-to-vhd</MediaLink>
946 </DataVirtualHardDisk>946 </DataVirtualHardDisk>
947 </DataVirtualHardDisks>947 </DataVirtualHardDisks>
@@ -1073,8 +1073,8 @@
1073 {1073 {
1074 HostCaching: "host-caching-mode-of-data-disk",1074 HostCaching: "host-caching-mode-of-data-disk",
1075 DiskName: "name-of-data-disk",1075 DiskName: "name-of-data-disk",
1076 LUN: "logical-unit-number-of-data-disk",1076 LUN: 31,
1077 LogicalDiskSizeInGB: "size-of-data-disk",1077 LogicalDiskSizeInGB: 42,
1078 MediaLink: "path-to-vhd",1078 MediaLink: "path-to-vhd",
1079 },1079 },
1080 },1080 },

Subscribers

People subscribed via source and target branches

to all changes: