engineyard/engineyard-cloud-client — pull request #4 by jaustinhughey (2013-08-02 03:30:21+00:00)
Title: remove instances

Includes several enhancements and specs for all of them. As of this writing all 85 spec examples pass on Ruby 2.0.0p247.

+ Find an environment by its name:
```
api = EY::CloudClient.new(token: token)
env = api.environment_by_name("myapp_production")
=>
```

+ Find an instance on an environment based on its AWSM id. Needed because at the time you add an instance, you won't have an Amazon ID (or other provisioned ID) because a different part of the SOA handles provisioning and, while an instance is created right then, it's provisioned later. So you can store the ID long term and then "scan" for the instance object, then pull out its Amazon ID after the fact.
```
env = api.env_by_name("myapp_prod")
i = env.instance_by_id(12345) # ID you have stored from when you created the instance
=>
```

+ Remove an instance given an instance object and an environment object. Checks to be sure the instance is indeed a valid instance (type of "app" or "util", ```provisioned?``` returns true) prior to handing it off to the API. Calls #request_instances at the end to "reload" the instance registry.
```
env = api.env_by_name("myapp_prod")
i = env.instance_by_id(12345)
env.remove_instance(i)
=> {request: { ... } }
```