pachadotdev / analogsea

Digital Ocean R client
https://pacha.dev/analogsea/
Apache License 2.0
154 stars 24 forks source link

Code does not handle cleanly the fact of duplicated droplets names #66

Closed behrica closed 9 years ago

behrica commented 9 years ago

Doing this:

droplet_new("test",image="coreos-beta")
droplet_new("test",image="coreos-beta")
droplet_delete("test")

creates 2 droplets and deletes the "first" one in the list coming from droplets().

I believe it would be saver to fail here (and in other cases), if the droplet name or snapshot name is not unique.

So eventually this line:

as.droplet.character <- function(x) droplets()[[x]]

should give an error, if x is more then once in the list.

Same for images.

hadley commented 9 years ago

This doesn't seem like a huge problem to me. If you want to use non-unique names, then it's your issue to deal with.

sckott commented 9 years ago

@behrica If you don't give a name, you get a random name from a list of 1000 words, which for any one person should be plenty so that they shouldn't get 2 of the same name during the life of any set of droplets. I think it's easy enough to positionally pass to droplet_delete(), like droplets()[[1]] %>% droplet_delete, or you can pass in the droplet id droplet_delete(1234567)

sckott commented 9 years ago

@behrica you can see the word list by executing words when analogsea is loaded

behrica commented 9 years ago

@sckott But droplets and images can be created by other means then this package. And even with this Packagei I can create two droplets with the same name, if I want.

So it can happen that a user has

or

-several times the same snapshot name

Therefore to have functions which take an droplet name and image name and do something with "it", seems dangerous to me. Specially, as the method docu seems to suggest that calling it by-name or by-id is the same. Right know the functions just "picks one" (the "first" in whatever order it comes from the API call (= undefined)). So the function behaves unpredictable for this special case of same name multiple times.

I believe a good precaution is to fail, if droplet or image names exist more the ones. (as it is a rare case, probably)

behrica commented 9 years ago

@hadley No a huge issue, I agree. Nice to have.

It´s more a question of not making the user of this package believe (by looking at the functions here), that names are unique. Maybe it could be just documented, that all methods "act on the first", if names are not unique.