Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/boto/ec2/buyreservation.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
| author | shellac |
|---|---|
| date | Mon, 22 Mar 2021 18:12:50 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4f3585e2f14b |
|---|---|
| 1 # Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/ | |
| 2 # | |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a | |
| 4 # copy of this software and associated documentation files (the | |
| 5 # "Software"), to deal in the Software without restriction, including | |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- | |
| 7 # tribute, sublicense, and/or sell copies of the Software, and to permit | |
| 8 # persons to whom the Software is furnished to do so, subject to the fol- | |
| 9 # lowing conditions: | |
| 10 # | |
| 11 # The above copyright notice and this permission notice shall be included | |
| 12 # in all copies or substantial portions of the Software. | |
| 13 # | |
| 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
| 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | |
| 16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | |
| 17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
| 18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
| 20 # IN THE SOFTWARE. | |
| 21 import boto.ec2 | |
| 22 from boto.sdb.db.property import StringProperty, IntegerProperty | |
| 23 from boto.manage import propget | |
| 24 from boto.compat import six | |
| 25 | |
| 26 InstanceTypes = ['m1.small', 'm1.large', 'm1.xlarge', | |
| 27 'c1.medium', 'c1.xlarge', 'm2.xlarge', | |
| 28 'm2.2xlarge', 'm2.4xlarge', 'cc1.4xlarge', | |
| 29 't1.micro'] | |
| 30 | |
| 31 | |
| 32 class BuyReservation(object): | |
| 33 | |
| 34 def get_region(self, params): | |
| 35 if not params.get('region', None): | |
| 36 prop = StringProperty(name='region', verbose_name='EC2 Region', | |
| 37 choices=boto.ec2.regions) | |
| 38 params['region'] = propget.get(prop, choices=boto.ec2.regions) | |
| 39 | |
| 40 def get_instance_type(self, params): | |
| 41 if not params.get('instance_type', None): | |
| 42 prop = StringProperty(name='instance_type', verbose_name='Instance Type', | |
| 43 choices=InstanceTypes) | |
| 44 params['instance_type'] = propget.get(prop) | |
| 45 | |
| 46 def get_quantity(self, params): | |
| 47 if not params.get('quantity', None): | |
| 48 prop = IntegerProperty(name='quantity', verbose_name='Number of Instances') | |
| 49 params['quantity'] = propget.get(prop) | |
| 50 | |
| 51 def get_zone(self, params): | |
| 52 if not params.get('zone', None): | |
| 53 prop = StringProperty(name='zone', verbose_name='EC2 Availability Zone', | |
| 54 choices=self.ec2.get_all_zones) | |
| 55 params['zone'] = propget.get(prop) | |
| 56 | |
| 57 def get(self, params): | |
| 58 self.get_region(params) | |
| 59 self.ec2 = params['region'].connect() | |
| 60 self.get_instance_type(params) | |
| 61 self.get_zone(params) | |
| 62 self.get_quantity(params) | |
| 63 | |
| 64 if __name__ == "__main__": | |
| 65 obj = BuyReservation() | |
| 66 params = {} | |
| 67 obj.get(params) | |
| 68 offerings = obj.ec2.get_all_reserved_instances_offerings(instance_type=params['instance_type'], | |
| 69 availability_zone=params['zone'].name) | |
| 70 print('\nThe following Reserved Instances Offerings are available:\n') | |
| 71 for offering in offerings: | |
| 72 offering.describe() | |
| 73 prop = StringProperty(name='offering', verbose_name='Offering', | |
| 74 choices=offerings) | |
| 75 offering = propget.get(prop) | |
| 76 print('\nYou have chosen this offering:') | |
| 77 offering.describe() | |
| 78 unit_price = float(offering.fixed_price) | |
| 79 total_price = unit_price * params['quantity'] | |
| 80 print('!!! You are about to purchase %d of these offerings for a total of $%.2f !!!' % (params['quantity'], total_price)) | |
| 81 answer = six.moves.input('Are you sure you want to do this? If so, enter YES: ') | |
| 82 if answer.strip().lower() == 'yes': | |
| 83 offering.purchase(params['quantity']) | |
| 84 else: | |
| 85 print('Purchase cancelled') |
