How to launch a droplet via API?
I am interested in a reliable way of launching droplets over API. I want to know how to check for all possible errors and how to detect if a new droplet is finally running.
Just doing POST to /v2/droplets sometimes might not be enough. I had following problems:
- An error response but a simple repeat works fine. I had following errors “There was an error while trying to create your tags. Please try again”, “Server was unable to give you a response.” Repeating the exact same request helped in those cases.
- No response at all (or network error) but droplet was launched. A search for the droplet is needed in such a case because droplet ID wasn’t returned. Listing all droplets is an option but don’t forget about pagination (200 per request is the limit). Tags cannot be used to list droplets because sometimes they are set much later. Name of the droplet can be used as identification but you cannot use it for direct request. Perhaps going through actions could be used to search for the droplet create action. But the list can be long too.
- A proper response (with ip, id etc.) but later droplet fails to start properly and ends with status “archive” (I had this twice today). This might be checked using “status” field - but what should the value be? In such case tags might be not be set. A better option would be to list actions on the droplet and search for the type “create”. But the documentation doesn’t even list all possible types and pagination can kick in here too.
It looks quite complex to me.
What would be a reliable yet simple approach to launch droplets that works around all possible cases and keeps working even if you have hundreds of droplets?