def get_template(self, name_or_id): matches = self.find_templates(name=name_or_id) if not matches: raise ImageNotFoundError( 'Unable to find image {}'.format(name_or_id)) elif len(matches) > 1: raise MultipleImagesError( 'Image name {} returned more than one image ' 'Use the ami-ID or remove duplicates from EC2'.format( name_or_id)) return matches[0]
def get_template(self, name, container=None): """ Return template with given name Raises MultipleItemsError if more than 1 exist with that name Args: container (str) -- specific container to search in """ templates = self.find_templates(name=name, container=container) if not templates: raise ImageNotFoundError(name) elif len(templates) > 1: raise MultipleImagesError( "Image with name '{}' exists in multiple containers".format( name)) return templates[0]
def get_template(self, name=None, id=None): """ Get a template by name OR id """ if name: matches = self.find_templates(name) if not matches: raise ImageNotFoundError(name) elif len(matches) > 1: raise MultipleImagesError(name) result = matches[0] elif id: try: raw_image = self.api.images.get(id) except os_exceptions.NotFound: raise ImageNotFoundError(id) result = OpenstackImage(system=self, uuid=raw_image.id, raw=raw_image) else: raise AttributeError("Must specify either 'name' or 'id' with get_template") return result