OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2009 Reza Lotun http://reza.lotun.name/ |
| 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 5 # copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including |
| 7 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 8 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 10 # lowing conditions: |
| 11 # |
| 12 # The above copyright notice and this permission notice shall be included |
| 13 # in all copies or substantial portions of the Software. |
| 14 # |
| 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 # IN THE SOFTWARE. |
| 22 |
| 23 from datetime import datetime |
| 24 from boto.resultset import ResultSet |
| 25 from boto.ec2.elb.listelement import ListElement |
| 26 import boto.utils |
| 27 import base64 |
| 28 |
| 29 # this should use the corresponding object from boto.ec2 |
| 30 |
| 31 |
| 32 class Ebs(object): |
| 33 def __init__(self, connection=None, snapshot_id=None, volume_size=None): |
| 34 self.connection = connection |
| 35 self.snapshot_id = snapshot_id |
| 36 self.volume_size = volume_size |
| 37 |
| 38 def __repr__(self): |
| 39 return 'Ebs(%s, %s)' % (self.snapshot_id, self.volume_size) |
| 40 |
| 41 def startElement(self, name, attrs, connection): |
| 42 pass |
| 43 |
| 44 def endElement(self, name, value, connection): |
| 45 if name == 'SnapshotId': |
| 46 self.snapshot_id = value |
| 47 elif name == 'VolumeSize': |
| 48 self.volume_size = value |
| 49 |
| 50 |
| 51 class InstanceMonitoring(object): |
| 52 def __init__(self, connection=None, enabled='false'): |
| 53 self.connection = connection |
| 54 self.enabled = enabled |
| 55 |
| 56 def __repr__(self): |
| 57 return 'InstanceMonitoring(%s)' % self.enabled |
| 58 |
| 59 def startElement(self, name, attrs, connection): |
| 60 pass |
| 61 |
| 62 def endElement(self, name, value, connection): |
| 63 if name == 'Enabled': |
| 64 self.enabled = value |
| 65 |
| 66 |
| 67 # this should use the BlockDeviceMapping from boto.ec2.blockdevicemapping |
| 68 class BlockDeviceMapping(object): |
| 69 def __init__(self, connection=None, device_name=None, virtual_name=None): |
| 70 self.connection = connection |
| 71 self.device_name = None |
| 72 self.virtual_name = None |
| 73 self.ebs = None |
| 74 |
| 75 def __repr__(self): |
| 76 return 'BlockDeviceMapping(%s, %s)' % (self.device_name, |
| 77 self.virtual_name) |
| 78 |
| 79 def startElement(self, name, attrs, connection): |
| 80 if name == 'Ebs': |
| 81 self.ebs = Ebs(self) |
| 82 return self.ebs |
| 83 |
| 84 def endElement(self, name, value, connection): |
| 85 if name == 'DeviceName': |
| 86 self.device_name = value |
| 87 elif name == 'VirtualName': |
| 88 self.virtual_name = value |
| 89 |
| 90 |
| 91 class LaunchConfiguration(object): |
| 92 def __init__(self, connection=None, name=None, image_id=None, |
| 93 key_name=None, security_groups=None, user_data=None, |
| 94 instance_type='m1.small', kernel_id=None, |
| 95 ramdisk_id=None, block_device_mappings=None, |
| 96 instance_monitoring=False, spot_price=None, |
| 97 instance_profile_name=None): |
| 98 """ |
| 99 A launch configuration. |
| 100 |
| 101 :type name: str |
| 102 :param name: Name of the launch configuration to create. |
| 103 |
| 104 :type image_id: str |
| 105 :param image_id: Unique ID of the Amazon Machine Image (AMI) which was |
| 106 assigned during registration. |
| 107 |
| 108 :type key_name: str |
| 109 :param key_name: The name of the EC2 key pair. |
| 110 |
| 111 :type security_groups: list |
| 112 :param security_groups: Names of the security groups with which to |
| 113 associate the EC2 instances. |
| 114 |
| 115 :type user_data: str |
| 116 :param user_data: The user data available to launched EC2 instances. |
| 117 |
| 118 :type instance_type: str |
| 119 :param instance_type: The instance type |
| 120 |
| 121 :type kern_id: str |
| 122 :param kern_id: Kernel id for instance |
| 123 |
| 124 :type ramdisk_id: str |
| 125 :param ramdisk_id: RAM disk id for instance |
| 126 |
| 127 :type block_device_mappings: list |
| 128 :param block_device_mappings: Specifies how block devices are exposed |
| 129 for instances |
| 130 |
| 131 :type instance_monitoring: bool |
| 132 :param instance_monitoring: Whether instances in group are launched |
| 133 with detailed monitoring. |
| 134 |
| 135 :type spot_price: float |
| 136 :param spot_price: The spot price you are bidding. Only applies |
| 137 if you are building an autoscaling group with spot instances. |
| 138 |
| 139 :type instance_profile_name: string |
| 140 :param instance_profile_name: The name or the Amazon Resource |
| 141 Name (ARN) of the instance profile associated with the IAM |
| 142 role for the instance. |
| 143 """ |
| 144 self.connection = connection |
| 145 self.name = name |
| 146 self.instance_type = instance_type |
| 147 self.block_device_mappings = block_device_mappings |
| 148 self.key_name = key_name |
| 149 sec_groups = security_groups or [] |
| 150 self.security_groups = ListElement(sec_groups) |
| 151 self.image_id = image_id |
| 152 self.ramdisk_id = ramdisk_id |
| 153 self.created_time = None |
| 154 self.kernel_id = kernel_id |
| 155 self.user_data = user_data |
| 156 self.created_time = None |
| 157 self.instance_monitoring = instance_monitoring |
| 158 self.spot_price = spot_price |
| 159 self.instance_profile_name = instance_profile_name |
| 160 self.launch_configuration_arn = None |
| 161 |
| 162 def __repr__(self): |
| 163 return 'LaunchConfiguration:%s' % self.name |
| 164 |
| 165 def startElement(self, name, attrs, connection): |
| 166 if name == 'SecurityGroups': |
| 167 return self.security_groups |
| 168 elif name == 'BlockDeviceMappings': |
| 169 self.block_device_mappings = ResultSet([('member', |
| 170 BlockDeviceMapping)]) |
| 171 return self.block_device_mappings |
| 172 elif name == 'InstanceMonitoring': |
| 173 self.instance_monitoring = InstanceMonitoring(self) |
| 174 return self.instance_monitoring |
| 175 |
| 176 def endElement(self, name, value, connection): |
| 177 if name == 'InstanceType': |
| 178 self.instance_type = value |
| 179 elif name == 'LaunchConfigurationName': |
| 180 self.name = value |
| 181 elif name == 'KeyName': |
| 182 self.key_name = value |
| 183 elif name == 'ImageId': |
| 184 self.image_id = value |
| 185 elif name == 'CreatedTime': |
| 186 self.created_time = boto.utils.parse_ts(value) |
| 187 elif name == 'KernelId': |
| 188 self.kernel_id = value |
| 189 elif name == 'RamdiskId': |
| 190 self.ramdisk_id = value |
| 191 elif name == 'UserData': |
| 192 try: |
| 193 self.user_data = base64.b64decode(value) |
| 194 except TypeError: |
| 195 self.user_data = value |
| 196 elif name == 'LaunchConfigurationARN': |
| 197 self.launch_configuration_arn = value |
| 198 elif name == 'InstanceMonitoring': |
| 199 self.instance_monitoring = value |
| 200 elif name == 'SpotPrice': |
| 201 self.spot_price = float(value) |
| 202 elif name == 'IamInstanceProfile': |
| 203 self.instance_profile_name = value |
| 204 else: |
| 205 setattr(self, name, value) |
| 206 |
| 207 def delete(self): |
| 208 """ Delete this launch configuration. """ |
| 209 return self.connection.delete_launch_configuration(self.name) |
OLD | NEW |