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

Use 'describe-images' to get ami ids #364

Merged
merged 1 commit into from
Jul 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 34 additions & 49 deletions perfkitbenchmarker/aws/aws_virtual_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,6 @@
AP_SOUTHEAST_1 = 'ap-southeast-1'
AP_SOUTHEAST_2 = 'ap-southeast-2'
SA_EAST_1 = 'sa-east-1'
UBUNTU_AMIS = {
HVM: {
US_EAST_1: 'ami-acff23c4',
US_WEST_1: 'ami-05717d40',
US_WEST_2: 'ami-fbce8bcb',
EU_WEST_1: 'ami-30b46b47',
AP_NORTHEAST_1: 'ami-d186dcd0',
AP_SOUTHEAST_1: 'ami-9afca7c8',
AP_SOUTHEAST_2: 'ami-956706af',
SA_EAST_1: 'ami-9970d884',
},
PV: {
US_EAST_1: 'ami-d2ff23ba',
US_WEST_1: 'ami-73717d36',
US_WEST_2: 'ami-f1ce8bc1',
EU_WEST_1: 'ami-4ab46b3d',
AP_NORTHEAST_1: 'ami-c786dcc6',
AP_SOUTHEAST_1: 'ami-eefca7bc',
AP_SOUTHEAST_2: 'ami-996706a3',
SA_EAST_1: 'ami-6770d87a',
}
}
HVM_US_EAST_1_WINDOWS_AMI = 'ami-cc93a8a4'
PLACEMENT_GROUP_PREFIXES = frozenset(
['c3', 'c4', 'cc2', 'cg1', 'g2', 'cr1', 'r3', 'hi1', 'i2'])
NUM_LOCAL_VOLUMES = {
Expand Down Expand Up @@ -128,6 +105,8 @@ class AwsVirtualMachine(virtual_machine.BaseVirtualMachine):

DEFAULT_ZONE = 'us-east-1a'
DEFAULT_MACHINE_TYPE = 'm3.medium'
IMAGE_NAME_FILTER = None
DEFAULT_ROOT_DISK_TYPE = 'standard'

_lock = threading.Lock()
imported_keyfile_set = set()
Expand Down Expand Up @@ -158,13 +137,38 @@ def SetVmSpecDefaults(cls, vm_spec):
region = vm_spec.zone[:-1]
vm_spec.image = cls._GetDefaultImage(vm_spec.machine_type, region)

@staticmethod
def _GetDefaultImage(machine_type, region):
@classmethod
def _GetDefaultImage(cls, machine_type, region):
"""Returns the default image given the machine type and region.

If no default is configured, this will return None.
"""
return None
if cls.IMAGE_NAME_FILTER is None:
return None

prefix = machine_type.split('.')[0]
virt_type = 'paravirtual' if prefix in NON_HVM_PREFIXES else 'hvm'

describe_cmd = util.AWS_PREFIX + [
'--region=%s' % region,
'ec2',
'describe-images',
'--query', 'Images[*].{Name:Name,ImageId:ImageId}',
'--filters',
'Name=name,Values=%s' % cls.IMAGE_NAME_FILTER,
'Name=block-device-mapping.volume-type,Values=%s' %
cls.DEFAULT_ROOT_DISK_TYPE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be indented? Looks a bit odd, but I'll let flake8 decide.

'Name=virtualization-type,Values=%s' % virt_type]
stdout, _ = util.IssueRetryableCommand(describe_cmd)

if not stdout:
return None

images = json.loads(stdout)
# We want to return the latest version of the image, and since the wildcard
# portion of the image name is the image's creation date, we can just take
# the image with the 'largest' name.
return max(images, key=lambda image: image['Name'])['ImageId']

def ImportKeyfile(self):
"""Imports the public keyfile to AWS."""
Expand Down Expand Up @@ -322,18 +326,7 @@ def AddMetadata(self, **kwargs):

class DebianBasedAwsVirtualMachine(AwsVirtualMachine,
linux_virtual_machine.DebianMixin):

@staticmethod
def _GetDefaultImage(machine_type, region):
"""Returns the default image given the machine type and region.

If no default is configured, this will return None.
"""
prefix = machine_type.split('.')[0]
if prefix in NON_HVM_PREFIXES:
return UBUNTU_AMIS[PV][region]
else:
return UBUNTU_AMIS[HVM][region]
IMAGE_NAME_FILTER = 'ubuntu/images/*/ubuntu-trusty-14.04-amd64-*'


class RhelBasedAwsVirtualMachine(AwsVirtualMachine,
Expand All @@ -344,23 +337,15 @@ class RhelBasedAwsVirtualMachine(AwsVirtualMachine,
class WindowsAwsVirtualMachine(AwsVirtualMachine,
windows_virtual_machine.WindowsMixin):

IMAGE_NAME_FILTER = 'Windows_Server-2012-R2_RTM-English-64Bit-Core-*'
DEFAULT_ROOT_DISK_TYPE = 'gp2'

def __init__(self, vm_spec):
super(WindowsAwsVirtualMachine, self).__init__(vm_spec)
self.user_name = 'Administrator'
self.user_data = ('<powershell>%s</powershell>' %
windows_virtual_machine.STARTUP_SCRIPT)

@staticmethod
def _GetDefaultImage(machine_type, region):
"""Returns the default image given the machine type and region.

If no default is configured, this will return None.
"""
prefix = machine_type.split('.')[0]
if prefix in NON_HVM_PREFIXES or region != US_EAST_1:
return None
return HVM_US_EAST_1_WINDOWS_AMI

@vm_util.Retry()
def _GetDecodedPasswordData(self):
# Retreive a base64 encoded, encrypted password for the VM.
Expand Down