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

Side by Side Diff: nova/nova.go

Issue 6872050: Fix nova RunServer to return details (Closed)
Patch Set: Created 11 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
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 20 matching lines...) Expand all
31 31
32 type Link struct { 32 type Link struct {
33 Href string 33 Href string
34 Rel string 34 Rel string
35 Type string 35 Type string
36 } 36 }
37 37
38 // Entity can describe a flavor, flavor detail or server. 38 // Entity can describe a flavor, flavor detail or server.
39 // Contains a list of links. 39 // Contains a list of links.
40 type Entity struct { 40 type Entity struct {
41 » Id string 41 » Id string
42 » Links []Link 42 » Links []Link
43 » Name string 43 » Name string
44 » AdminPass string
gz 2012/12/03 12:24:35 As I understand this code, Entity is intended to b
wallyworld 2012/12/03 23:53:55 Ok, will remove from this branch and we can introd
44 } 45 }
45 46
46 // ListFlavours lists IDs, names, and links for available flavors. 47 // ListFlavours lists IDs, names, and links for available flavors.
47 func (c *Client) ListFlavors() ([]Entity, error) { 48 func (c *Client) ListFlavors() ([]Entity, error) {
48 var resp struct { 49 var resp struct {
49 Flavors []Entity 50 Flavors []Entity
50 } 51 }
51 requestData := goosehttp.RequestData{RespValue: &resp} 52 requestData := goosehttp.RequestData{RespValue: &resp}
52 err := c.client.SendRequest(client.GET, "compute", apiFlavors, &requestD ata, "failed to get list of flavors") 53 err := c.client.SendRequest(client.GET, "compute", apiFlavors, &requestD ata, "failed to get list of flavors")
53 return resp.Flavors, err 54 return resp.Flavors, err
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 Name string `json:"name"` 153 Name string `json:"name"`
153 FlavorId string `json:"flavorRef"` 154 FlavorId string `json:"flavorRef"`
154 ImageId string `json:"imageRef"` 155 ImageId string `json:"imageRef"`
155 UserData *string `json:"user_data"` 156 UserData *string `json:"user_data"`
156 SecurityGroupNames []struct { 157 SecurityGroupNames []struct {
157 Name string `json:"name"` 158 Name string `json:"name"`
158 } `json:"security_groups"` 159 } `json:"security_groups"`
159 } 160 }
160 161
161 // RunServer creates a new server. 162 // RunServer creates a new server.
162 func (c *Client) RunServer(opts RunServerOpts) error { 163 func (c *Client) RunServer(opts RunServerOpts) (*Entity, error) {
163 var req struct { 164 var req struct {
164 Server RunServerOpts `json:"server"` 165 Server RunServerOpts `json:"server"`
165 } 166 }
166 req.Server = opts 167 req.Server = opts
167 if opts.UserData != nil { 168 if opts.UserData != nil {
168 data := []byte(*opts.UserData) 169 data := []byte(*opts.UserData)
169 encoded := base64.StdEncoding.EncodeToString(data) 170 encoded := base64.StdEncoding.EncodeToString(data)
170 req.Server.UserData = &encoded 171 req.Server.UserData = &encoded
171 } 172 }
172 » requestData := goosehttp.RequestData{ReqValue: req, ExpectedStatus: []in t{http.StatusAccepted}} 173 » var resp struct {
174 » » Server Entity `json:"server"`
175 » }
176 » requestData := goosehttp.RequestData{ReqValue: req, RespValue: &resp, Ex pectedStatus: []int{http.StatusAccepted}}
173 err := c.client.SendRequest(client.POST, "compute", apiServers, &request Data, 177 err := c.client.SendRequest(client.POST, "compute", apiServers, &request Data,
174 "failed to run a server with %#v", opts) 178 "failed to run a server with %#v", opts)
175 » return err 179 » if err != nil {
180 » » return nil, err
181 » }
182 » return &resp.Server, nil
176 } 183 }
177 184
178 type SecurityGroupRule struct { 185 type SecurityGroupRule struct {
179 FromPort *int `json:"from_port"` // Can be nil 186 FromPort *int `json:"from_port"` // Can be nil
180 IPProtocol *string `json:"ip_protocol"` // Can be nil 187 IPProtocol *string `json:"ip_protocol"` // Can be nil
181 ToPort *int `json:"to_port"` // Can be nil 188 ToPort *int `json:"to_port"` // Can be nil
182 ParentGroupId int `json:"parent_group_id"` 189 ParentGroupId int `json:"parent_group_id"`
183 IPRange map[string]string `json:"ip_range"` // Can be empty 190 IPRange map[string]string `json:"ip_range"` // Can be empty
184 Id int 191 Id int
185 Group map[string]string // Can be empty 192 Group map[string]string // Can be empty
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } `json:"removeFloatingIp"` 419 } `json:"removeFloatingIp"`
413 } 420 }
414 req.RemoveFloatingIP.Address = address 421 req.RemoveFloatingIP.Address = address
415 422
416 url := fmt.Sprintf("%s/%s/action", apiServers, serverId) 423 url := fmt.Sprintf("%s/%s/action", apiServers, serverId)
417 requestData := goosehttp.RequestData{ReqValue: req, ExpectedStatus: []in t{http.StatusAccepted}} 424 requestData := goosehttp.RequestData{ReqValue: req, ExpectedStatus: []in t{http.StatusAccepted}}
418 err := c.client.SendRequest(client.POST, "compute", url, &requestData, 425 err := c.client.SendRequest(client.POST, "compute", url, &requestData,
419 "failed to remove floating ip %s to server %s", address, serverI d) 426 "failed to remove floating ip %s to server %s", address, serverI d)
420 return err 427 return err
421 } 428 }
OLDNEW
« no previous file with comments | « [revision details] ('k') | nova/nova_test.go » ('j') | nova/nova_test.go » ('J')

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