<commit_before># vim: set fileencoding=utf-8 :

import base64
import os
import re
import sys
import time
import urllib
import urllib2
from boto.ec2.connection import EC2Connection
from boto.s3.connection import S3Connection
from boto.exception import EC2ResponseError, S3CreateError, S3ResponseError

from mint import helperfuncs
from mint.mint_error import EC2Exception as MintEC2Exception
from mint.mint_error import TargetExists, TargetMissing, PermissionDenied

from catalogService import errors
from catalogService import storage
from catalogService.rest import baseDriver
from catalogService.rest.models import clouds
from catalogService.rest.models import images
from catalogService.rest.models import instances
from catalogService.rest.models import keypairs
from catalogService.rest.models import securityGroups

CATALOG_DYN_SECURITY_GROUP = 'dynamic'
CATALOG_DYN_SECURITY_GROUP_DESC = 'Generated Security Group'
CATALOG_DEF_SECURITY_GROUP = 'catalog-default'
CATALOG_DEF_SECURITY_GROUP_DESC = 'Default EC2 Catalog Security Group'
CATALOG_DEF_SECURITY_GROUP_PERMS = (
        # proto  start_port  end_port
        ('tcp',  22,         22),
        ('tcp',  80,         80),
        ('tcp',  443,        443),
        ('tcp',  8003 ,      8003),
)
CATALOG_DEF_SECURITY_GROUP_WBEM_PORTS = (
        ('tcp',  5989,       5989),
)

EC2_ALIAS = 'ec2'
EC2_DESCRIPTION = "Amazon Elastic Compute Cloud"

EC2_DEVPAY_OFFERING_BASE_URL = "https://aws-portal.amazon.com/gp/aws/user/subscription/index.html?productCode=%s"

class EC2_IPRange(instances.xmlNode.BaseMultiNode):
    tag = 'ipRange'

class EC2_Permissions(instances.xmlNode.BaseMultiNode):
    tag = 'permission'
    __slots__ = ['ipRange', 'ipProtocol', 'fromPort', 'toPort']
    _slotTypeMap = instances.xmlNode.BaseMultiNode._slotTypeMap.copy()
    _slotTypeMap['ipRange'] = EC2_IPRange

class EC2_SecurityGroup(securityGroups.BaseSecurityGroup):
    multiple = True
    _slotTypeMap = securityGroups.BaseSecurityGroup._slotTypeMap.copy()
    _slotTypeMap['permission'] = EC2_Permissions

class EC2_Image(images.BaseImage):
    "EC2 Image"

    _constructorOverrides = dict(cloudName = 'aws', cloudAlias = 'ec2')

class EC2_Instance(instances.BaseInstance):
    "EC2 Instance"

    __slots__ = instances.BaseInstance.__slots__ + [
                'keyName', 'securityGroup', ]

    _constructorOverrides = EC2_Image._constructorOverrides.copy()
    _slotTypeMap = instances.BaseInstance._slotTypeMap.copy()
    _slotTypeMap['securityGroup'] = EC2_SecurityGroup

class EC2_Cloud(clouds.BaseCloud):
    "EC2 Cloud"

    _constructorOverrides = EC2_Image._constructorOverrides.copy()
    _constructorOverrides['description'] = EC2_DESCRIPTION

class EC2_InstanceTypes(instances.InstanceTypes):
    "EC2 Instance Types"

    idMap = [
        ('m1.small', "Small"),
        ('m1.large', "Large"),
        ('m1.xlarge', "Extra Large"),
        ('c1.medium', "High-CPU Medium"),
        ('c1.xlarge', "High-CPU Extra Large"),
    ]

