OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/ |
| 2 # |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a |
| 4 # copy of this software and associated documentation files (the |
| 5 # "Software"), to deal in the Software without restriction, including |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 7 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 # persons to whom the Software is furnished to do so, subject to the fol- |
| 9 # lowing conditions: |
| 10 # |
| 11 # The above copyright notice and this permission notice shall be included |
| 12 # in all copies or substantial portions of the Software. |
| 13 # |
| 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 20 # IN THE SOFTWARE. |
| 21 |
| 22 |
| 23 from boto.ec2.ec2object import EC2Object |
| 24 |
| 25 class Address(EC2Object): |
| 26 """ |
| 27 Represents an EC2 Elastic IP Address |
| 28 |
| 29 :ivar public_ip: The Elastic IP address. |
| 30 :ivar instance_id: The instance the address is associated with (if any). |
| 31 :ivar domain: Indicates whether the address is a EC2 address or a VPC addres
s (standard|vpc). |
| 32 :ivar allocation_id: The allocation ID for the address (VPC addresses only). |
| 33 :ivar association_id: The association ID for the address (VPC addresses only
). |
| 34 :ivar network_interface_id: The network interface (if any) that the address
is associated with (VPC addresses only). |
| 35 :ivar network_interface_owner_id: The owner IID (VPC addresses only). |
| 36 :ivar private_ip_address: The private IP address associated with the Elastic
IP address (VPC addresses only). |
| 37 """ |
| 38 |
| 39 def __init__(self, connection=None, public_ip=None, instance_id=None): |
| 40 EC2Object.__init__(self, connection) |
| 41 self.connection = connection |
| 42 self.public_ip = public_ip |
| 43 self.instance_id = instance_id |
| 44 self.domain = None |
| 45 self.allocation_id = None |
| 46 self.association_id = None |
| 47 self.network_interface_id = None |
| 48 self.network_interface_owner_id = None |
| 49 self.private_ip_address = None |
| 50 |
| 51 def __repr__(self): |
| 52 return 'Address:%s' % self.public_ip |
| 53 |
| 54 def endElement(self, name, value, connection): |
| 55 if name == 'publicIp': |
| 56 self.public_ip = value |
| 57 elif name == 'instanceId': |
| 58 self.instance_id = value |
| 59 elif name == 'domain': |
| 60 self.domain = value |
| 61 elif name == 'allocationId': |
| 62 self.allocation_id = value |
| 63 elif name == 'associationId': |
| 64 self.association_id = value |
| 65 elif name == 'networkInterfaceId': |
| 66 self.network_interface_id = value |
| 67 elif name == 'networkInterfaceOwnerId': |
| 68 self.network_interface_owner_id = value |
| 69 elif name == 'privateIpAddress': |
| 70 self.private_ip_address = value |
| 71 else: |
| 72 setattr(self, name, value) |
| 73 |
| 74 def release(self): |
| 75 """ |
| 76 Free up this Elastic IP address. |
| 77 :see: :meth:`boto.ec2.connection.EC2Connection.release_address` |
| 78 """ |
| 79 if self.allocation_id: |
| 80 return self.connection.release_address(None, self.allocation_id) |
| 81 else: |
| 82 return self.connection.release_address(self.public_ip) |
| 83 |
| 84 delete = release |
| 85 |
| 86 def associate(self, instance_id): |
| 87 """ |
| 88 Associate this Elastic IP address with a currently running instance. |
| 89 :see: :meth:`boto.ec2.connection.EC2Connection.associate_address` |
| 90 """ |
| 91 return self.connection.associate_address(instance_id, self.public_ip) |
| 92 |
| 93 def disassociate(self): |
| 94 """ |
| 95 Disassociate this Elastic IP address from a currently running instance. |
| 96 :see: :meth:`boto.ec2.connection.EC2Connection.disassociate_address` |
| 97 """ |
| 98 if self.association_id: |
| 99 return self.connection.disassociate_address(None, self.association_i
d) |
| 100 else: |
| 101 return self.connection.disassociate_address(self.public_ip) |
| 102 |
| 103 |
OLD | NEW |