Ejemplo n.º 1
0
    def delete_server(self, server):
        '''Deletes a server and waits for it to disappear from Nova.'''
        if not server:
            return
        try:
            server.delete()
        except Exception as exc:
            self.ignore_not_found(exc)
            return

        while True:
            yield

            try:
                self.refresh_server(server)
            except Exception as exc:
                self.ignore_not_found(exc)
                break
            else:
                # Some clouds append extra (STATUS) strings to the status
                short_server_status = server.status.split('(')[0]
                if short_server_status in ("DELETED", "SOFT_DELETED"):
                    break
                if short_server_status == "ERROR":
                    fault = getattr(server, 'fault', {})
                    message = fault.get('message', 'Unknown')
                    code = fault.get('code')
                    errmsg = (_("Server %(name)s delete failed: (%(code)s) "
                                "%(message)s"))
                    raise exception.Error(errmsg % {
                        "name": server.name,
                        "code": code,
                        "message": message
                    })
Ejemplo n.º 2
0
    def get_image_id_by_name(self, image_identifier):
        '''Return an id for the specified image name.

        :param image_identifier: image name
        :returns: the id of the requested :image_identifier:
        :raises: exception.ImageNotFound,
                 exception.PhysicalResourceNameAmbiguity
        '''
        try:
            filters = {'name': image_identifier}
            image_list = list(self.client().images.list(filters=filters))
        except exc.ClientException as ex:
            raise exception.Error(
                _("Error retrieving image list from glance: %s") % ex)
        num_matches = len(image_list)
        if num_matches == 0:
            LOG.info(_LI("Image %s was not found in glance"), image_identifier)
            raise exception.ImageNotFound(image_name=image_identifier)
        elif num_matches > 1:
            LOG.info(_LI("Multiple images %s were found in glance with name"),
                     image_identifier)
            raise exception.PhysicalResourceNameAmbiguity(
                name=image_identifier)
        else:
            return image_list[0].id
Ejemplo n.º 3
0
    def check_rebuild(self, server, image_id):
        """Verify that a rebuilding server is rebuilt.

        Raise error if it ends up in an ERROR state.
        """
        self.refresh_server(server)
        while server.status == 'REBUILD':
            yield
            self.refresh_server(server)
        if server.status == 'ERROR':
            raise exception.Error(
                _("Rebuilding server failed, status '%s'") % server.status)
Ejemplo n.º 4
0
    def check_resize(self, server, flavor, flavor_id):
        """Verify that a resizing server is properly resized.

        If that's the case, confirm the resize, if not raise an error.
        """
        self.refresh_server(server)
        while server.status == 'RESIZE':
            yield
            self.refresh_server(server)
        if server.status == 'VERIFY_RESIZE':
            server.confirm_resize()
        else:
            raise exception.Error(
                _("Resizing to '%(flavor)s' failed, status '%(status)s'") %
                dict(flavor=flavor, status=server.status))
Ejemplo n.º 5
0
    def get_price(self, resource):
        '''Get the price of resource in seconds.

        If no exact price found, it shows that rule of the server's flavor
        has not been set, will return 0 as the price notify admin to set
        it.

        :param: resource: Resource object to find price.
        '''
        flavor = resource.properties.get('flavor', None)
        if not flavor:
            raise exception.Error(msg='Flavor should be provided to get '
                                      'the price of server.')
        p_mapping = self.properties.get(self.PRICE_MAPPING)
        price = 0
        for pm in p_mapping:
            if flavor == pm.get(self.FLAVOR):
                price = pm.get(self.PRICE)
        if self.PER_HOUR == self.properties.get(self.UNIT) and price > 0:
            price = price * 1.0 / 3600
        return price
Ejemplo n.º 6
0
    def _create(self):

        con = self.context

        volume_api_version = self.get_volume_api_version()
        if volume_api_version == 1:
            service_type = 'volume'
            client_version = '1'
        elif volume_api_version == 2:
            service_type = 'volumev2'
            client_version = '2'
        else:
            raise exception.Error(_('No volume service available.'))
        LOG.info(_LI('Creating Cinder client with volume API version %d.'),
                 volume_api_version)

        endpoint_type = self._get_client_option('cinder', 'endpoint_type')
        args = {
            'service_type': service_type,
            'auth_url': con.auth_url or '',
            'project_id': con.tenant,
            'username': None,
            'api_key': None,
            'endpoint_type': endpoint_type,
            'http_log_debug': self._get_client_option('cinder',
                                                      'http_log_debug'),
            'cacert': self._get_client_option('cinder', 'ca_file'),
            'insecure': self._get_client_option('cinder', 'insecure')
        }

        client = cc.Client(client_version, **args)
        management_url = self.url_for(service_type=service_type,
                                      endpoint_type=endpoint_type)
        client.client.auth_token = self.auth_token
        client.client.management_url = management_url

        client.volume_api_version = volume_api_version

        return client