_configurationDescriptorXmlData = """<?xml version='1.0' encoding='UTF-8'?>
<descriptor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.rpath.org/permanent/descriptor-1.0.xsd descriptor-1.0.xsd">
  <metadata>
    <displayName>EC2 Cloud Configuration</displayName>
    <descriptions>
      <desc>Configure Amazon EC2</desc>
    </descriptions>
  </metadata>
  <dataFields>
    <field>
      <name>name</name>
      <descriptions>
        <desc>Name</desc>
      </descriptions>
      <type>str</type>
      <default>aws</default>
      <hidden>true</hidden>
    </field>
    <field>
      <name>cloudAlias</name>
      <descriptions>
        <desc>Name</desc>
      </descriptions>
      <type>str</type>
      <default>ec2</default>
      <hidden>true</hidden>
    </field>
    <field>
      <name>fullDescription</name>
      <descriptions>
        <desc>Full Description</desc>
      </descriptions>
      <type>str</type>
      <default>Amazon Elastic Compute Cloud</default>
      <hidden>true</hidden>
    </field>
    <field>
      <name>accountId</name>
      <descriptions>
        <desc>AWS Account Number</desc>
      </descriptions>
      <type>str</type>
      <constraints>
        <descriptions>
          <desc>Field must contain between 1 and 12 characters</desc>
        </descriptions>
        <length>12</length>
      </constraints>
      <required>true</required>
      <help href='configuration/accountNumber.html'/>
    </field>
    <field>
      <name>publicAccessKeyId</name>
      <descriptions>
        <desc>Access Key ID</desc>
      </descriptions>
      <type>str</type>
      <constraints><commit_msg>RBL-7781: ec2 image build fails at final steps<commit_after># vim: set fileencoding=utf-8 :

import base64
import os
import re
import sys
import time
import urllib
import urllib2
from boto.ec2.connection import EC2Connection
from boto.s3.connection import S3Connection
from boto.exception import EC2ResponseError, S3CreateError, S3ResponseError

from mint import helperfuncs
from mint.mint_error import EC2Exception as MintEC2Exception
from mint.mint_error import TargetExists, TargetMissing, PermissionDenied

from catalogService import errors
from catalogService import storage
from catalogService.rest import baseDriver
from catalogService.rest.models import clouds
from catalogService.rest.models import images
from catalogService.rest.models import instances
from catalogService.rest.models import keypairs
from catalogService.rest.models import securityGroups

CATALOG_DYN_SECURITY_GROUP = 'dynamic'
CATALOG_DYN_SECURITY_GROUP_DESC = 'Generated Security Group'
CATALOG_DEF_SECURITY_GROUP = 'catalog-default'
CATALOG_DEF_SECURITY_GROUP_DESC = 'Default EC2 Catalog Security Group'
CATALOG_DEF_SECURITY_GROUP_PERMS = (
        # proto  start_port  end_port
        ('tcp',  22,         22),
        ('tcp',  80,         80),
        ('tcp',  443,        443),
        ('tcp',  8003 ,      8003),
)
CATALOG_DEF_SECURITY_GROUP_WBEM_PORTS = (
        ('tcp',  5989,       5989),
)

EC2_ALIAS = 'ec2'
EC2_DESCRIPTION = "Amazon Elastic Compute Cloud"

EC2_DEVPAY_OFFERING_BASE_URL = "https://aws-portal.amazon.com/gp/aws/user/subscription/index.html?productCode=%s"

class EC2_IPRange(instances.xmlNode.BaseMultiNode):
    tag = 'ipRange'

class EC2_Permissions(instances.xmlNode.BaseMultiNode):
    tag = 'permission'
    __slots__ = ['ipRange', 'ipProtocol', 'fromPort', 'toPort']
    _slotTypeMap = instances.xmlNode.BaseMultiNode._slotTypeMap.copy()
    _slotTypeMap['ipRange'] = EC2_IPRange

class EC2_SecurityGroup(securityGroups.BaseSecurityGroup):
    multiple = True
    _slotTypeMap = securityGroups.BaseSecurityGroup._slotTypeMap.copy()
    _slotTypeMap['permission'] = EC2_Permissions

class EC2_Image(images.BaseImage):
    "EC2 Image"

    _constructorOverrides = dict(cloudName = 'aws', cloudAlias = 'ec2')

class EC2_Instance(instances.BaseInstance):
    "EC2 Instance"

    __slots__ = instances.BaseInstance.__slots__ + [
                'keyName', 'securityGroup', ]

    _constructorOverrides = EC2_Image._constructorOverrides.copy()
    _slotTypeMap = instances.BaseInstance._slotTypeMap.copy()
    _slotTypeMap['securityGroup'] = EC2_SecurityGroup

class EC2_Cloud(clouds.BaseCloud):
    "EC2 Cloud"

    _constructorOverrides = EC2_Image._constructorOverrides.copy()
    _constructorOverrides['description'] = EC2_DESCRIPTION

class EC2_InstanceTypes(instances.InstanceTypes):
    "EC2 Instance Types"

    idMap = [
        ('m1.small', "Small"),
        ('m1.large', "Large"),
        ('m1.xlarge', "Extra Large"),
        ('c1.medium', "High-CPU Medium"),
        ('c1.xlarge', "High-CPU Extra Large"),
    ]

_configurationDescriptorXmlData = """<?xml version='1.0' encoding='UTF-8'?>
<descriptor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.rpath.org/permanent/descriptor-1.0.xsd descriptor-1.0.xsd">
  <metadata>
    <displayName>EC2 Cloud Configuration</displayName>
    <descriptions>
      <desc>Configure Amazon EC2</desc>
    </descriptions>
  </metadata>
  <dataFields>
    <field>
      <name>name</name>
      <descriptions>
        <desc>Name</desc>
      </descriptions>
      <type>str</type>
      <default>aws</default>
      <hidden>true</hidden>
    </field>
    <field>
      <name>cloudAlias</name>
      <descriptions>
        <desc>Name</desc>
      </descriptions>
      <type>str</type>
      <default>ec2</default>
      <hidden>true</hidden>
    </field>
    <field>
      <name>fullDescription</name>
      <descriptions>
        <desc>Full Description</desc>
      </descriptions>
      <type>str</type>
      <default>Amazon Elastic Compute Cloud</default>
      <hidden>true</hidden>
    </field>
    <field>
      <name>accountId</name>
      <descriptions>
        <desc>AWS Account Number</desc>
      </descriptions>
      <type>str</type>
      <constraints>
        <descriptions>
          <desc>Field must contain between 1 and 12 characters and cannot contain hyphens</desc>
        </descriptions>
        <regexp>^[^-]+$</regexp>
        <length>12</length>
      </constraints>
      <required>true</required>
      <help href='configuration/accountNumber.html'/>
    </field>
    <field>
      <name>publicAccessKeyId</name>
      <descriptions>
        <desc>Access Key ID</desc>
      </descriptions>
      <type>str</type>
      <constraints>
{'fraction_non_alphanumeric': 0.11730953139942621, 'fraction_numerical': 0.019870364467112954, 'mean_word_length': 3.577821011673152, 'pattern_counts': {'":': 0, '<': 173, '<?xml version=': 2, '>': 173, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '123478', 'n_tokens_mistral': 3061, 'n_tokens_neox': 2986, 'n_words': 578}