Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Side by Side Diff: nova/nova.go

Issue 6867052: Return slices not pointers (Closed)
Patch Set: Return slices not pointers Created 12 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « glance/glance_test.go ('k') | nova/nova_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // The nova package provides a way to access the OpenStack Compute APIs. 1 // The nova package provides a way to access the OpenStack Compute APIs.
2 // See http://docs.openstack.org/api/openstack-compute/2/content/. 2 // See http://docs.openstack.org/api/openstack-compute/2/content/.
3 package nova 3 package nova
4 4
5 import ( 5 import (
6 "encoding/base64" 6 "encoding/base64"
7 "fmt" 7 "fmt"
8 "launchpad.net/goose/client" 8 "launchpad.net/goose/client"
9 goosehttp "launchpad.net/goose/http" 9 goosehttp "launchpad.net/goose/http"
10 "net/http" 10 "net/http"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 type FlavorDetail struct { 56 type FlavorDetail struct {
57 Name string 57 Name string
58 RAM int 58 RAM int
59 VCPUs int 59 VCPUs int
60 Disk int 60 Disk int
61 Id string 61 Id string
62 Swap interface{} // Can be an empty string (?!) 62 Swap interface{} // Can be an empty string (?!)
63 } 63 }
64 64
65 // ListFlavorsDetail lists all details for available flavors. 65 // ListFlavorsDetail lists all details for available flavors.
66 func (c *Client) ListFlavorsDetail() (*[]FlavorDetail, error) { 66 func (c *Client) ListFlavorsDetail() ([]FlavorDetail, error) {
67 var resp struct { 67 var resp struct {
68 Flavors []FlavorDetail 68 Flavors []FlavorDetail
69 } 69 }
70 requestData := goosehttp.RequestData{RespValue: &resp} 70 requestData := goosehttp.RequestData{RespValue: &resp}
71 err := c.client.SendRequest(client.GET, "compute", apiFlavorsDetail, &re questData, 71 err := c.client.SendRequest(client.GET, "compute", apiFlavorsDetail, &re questData,
72 "failed to get list of flavors details") 72 "failed to get list of flavors details")
73 if err != nil { 73 if err != nil {
74 return nil, err 74 return nil, err
75 } 75 }
76 » return &resp.Flavors, nil 76 » return resp.Flavors, nil
77 } 77 }
78 78
79 // ListServers lists IDs, names, and links for all servers. 79 // ListServers lists IDs, names, and links for all servers.
80 func (c *Client) ListServers() (*[]Entity, error) { 80 func (c *Client) ListServers() ([]Entity, error) {
81 var resp struct { 81 var resp struct {
82 Servers []Entity 82 Servers []Entity
83 } 83 }
84 requestData := goosehttp.RequestData{RespValue: &resp, ExpectedStatus: [ ]int{http.StatusOK}} 84 requestData := goosehttp.RequestData{RespValue: &resp, ExpectedStatus: [ ]int{http.StatusOK}}
85 err := c.client.SendRequest(client.GET, "compute", apiServers, &requestD ata, 85 err := c.client.SendRequest(client.GET, "compute", apiServers, &requestD ata,
86 "failed to get list of servers") 86 "failed to get list of servers")
87 if err != nil { 87 if err != nil {
88 return nil, err 88 return nil, err
89 } 89 }
90 » return &resp.Servers, nil 90 » return resp.Servers, nil
91 } 91 }
92 92
93 type ServerDetail struct { 93 type ServerDetail struct {
94 AddressIPv4 string 94 AddressIPv4 string
95 AddressIPv6 string 95 AddressIPv6 string
96 Created string 96 Created string
97 Flavor Entity 97 Flavor Entity
98 HostId string 98 HostId string
99 Id string 99 Id string
100 Image Entity 100 Image Entity
101 Links []Link 101 Links []Link
102 Name string 102 Name string
103 Progress int 103 Progress int
104 Status string 104 Status string
105 TenantId string `json:"tenant_id"` 105 TenantId string `json:"tenant_id"`
106 Updated string 106 Updated string
107 UserId string `json:"user_id"` 107 UserId string `json:"user_id"`
108 } 108 }
109 109
110 // ListServersDetail lists all details for available servers. 110 // ListServersDetail lists all details for available servers.
111 func (c *Client) ListServersDetail() (*[]ServerDetail, error) { 111 func (c *Client) ListServersDetail() ([]ServerDetail, error) {
112 var resp struct { 112 var resp struct {
113 Servers []ServerDetail 113 Servers []ServerDetail
114 } 114 }
115 requestData := goosehttp.RequestData{RespValue: &resp} 115 requestData := goosehttp.RequestData{RespValue: &resp}
116 err := c.client.SendRequest(client.GET, "compute", apiServersDetail, &re questData, 116 err := c.client.SendRequest(client.GET, "compute", apiServersDetail, &re questData,
117 "failed to get list of servers details") 117 "failed to get list of servers details")
118 if err != nil { 118 if err != nil {
119 return nil, err 119 return nil, err
120 } 120 }
121 » return &resp.Servers, nil 121 » return resp.Servers, nil
122 } 122 }
123 123
124 // GetServer lists details for the specified server. 124 // GetServer lists details for the specified server.
125 func (c *Client) GetServer(serverId string) (*ServerDetail, error) { 125 func (c *Client) GetServer(serverId string) (*ServerDetail, error) {
126 var resp struct { 126 var resp struct {
127 Server ServerDetail 127 Server ServerDetail
128 } 128 }
129 url := fmt.Sprintf("%s/%s", apiServers, serverId) 129 url := fmt.Sprintf("%s/%s", apiServers, serverId)
130 requestData := goosehttp.RequestData{RespValue: &resp} 130 requestData := goosehttp.RequestData{RespValue: &resp}
131 err := c.client.SendRequest(client.GET, "compute", url, &requestData, 131 err := c.client.SendRequest(client.GET, "compute", url, &requestData,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 193
194 type SecurityGroup struct { 194 type SecurityGroup struct {
195 Rules []SecurityGroupRule 195 Rules []SecurityGroupRule
196 TenantId string `json:"tenant_id"` 196 TenantId string `json:"tenant_id"`
197 Id int 197 Id int
198 Name string 198 Name string
199 Description string 199 Description string
200 } 200 }
201 201
202 // ListSecurityGroups lists IDs, names, and other details for all security group s. 202 // ListSecurityGroups lists IDs, names, and other details for all security group s.
203 func (c *Client) ListSecurityGroups() (*[]SecurityGroup, error) { 203 func (c *Client) ListSecurityGroups() ([]SecurityGroup, error) {
204 var resp struct { 204 var resp struct {
205 Groups []SecurityGroup `json:"security_groups"` 205 Groups []SecurityGroup `json:"security_groups"`
206 } 206 }
207 requestData := goosehttp.RequestData{RespValue: &resp} 207 requestData := goosehttp.RequestData{RespValue: &resp}
208 err := c.client.SendRequest(client.GET, "compute", apiSecurityGroups, &r equestData, 208 err := c.client.SendRequest(client.GET, "compute", apiSecurityGroups, &r equestData,
209 "failed to list security groups") 209 "failed to list security groups")
210 if err != nil { 210 if err != nil {
211 return nil, err 211 return nil, err
212 } 212 }
213 » return &resp.Groups, nil 213 » return resp.Groups, nil
214 } 214 }
215 215
216 // GetServerSecurityGroups list security groups for a specific server. 216 // GetServerSecurityGroups list security groups for a specific server.
217 func (c *Client) GetServerSecurityGroups(serverId string) (*[]SecurityGroup, err or) { 217 func (c *Client) GetServerSecurityGroups(serverId string) ([]SecurityGroup, erro r) {
218 218
219 var resp struct { 219 var resp struct {
220 Groups []SecurityGroup `json:"security_groups"` 220 Groups []SecurityGroup `json:"security_groups"`
221 } 221 }
222 url := fmt.Sprintf("%s/%s/%s", apiServers, serverId, apiSecurityGroups) 222 url := fmt.Sprintf("%s/%s/%s", apiServers, serverId, apiSecurityGroups)
223 requestData := goosehttp.RequestData{RespValue: &resp} 223 requestData := goosehttp.RequestData{RespValue: &resp}
224 err := c.client.SendRequest(client.GET, "compute", url, &requestData, 224 err := c.client.SendRequest(client.GET, "compute", url, &requestData,
225 "failed to list server (%s) security groups", serverId) 225 "failed to list server (%s) security groups", serverId)
226 if err != nil { 226 if err != nil {
227 return nil, err 227 return nil, err
228 } 228 }
229 » return &resp.Groups, nil 229 » return resp.Groups, nil
230 } 230 }
231 231
232 // CreateSecurityGroup creates a new security group. 232 // CreateSecurityGroup creates a new security group.
233 func (c *Client) CreateSecurityGroup(name, description string) (*SecurityGroup, error) { 233 func (c *Client) CreateSecurityGroup(name, description string) (*SecurityGroup, error) {
234 var req struct { 234 var req struct {
235 SecurityGroup struct { 235 SecurityGroup struct {
236 Name string `json:"name"` 236 Name string `json:"name"`
237 Description string `json:"description"` 237 Description string `json:"description"`
238 } `json:"security_group"` 238 } `json:"security_group"`
239 } 239 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 333
334 type FloatingIP struct { 334 type FloatingIP struct {
335 FixedIP interface{} `json:"fixed_ip"` // Can be a string or null 335 FixedIP interface{} `json:"fixed_ip"` // Can be a string or null
336 Id int `json:"id"` 336 Id int `json:"id"`
337 InstanceId interface{} `json:"instance_id"` // Can be a string or null 337 InstanceId interface{} `json:"instance_id"` // Can be a string or null
338 IP string `json:"ip"` 338 IP string `json:"ip"`
339 Pool string `json:"pool"` 339 Pool string `json:"pool"`
340 } 340 }
341 341
342 // ListFloatingIPs lists floating IP addresses associated with the tenant or acc ount. 342 // ListFloatingIPs lists floating IP addresses associated with the tenant or acc ount.
343 func (c *Client) ListFloatingIPs() (*[]FloatingIP, error) { 343 func (c *Client) ListFloatingIPs() ([]FloatingIP, error) {
344 var resp struct { 344 var resp struct {
345 FloatingIPs []FloatingIP `json:"floating_ips"` 345 FloatingIPs []FloatingIP `json:"floating_ips"`
346 } 346 }
347 347
348 requestData := goosehttp.RequestData{RespValue: &resp} 348 requestData := goosehttp.RequestData{RespValue: &resp}
349 err := c.client.SendRequest(client.GET, "compute", apiFloatingIPs, &requ estData, 349 err := c.client.SendRequest(client.GET, "compute", apiFloatingIPs, &requ estData,
350 "failed to list floating ips") 350 "failed to list floating ips")
351 if err != nil { 351 if err != nil {
352 return nil, err 352 return nil, err
353 } 353 }
354 » return &resp.FloatingIPs, nil 354 » return resp.FloatingIPs, nil
355 } 355 }
356 356
357 // GetFloatingIP lists details of the floating IP address associated with specif ied id. 357 // GetFloatingIP lists details of the floating IP address associated with specif ied id.
358 func (c *Client) GetFloatingIP(ipId int) (*FloatingIP, error) { 358 func (c *Client) GetFloatingIP(ipId int) (*FloatingIP, error) {
359 var resp struct { 359 var resp struct {
360 FloatingIP FloatingIP `json:"floating_ip"` 360 FloatingIP FloatingIP `json:"floating_ip"`
361 } 361 }
362 362
363 url := fmt.Sprintf("%s/%d", apiFloatingIPs, ipId) 363 url := fmt.Sprintf("%s/%d", apiFloatingIPs, ipId)
364 requestData := goosehttp.RequestData{RespValue: &resp} 364 requestData := goosehttp.RequestData{RespValue: &resp}
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 } `json:"removeFloatingIp"` 418 } `json:"removeFloatingIp"`
419 } 419 }
420 req.RemoveFloatingIP.Address = address 420 req.RemoveFloatingIP.Address = address
421 421
422 url := fmt.Sprintf("%s/%s/action", apiServers, serverId) 422 url := fmt.Sprintf("%s/%s/action", apiServers, serverId)
423 requestData := goosehttp.RequestData{ReqValue: req, ExpectedStatus: []in t{http.StatusAccepted}} 423 requestData := goosehttp.RequestData{ReqValue: req, ExpectedStatus: []in t{http.StatusAccepted}}
424 err := c.client.SendRequest(client.POST, "compute", url, &requestData, 424 err := c.client.SendRequest(client.POST, "compute", url, &requestData,
425 "failed to remove floating ip %s to server %s", address, serverI d) 425 "failed to remove floating ip %s to server %s", address, serverI d)
426 return err 426 return err
427 } 427 }
OLDNEW
« no previous file with comments | « glance/glance_test.go ('k') | nova/nova_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b