コード例 #1
0
ファイル: openstack.py プロジェクト: huzaifarasheedmir/rally
    def get_image_uuid(self):
        """Get image uuid. Download image if necessary."""

        image_uuid = self.config["image"].get("uuid", None)
        if image_uuid:
            return image_uuid
        else:
            if not self.glance:
                raise exceptions.InvalidConfigException(
                    "If glance is not available in the service catalog"
                    " obtained by the openstack server provider, then"
                    " images cannot be uploaded so the uuid of an"
                    " existing image must be specified in the"
                    " deployment config.")

        for image in self.glance.images.list():
            if image.checksum == self.config["image"]["checksum"]:
                LOG.info(_("Found image with appropriate checksum. Using it."))
                return image.id

        LOG.info(_("Downloading new image %s") % self.config["image"]["url"])
        image = self.glance.images.create(
            name=self.config["image"]["name"],
            copy_from=self.config["image"]["url"],
            disk_format=self.config["image"]["format"],
            container_format="bare")
        image.get()

        if image.checksum != self.config["image"]["checksum"]:
            raise exceptions.ChecksumMismatch(url=self.config["image"]["url"])

        return image.id
コード例 #2
0
ファイル: openstack.py プロジェクト: SunilMamillapalli/rally
    def get_image_uuid(self):
        """Get image uuid. Download image if necessary."""

        image_uuid = self.config['image'].get('uuid', None)
        if image_uuid:
            return image_uuid
        else:
            if not self.glance:
                raise exceptions.InvalidConfigException(
                    'If glance is not available in the service catalog'
                    ' obtained by the openstack server provider, then'
                    ' images cannot be uploaded so the uuid of an'
                    ' existing image must be specified in the'
                    ' deployment config.')

        for image in self.glance.images.list():
            if image.checksum == self.config['image']['checksum']:
                LOG.info(_('Found image with appropriate checksum. Using it.'))
                return image.id

        LOG.info(_('Downloading new image %s') % self.config['image']['url'])
        image = self.glance.images.create(name=self.config['image']['name'])
        try:
            image.update(data=urllib2.urlopen(self.config['image']['url']),
                         disk_format=self.config['image']['format'],
                         container_format='bare')
        except urllib2.URLError:
            LOG.error(_('Unable to retrieve %s') % self.config['image']['url'])
            raise
        image.get()

        if image.checksum != self.config['image']['checksum']:
            raise exceptions.ChecksumMismatch(url=self.config['image']['url'])

        return image.id