yukw777 opened a new pull request #1398: Support for aws ec2 spot instances URL: https://github.com/apache/libcloud/pull/1398 ## Support for aws ec2 spot instances ### Description Support for aws ec2 spot instances. The previous PR (https://github.com/apache/libcloud/pull/1207) went stale, so I decided to create a new one. I've added a unit test and ran a manual test with the following script: ```python import os import time from libcloud.compute.types import Provider from libcloud.compute.providers import get_driver from libcloud.compute.base import NodeImage from libcloud.compute.types import NodeState SIZE_ID = 't1.micro' AMI_ID = 'ami-04b9e92b5572fa0d1' REGION = 'us-east-1' KEYPAIR_NAME = 'key' SECURITY_GROUP_NAMES = ['default'] NODE_NAME = 'test-spot-node' def create_spot_request(accessid, secretkey): cls = get_driver(Provider.EC2) driver = cls(accessid, secretkey, region=REGION) sizes = driver.list_sizes() size = [s for s in sizes if s.id == SIZE_ID][0] image = NodeImage(id=AMI_ID, name=None, driver=driver) # create the spot instance node = driver.create_node( name=NODE_NAME, size=size, image=image, ex_spot=True, ex_spot_max_price=0.005, ex_keyname=KEYPAIR_NAME, ex_security_groups=SECURITY_GROUP_NAMES) print("Spot instance created: '%s" % node.id) assert node.extra.get('instance_lifecycle') == 'spot' print("Destroying node...") driver.destroy_node(node) while node.state != NodeState.TERMINATED: print("...waiting to be terminated (State: %s)" % node.state) node = driver.list_nodes(ex_node_ids=[node.id])[0] time.sleep(5) def main(): accessid = os.getenv('ACCESSID') secretkey = os.getenv('SECRETKEY') if accessid and secretkey: create_spot_request(accessid, secretkey) else: print('ACCESSID and SECRETKEY are sourced from the environment') if __name__ == "__main__": main() ``` ### Status done, ready for review ### Checklist (tick everything that applies) - [x] [Code linting](http://libcloud.readthedocs.org/en/latest/development.html#code-style-guide) (required, can be done after the PR checks) - [x] Documentation - [x] [Tests](http://libcloud.readthedocs.org/en/latest/testing.html) - [x] [ICLA](http://libcloud.readthedocs.org/en/latest/development.html#contributing-bigger-changes) (required for bigger changes)
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
