Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(870)

Side by Side Diff: third_party/gsutil/boto/ec2/buyreservation.py

Issue 12042069: Scripts to download files from google storage based on sha1 sums (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Removed gsutil/tests and gsutil/docs Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
22 import boto.ec2
23 from boto.sdb.db.property import StringProperty, IntegerProperty
24 from boto.manage import propget
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 class BuyReservation(object):
32
33 def get_region(self, params):
34 if not params.get('region', None):
35 prop = StringProperty(name='region', verbose_name='EC2 Region',
36 choices=boto.ec2.regions)
37 params['region'] = propget.get(prop, choices=boto.ec2.regions)
38
39 def get_instance_type(self, params):
40 if not params.get('instance_type', None):
41 prop = StringProperty(name='instance_type', verbose_name='Instance T ype',
42 choices=InstanceTypes)
43 params['instance_type'] = propget.get(prop)
44
45 def get_quantity(self, params):
46 if not params.get('quantity', None):
47 prop = IntegerProperty(name='quantity', verbose_name='Number of Inst ances')
48 params['quantity'] = propget.get(prop)
49
50 def get_zone(self, params):
51 if not params.get('zone', None):
52 prop = StringProperty(name='zone', verbose_name='EC2 Availability Zo ne',
53 choices=self.ec2.get_all_zones)
54 params['zone'] = propget.get(prop)
55
56 def get(self, params):
57 self.get_region(params)
58 self.ec2 = params['region'].connect()
59 self.get_instance_type(params)
60 self.get_zone(params)
61 self.get_quantity(params)
62
63 if __name__ == "__main__":
64 obj = BuyReservation()
65 params = {}
66 obj.get(params)
67 offerings = obj.ec2.get_all_reserved_instances_offerings(instance_type=param s['instance_type'],
68 availability_zone=p arams['zone'].name)
69 print '\nThe following Reserved Instances Offerings are available:\n'
70 for offering in offerings:
71 offering.describe()
72 prop = StringProperty(name='offering', verbose_name='Offering',
73 choices=offerings)
74 offering = propget.get(prop)
75 print '\nYou have chosen this offering:'
76 offering.describe()
77 unit_price = float(offering.fixed_price)
78 total_price = unit_price * params['quantity']
79 print '!!! You are about to purchase %d of these offerings for a total of $% .2f !!!' % (params['quantity'], total_price)
80 answer = raw_input('Are you sure you want to do this? If so, enter YES: ')
81 if answer.strip().lower() == 'yes':
82 offering.purchase(params['quantity'])
83 else:
84 print 'Purchase cancelled'
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698