Merge lp:~allenap/gwacl/update-role into lp:gwacl

Proposed by Gavin Panella on 2013-07-16
Status: Merged
Approved by: Gavin Panella on 2013-07-16
Approved revision: 184
Merged at revision: 184
Proposed branch: lp:~allenap/gwacl/update-role
Merge into: lp:gwacl
Diff against target: 76 lines (+55/-0)
2 files modified
management_base.go (+30/-0)
management_base_test.go (+25/-0)
To merge this branch: bzr merge lp:~allenap/gwacl/update-role
Reviewer Review Type Date Requested Status
Raphaël Badin (community) 2013-07-16 Approve on 2013-07-16
Review via email: mp+175048@code.launchpad.net

Commit message

New API method UpdateRole.

To post a comment you must log in.
Raphaël Badin (rvb) wrote :

Looks good.

[0]

14 + RoleName string
15 + PersistentVMRole *PersistentVMRole

The PersistentVMRole object already contains the RoleName.

[1]

"alas, struct embedding is too clunky, so copy-n-paste it is"

:/

review: Approve
Gavin Panella (allenap) wrote :

> [0]
>
> 14 + RoleName string
> 15 + PersistentVMRole *PersistentVMRole
>
> The PersistentVMRole object already contains the RoleName.

There's nothing in the docs to say that you can't change the name of the role by specifying a different name. In other words, PersistentVMRole defines the role resource, and ServiceName, DeploymentName and RoleName define the resource's location.

Thanks for the review :)

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 2013-07-16 13:59:10 +0000
3+++ management_base.go 2013-07-16 15:45:31 +0000
4@@ -385,6 +385,36 @@
5 return &role, nil
6 }
7
8+type UpdateRoleRequest struct {
9+ // It would be nice to inherit ServiceName, DeploymentName and RoleName
10+ // from performRoleOperationRequest... alas, struct embedding is too
11+ // clunky, so copy-n-paste it is. My kingdom for a macro!
12+ ServiceName string
13+ DeploymentName string
14+ RoleName string
15+ PersistentVMRole *PersistentVMRole
16+}
17+
18+// UpdateRole pushes a PersistentVMRole document back up to Azure for the
19+// specified role. See
20+// http://msdn.microsoft.com/en-us/library/windowsazure/jj157187.aspx
21+func (api *ManagementAPI) UpdateRole(request *UpdateRoleRequest) error {
22+ checkPathComponents(
23+ request.ServiceName, request.DeploymentName, request.RoleName)
24+ url := ("services/hostedservices/" + request.ServiceName +
25+ "/deployments/" + request.DeploymentName + "/roles/" +
26+ request.RoleName)
27+ role, err := request.PersistentVMRole.Serialize()
28+ if err != nil {
29+ return err
30+ }
31+ _, err = api.session.put(url, "2012-03-01", []byte(role), "application/octet-stream")
32+ if err != nil {
33+ return err
34+ }
35+ return nil
36+}
37+
38 type CreateAffinityGroupRequest struct {
39 CreateAffinityGroup *CreateAffinityGroup
40 }
41
42=== modified file 'management_base_test.go'
43--- management_base_test.go 2013-07-16 13:59:10 +0000
44+++ management_base_test.go 2013-07-16 15:45:31 +0000
45@@ -850,6 +850,31 @@
46 c.Check(role.RoleName, Equals, "rolename")
47 }
48
49+func (suite *managementBaseAPISuite) TestUpdateRole(c *C) {
50+ api := makeAPI(c)
51+ request := &UpdateRoleRequest{
52+ ServiceName: "serviceName",
53+ DeploymentName: "deploymentName",
54+ RoleName: "roleName",
55+ PersistentVMRole: &PersistentVMRole{
56+ RoleName: "newRoleNamePerhaps",
57+ },
58+ }
59+ rigFixedResponseDispatcher(&x509Response{StatusCode: http.StatusOK})
60+ recordedRequests := make([]*X509Request, 0)
61+ rigRecordingDispatcher(&recordedRequests)
62+
63+ err := api.UpdateRole(request)
64+ c.Assert(err, IsNil)
65+
66+ expectedURL := (AZURE_URL + api.session.subscriptionId +
67+ "/services/hostedservices/" + request.ServiceName + "/deployments/" +
68+ request.DeploymentName + "/roles/" + request.RoleName)
69+ expectedXML, err := request.PersistentVMRole.Serialize()
70+ c.Assert(err, IsNil)
71+ checkOneRequest(c, &recordedRequests, expectedURL, "2012-03-01", []byte(expectedXML), "PUT")
72+}
73+
74 func (suite *managementBaseAPISuite) TestCreateAffinityGroup(c *C) {
75 api := makeAPI(c)
76 cag := NewCreateAffinityGroup(

Subscribers

People subscribed via source and target branches

to all changes: