Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize InstanceType names. #680

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions boto/ec2/__init__.py
Expand Up @@ -14,7 +14,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
Expand All @@ -25,13 +25,17 @@
"""
from boto.ec2.connection import EC2Connection

InstanceTypes = ['t1.micro', 'm1.small', 'm1.medium', 'm1.large', 'm1.xlarge',
'c1.medium', 'c1.xlarge', 'm2.xlarge', 'm2.2xlarge',
'm2.4xlarge', 'cc1.4xlarge', 'cc2.8xlarge', 'cg1.4xlarge']

def regions(**kw_params):
"""
Get all available regions for the EC2 service.
You may pass any of the arguments accepted by the EC2Connection
object's constructor as keyword arguments and they will be
passed along to the EC2Connection object.

:rtype: list
:return: A list of :class:`boto.ec2.regioninfo.RegionInfo`
"""
Expand All @@ -40,14 +44,14 @@ def regions(**kw_params):

def connect_to_region(region_name, **kw_params):
"""
Given a valid region name, return a
Given a valid region name, return a
:class:`boto.ec2.connection.EC2Connection`.
Any additional parameters after the region_name are passed on to
the connect method of the region object.

:type: str
:param region_name: The name of the region to connect to.

:rtype: :class:`boto.ec2.connection.EC2Connection` or ``None``
:return: A connection to the given region, or None if an invalid region
name is given
Expand All @@ -56,7 +60,7 @@ def connect_to_region(region_name, **kw_params):
if region.name == region_name:
return region.connect(**kw_params)
return None

def get_region(region_name, **kw_params):
"""
Find and return a :class:`boto.ec2.regioninfo.RegionInfo` object
Expand All @@ -73,4 +77,4 @@ def get_region(region_name, **kw_params):
if region.name == region_name:
return region
return None

10 changes: 3 additions & 7 deletions boto/ec2/buyreservation.py
Expand Up @@ -14,19 +14,15 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

import boto.ec2
from boto.sdb.db.property import StringProperty, IntegerProperty
from boto.manage import propget

InstanceTypes = ['m1.small', 'm1.large', 'm1.xlarge',
'c1.medium', 'c1.xlarge', 'm2.xlarge',
'm2.2xlarge', 'm2.4xlarge', 'cc1.4xlarge',
't1.micro']
from boto.ec2 import InstanceTypes

class BuyReservation(object):

Expand All @@ -52,7 +48,7 @@ def get_zone(self, params):
prop = StringProperty(name='zone', verbose_name='EC2 Availability Zone',
choices=self.ec2.get_all_zones)
params['zone'] = propget.get(prop)

def get(self, params):
self.get_region(params)
self.ec2 = params['region'].connect()
Expand Down
47 changes: 22 additions & 25 deletions boto/manage/server.py
Expand Up @@ -15,7 +15,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
Expand All @@ -35,10 +35,7 @@
import os, time, StringIO
from contextlib import closing
from boto.exception import EC2ResponseError

InstanceTypes = ['m1.small', 'm1.large', 'm1.xlarge',
'c1.medium', 'c1.xlarge',
'm2.2xlarge', 'm2.4xlarge']
from boto.ec2 import InstanceTypes

class Bundler(object):

Expand Down Expand Up @@ -134,7 +131,7 @@ def get_ami_list(self):
if ami.location.find('pyami') >= 0:
my_amis.append((ami.location, ami))
return my_amis

def get_region(self, params):
region = params.get('region', None)
if isinstance(region, str) or isinstance(region, unicode):
Expand Down Expand Up @@ -171,7 +168,7 @@ def get_zone(self, params):
prop = StringProperty(name='zone', verbose_name='EC2 Availability Zone',
choices=self.ec2.get_all_zones)
params['zone'] = propget.get(prop)

def get_ami_id(self, params):
valid = False
while not valid:
Expand Down Expand Up @@ -271,20 +268,20 @@ def create(cls, config_file=None, logical_volume = None, cfg = None, **params):
"""
Create a new instance based on the specified configuration file or the specified
configuration and the passed in parameters.
If the config_file argument is not None, the configuration is read from there.

