Пример #1
0
// Compute v2 4.1.1: list servers
func List(c *client.Client, f string) (servers *ServerResponse, err error) {
	resp, err := c.Get("compute", "/servers")
	if err != nil {
		return nil, err
	}

	var s ServerResponse
	err = json.Unmarshal(resp.Body, &s)
	if err != nil {
		return nil, err
	}

	return &s, nil
}
Пример #2
0
// Compute v2 4.4.1: list flavors
func List(c *client.Client, f string) (body *[]interface{}, err error) {
	resp, err := c.Get("compute", "/flavors")
	if err != nil {
		return nil, err
	}

	//    var body FlavorResponse
	//    err = json.Unmarshal(resp.Body, &body)
	js, err := json.NewJsonStruct(resp.Body)
	if err != nil {
		return nil, err
	}
	b, err := js.GetKey("flavors").Array()
	return &b, nil
}
Пример #3
0
// Compute v2 4.1.1: list servers
func Show(c *client.Client, attr Attr) (s *ServerResponse, err error) {
	print("attr: ", attr["name"], "\n")
	// Look for search filters
	var f []string
	for _, v := range ServerAttrs {
		if val, ok := attr[v]; ok {
			f = append(f, attr[val])
		}
	}
	filter := strings.Join(f, "&")
	print("filter: ", filter, "\n")

	resp, err := c.Get("compute", "/servers/detail")
	if err != nil {
		return nil, err
	}

	err = json.Unmarshal(resp.Body, &s)
	if err != nil {
		return nil, err
	}

	return
}