http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/ec2.py ---------------------------------------------------------------------- diff --git a/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/ec2.py b/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/ec2.py deleted file mode 100644 index f21b49e..0000000 --- a/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/ec2.py +++ /dev/null @@ -1,6773 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -""" -Amazon EC2, Eucalyptus, Nimbus and Outscale drivers. -""" - -import re -import sys -import base64 -import copy -import warnings - -try: - from lxml import etree as ET -except ImportError: - from xml.etree import ElementTree as ET - -from libcloud.utils.py3 import b, basestring, ensure_string - -from libcloud.utils.xml import fixxpath, findtext, findattr, findall -from libcloud.utils.publickey import get_pubkey_ssh2_fingerprint -from libcloud.utils.publickey import get_pubkey_comment -from libcloud.utils.iso8601 import parse_date -from libcloud.common.aws import AWSBaseResponse, SignedAWSConnection -from libcloud.common.aws import DEFAULT_SIGNATURE_VERSION -from libcloud.common.types import (InvalidCredsError, MalformedResponseError, - LibcloudError) -from libcloud.compute.providers import Provider -from libcloud.compute.base import Node, NodeDriver, NodeLocation, NodeSize -from libcloud.compute.base import NodeImage, StorageVolume, VolumeSnapshot -from libcloud.compute.base import KeyPair -from libcloud.compute.types import NodeState, KeyPairDoesNotExistError, \ - StorageVolumeState, VolumeSnapshotState - -__all__ = [ - 'API_VERSION', - 'NAMESPACE', - 'INSTANCE_TYPES', - 'OUTSCALE_INSTANCE_TYPES', - 'OUTSCALE_SAS_REGION_DETAILS', - 'OUTSCALE_INC_REGION_DETAILS', - 'DEFAULT_EUCA_API_VERSION', - 'EUCA_NAMESPACE', - - 'EC2NodeDriver', - 'BaseEC2NodeDriver', - - 'NimbusNodeDriver', - 'EucNodeDriver', - - 'OutscaleSASNodeDriver', - 'OutscaleINCNodeDriver', - - 'EC2NodeLocation', - 'EC2ReservedNode', - 'EC2SecurityGroup', - 'EC2PlacementGroup', - 'EC2Network', - 'EC2NetworkSubnet', - 'EC2NetworkInterface', - 'EC2RouteTable', - 'EC2Route', - 'EC2SubnetAssociation', - 'ExEC2AvailabilityZone', - - 'IdempotentParamError' -] - -API_VERSION = '2013-10-15' -NAMESPACE = 'http://ec2.amazonaws.com/doc/%s/' % (API_VERSION) - -# Eucalyptus Constants -DEFAULT_EUCA_API_VERSION = '3.3.0' -EUCA_NAMESPACE = 'http://msgs.eucalyptus.com/%s' % (DEFAULT_EUCA_API_VERSION) - -""" -Sizes must be hardcoded, because Amazon doesn't provide an API to fetch them. -From http://aws.amazon.com/ec2/instance-types/ -and <http://aws.amazon.com/ec2/previous-generation/> -ram = [MiB], disk = [GB] -""" - - -def GiB(value): - return int(value * 1024) - - -INSTANCE_TYPES = { - 't1.micro': { - 'id': 't1.micro', - 'name': 'Micro Instance', - 'ram': GiB(0.613), - 'disk': 15, # GB - 'bandwidth': None - }, - 'm1.small': { - 'id': 'm1.small', - 'name': 'Small Instance', - 'ram': GiB(1.7), - 'disk': 160, # GB - 'bandwidth': None - }, - 'm1.medium': { - 'id': 'm1.medium', - 'name': 'Medium Instance', - 'ram': GiB(3.75), - 'disk': 410, # GB - 'bandwidth': None - }, - 'm1.large': { - 'id': 'm1.large', - 'name': 'Large Instance', - 'ram': GiB(7.5), - 'disk': 2 * 420, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 2 - } - }, - 'm1.xlarge': { - 'id': 'm1.xlarge', - 'name': 'Extra Large Instance', - 'ram': GiB(15), - 'disk': 4 * 420, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 4 - } - }, - 'c1.medium': { - 'id': 'c1.medium', - 'name': 'High-CPU Medium Instance', - 'ram': GiB(1.7), - 'disk': 350, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 2 - } - }, - 'c1.xlarge': { - 'id': 'c1.xlarge', - 'name': 'High-CPU Extra Large Instance', - 'ram': GiB(7), - 'disk': 4 * 420, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 8 - } - }, - 'm2.xlarge': { - 'id': 'm2.xlarge', - 'name': 'High-Memory Extra Large Instance', - 'ram': GiB(17.1), - 'disk': 420, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 2 - } - }, - 'm2.2xlarge': { - 'id': 'm2.2xlarge', - 'name': 'High-Memory Double Extra Large Instance', - 'ram': GiB(34.2), - 'disk': 850, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 4 - } - }, - 'm2.4xlarge': { - 'id': 'm2.4xlarge', - 'name': 'High-Memory Quadruple Extra Large Instance', - 'ram': GiB(68.4), - 'disk': 2 * 840, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 8 - } - }, - 'm3.medium': { - 'id': 'm3.medium', - 'name': 'Medium Instance', - 'ram': GiB(3.75), - 'disk': 4, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 1 - } - }, - 'm3.large': { - 'id': 'm3.large', - 'name': 'Large Instance', - 'ram': GiB(7.5), - 'disk': 32, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 2 - } - }, - 'm3.xlarge': { - 'id': 'm3.xlarge', - 'name': 'Extra Large Instance', - 'ram': GiB(15), - 'disk': 2 * 40, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 4 - } - }, - 'm3.2xlarge': { - 'id': 'm3.2xlarge', - 'name': 'Double Extra Large Instance', - 'ram': GiB(30), - 'disk': 2 * 80, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 8 - } - }, - 'm4.large': { - 'id': 'm4.large', - 'name': 'Large Instance', - 'ram': GiB(8), - 'disk': 0, # EBS only - 'bandwidth': None, - 'extra': { - 'cpu': 2 - } - }, - 'm4.xlarge': { - 'id': 'm4.xlarge', - 'name': 'Extra Large Instance', - 'ram': GiB(16), - 'disk': 0, # EBS only - 'bandwidth': None, - 'extra': { - 'cpu': 4 - } - }, - 'm4.2xlarge': { - 'id': 'm4.2xlarge', - 'name': 'Double Extra Large Instance', - 'ram': GiB(32), - 'disk': 0, # EBS only - 'bandwidth': None, - 'extra': { - 'cpu': 8 - } - }, - 'm4.4xlarge': { - 'id': 'm4.4xlarge', - 'name': 'Quadruple Extra Large Instance', - 'ram': GiB(64), - 'disk': 0, # EBS only - 'bandwidth': None, - 'extra': { - 'cpu': 16 - } - }, - 'm4.10xlarge': { - 'id': 'm4.10xlarge', - 'name': '10 Extra Large Instance', - 'ram': GiB(160), - 'disk': 0, # EBS only - 'bandwidth': None, - 'extra': { - 'cpu': 40 - } - }, - 'cg1.4xlarge': { - 'id': 'cg1.4xlarge', - 'name': 'Cluster GPU Quadruple Extra Large Instance', - 'ram': GiB(22.5), - 'disk': 2 * 840, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 16 - } - }, - 'g2.2xlarge': { - 'id': 'g2.2xlarge', - 'name': 'Cluster GPU G2 Double Extra Large Instance', - 'ram': GiB(15), - 'disk': 60, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 8 - } - }, - 'g2.8xlarge': { - 'id': 'g2.8xlarge', - 'name': 'Cluster GPU G2 Eight Extra Large Instance', - 'ram': GiB(60), - 'disk': 2 * 120, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 32 - } - }, - 'cc1.4xlarge': { - 'id': 'cc1.4xlarge', - 'name': 'Cluster Compute Quadruple Extra Large Instance', - 'ram': 23552, - 'disk': 1690, - 'bandwidth': None - }, - 'cc2.8xlarge': { - 'id': 'cc2.8xlarge', - 'name': 'Cluster Compute Eight Extra Large Instance', - 'ram': GiB(60.5), - 'disk': 4 * 840, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 32 - } - }, - # c3 instances have 2 SSDs of the specified disk size - 'c3.large': { - 'id': 'c3.large', - 'name': 'Compute Optimized Large Instance', - 'ram': GiB(3.75), - 'disk': 2 * 16, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 2 - } - }, - 'c3.xlarge': { - 'id': 'c3.xlarge', - 'name': 'Compute Optimized Extra Large Instance', - 'ram': GiB(7.5), - 'disk': 2 * 40, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 4 - } - }, - 'c3.2xlarge': { - 'id': 'c3.2xlarge', - 'name': 'Compute Optimized Double Extra Large Instance', - 'ram': GiB(15), - 'disk': 2 * 80, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 8 - } - }, - 'c3.4xlarge': { - 'id': 'c3.4xlarge', - 'name': 'Compute Optimized Quadruple Extra Large Instance', - 'ram': GiB(30), - 'disk': 2 * 160, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 16 - } - }, - 'c3.8xlarge': { - 'id': 'c3.8xlarge', - 'name': 'Compute Optimized Eight Extra Large Instance', - 'ram': GiB(60), - 'disk': 2 * 320, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 32 - } - }, - 'c4.large': { - 'id': 'c4.large', - 'name': 'Compute Optimized Large Instance', - 'ram': GiB(3.75), - 'disk': 0, # EBS only - 'bandwidth': None, - 'extra': { - 'cpu': 2 - } - }, - 'c4.xlarge': { - 'id': 'c4.xlarge', - 'name': 'Compute Optimized Extra Large Instance', - 'ram': GiB(7.5), - 'disk': 0, # EBS only - 'bandwidth': None, - 'extra': { - 'cpu': 4 - } - }, - 'c4.2xlarge': { - 'id': 'c4.2xlarge', - 'name': 'Compute Optimized Double Large Instance', - 'ram': GiB(15), - 'disk': 0, # EBS only - 'bandwidth': None, - 'extra': { - 'cpu': 8 - } - }, - 'c4.4xlarge': { - 'id': 'c4.4xlarge', - 'name': 'Compute Optimized Quadruple Extra Large Instance', - 'ram': GiB(30), - 'disk': 0, # EBS only - 'bandwidth': None, - 'extra': { - 'cpu': 16 - } - }, - 'c4.8xlarge': { - 'id': 'c4.8xlarge', - 'name': 'Compute Optimized Eight Extra Large Instance', - 'ram': GiB(60), - 'disk': 0, # EBS only - 'bandwidth': None, - 'extra': { - 'cpu': 32 - } - }, - 'cr1.8xlarge': { - 'id': 'cr1.8xlarge', - 'name': 'High Memory Cluster Eight Extra Large', - 'ram': GiB(244), - 'disk': 2 * 120, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 32 - } - }, - 'hs1.4xlarge': { - 'id': 'hs1.4xlarge', - 'name': 'High Storage Quadruple Extra Large Instance', - 'ram': GiB(64), - 'disk': 2 * 1024, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 16 - } - }, - 'hs1.8xlarge': { - 'id': 'hs1.8xlarge', - 'name': 'High Storage Eight Extra Large Instance', - 'ram': GiB(117), - 'disk': 24 * 2000, - 'bandwidth': None, - 'extra': { - 'cpu': 17 - } - }, - # i2 instances have up to eight SSD drives - 'i2.xlarge': { - 'id': 'i2.xlarge', - 'name': 'High I/O Storage Optimized Extra Large Instance', - 'ram': GiB(30.5), - 'disk': 800, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 4 - } - }, - 'i2.2xlarge': { - 'id': 'i2.2xlarge', - 'name': 'High I/O Storage Optimized Double Extra Large Instance', - 'ram': GiB(61), - 'disk': 2 * 800, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 8 - } - }, - 'i2.4xlarge': { - 'id': 'i2.4xlarge', - 'name': 'High I/O Storage Optimized Quadruple Large Instance', - 'ram': GiB(122), - 'disk': 4 * 800, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 16 - } - }, - 'i2.8xlarge': { - 'id': 'i2.8xlarge', - 'name': 'High I/O Storage Optimized Eight Extra Large Instance', - 'ram': GiB(244), - 'disk': 8 * 800, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 32 - } - }, - 'd2.xlarge': { - 'id': 'd2.xlarge', - 'name': 'Dense Storage Optimized Extra Large Instance', - 'ram': GiB(30.5), - 'disk': 3 * 2000, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 4 - } - }, - 'd2.2xlarge': { - 'id': 'd2.2xlarge', - 'name': 'Dense Storage Optimized Double Extra Large Instance', - 'ram': GiB(61), - 'disk': 6 * 2000, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 8 - } - }, - 'd2.4xlarge': { - 'id': 'd2.4xlarge', - 'name': 'Dense Storage Optimized Quadruple Extra Large Instance', - 'ram': GiB(122), - 'disk': 12 * 2000, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 16 - } - }, - 'd2.8xlarge': { - 'id': 'd2.8xlarge', - 'name': 'Dense Storage Optimized Eight Extra Large Instance', - 'ram': GiB(244), - 'disk': 24 * 2000, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 36 - } - }, - # 1x SSD - 'r3.large': { - 'id': 'r3.large', - 'name': 'Memory Optimized Large instance', - 'ram': GiB(15.25), - 'disk': 32, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 2 - } - }, - 'r3.xlarge': { - 'id': 'r3.xlarge', - 'name': 'Memory Optimized Extra Large instance', - 'ram': GiB(30.5), - 'disk': 80, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 4 - } - }, - 'r3.2xlarge': { - 'id': 'r3.2xlarge', - 'name': 'Memory Optimized Double Extra Large instance', - 'ram': GiB(61), - 'disk': 160, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 8 - } - }, - 'r3.4xlarge': { - 'id': 'r3.4xlarge', - 'name': 'Memory Optimized Quadruple Extra Large instance', - 'ram': GiB(122), - 'disk': 320, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 16 - } - }, - 'r3.8xlarge': { - 'id': 'r3.8xlarge', - 'name': 'Memory Optimized Eight Extra Large instance', - 'ram': GiB(244), - 'disk': 2 * 320, # GB - 'bandwidth': None, - 'extra': { - 'cpu': 32 - } - }, - # Burstable Performance General Purpose - 't2.nano': { - 'id': 't2.nano', - 'name': 'Burstable Performance Nano Instance', - 'ram': 512, - 'disk': 0, # EBS Only - 'bandwidth': None, - 'extra': { - 'cpu': 1 - } - }, - 't2.micro': { - 'id': 't2.micro', - 'name': 'Burstable Performance Micro Instance', - 'ram': GiB(1), - 'disk': 0, # EBS Only - 'bandwidth': None, - 'extra': { - 'cpu': 1 - } - }, - 't2.small': { - 'id': 't2.small', - 'name': 'Burstable Performance Small Instance', - 'ram': GiB(2), - 'disk': 0, # EBS Only - 'bandwidth': None, - 'extra': { - 'cpu': 11 - } - }, - 't2.medium': { - 'id': 't2.medium', - 'name': 'Burstable Performance Medium Instance', - 'ram': GiB(4), - 'disk': 0, # EBS Only - 'bandwidth': None, - 'extra': { - 'cpu': 2 - } - }, - 't2.large': { - 'id': 't2.large', - 'name': 'Burstable Performance Medium Instance', - 'ram': GiB(8), - 'disk': 0, # EBS Only - 'bandwidth': None, - 'extra': { - 'cpu': 2 - } - } -} - -# From <https://aws.amazon.com/marketplace/help/200777880> -REGION_DETAILS = { - # US East (Northern Virginia) Region - 'us-east-1': { - 'endpoint': 'ec2.us-east-1.amazonaws.com', - 'api_name': 'ec2_us_east', - 'country': 'USA', - 'signature_version': '2', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'm3.medium', - 'm3.large', - 'm3.xlarge', - 'm3.2xlarge', - 'm4.large', - 'm4.xlarge', - 'm4.2xlarge', - 'm4.4xlarge', - 'm4.10xlarge', - 'c1.medium', - 'c1.xlarge', - 'cc2.8xlarge', - 'c3.large', - 'c3.xlarge', - 'c3.2xlarge', - 'c3.4xlarge', - 'c3.8xlarge', - 'c4.large', - 'c4.xlarge', - 'c4.2xlarge', - 'c4.4xlarge', - 'c4.8xlarge', - 'cg1.4xlarge', - 'g2.2xlarge', - 'g2.8xlarge', - 'cr1.8xlarge', - 'hs1.8xlarge', - 'i2.xlarge', - 'i2.2xlarge', - 'i2.4xlarge', - 'i2.8xlarge', - 'd2.xlarge', - 'd2.2xlarge', - 'd2.4xlarge', - 'd2.8xlarge', - 'r3.large', - 'r3.xlarge', - 'r3.2xlarge', - 'r3.4xlarge', - 'r3.8xlarge', - 't2.nano', - 't2.micro', - 't2.small', - 't2.medium', - 't2.large' - ] - }, - # US West (Northern California) Region - 'us-west-1': { - 'endpoint': 'ec2.us-west-1.amazonaws.com', - 'api_name': 'ec2_us_west', - 'country': 'USA', - 'signature_version': '2', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'm3.medium', - 'm3.large', - 'm3.xlarge', - 'm3.2xlarge', - 'm4.large', - 'm4.xlarge', - 'm4.2xlarge', - 'm4.4xlarge', - 'm4.10xlarge', - 'c1.medium', - 'c1.xlarge', - 'g2.2xlarge', - 'g2.8xlarge', - 'c3.large', - 'c3.xlarge', - 'c3.2xlarge', - 'c3.4xlarge', - 'c3.8xlarge', - 'c4.large', - 'c4.xlarge', - 'c4.2xlarge', - 'c4.4xlarge', - 'c4.8xlarge', - 'i2.xlarge', - 'i2.2xlarge', - 'i2.4xlarge', - 'i2.8xlarge', - 'r3.large', - 'r3.xlarge', - 'r3.2xlarge', - 'r3.4xlarge', - 'r3.8xlarge', - 't2.nano', - 't2.micro', - 't2.small', - 't2.medium', - 't2.large' - ] - }, - # US West (Oregon) Region - 'us-west-2': { - 'endpoint': 'ec2.us-west-2.amazonaws.com', - 'api_name': 'ec2_us_west_oregon', - 'country': 'US', - 'signature_version': '2', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'm3.medium', - 'm3.large', - 'm3.xlarge', - 'm3.2xlarge', - 'm4.large', - 'm4.xlarge', - 'm4.2xlarge', - 'm4.4xlarge', - 'm4.10xlarge', - 'c1.medium', - 'c1.xlarge', - 'g2.2xlarge', - 'g2.8xlarge', - 'c3.large', - 'c3.xlarge', - 'c3.2xlarge', - 'c3.4xlarge', - 'c3.8xlarge', - 'c4.large', - 'c4.xlarge', - 'c4.2xlarge', - 'c4.4xlarge', - 'c4.8xlarge', - 'hs1.8xlarge', - 'cc2.8xlarge', - 'i2.xlarge', - 'i2.2xlarge', - 'i2.4xlarge', - 'i2.8xlarge', - 'd2.xlarge', - 'd2.2xlarge', - 'd2.4xlarge', - 'd2.8xlarge', - 'r3.large', - 'r3.xlarge', - 'r3.2xlarge', - 'r3.4xlarge', - 'r3.8xlarge', - 't2.nano', - 't2.micro', - 't2.small', - 't2.medium', - 't2.large' - ] - }, - # EU (Ireland) Region - 'eu-west-1': { - 'endpoint': 'ec2.eu-west-1.amazonaws.com', - 'api_name': 'ec2_eu_west', - 'country': 'Ireland', - 'signature_version': '2', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'm3.medium', - 'm3.large', - 'm3.xlarge', - 'm3.2xlarge', - 'm4.large', - 'm4.xlarge', - 'm4.2xlarge', - 'm4.4xlarge', - 'm4.10xlarge', - 'c1.medium', - 'c1.xlarge', - 'g2.2xlarge', - 'g2.8xlarge', - 'c3.large', - 'c3.xlarge', - 'c3.2xlarge', - 'c3.4xlarge', - 'c3.8xlarge', - 'c4.large', - 'c4.xlarge', - 'c4.2xlarge', - 'c4.4xlarge', - 'c4.8xlarge', - 'hs1.8xlarge', - 'cc2.8xlarge', - 'i2.xlarge', - 'i2.2xlarge', - 'i2.4xlarge', - 'i2.8xlarge', - 'd2.xlarge', - 'd2.2xlarge', - 'd2.4xlarge', - 'd2.8xlarge', - 'r3.large', - 'r3.xlarge', - 'r3.2xlarge', - 'r3.4xlarge', - 'r3.8xlarge', - 't2.nano', - 't2.micro', - 't2.small', - 't2.medium', - 't2.large' - ] - }, - # EU (Frankfurt) Region - 'eu-central-1': { - 'endpoint': 'ec2.eu-central-1.amazonaws.com', - 'api_name': 'ec2_eu_central', - 'country': 'Frankfurt', - 'signature_version': '4', - 'instance_types': [ - 'm3.medium', - 'm3.large', - 'm3.xlarge', - 'm3.2xlarge', - 'c3.large', - 'c3.xlarge', - 'c3.2xlarge', - 'c3.4xlarge', - 'c4.large', - 'c4.xlarge', - 'c4.2xlarge', - 'c4.4xlarge', - 'c4.8xlarge', - 'm4.large', - 'm4.xlarge', - 'm4.2xlarge', - 'm4.4xlarge', - 'm4.10xlarge', - 'c3.8xlarge', - 'i2.xlarge', - 'i2.2xlarge', - 'i2.4xlarge', - 'i2.8xlarge', - 'd2.xlarge', - 'd2.2xlarge', - 'd2.4xlarge', - 'd2.8xlarge', - 'r3.large', - 'r3.xlarge', - 'r3.2xlarge', - 'r3.4xlarge', - 'r3.8xlarge', - 't2.micro', - 't2.small', - 't2.medium', - 't2.large' - ] - }, - # Asia Pacific (Singapore) Region - 'ap-southeast-1': { - 'endpoint': 'ec2.ap-southeast-1.amazonaws.com', - 'api_name': 'ec2_ap_southeast', - 'country': 'Singapore', - 'signature_version': '2', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'm3.medium', - 'm3.large', - 'm3.xlarge', - 'm3.2xlarge', - 'm4.large', - 'm4.xlarge', - 'm4.2xlarge', - 'm4.4xlarge', - 'm4.10xlarge', - 'c1.medium', - 'c1.xlarge', - 'c3.large', - 'c3.xlarge', - 'c3.2xlarge', - 'c3.4xlarge', - 'c3.8xlarge', - 'c4.large', - 'c4.xlarge', - 'c4.2xlarge', - 'c4.4xlarge', - 'c4.8xlarge', - 'hs1.8xlarge', - 'i2.xlarge', - 'i2.2xlarge', - 'i2.4xlarge', - 'i2.8xlarge', - 'd2.xlarge', - 'd2.2xlarge', - 'd2.4xlarge', - 'd2.8xlarge', - 't2.nano', - 't2.micro', - 't2.small', - 't2.medium', - 't2.large' - ] - }, - # Asia Pacific (Tokyo) Region - 'ap-northeast-1': { - 'endpoint': 'ec2.ap-northeast-1.amazonaws.com', - 'api_name': 'ec2_ap_northeast', - 'country': 'Japan', - 'signature_version': '2', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'm3.medium', - 'm3.large', - 'm3.xlarge', - 'm3.2xlarge', - 'c1.medium', - 'g2.2xlarge', - 'g2.8xlarge', - 'c1.xlarge', - 'c3.large', - 'c3.xlarge', - 'c3.2xlarge', - 'c3.4xlarge', - 'c3.8xlarge', - 'c4.large', - 'c4.xlarge', - 'c4.2xlarge', - 'c4.4xlarge', - 'c4.8xlarge', - 'm4.large', - 'm4.xlarge', - 'm4.2xlarge', - 'm4.4xlarge', - 'm4.10xlarge', - 'hs1.8xlarge', - 'i2.xlarge', - 'i2.2xlarge', - 'i2.4xlarge', - 'i2.8xlarge', - 'd2.xlarge', - 'd2.2xlarge', - 'd2.4xlarge', - 'd2.8xlarge', - 'r3.large', - 'r3.xlarge', - 'r3.2xlarge', - 'r3.4xlarge', - 'r3.8xlarge', - 't2.nano', - 't2.micro', - 't2.small', - 't2.medium', - 't2.large' - ] - }, - # Asia Pacific (Seoul) Region - 'ap-northeast-2': { - 'endpoint': 'ec2.ap-northeast-2.amazonaws.com', - 'api_name': 'ec2_ap_northeast', - 'country': 'South Korea', - 'signature_version': '4', - 'instance_types': [ - 'c4.large', - 'c4.xlarge', - 'c4.2xlarge', - 'c4.4xlarge', - 'c4.8xlarge', - 'm4.large', - 'm4.xlarge', - 'm4.2xlarge', - 'm4.4xlarge', - 'm4.10xlarge', - 'i2.xlarge', - 'i2.2xlarge', - 'i2.4xlarge', - 'i2.8xlarge', - 'd2.xlarge', - 'd2.2xlarge', - 'd2.4xlarge', - 'd2.8xlarge', - 'r3.large', - 'r3.xlarge', - 'r3.2xlarge', - 'r3.4xlarge', - 'r3.8xlarge', - 't2.nano', - 't2.micro', - 't2.small', - 't2.medium', - 't2.large' - ] - }, - # South America (Sao Paulo) Region - 'sa-east-1': { - 'endpoint': 'ec2.sa-east-1.amazonaws.com', - 'api_name': 'ec2_sa_east', - 'country': 'Brazil', - 'signature_version': '2', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'm3.medium', - 'm3.large', - 'm3.xlarge', - 'm3.2xlarge', - 'c1.medium', - 'c1.xlarge', - 't2.nano', - 't2.micro', - 't2.small', - 't2.medium', - 't2.large' - ] - }, - # Asia Pacific (Sydney) Region - 'ap-southeast-2': { - 'endpoint': 'ec2.ap-southeast-2.amazonaws.com', - 'api_name': 'ec2_ap_southeast_2', - 'country': 'Australia', - 'signature_version': '2', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'm3.medium', - 'm3.large', - 'm3.xlarge', - 'm3.2xlarge', - 'm4.large', - 'm4.xlarge', - 'm4.2xlarge', - 'm4.4xlarge', - 'm4.10xlarge', - 'c1.medium', - 'c1.xlarge', - 'c3.large', - 'c3.xlarge', - 'c3.2xlarge', - 'c3.4xlarge', - 'c3.8xlarge', - 'c4.large', - 'c4.xlarge', - 'c4.2xlarge', - 'c4.4xlarge', - 'c4.8xlarge', - 'hs1.8xlarge', - 'i2.xlarge', - 'i2.2xlarge', - 'i2.4xlarge', - 'i2.8xlarge', - 'd2.xlarge', - 'd2.2xlarge', - 'd2.4xlarge', - 'd2.8xlarge', - 'r3.large', - 'r3.xlarge', - 'r3.2xlarge', - 'r3.4xlarge', - 'r3.8xlarge', - 't2.micro', - 't2.small', - 't2.medium', - 't2.large' - ] - }, - 'us-gov-west-1': { - 'endpoint': 'ec2.us-gov-west-1.amazonaws.com', - 'api_name': 'ec2_us_govwest', - 'country': 'US', - 'signature_version': '2', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'm3.medium', - 'm3.large', - 'm3.xlarge', - 'm3.2xlarge', - 'c1.medium', - 'c1.xlarge', - 'g2.2xlarge', - 'g2.8xlarge', - 'c3.large', - 'c3.xlarge', - 'c3.2xlarge', - 'c3.4xlarge', - 'c3.8xlarge', - 'c4.large', - 'c4.xlarge', - 'c4.2xlarge', - 'c4.4xlarge', - 'c4.8xlarge', - 'hs1.4xlarge', - 'hs1.8xlarge', - 'i2.xlarge', - 'i2.2xlarge', - 'i2.4xlarge', - 'i2.8xlarge', - 'r3.large', - 'r3.xlarge', - 'r3.2xlarge', - 'r3.4xlarge', - 'r3.8xlarge', - 't2.nano', - 't2.micro', - 't2.small', - 't2.medium', - 't2.large' - ] - }, - 'nimbus': { - # Nimbus clouds have 3 EC2-style instance types but their particular - # RAM allocations are configured by the admin - 'country': 'custom', - 'signature_version': '2', - 'instance_types': [ - 'm1.small', - 'm1.large', - 'm1.xlarge' - ] - } -} - - -""" -Sizes must be hardcoded because Outscale doesn't provide an API to fetch them. -Outscale cloud instances share some names with EC2 but have different -specifications so declare them in another constant. -""" -OUTSCALE_INSTANCE_TYPES = { - 't1.micro': { - 'id': 't1.micro', - 'name': 'Micro Instance', - 'ram': 615, - 'disk': 0, - 'bandwidth': None - }, - 'm1.small': { - 'id': 'm1.small', - 'name': 'Standard Small Instance', - 'ram': 1740, - 'disk': 150, - 'bandwidth': None - }, - 'm1.medium': { - 'id': 'm1.medium', - 'name': 'Standard Medium Instance', - 'ram': 3840, - 'disk': 420, - 'bandwidth': None - }, - 'm1.large': { - 'id': 'm1.large', - 'name': 'Standard Large Instance', - 'ram': 7680, - 'disk': 840, - 'bandwidth': None - }, - 'm1.xlarge': { - 'id': 'm1.xlarge', - 'name': 'Standard Extra Large Instance', - 'ram': 15360, - 'disk': 1680, - 'bandwidth': None - }, - 'c1.medium': { - 'id': 'c1.medium', - 'name': 'Compute Optimized Medium Instance', - 'ram': 1740, - 'disk': 340, - 'bandwidth': None - }, - 'c1.xlarge': { - 'id': 'c1.xlarge', - 'name': 'Compute Optimized Extra Large Instance', - 'ram': 7168, - 'disk': 1680, - 'bandwidth': None - }, - 'c3.large': { - 'id': 'c3.large', - 'name': 'Compute Optimized Large Instance', - 'ram': 3840, - 'disk': 32, - 'bandwidth': None - }, - 'c3.xlarge': { - 'id': 'c3.xlarge', - 'name': 'Compute Optimized Extra Large Instance', - 'ram': 7168, - 'disk': 80, - 'bandwidth': None - }, - 'c3.2xlarge': { - 'id': 'c3.2xlarge', - 'name': 'Compute Optimized Double Extra Large Instance', - 'ram': 15359, - 'disk': 160, - 'bandwidth': None - }, - 'c3.4xlarge': { - 'id': 'c3.4xlarge', - 'name': 'Compute Optimized Quadruple Extra Large Instance', - 'ram': 30720, - 'disk': 320, - 'bandwidth': None - }, - 'c3.8xlarge': { - 'id': 'c3.8xlarge', - 'name': 'Compute Optimized Eight Extra Large Instance', - 'ram': 61440, - 'disk': 640, - 'bandwidth': None - }, - 'm2.xlarge': { - 'id': 'm2.xlarge', - 'name': 'High Memory Extra Large Instance', - 'ram': 17510, - 'disk': 420, - 'bandwidth': None - }, - 'm2.2xlarge': { - 'id': 'm2.2xlarge', - 'name': 'High Memory Double Extra Large Instance', - 'ram': 35020, - 'disk': 840, - 'bandwidth': None - }, - 'm2.4xlarge': { - 'id': 'm2.4xlarge', - 'name': 'High Memory Quadruple Extra Large Instance', - 'ram': 70042, - 'disk': 1680, - 'bandwidth': None - }, - 'nv1.small': { - 'id': 'nv1.small', - 'name': 'GPU Small Instance', - 'ram': 1739, - 'disk': 150, - 'bandwidth': None - }, - 'nv1.medium': { - 'id': 'nv1.medium', - 'name': 'GPU Medium Instance', - 'ram': 3839, - 'disk': 420, - 'bandwidth': None - }, - 'nv1.large': { - 'id': 'nv1.large', - 'name': 'GPU Large Instance', - 'ram': 7679, - 'disk': 840, - 'bandwidth': None - }, - 'nv1.xlarge': { - 'id': 'nv1.xlarge', - 'name': 'GPU Extra Large Instance', - 'ram': 15358, - 'disk': 1680, - 'bandwidth': None - }, - 'g2.2xlarge': { - 'id': 'g2.2xlarge', - 'name': 'GPU Double Extra Large Instance', - 'ram': 15360, - 'disk': 60, - 'bandwidth': None - }, - 'cc1.4xlarge': { - 'id': 'cc1.4xlarge', - 'name': 'Cluster Compute Quadruple Extra Large Instance', - 'ram': 24576, - 'disk': 1680, - 'bandwidth': None - }, - 'cc2.8xlarge': { - 'id': 'cc2.8xlarge', - 'name': 'Cluster Compute Eight Extra Large Instance', - 'ram': 65536, - 'disk': 3360, - 'bandwidth': None - }, - 'hi1.xlarge': { - 'id': 'hi1.xlarge', - 'name': 'High Storage Extra Large Instance', - 'ram': 15361, - 'disk': 1680, - 'bandwidth': None - }, - 'm3.xlarge': { - 'id': 'm3.xlarge', - 'name': 'High Storage Optimized Extra Large Instance', - 'ram': 15357, - 'disk': 0, - 'bandwidth': None - }, - 'm3.2xlarge': { - 'id': 'm3.2xlarge', - 'name': 'High Storage Optimized Double Extra Large Instance', - 'ram': 30720, - 'disk': 0, - 'bandwidth': None - }, - 'm3s.xlarge': { - 'id': 'm3s.xlarge', - 'name': 'High Storage Optimized Extra Large Instance', - 'ram': 15359, - 'disk': 0, - 'bandwidth': None - }, - 'm3s.2xlarge': { - 'id': 'm3s.2xlarge', - 'name': 'High Storage Optimized Double Extra Large Instance', - 'ram': 30719, - 'disk': 0, - 'bandwidth': None - }, - 'cr1.8xlarge': { - 'id': 'cr1.8xlarge', - 'name': 'Memory Optimized Eight Extra Large Instance', - 'ram': 249855, - 'disk': 240, - 'bandwidth': None - }, - 'os1.2xlarge': { - 'id': 'os1.2xlarge', - 'name': 'Memory Optimized, High Storage, Passthrough NIC Double Extra ' - 'Large Instance', - 'ram': 65536, - 'disk': 60, - 'bandwidth': None - }, - 'os1.4xlarge': { - 'id': 'os1.4xlarge', - 'name': 'Memory Optimized, High Storage, Passthrough NIC Quadruple Ext' - 'ra Large Instance', - 'ram': 131072, - 'disk': 120, - 'bandwidth': None - }, - 'os1.8xlarge': { - 'id': 'os1.8xlarge', - 'name': 'Memory Optimized, High Storage, Passthrough NIC Eight Extra L' - 'arge Instance', - 'ram': 249856, - 'disk': 500, - 'bandwidth': None - }, - 'oc1.4xlarge': { - 'id': 'oc1.4xlarge', - 'name': 'Outscale Quadruple Extra Large Instance', - 'ram': 24575, - 'disk': 1680, - 'bandwidth': None - }, - 'oc2.8xlarge': { - 'id': 'oc2.8xlarge', - 'name': 'Outscale Eight Extra Large Instance', - 'ram': 65535, - 'disk': 3360, - 'bandwidth': None - } -} - - -""" -The function manipulating Outscale cloud regions will be overridden because -Outscale instances types are in a separate dict so also declare Outscale cloud -regions in some other constants. -""" -OUTSCALE_SAS_REGION_DETAILS = { - 'eu-west-3': { - 'endpoint': 'api-ppd.outscale.com', - 'api_name': 'osc_sas_eu_west_3', - 'country': 'FRANCE', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - }, - 'eu-west-1': { - 'endpoint': 'api.eu-west-1.outscale.com', - 'api_name': 'osc_sas_eu_west_1', - 'country': 'FRANCE', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - }, - 'eu-west-2': { - 'endpoint': 'fcu.eu-west-2.outscale.com', - 'api_name': 'osc_sas_eu_west_2', - 'country': 'FRANCE', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - }, - 'us-east-1': { - 'endpoint': 'api.us-east-1.outscale.com', - 'api_name': 'osc_sas_us_east_1', - 'country': 'USA', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - }, - 'us-east-2': { - 'endpoint': 'fcu.us-east-2.outscale.com', - 'api_name': 'osc_sas_us_east_2', - 'country': 'USA', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - }, - 'us-east-2': { - 'endpoint': 'fcu.us-east-2.outscale.com', - 'api_name': 'osc_sas_us_east_2', - 'country': 'USA', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - }, - 'us-east-2': { - 'endpoint': 'fcu.us-east-2.outscale.com', - 'api_name': 'osc_sas_us_east_2', - 'country': 'USA', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - }, - 'us-east-2': { - 'endpoint': 'fcu.us-east-2.outscale.com', - 'api_name': 'osc_sas_us_east_2', - 'country': 'USA', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - } -} - - -OUTSCALE_INC_REGION_DETAILS = { - 'eu-west-1': { - 'endpoint': 'api.eu-west-1.outscale.com', - 'api_name': 'osc_inc_eu_west_1', - 'country': 'FRANCE', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - }, - 'eu-west-2': { - 'endpoint': 'fcu.eu-west-2.outscale.com', - 'api_name': 'osc_inc_eu_west_2', - 'country': 'FRANCE', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - }, - 'eu-west-3': { - 'endpoint': 'api-ppd.outscale.com', - 'api_name': 'osc_inc_eu_west_3', - 'country': 'FRANCE', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - }, - 'us-east-1': { - 'endpoint': 'api.us-east-1.outscale.com', - 'api_name': 'osc_inc_us_east_1', - 'country': 'USA', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - }, - 'us-east-2': { - 'endpoint': 'fcu.us-east-2.outscale.com', - 'api_name': 'osc_inc_us_east_2', - 'country': 'USA', - 'instance_types': [ - 't1.micro', - 'm1.small', - 'm1.medium', - 'm1.large', - 'm1.xlarge', - 'c1.medium', - 'c1.xlarge', - 'm2.xlarge', - 'm2.2xlarge', - 'm2.4xlarge', - 'nv1.small', - 'nv1.medium', - 'nv1.large', - 'nv1.xlarge', - 'cc1.4xlarge', - 'cc2.8xlarge', - 'm3.xlarge', - 'm3.2xlarge', - 'cr1.8xlarge', - 'os1.8xlarge' - ] - } -} - - -""" -Define the extra dictionary for specific resources -""" -RESOURCE_EXTRA_ATTRIBUTES_MAP = { - 'ebs_volume': { - 'snapshot_id': { - 'xpath': 'ebs/snapshotId', - 'transform_func': str - }, - 'volume_id': { - 'xpath': 'ebs/volumeId', - 'transform_func': str - }, - 'volume_size': { - 'xpath': 'ebs/volumeSize', - 'transform_func': int - }, - 'delete': { - 'xpath': 'ebs/deleteOnTermination', - 'transform_func': str - }, - 'volume_type': { - 'xpath': 'ebs/volumeType', - 'transform_func': str - }, - 'iops': { - 'xpath': 'ebs/iops', - 'transform_func': int - } - }, - 'elastic_ip': { - 'allocation_id': { - 'xpath': 'allocationId', - 'transform_func': str, - }, - 'association_id': { - 'xpath': 'associationId', - 'transform_func': str, - }, - 'interface_id': { - 'xpath': 'networkInterfaceId', - 'transform_func': str, - }, - 'owner_id': { - 'xpath': 'networkInterfaceOwnerId', - 'transform_func': str, - }, - 'private_ip': { - 'xpath': 'privateIp', - 'transform_func': str, - } - }, - 'image': { - 'state': { - 'xpath': 'imageState', - 'transform_func': str - }, - 'owner_id': { - 'xpath': 'imageOwnerId', - 'transform_func': str - }, - 'owner_alias': { - 'xpath': 'imageOwnerAlias', - 'transform_func': str - }, - 'is_public': { - 'xpath': 'isPublic', - 'transform_func': str - }, - 'architecture': { - 'xpath': 'architecture', - 'transform_func': str - }, - 'image_type': { - 'xpath': 'imageType', - 'transform_func': str - }, - 'image_location': { - 'xpath': 'imageLocation', - 'transform_func': str - }, - 'platform': { - 'xpath': 'platform', - 'transform_func': str - }, - 'description': { - 'xpath': 'description', - 'transform_func': str - }, - 'root_device_type': { - 'xpath': 'rootDeviceType', - 'transform_func': str - }, - 'virtualization_type': { - 'xpath': 'virtualizationType', - 'transform_func': str - }, - 'hypervisor': { - 'xpath': 'hypervisor', - 'transform_func': str - }, - 'kernel_id': { - 'xpath': 'kernelId', - 'transform_func': str - }, - 'ramdisk_id': { - 'xpath': 'ramdiskId', - 'transform_func': str - } - }, - 'network': { - 'state': { - 'xpath': 'state', - 'transform_func': str - }, - 'dhcp_options_id': { - 'xpath': 'dhcpOptionsId', - 'transform_func': str - }, - 'instance_tenancy': { - 'xpath': 'instanceTenancy', - 'transform_func': str - }, - 'is_default': { - 'xpath': 'isDefault', - 'transform_func': str - } - }, - 'network_interface': { - 'subnet_id': { - 'xpath': 'subnetId', - 'transform_func': str - }, - 'vpc_id': { - 'xpath': 'vpcId', - 'transform_func': str - }, - 'zone': { - 'xpath': 'availabilityZone', - 'transform_func': str - }, - 'description': { - 'xpath': 'description', - 'transform_func': str - }, - 'owner_id': { - 'xpath': 'ownerId', - 'transform_func': str - }, - 'mac_address': { - 'xpath': 'macAddress', - 'transform_func': str - }, - 'private_dns_name': { - 'xpath': 'privateIpAddressesSet/privateDnsName', - 'transform_func': str - }, - 'source_dest_check': { - 'xpath': 'sourceDestCheck', - 'transform_func': str - } - }, - 'network_interface_attachment': { - 'attachment_id': { - 'xpath': 'attachment/attachmentId', - 'transform_func': str - }, - 'instance_id': { - 'xpath': 'attachment/instanceId', - 'transform_func': str - }, - 'owner_id': { - 'xpath': 'attachment/instanceOwnerId', - 'transform_func': str - }, - 'device_index': { - 'xpath': 'attachment/deviceIndex', - 'transform_func': int - }, - 'status': { - 'xpath': 'attachment/status', - 'transform_func': str - }, - 'attach_time': { - 'xpath': 'attachment/attachTime', - 'transform_func': parse_date - }, - 'delete': { - 'xpath': 'attachment/deleteOnTermination', - 'transform_func': str - } - }, - 'node': { - 'availability': { - 'xpath': 'placement/availabilityZone', - 'transform_func': str - }, - 'architecture': { - 'xpath': 'architecture', - 'transform_func': str - }, - 'client_token': { - 'xpath': 'clientToken', - 'transform_func': str - }, - 'dns_name': { - 'xpath': 'dnsName', - 'transform_func': str - }, - 'hypervisor': { - 'xpath': 'hypervisor', - 'transform_func': str - }, - 'iam_profile': { - 'xpath': 'iamInstanceProfile/id', - 'transform_func': str - }, - 'image_id': { - 'xpath': 'imageId', - 'transform_func': str - }, - 'instance_id': { - 'xpath': 'instanceId', - 'transform_func': str - }, - 'instance_lifecycle': { - 'xpath': 'instanceLifecycle', - 'transform_func': str - }, - 'instance_tenancy': { - 'xpath': 'placement/tenancy', - 'transform_func': str - }, - 'instance_type': { - 'xpath': 'instanceType', - 'transform_func': str - }, - 'key_name': { - 'xpath': 'keyName', - 'transform_func': str - }, - 'launch_index': { - 'xpath': 'amiLaunchIndex', - 'transform_func': int - }, - 'launch_time': { - 'xpath': 'launchTime', - 'transform_func': str - }, - 'kernel_id': { - 'xpath': 'kernelId', - 'transform_func': str - }, - 'monitoring': { - 'xpath': 'monitoring/state', - 'transform_func': str - }, - 'platform': { - 'xpath': 'platform', - 'transform_func': str - }, - 'private_dns': { - 'xpath': 'privateDnsName', - 'transform_func': str - }, - 'ramdisk_id': { - 'xpath': 'ramdiskId', - 'transform_func': str - }, - 'root_device_type': { - 'xpath': 'rootDeviceType', - 'transform_func': str - }, - 'root_device_name': { - 'xpath': 'rootDeviceName', - 'transform_func': str - }, - 'reason': { - 'xpath': 'reason', - 'transform_func': str - }, - 'source_dest_check': { - 'xpath': 'sourceDestCheck', - 'transform_func': str - }, - 'status': { - 'xpath': 'instanceState/name', - 'transform_func': str - }, - 'subnet_id': { - 'xpath': 'subnetId', - 'transform_func': str - }, - 'virtualization_type': { - 'xpath': 'virtualizationType', - 'transform_func': str - }, - 'ebs_optimized': { - 'xpath': 'ebsOptimized', - 'transform_func': str - }, - 'vpc_id': { - 'xpath': 'vpcId', - 'transform_func': str - } - }, - 'reserved_node': { - 'instance_type': { - 'xpath': 'instanceType', - 'transform_func': str - }, - 'availability': { - 'xpath': 'availabilityZone', - 'transform_func': str - }, - 'start': { - 'xpath': 'start', - 'transform_func': str - }, - 'duration': { - 'xpath': 'duration', - 'transform_func': int - }, - 'usage_price': { - 'xpath': 'usagePrice', - 'transform_func': float - }, - 'fixed_price': { - 'xpath': 'fixedPrice', - 'transform_func': float - }, - 'instance_count': { - 'xpath': 'instanceCount', - 'transform_func': int - }, - 'description': { - 'xpath': 'productDescription', - 'transform_func': str - }, - 'instance_tenancy': { - 'xpath': 'instanceTenancy', - 'transform_func': str - }, - 'currency_code': { - 'xpath': 'currencyCode', - 'transform_func': str - }, - 'offering_type': { - 'xpath': 'offeringType', - 'transform_func': str - } - }, - 'security_group': { - 'vpc_id': { - 'xpath': 'vpcId', - 'transform_func': str - }, - 'description': { - 'xpath': 'groupDescription', - 'transform_func': str - }, - 'owner_id': { - 'xpath': 'ownerId', - 'transform_func': str - } - }, - 'snapshot': { - 'volume_id': { - 'xpath': 'volumeId', - 'transform_func': str - }, - 'state': { - 'xpath': 'status', - 'transform_func': str - }, - 'description': { - 'xpath': 'description', - 'transform_func': str - }, - 'progress': { - 'xpath': 'progress', - 'transform_func': str - }, - 'start_time': { - 'xpath': 'startTime', - 'transform_func': parse_date - } - }, - 'subnet': { - 'cidr_block': { - 'xpath': 'cidrBlock', - 'transform_func': str - }, - 'available_ips': { - 'xpath': 'availableIpAddressCount', - 'transform_func': int - }, - 'zone': { - 'xpath': 'availabilityZone', - 'transform_func': str - }, - 'vpc_id': { - 'xpath': 'vpcId', - 'transform_func': str - } - }, - 'volume': { - 'device': { - 'xpath': 'attachmentSet/item/device', - 'transform_func': str - }, - 'snapshot_id': { - 'xpath': 'snapshotId', - 'transform_func': lambda v: str(v) or None - }, - 'iops': { - 'xpath': 'iops', - 'transform_func': int - }, - 'zone': { - 'xpath': 'availabilityZone', - 'transform_func': str - }, - 'create_time': { - 'xpath': 'createTime', - 'transform_func': parse_date - }, - 'state': { - 'xpath': 'status', - 'transform_func': str - }, - 'attach_time': { - 'xpath': 'attachmentSet/item/attachTime', - 'transform_func': parse_date - }, - 'attachment_status': { - 'xpath': 'attachmentSet/item/status', - 'transform_func': str - }, - 'instance_id': { - 'xpath': 'attachmentSet/item/instanceId', - 'transform_func': str - }, - 'delete': { - 'xpath': 'attachmentSet/item/deleteOnTermination', - 'transform_func': str - }, - 'type': { - 'xpath': 'volumeType', - 'transform_func': str - } - }, - 'route_table': { - 'vpc_id': { - 'xpath': 'vpcId', - 'transform_func': str - } - } -} - -VALID_EC2_REGIONS = REGION_DETAILS.keys() -VALID_EC2_REGIONS = [r for r in VALID_EC2_REGIONS if r != 'nimbus'] - - -class EC2NodeLocation(NodeLocation): - def __init__(self, id, name, country, driver, availability_zone): - super(EC2NodeLocation, self).__init__(id, name, country, driver) - self.availability_zone = availability_zone - - def __repr__(self): - return (('<EC2NodeLocation: id=%s, name=%s, country=%s, ' - 'availability_zone=%s driver=%s>') - % (self.id, self.name, self.country, - self.availability_zone, self.driver.name)) - - -class EC2Response(AWSBaseResponse): - """ - EC2 specific response parsing and error handling. - """ - - def parse_error(self): - err_list = [] - # Okay, so for Eucalyptus, you can get a 403, with no body, - # if you are using the wrong user/password. - msg = "Failure: 403 Forbidden" - if self.status == 403 and self.body[:len(msg)] == msg: - raise InvalidCredsError(msg) - - try: - body = ET.XML(self.body) - except: - raise MalformedResponseError("Failed to parse XML", - body=self.body, driver=EC2NodeDriver) - - for err in body.findall('Errors/Error'): - code, message = err.getchildren() - err_list.append('%s: %s' % (code.text, message.text)) - if code.text == 'InvalidClientTokenId': - raise InvalidCredsError(err_list[-1]) - if code.text == 'SignatureDoesNotMatch': - raise InvalidCredsError(err_list[-1]) - if code.text == 'AuthFailure': - raise InvalidCredsError(err_list[-1]) - if code.text == 'OptInRequired': - raise InvalidCredsError(err_list[-1]) - if code.text == 'IdempotentParameterMismatch': - raise IdempotentParamError(err_list[-1]) - if code.text == 'InvalidKeyPair.NotFound': - # TODO: Use connection context instead - match = re.match(r'.*\'(.+?)\'.*', message.text) - - if match: - name = match.groups()[0] - else: - name = None - - raise KeyPairDoesNotExistError(name=name, - driver=self.connection.driver) - return '\n'.join(err_list) - - -class EC2Connection(SignedAWSConnection): - """ - Represents a single connection to the EC2 Endpoint. - """ - - version = API_VERSION - host = REGION_DETAILS['us-east-1']['endpoint'] - responseCls = EC2Response - service_name = 'ec2' - - -class ExEC2AvailabilityZone(object): - """ - Extension class which stores information about an EC2 availability zone. - - Note: This class is EC2 specific. - """ - - def __init__(self, name, zone_state, region_name): - self.name = name - self.zone_state = zone_state - self.region_name = region_name - - def __repr__(self): - return (('<ExEC2AvailabilityZone: name=%s, zone_state=%s, ' - 'region_name=%s>') - % (self.name, self.zone_state, self.region_name)) - - -class EC2ReservedNode(Node): - """ - Class which stores information about EC2 reserved instances/nodes - Inherits from Node and passes in None for name and private/public IPs - - Note: This class is EC2 specific. - """ - - def __init__(self, id, state, driver, size=None, image=None, extra=None): - super(EC2ReservedNode, self).__init__(id=id, name=None, state=state, - public_ips=None, - private_ips=None, - driver=driver, extra=extra) - - def __repr__(self): - return (('<EC2ReservedNode: id=%s>') % (self.id)) - - -class EC2SecurityGroup(object): - """ - Represents information about a Security group - - Note: This class is EC2 specific. - """ - - def __init__(self, id, name, ingress_rules, egress_rules, extra=None): - self.id = id - self.name = name - self.ingress_rules = ingress_rules - self.egress_rules = egress_rules - self.extra = extra or {} - - def __repr__(self): - return (('<EC2SecurityGroup: id=%s, name=%s') - % (self.id, self.name)) - - -class EC2PlacementGroup(object): - """ - Represents information about a Placement Grous - - Note: This class is EC2 specific. - """ - def __init__(self, name, state, strategy='cluster', extra=None): - self.name = name - self.strategy = strategy - self.extra = extra or {} - - def __repr__(self): - return '<EC2PlacementGroup: name=%s, state=%s>' % (self.name, - self.strategy) - - -class EC2Network(object): - """ - Represents information about a VPC (Virtual Private Cloud) network - - Note: This class is EC2 specific. - """ - - def __init__(self, id, name, cidr_block, extra=None): - self.id = id - self.name = name - self.cidr_block = cidr_block - self.extra = extra or {} - - def __repr__(self): - return (('<EC2Network: id=%s, name=%s') - % (self.id, self.name)) - - -class EC2NetworkSubnet(object): - """ - Represents information about a VPC (Virtual Private Cloud) subnet - - Note: This class is EC2 specific. - """ - - def __init__(self, id, name, state, extra=None): - self.id = id - self.name = name - self.state = state - self.extra = extra or {} - - def __repr__(self): - return (('<EC2NetworkSubnet: id=%s, name=%s') % (self.id, self.name)) - - -class EC2NetworkInterface(object): - """ - Represents information about a VPC network interface - - Note: This class is EC2 specific. The state parameter denotes the current - status of the interface. Valid values for state are attaching, attached, - detaching and detached. - """ - - def __init__(self, id, name, state, extra=None): - self.id = id - self.name = name - self.state = state - self.extra = extra or {} - - def __repr__(self): - return (('<EC2NetworkInterface: id=%s, name=%s') - % (self.id, self.name)) - - -class ElasticIP(object): - """ - Represents information about an elastic IP address - - :param ip: The elastic IP address - :type ip: ``str`` - - :param domain: The domain that the IP resides in (EC2-Classic/VPC). - EC2 classic is represented with standard and VPC - is represented with vpc. - :type domain: ``str`` - - :param instance_id: The identifier of the instance which currently - has the IP associated. - :type instance_id: ``str`` - - Note: This class is used to support both EC2 and VPC IPs. - For VPC specific attributes are stored in the extra - dict to make promotion to the base API easier. - """ - - def __init__(self, ip, domain, instance_id, extra=None): - self.ip = ip - self.domain = domain - self.instance_id = instance_id - self.extra = extra or {} - - def __repr__(self): - return (('<ElasticIP: ip=%s, domain=%s, instance_id=%s>') - % (self.ip, self.domain, self.instance_id)) - - -class VPCInternetGateway(object): - """ - Class which stores information about VPC Internet Gateways. - - Note: This class is VPC specific. - """ - - def __init__(self, id, name, vpc_id, state, driver, extra=None): - self.id = id - self.name = name - self.vpc_id = vpc_id - self.state = state - self.extra = extra or {} - - def __repr__(self): - return (('<VPCInternetGateway: id=%s>') % (self.id)) - - -class EC2RouteTable(object): - """ - Class which stores information about VPC Route Tables. - - Note: This class is VPC specific. - """ - - def __init__(self, id, name, routes, subnet_associations, - propagating_gateway_ids, extra=None): - """ - :param id: The ID of the route table. - :type id: ``str`` - - :param name: The name of the route table. - :type name: ``str`` - - :param routes: A list of routes in the route table. - :type routes: ``list`` of :class:`EC2Route` - - :param subnet_associations: A list of associations between the - route table and one or more subnets. - :type subnet_associations: ``list`` of - :class:`EC2SubnetAssociation` - - :param propagating_gateway_ids: The list of IDs of any virtual - private gateways propagating the - routes. - :type propagating_gateway_ids: ``list`` - """ - - self.id = id - self.name = name - self.routes = routes - self.subnet_associations = subnet_associations - self.propagating_gateway_ids = propagating_gateway_ids - self.extra = extra or {} - - def __repr__(self): - return (('<EC2RouteTable: id=%s>') % (self.id)) - - -class EC2Route(object): - """ - Class which stores information about a Route. - - Note: This class is VPC specific. - """ - - def __init__(self, cidr, gateway_id, instance_id, owner_id, - interface_id, state, origin, vpc_peering_connection_id): - """ - :param cidr: The CIDR block used for the destination match. - :type cidr: ``str`` - - :param gateway_id: The ID of a gateway attached to the VPC. - :type gateway_id: ``str`` - - :param instance_id: The ID of a NAT instance in the VPC. - :type instance_id: ``str`` - - :param owner_id: The AWS account ID of the owner of the instance. - :type owner_id: ``str`` - - :param interface_id: The ID of the network interface. - :type interface_id: ``str`` - - :param state: The state of the route (active | blackhole). - :type state: ``str`` - - :param origin: Describes how the route was created. - :type origin: ``str`` - - :param vpc_peering_connection_id: The ID of the VPC - peering connection. - :type vpc_peering_connection_id: ``str`` - """ - - self.cidr = cidr - self.gateway_id = gateway_id - self.instance_id = instance_id - self.owner_id = owner_id - self.interface_id = interface_id - self.state = state - self.origin = origin - self.vpc_peering_connection_id = vpc_peering_connection_id - - def __repr__(self): - return (('<EC2Route: cidr=%s>') % (self.cidr)) - - -class EC2SubnetAssociation(object): - """ - Class which stores information about Route Table associated with - a given Subnet in a VPC - - Note: This class is VPC specific. - """ - - def __init__(self, id, route_table_id, subnet_id, main=False): - """ - :param id: The ID of the subnet association in the VPC. - :type id: ``str`` - - :param route_table_id: The ID of a route table in the VPC. - :type route_table_id: ``str`` - - :param subnet_id: The ID of a subnet in the VPC. - :type subnet_id: ``str`` - - :param main: If true, means this is a main VPC route table. - :type main: ``bool`` - """ - - self.id = id - self.route_table_id = route_table_id - self.subnet_id = subnet_id - self.main = main - - def __repr__(self): - return (('<EC2SubnetAssociation: id=%s>') % (self.id)) - - -class BaseEC2NodeDriver(NodeDriver): - """ - Base Amazon EC2 node driver. - - Used for main EC2 and other derivate driver classes to inherit from it. - """ - - connectionCls = EC2Connection - features = {'create_node': ['ssh_key']} - path = '/' - signature_version = DEFAULT_SIGNATURE_VERSION - - NODE_STATE_MAP = { - 'pending': NodeState.PENDING, - 'running': NodeState.RUNNING, - 'shutting-down': NodeState.UNKNOWN, - 'terminated': NodeState.TERMINATED - } - - # http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_Volume.html - VOLUME_STATE_MAP = { - 'available': StorageVolumeState.AVAILABLE, - 'in-use': StorageVolumeState.INUSE, - 'error': StorageVolumeState.ERROR, - 'creating': StorageVolumeState.CREATING, - 'deleting': StorageVolumeState.DELETING, - 'deleted': StorageVolumeState.DELETED, - 'error_deleting': StorageVolumeState.ERROR - } - - SNAPSHOT_STATE_MAP = { - 'pending': VolumeSnapshotState.CREATING, - 'completed': VolumeSnapshotState.AVAILABLE, - 'error': VolumeSnapshotState.ERROR, - } - - def list_nodes(self, ex_node_ids=None, ex_filters=None): - """ - List all nodes - - Ex_node_ids parameter is used to filter the list of - nodes that should be returned. Only the nodes - with the corresponding node ids will be returned. - - :param ex_node_ids: List of ``node.id`` - :type ex_node_ids: ``list`` of ``str`` - - :param ex_filters: The filters so that the response includes - information for only certain nodes. - :type ex_filters: ``dict`` - - :rtype: ``list`` of :class:`Node` - """ - - params = {'Action': 'DescribeInstances'} - - if ex_node_ids: - params.update(self._pathlist('InstanceId', ex_node_ids)) - - if ex_filters: - params.update(self._build_filters(ex_filters)) - - elem = self.connection.request(self.path, params=params).object - - nodes = [] - for rs in findall(element=elem, xpath='reservationSet/item', - namespace=NAMESPACE): - nodes += self._to_nodes(rs, 'instancesSet/item') - - nodes_elastic_ips_mappings = self.ex_describe_addresses(nodes) - - for node in nodes: - ips = nodes_elastic_ips_mappings[node.id] - node.public_ips.extend(ips) - - return nodes - - def list_sizes(self, location=None): - available_types = REGION_DETAILS[self.region_name]['instance_types'] - sizes = [] - - for instance_type in available_types: - attributes = INSTANCE_TYPES[instance_type] - attributes = copy.deepcopy(attributes) - price = self._get_size_price(size_id=instance_type) - attributes.update({'price': price}) - sizes.append(NodeSize(driver=self, **attributes)) - return sizes - - def list_images(self, location=None, ex_image_ids=None, ex_owner=None, - ex_executableby=None, ex_filters=None): - """ - List all images - @inherits: :class:`NodeDriver.list_images` - - Ex_image_ids parameter is used to filter the list of - images that should be returned. Only the images - with the corresponding image ids will be returned. - - Ex_owner parameter is used to filter the list of - images that should be returned. Only the images - with the corresponding owner will be returned. - Valid values: amazon|aws-marketplace|self|all|aws id - - Ex_executableby parameter describes images for which - the specified user has explicit launch permissions. - The user can be an AWS account ID, self to return - images for which the sender of the request has - explicit launch permissions, or all to return - images with public launch permissions. - Valid values: all|self|aws id - - Ex_filters parameter is used to filter the list of - images that should be returned. Only images matching - the filter will be returned. - - :param ex_image_ids: List of ``NodeImage.id`` - :type ex_image_ids: ``list`` of ``str`` - - :param ex_owner: Owner name - :type ex_owner: ``str`` - - :param ex_executableby: Executable by - :type ex_executableby: ``str`` - - :param ex_filters: Filter by - :type ex_filters: ``dict`` - - :rtype: ``list`` of :class:`NodeImage` - """ - params = {'Action': 'DescribeImages'} - - if ex_owner: - params.update({'Owner.1': ex_owner}) - - if ex_executableby: - params.update({'ExecutableBy.1': ex_executableby}) - - if ex_image_ids: - for index, image_id in enumerate(ex_image_ids): - index += 1 - params.update({'ImageId.%s' % (index): image_id}) - - if ex_filters: - params.update(self._build_filters(ex_filters)) - - images = self._to_images( - self.connection.request(self.path, params=params).object - ) - return images - - def get_image(self, image_id): - """ - Get an image based on an image_id - - :param image_id: Image identifier - :type image_id: ``str`` - - :return: A NodeImage object - :rtype: :class:`NodeImage` - - """ - images = self.list_images(ex_image_ids=[image_id]) - image = images[0] - - return image - - def list_locations(self): - locations = [] - for index, availability_zone in \ - enumerate(self.ex_list_availability_zones()): - locations.append(EC2NodeLocation( - index, availability_zone.name, self.country, self, - availability_zone) - ) - return locations - - def list_volumes(self, node=None): - params = { - 'Action': 'DescribeVolumes', - } - if node: - filters = {'attachment.instance-id': node.id} - params.update(self._build_filters(filters)) - - response = self.connection.request(self.path, params=params).object - volumes = [self._to_volume(el) for el in response.findall( - fixxpath(xpath='volumeSet/item', namespace=NAMESPACE)) - ] - return volumes - - def create_node(self, **kwargs): - """ - Create a new EC2 node. - - Reference: http://bit.ly/8ZyPSy [docs.amazonwebservices.com] - - @inherits: :class:`NodeDriver.create_node` - - :keyword ex_keyname: The name of the key pair - :type ex_keyname: ``str`` - - :keyword ex_userdata: User data - :type ex_userdata: ``str`` - - :keyword ex_security_groups: A list of names of security groups to - assign to the node. - :type ex_security_groups: ``list`` - - :keyword ex_security_group_ids: A list of ids of security groups to - assign to the node.[for VPC nodes only] - :type ex_security_group_ids: ``list`` - - :keyword ex_metadata: Key/Value metadata to associate with a node - :type ex_metadata: ``dict`` - - :keyword ex_mincount: Minimum number of instances to launch - :type ex_mincount: ``int`` - - :keyword ex_maxcount: Maximum number of instances to launch - :type ex_maxcount: ``int`` - - :keyword ex_clienttoken: Unique identifier to ensure idempotency - :type ex_clienttoken: ``str`` - - :keyword ex_blockdevicemappings: ``list`` of ``dict`` block device - mappings. - :type ex_blockdevicemappings: ``list`` of ``dict`` - - :keyword ex_iamprofile: Name or ARN of IAM profile - :type ex_iamprofile: ``str`` - - :keyword ex_ebs_optimized: EBS-Optimized if True - :type ex_ebs_optimized: ``bool`` - - :keyword ex_subnet: The subnet to launch the instance into. - :type ex_subnet: :class:`.EC2Subnet` - - :keyword ex_placement_group: The name of the placement group to - launch the instance into. - :type ex_placement_group: ``str`` - - :keyword ex_assign_public_ip: If True, the instance will - be assigned a public ip address. - Note : It takes takes a short - while for the instance to be - assigned the public ip so the - node returned will NOT have - the public ip assigned yet. - :type ex_assign_public_ip: ``bool`` - - :keyword ex_terminate_on_shutdown: Indicates if the instance - should be terminated instead - of just shut down when using - the operating systems command - for system shutdown. - :type ex_terminate_on_shutdown: ``bool`` - """ - image = kwargs["image"] - size = kwargs["size"] - params = { - 'Action': 'RunInstances', - 'ImageId': image.id, - 'MinCount': str(kwargs.get('ex_mincount', '1')), - 'MaxCount': str(kwargs.get('ex_maxcount', '1')), - 'InstanceType': size.id - } - - if kwargs.get("ex_terminate_on_shutdown", False): - params["InstanceInitiatedShutdownBehavior"] = "terminate" - - if 'ex_security_groups' in kwargs and 'ex_securitygroup' in kwargs: - raise ValueError('You can only supply ex_security_groups or' - ' ex_securitygroup') - - # ex_securitygroup is here for backward compatibility - ex_security_groups = kwargs.get('ex_security_groups', None) - ex_securitygroup = kwargs.get('ex_securitygroup', None) - security_groups = ex_security_groups or ex_securitygroup - - if security_groups: - if not isinstance(security_groups, (tuple, list)): - security_groups = [security_groups] - - for sig in range(len(security_groups)): - params['SecurityGroup.%d' % (sig + 1,)] =\ - security_groups[sig] - - if 'ex_security_group_ids' in kwargs and 'ex_subnet' not in kwargs: - raise ValueError('You can only supply ex_security_group_ids' - ' combinated with ex_subnet') - - security_group_ids = kwargs.get('ex_security_group_ids', None) - security_group_id_params = {} - - if security_group_ids: - if not isinstance(security_group_ids, (tuple, list)): - security_group_ids = [security_group_ids] - - for sig in range(len(security_group_ids)): - security_group_id_params['SecurityGroupId.%d' % (sig + 1,)] =\ - security_group_ids[sig] - - if 'location' in kwargs: - availability_zone = getattr(kwargs['location'], - 'availability_zone', None) - if availability_zone: - if availability_zone.region_name != self.region_name: - raise AttributeError('Invalid availability zone: %s' - % (availability_zone.name)) - params['Placement.AvailabilityZone'] = availability_zone.name - - if 'auth' in kwargs and 'ex_keyname' in kwargs: - raise AttributeError('Cannot specify auth and ex_keyname together') - - if 'auth' in kwargs: - auth = self._get_and_check_auth(kwargs['auth']) - key = self.ex_find_or_import_keypair_by_key_material(auth.pubkey) - params['KeyName'] = key['keyName'] - - if 'ex_keyname' in kwargs: - params['KeyName'] = kwargs['ex_keyname'] - - if 'ex_userdata' in kwargs: - params['UserData'] = base64.b64encode(b(kwargs['ex_userdata']))\ - .decode('utf-8') - - if 'ex_clienttoken' in kwargs: - params['ClientToken'] = kwargs['ex_clienttoken'] - - if 'ex_blockdevicemappings' in kwargs: - params.update(self._get_block_device_mapping_params( - kwargs['ex_blockdevicemappings'])) - - if 'ex_iamprofile' in kwargs: - if not isinstance(kwargs['ex_iamprofile'], basestring): - raise AttributeError('ex_iamprofile not string') - - if kwargs['ex_iamprofile'].startswith('arn:aws:iam:'): - params['IamInstanceProfile.Arn'] = kwargs['ex_iamprofile'] - else: - params['IamInstanceProfile.Name'] = kwargs['ex_iamprofile'] - - if 'ex_ebs_optimized' in kwargs: - params['EbsOptimized'] = kwargs['ex_ebs_optimized'] - - subnet_id = None - if 'ex_subnet' in kwargs: - subnet_id = kwargs['ex_subnet'].id - - if 'ex_placement_group' in kwargs and kwargs['ex_placement_group']: - params['Placement.GroupName'] = kwargs['ex_placement_group'] - - assign_public_ip = kwargs.get('ex_assign_public_ip', False) - # In the event that a public ip is requested a NetworkInterface - # needs to be specified. Some properties that would - # normally be at the root (security group ids and subnet id) - # need to be moved to the level of the NetworkInterface because - # the NetworkInterface is no longer created implicitly - if assign_public_ip: - root_key = 'NetworkInterface.1.' - params[root_key + 'AssociatePublicIpAddress'] = "true" - # This means that when the instance is terminated, the - # NetworkInterface we created for the instance will be - # deleted automatically - params[root_key + 'DeleteOnTermination'] = "true" - # Required to be 0 if we are associating a public ip - params[root_key + 'DeviceIndex'] = "0" - - if subnet_id: - params[root_key + 'SubnetId'] = subnet_id - - for key, security_group_id in security_group_id_params.items(): - key = root_key + key - params[key] = security_group_id - else: - params.update(security_group_id_params) - if subnet_id: - params['SubnetId'] = subnet_id - - object = self.connection.request(self.path, params=params).object - nodes = self._to_nodes(object, 'instancesSet/item') - - for node in nodes: - tags = {'Name': kwargs['name']} - if 'ex_metadata' in kwargs: - tags.update(kwargs['ex_metadata']) - - try: - self.ex_create_tags(resource=node, tags=tags) - except Exception: - continue - - node.name = kwargs['name'] - node.extra.update({'tags': tags}) - - if len(nodes) == 1: - return nodes[0] - else: - return nodes - - def reboot_node(self, node): - params = {'Action': 'RebootInstances'} - params.update(self._pathlist('InstanceId', [node.id])) - res = self.connection.request(self.path, params=params).object - return self._get_boolea
<TRUNCATED>