If the config_file argument is not None, the configuration is read from there.
Otherwise, the cfg argument is used.

The config file may include other config files with a #import reference. The included
config files must reside in the same directory as the specified file.
The logical_volume argument, if supplied, will be used to get the current physical
volume ID and use that as an override of the value specified in the config file. This
may be useful for debugging purposes when you want to debug with a production config
file but a test Volume.
The dictionary argument may be used to override any EC2 configuration values in the
config file.
config files must reside in the same directory as the specified file.

The logical_volume argument, if supplied, will be used to get the current physical
volume ID and use that as an override of the value specified in the config file. This
may be useful for debugging purposes when you want to debug with a production config
file but a test Volume.

The dictionary argument may be used to override any EC2 configuration values in the
config file.
"""
if config_file:
cfg = Config(path=config_file)
Expand All @@ -304,7 +301,7 @@ def create(cls, config_file=None, logical_volume = None, cfg = None, **params):
zone = params.get('zone')
# deal with possibly passed in logical volume:
if logical_volume != None:
cfg.set('EBS', 'logical_volume_name', logical_volume.name)
cfg.set('EBS', 'logical_volume_name', logical_volume.name)
cfg_fp = StringIO.StringIO()
cfg.write(cfg_fp)
# deal with the possibility that zone and/or keypair are strings read from the config file:
Expand All @@ -328,7 +325,7 @@ def create(cls, config_file=None, logical_volume = None, cfg = None, **params):
print 'Waiting for instance to start so we can set its elastic IP address...'
# Sometimes we get a message from ec2 that says that the instance does not exist.
# Hopefully the following delay will giv eec2 enough time to get to a stable state:
time.sleep(5)
time.sleep(5)
while instance.update() != 'running':
time.sleep(1)
instance.use_ip(elastic_ip)
Expand All @@ -346,7 +343,7 @@ def create(cls, config_file=None, logical_volume = None, cfg = None, **params):
l.append(s)
i += 1
return l

@classmethod
def create_from_instance_id(cls, instance_id, name, description=''):
regions = boto.ec2.regions()
Expand Down Expand Up @@ -393,7 +390,7 @@ def create_from_current_instances(cls):
s.put()
servers.append(s)
return servers

def __init__(self, id=None, **kw):
Model.__init__(self, id, **kw)
self.ssh_key_file = None
Expand Down Expand Up @@ -421,7 +418,7 @@ def _setup_ec2(self):
self._instance = instance
except EC2ResponseError:
pass

def _status(self):
status = ''
if self._instance:
Expand Down Expand Up @@ -553,4 +550,4 @@ def install(self, pkg):
return self.run('apt-get -y install %s' % pkg)



15 changes: 7 additions & 8 deletions boto/mashups/order.py
Expand Up @@ -14,7 +14,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
Expand All @@ -30,11 +30,10 @@
from boto.pyami.config import Config
from boto.sdb.persist import get_domain, set_domain
import time, StringIO

InstanceTypes = ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge']
from boto.ec2 import InstanceTypes

class Item(IObject):

def __init__(self):
self.region = None
self.name = None
Expand Down Expand Up @@ -84,7 +83,7 @@ def set_zone(self, zone=None):
else:
l = [(z, z.name, z.state) for z in self.ec2.get_all_zones()]
self.zone = self.choose_from_list(l, prompt='Choose Availability Zone')

def set_ami(self, ami=None):
if ami:
self.ami = ami
Expand Down Expand Up @@ -172,7 +171,7 @@ def add_item(self, **params):

def display(self):
print 'This Order consists of the following items'
print
print
print 'QTY\tNAME\tTYPE\nAMI\t\tGroups\t\t\tKeyPair'
for item in self.items:
print '%s\t%s\t%s\t%s\t%s\t%s' % (item.quantity, item.name, item.instance_type,
Expand Down Expand Up @@ -206,6 +205,6 @@ def place(self, block=True):
return s[0]
else:
return s