def describe_instances(self, xml_bytes): """ Parse the reservations XML payload that is returned from an AWS describeInstances API call. Instead of returning the reservations as the "top-most" object, we return the object that most developers and their code will be interested in: the instances. In instances reservation is available on the instance object. The following instance attributes are optional: * ami_launch_index * key_name * kernel_id * product_codes * ramdisk_id * reason @param xml_bytes: raw XML payload from AWS. """ root = XML(xml_bytes) results = [] # May be a more elegant way to do this: for reservation_data in root.find("reservationSet"): # Create a reservation object with the parsed data. reservation = model.Reservation( reservation_id=reservation_data.findtext("reservationId"), owner_id=reservation_data.findtext("ownerId")) # Get the list of instances. instances = self.instances_set( reservation_data, reservation) results.extend(instances) return results
def _parse_run_instances(self, xml_bytes): """ Parse the reservations XML payload that is returned from an AWS RunInstances API call. """ root = XML(xml_bytes) # Get the security group information. groups = [] for group_data in root.find("groupSet"): group_id = group_data.findtext("groupId") groups.append(group_id) # Create a reservation object with the parsed data. reservation = model.Reservation( reservation_id=root.findtext("reservationId"), owner_id=root.findtext("ownerId"), groups=groups) # Get the list of instances. instances = self._parse_instances_set(root, reservation) return instances