PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/boto-2.5.2/boto/ec2/networkinterface.py

#
Python | 163 lines | 96 code | 7 blank | 60 comment | 11 complexity | 0fc66ecb38309bbc4db7479d7e6c153e MD5 | raw file
  1. # Copyright (c) 2011 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. Represents an EC2 Elastic Network Interface
  23. """
  24. from boto.ec2.ec2object import TaggedEC2Object
  25. from boto.resultset import ResultSet
  26. from boto.ec2.group import Group
  27. class Attachment(object):
  28. """
  29. :ivar id: The ID of the attachment.
  30. :ivar instance_id: The ID of the instance.
  31. :ivar device_index: The index of this device.
  32. :ivar status: The status of the device.
  33. :ivar attach_time: The time the device was attached.
  34. :ivar delete_on_termination: Whether the device will be deleted
  35. when the instance is terminated.
  36. """
  37. def __init__(self):
  38. self.id = None
  39. self.instance_id = None
  40. self.instance_owner_id = None
  41. self.device_index = 0
  42. self.status = None
  43. self.attach_time = None
  44. self.delete_on_termination = False
  45. def __repr__(self):
  46. return 'Attachment:%s' % self.id
  47. def startElement(self, name, attrs, connection):
  48. return None
  49. def endElement(self, name, value, connection):
  50. if name == 'attachmentId':
  51. self.id = value
  52. elif name == 'instanceId':
  53. self.instance_id = value
  54. elif name == 'instanceOwnerId':
  55. self.instance_owner_id = value
  56. elif name == 'status':
  57. self.status = value
  58. elif name == 'attachTime':
  59. self.attach_time = value
  60. elif name == 'deleteOnTermination':
  61. if value.lower() == 'true':
  62. self.delete_on_termination = True
  63. else:
  64. self.delete_on_termination = False
  65. else:
  66. setattr(self, name, value)
  67. class NetworkInterface(TaggedEC2Object):
  68. """
  69. An Elastic Network Interface.
  70. :ivar id: The ID of the ENI.
  71. :ivar subnet_id: The ID of the VPC subnet.
  72. :ivar vpc_id: The ID of the VPC.
  73. :ivar description: The description.
  74. :ivar owner_id: The ID of the owner of the ENI.
  75. :ivar requester_managed:
  76. :ivar status: The interface's status (available|in-use).
  77. :ivar mac_address: The MAC address of the interface.
  78. :ivar private_ip_address: The IP address of the interface within
  79. the subnet.
  80. :ivar source_dest_check: Flag to indicate whether to validate
  81. network traffic to or from this network interface.
  82. :ivar groups: List of security groups associated with the interface.
  83. :ivar attachment: The attachment object.
  84. """
  85. def __init__(self, connection=None):
  86. TaggedEC2Object.__init__(self, connection)
  87. self.id = None
  88. self.subnet_id = None
  89. self.vpc_id = None
  90. self.availability_zone = None
  91. self.description = None
  92. self.owner_id = None
  93. self.requester_managed = False
  94. self.status = None
  95. self.mac_address = None
  96. self.private_ip_address = None
  97. self.source_dest_check = None
  98. self.groups = []
  99. self.attachment = None
  100. def __repr__(self):
  101. return 'NetworkInterface:%s' % self.id
  102. def startElement(self, name, attrs, connection):
  103. retval = TaggedEC2Object.startElement(self, name, attrs, connection)
  104. if retval is not None:
  105. return retval
  106. if name == 'groupSet':
  107. self.groups = ResultSet([('item', Group)])
  108. return self.groups
  109. elif name == 'attachment':
  110. self.attachment = Attachment()
  111. return self.attachment
  112. else:
  113. return None
  114. def endElement(self, name, value, connection):
  115. if name == 'networkInterfaceId':
  116. self.id = value
  117. elif name == 'subnetId':
  118. self.subnet_id = value
  119. elif name == 'vpcId':
  120. self.vpc_id = value
  121. elif name == 'availabilityZone':
  122. self.availability_zone = value
  123. elif name == 'description':
  124. self.description = value
  125. elif name == 'ownerId':
  126. self.owner_id = value
  127. elif name == 'requesterManaged':
  128. if value.lower() == 'true':
  129. self.requester_managed = True
  130. else:
  131. self.requester_managed = False
  132. elif name == 'status':
  133. self.status = value
  134. elif name == 'macAddress':
  135. self.mac_address = value
  136. elif name == 'privateIpAddress':
  137. self.private_ip_address = value
  138. elif name == 'sourceDestCheck':
  139. if value.lower() == 'true':
  140. self.source_dest_check = True
  141. else:
  142. self.source_dest_check = False
  143. else:
  144. setattr(self, name, value)
  145. def delete(self):
  146. return self.connection.delete_network_interface(self.id)