Beispiel #1
0
    def schedule_create_volume(self, context, volume_id, **_kwargs):
        """Picks a host that is up and has the fewest volumes."""
        elevated = context.elevated()

        volume_ref = db.volume_get(context, volume_id)
        availability_zone = volume_ref.get('availability_zone')

        zone, host = None, None
        if availability_zone:
            zone, _x, host = availability_zone.partition(':')
        if host and context.is_admin:
            service = db.service_get_by_args(elevated, host, 'cinder-volume')
            if not utils.service_is_up(service):
                raise exception.WillNotSchedule(host=host)
            driver.cast_to_volume_host(context, host, 'create_volume',
                    volume_id=volume_id, **_kwargs)
            return None

        results = db.service_get_all_volume_sorted(elevated)
        if zone:
            results = [(service, gigs) for (service, gigs) in results
                       if service['availability_zone'] == zone]
        for result in results:
            (service, volume_gigabytes) = result
            if volume_gigabytes + volume_ref['size'] > FLAGS.max_gigabytes:
                msg = _("Not enough allocatable volume gigabytes remaining")
                raise exception.NoValidHost(reason=msg)
            if utils.service_is_up(service) and not service['disabled']:
                driver.cast_to_volume_host(context, service['host'],
                        'create_volume', volume_id=volume_id, **_kwargs)
                return None
        msg = _("Is the appropriate service running?")
        raise exception.NoValidHost(reason=msg)
Beispiel #2
0
    def schedule_create_volume(self, context, volume_id, *_args, **_kwargs):
        """Picks a host that is up and has the fewest volumes."""
        elevated = context.elevated()

        volume_ref = db.volume_get(context, volume_id)
        availability_zone = volume_ref.get("availability_zone")

        zone, host = None, None
        if availability_zone:
            zone, _x, host = availability_zone.partition(":")
        if host and context.is_admin:
            service = db.service_get_by_args(elevated, host, "cinder-volume")
            if not utils.service_is_up(service):
                raise exception.WillNotSchedule(host=host)
            driver.cast_to_volume_host(context, host, "create_volume", volume_id=volume_id, **_kwargs)
            return None

        results = db.service_get_all_volume_sorted(elevated)
        if zone:
            results = [(service, gigs) for (service, gigs) in results if service["availability_zone"] == zone]
        for result in results:
            (service, volume_gigabytes) = result
            if volume_gigabytes + volume_ref["size"] > FLAGS.max_gigabytes:
                msg = _("Not enough allocatable volume gigabytes remaining")
                raise exception.NoValidHost(reason=msg)
            if utils.service_is_up(service) and not service["disabled"]:
                driver.cast_to_volume_host(context, service["host"], "create_volume", volume_id=volume_id, **_kwargs)
                return None
        msg = _("Is the appropriate service running?")
        raise exception.NoValidHost(reason=msg)
Beispiel #3
0
 def test_service_get_all_volume_sorted(self):
     values = [
         ({'host': 'h1', 'binary': 'a', 'topic': FLAGS.volume_topic}, 100),
         ({'host': 'h2', 'binary': 'b', 'topic': FLAGS.volume_topic}, 200),
         ({'host': 'h3', 'binary': 'b', 'topic': FLAGS.volume_topic}, 300)]
     services = []
     for vals, size in values:
         services.append(self._create_service(vals))
         db.volume_create(self.ctxt, {'host': vals['host'], 'size': size})
     for service, size in db.service_get_all_volume_sorted(self.ctxt):
         self._assertEqualObjects(services.pop(0), service)
         self.assertEqual(values.pop(0)[1], size)
