[GO] Api Cloudstack

Hello,

My name is Julien. I am French. I don’t speak very well in English. Sorry.

I visited this GitHub : https://github.com/mindjiver/gopherstack

I like it. This “Gopherstack” directory meets my needs.

Only small problem, we can recover the IP and the state of a single machine VM according to the given ID …

So, my question is :
How can I recover the IP and state of all my VMs and not just one?

Do you have an idea ? Please ?

Thanks !

Julien.

2 Likes
cs.ListVirtualMachines(vmid)

takes only the id off one machine and then call this function

// Returns Cloudstack string representation of the Virtual Machine state
func (c CloudstackClient) ListVirtualMachines(id string) (ListVirtualMachinesResponse, error) {
	var resp ListVirtualMachinesResponse
	params := url.Values{}
	params.Set("id", id)
	response, err := NewRequest(c, "listVirtualMachines", params)
	if err != nil {
		return resp, err
	}
	resp = response.(ListVirtualMachinesResponse)
	return resp, err
}

But id isn’t a required parameter to the API https://cloudstack.apache.org/api/apidocs-4.13/apis/listVirtualMachines.html

so maybe you could add your own function

func (c CloudstackClient) ListAllVirtualMachines() (ListVirtualMachinesResponse, error) {
	var resp ListVirtualMachinesResponse
	params := url.Values{}
	response, err := NewRequest(c, "listVirtualMachines", params)
	if err != nil {
		return resp, err
	}
	resp = response.(ListVirtualMachinesResponse)
	return resp, err
}

But if you put it in your own package you need to add gopherstack package before all types and put gopherstack.CloudstackClient as a parameter and not a reciever

func ListAllVirtualMachines(c gopherstack.CloudstackClient) (gopherstack.ListVirtualMachinesResponse, error) {
	var resp gopherstack.ListVirtualMachinesResponse
	params := url.Values{}
	response, err := gopherstack.NewRequest(c, "listVirtualMachines", params)
	if err != nil {
		return resp, err
	}
	resp = response.(gopherstack.ListVirtualMachinesResponse)
	return resp, err
}

This is just an idea I haven’t tested it.

2 Likes

Thank you for your help. I found. We can close the subject :wink:

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.