~ubuntu-branches/ubuntu/utopic/cinder/utopic

« back to all changes in this revision

Viewing changes to cinder/scheduler/chance.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Adam Gandelman, Chuck Short
  • Date: 2013-09-08 21:09:46 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20130908210946-3dbzq1jy5uji4wad
Tags: 1:2013.2~b3-0ubuntu1
[ James Page ]
* d/control: Switch ceph-common -> python-ceph inline with upstream
  refactoring of Ceph RBD driver, move to Suggests of python-cinder.
  (LP: #1190791). 

[ Adam Gandelman ]
* debian/patches/avoid_paramiko_vers_depends.patch: Dropped, no longer
  required.
* Add minimum requirement python-greenlet (>= 0.3.2).
* Add minimum requirement python-eventlet (>= 0.12.0).
* Add minimum requirement python-paramiko (>= 1.8).

[ Chuck Short ]
* New upstream release.
* debian/patches/skip-sqlachemy-failures.patch: Skip testfailures
  with sqlalchemy 0.8 until they are fixed upstream.
* debian/control: Add python-babel to build-depends.
* debian/control: Add python-novaclient to build-depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
        """Filter a list of hosts based on request_spec."""
40
40
 
41
41
        filter_properties = kwargs.get('filter_properties', {})
 
42
        if not filter_properties:
 
43
            filter_properties = {}
42
44
        ignore_hosts = filter_properties.get('ignore_hosts', [])
43
45
        hosts = [host for host in hosts if host not in ignore_hosts]
44
46
        return hosts
45
47
 
46
 
    def _schedule(self, context, topic, request_spec, **kwargs):
47
 
        """Picks a host that is up at random."""
 
48
    def _get_weighted_candidates(self, context, topic, request_spec, **kwargs):
 
49
        """Returns a list of the available hosts."""
48
50
 
49
51
        elevated = context.elevated()
50
52
        hosts = self.hosts_up(elevated, topic)
52
54
            msg = _("Is the appropriate service running?")
53
55
            raise exception.NoValidHost(reason=msg)
54
56
 
55
 
        hosts = self._filter_hosts(request_spec, hosts, **kwargs)
 
57
        return self._filter_hosts(request_spec, hosts, **kwargs)
 
58
 
 
59
    def _schedule(self, context, topic, request_spec, **kwargs):
 
60
        """Picks a host that is up at random."""
 
61
        hosts = self._get_weighted_candidates(context, topic,
 
62
                                              request_spec, **kwargs)
56
63
        if not hosts:
57
64
            msg = _("Could not find another host")
58
65
            raise exception.NoValidHost(reason=msg)
59
 
 
60
66
        return hosts[int(random.random() * len(hosts))]
61
67
 
62
68
    def schedule_create_volume(self, context, request_spec, filter_properties):
71
77
        updated_volume = driver.volume_update_db(context, volume_id, host)
72
78
        self.volume_rpcapi.create_volume(context, updated_volume, host,
73
79
                                         snapshot_id, image_id)
 
80
 
 
81
    def host_passes_filters(self, context, host, request_spec,
 
82
                            filter_properties):
 
83
        """Check if the specified host passes the filters."""
 
84
        weighed_hosts = self._get_weighted_candidates(
 
85
            context,
 
86
            CONF.volume_topic,
 
87
            request_spec,
 
88
            filter_properties=filter_properties)
 
89
 
 
90
        for weighed_host in weighed_hosts:
 
91
            if weighed_host == host:
 
92
                elevated = context.elevated()
 
93
                host_states = self.host_manager.get_all_host_states(elevated)
 
94
                for host_state in host_states:
 
95
                    if host_state.host == host:
 
96
                        return host_state
 
97
 
 
98
        msg = (_('cannot place volume %(id)s on %(host)s')
 
99
               % {'id': request_spec['volume_id'], 'host': host})
 
100
        raise exception.NoValidHost(reason=msg)