Beispiel #4
0
 def test_service_get_all_volume_sorted(self):
     values = [
         ({"host": "h1", "binary": "a", "topic": CONF.volume_topic}, 100),
         ({"host": "h2", "binary": "b", "topic": CONF.volume_topic}, 200),
         ({"host": "h3", "binary": "b", "topic": CONF.volume_topic}, 300),
     ]
     services = []
     for vals, size in values:
         services.append(self._create_service(vals))
         db.volume_create(self.ctxt, {"host": vals["host"], "size": size})
     for service, size in db.service_get_all_volume_sorted(self.ctxt):
         self._assertEqualObjects(services.pop(0), service)
         self.assertEqual(values.pop(0)[1], size)
    def schedule_create_volume(self, context, request_spec, filter_properties):
        """Picks a host that is up and has the fewest volumes."""
        elevated = context.elevated()

        volume_id = request_spec.get('volume_id')
        snapshot_id = request_spec.get('snapshot_id')
        image_id = request_spec.get('image_id')
        volume_properties = request_spec.get('volume_properties')
        volume_size = volume_properties.get('size')
        availability_zone = volume_properties.get('availability_zone')

        zone, host = None, None
        if availability_zone:
            zone, _x, host = availability_zone.partition(':')
        if host and context.is_admin:
            topic = CONF.volume_topic
            service = db.service_get_by_args(elevated, host, topic)
            if not utils.service_is_up(service):
                raise exception.WillNotSchedule(host=host)
            updated_volume = driver.volume_update_db(context, volume_id, host)
            self.volume_rpcapi.create_volume(context,
                                             updated_volume,
                                             host,
                                             request_spec,
                                             filter_properties,
                                             snapshot_id=snapshot_id,
                                             image_id=image_id)
            return None

        results = db.service_get_all_volume_sorted(elevated)
        if zone:
            results = [(s, gigs) for (s, gigs) in results
                       if s['availability_zone'] == zone]
        for result in results:
            (service, volume_gigabytes) = result
            if volume_gigabytes + volume_size > CONF.max_gigabytes:
                msg = _("Not enough allocatable volume gigabytes remaining")
                raise exception.NoValidHost(reason=msg)
            if utils.service_is_up(service) and not service['disabled']:
                updated_volume = driver.volume_update_db(
                    context, volume_id, service['host'])
                self.volume_rpcapi.create_volume(context,
                                                 updated_volume,
                                                 service['host'],
                                                 request_spec,
                                                 filter_properties,
                                                 snapshot_id=snapshot_id,
                                                 image_id=image_id)
                return None
        msg = _("Is the appropriate service running?")
        raise exception.NoValidHost(reason=msg)
 def test_service_get_all_volume_sorted(self):
     values = [
         ({'host': 'h1', 'binary': 'a', 'topic': CONF.volume_topic},
          100),
         ({'host': 'h2', 'binary': 'b', 'topic': CONF.volume_topic},
          200),
         ({'host': 'h3', 'binary': 'b', 'topic': CONF.volume_topic},
          300)]
     services = []
     for vals, size in values:
         services.append(self._create_service(vals))
         db.volume_create(self.ctxt, {'host': vals['host'], 'size': size})
     for service, size in db.service_get_all_volume_sorted(self.ctxt):
         self._assertEqualObjects(services.pop(0), service)
         self.assertEqual(values.pop(0)[1], size)
Beispiel #7
0
    def schedule_create_volume(self, context, request_spec, filter_properties):
        """Picks a host that is up and has the fewest volumes."""
        elevated = context.elevated()

        volume_id = request_spec.get('volume_id')
        snapshot_id = request_spec.get('snapshot_id')
        image_id = request_spec.get('image_id')
        volume_properties = request_spec.get('volume_properties')
        volume_size = volume_properties.get('size')
        availability_zone = volume_properties.get('availability_zone')

        zone, host = None, None
        if availability_zone:
            zone, _x, host = availability_zone.partition(':')
        if host and context.is_admin:
            topic = FLAGS.volume_topic
            service = db.service_get_by_args(elevated, host, topic)
            if not utils.service_is_up(service):
                raise exception.WillNotSchedule(host=host)
            updated_volume = driver.volume_update_db(context, volume_id, host)
            self.volume_rpcapi.create_volume(context,
                                             updated_volume,
                                             host,
                                             snapshot_id,
                                             image_id)
            return None

        results = db.service_get_all_volume_sorted(elevated)
        if zone:
            results = [(service, gigs) for (service, gigs) in results
                       if service['availability_zone'] == zone]
        for result in results:
            (service, volume_gigabytes) = result
            if volume_gigabytes + volume_size > FLAGS.max_gigabytes:
                msg = _("Not enough allocatable volume gigabytes remaining")
                raise exception.NoValidHost(reason=msg)
            if utils.service_is_up(service) and not service['disabled']:
                updated_volume = driver.volume_update_db(context, volume_id,
                                                         service['host'])
                self.volume_rpcapi.create_volume(context,
                                                 updated_volume,
                                                 service['host'],
                                                 snapshot_id,
                                                 image_id)
                return None
        msg = _("Is the appropriate service running?")
        raise exception.NoValidHost(reason=msg)
Beispiel #8
0
    def _get_weighted_candidates(self, context, topic, request_spec, **kwargs):
        """Picks a host that is up and has the fewest volumes."""
        elevated = context.elevated()

        volume_id = request_spec.get('volume_id')
        snapshot_id = request_spec.get('snapshot_id')
        image_id = request_spec.get('image_id')
        volume_properties = request_spec.get('volume_properties')
        volume_size = volume_properties.get('size')
        availability_zone = volume_properties.get('availability_zone')
        filter_properties = kwargs.get('filter_properties', {})

        zone, host = None, None
        if availability_zone:
            zone, _x, host = availability_zone.partition(':')
        if host and context.is_admin:
            service = db.service_get_by_args(elevated, host, topic)
            if not utils.service_is_up(service):
                raise exception.WillNotSchedule(host=host)
            return [host]

        candidates = []
        results = db.service_get_all_volume_sorted(elevated)
        if zone:
            results = [(s, gigs) for (s, gigs) in results
                       if s['availability_zone'] == zone]
        for result in results:
            (service, volume_gigabytes) = result
            no_skip = service['host'] != filter_properties.get('vol_exists_on')
            if no_skip and volume_gigabytes + volume_size > CONF.max_gigabytes:
                continue
            if utils.service_is_up(service) and not service['disabled']:
                candidates.append(service['host'])

        if candidates:
            return candidates
        else:
            msg = _("No service with adequate space or no service running")
            raise exception.NoValidHost(reason=msg)