def _satisfies_extra_specs(self, host_state, instance_type): """Check that the host_state provided by the compute service satisfy the extra specs associated with the instance type. """ if 'extra_specs' not in instance_type: return True for key, req in instance_type['extra_specs'].iteritems(): # Either not scope format, or in capabilities scope scope = key.split(':') if len(scope) > 1: if scope[0] != "capabilities": continue else: del scope[0] cap = self._get_capabilities(host_state, scope) if cap is None: return False if not extra_specs_ops.match(str(cap), req): LOG.debug("%(host_state)s fails extra_spec requirements. " "'%(req)s' does not match '%(cap)s'", {'host_state': host_state, 'req': req, 'cap': cap}) return False return True
def _satisfies_extra_specs(self, host_state, instance_type): """Check that the host_state provided by the compute service satisfy the extra specs associated with the instance type. """ if 'extra_specs' not in instance_type: return True for key, req in instance_type['extra_specs'].iteritems(): # Either not scope format, or in capabilities scope scope = key.split(':') if len(scope) > 1: if scope[0] != "capabilities": continue else: del scope[0] cap = self._get_capabilities(host_state, scope) if cap is None: return False if not extra_specs_ops.match(str(cap), req): LOG.debug( "%(host_state)s fails extra_spec requirements. " "'%(req)s' does not match '%(cap)s'", { 'host_state': host_state, 'req': req, 'cap': cap }) return False return True
def host_passes(self, host_state, filter_properties): """Return a list of hosts that can create instance_type Check that the extra specs associated with the instance type match the metadata provided by aggregates. If not present return False. """ instance_type = filter_properties.get('instance_type') if 'extra_specs' not in instance_type: return True metadata = utils.aggregate_metadata_get_by_host(host_state) for key, req in instance_type['extra_specs'].iteritems(): # Either not scope format, or aggregate_instance_extra_specs scope scope = key.split(':', 1) if len(scope) > 1: if scope[0] != _SCOPE: continue else: del scope[0] key = scope[0] aggregate_vals = metadata.get(key, None) if not aggregate_vals: LOG.debug( "%(host_state)s fails instance_type extra_specs " "requirements. Extra_spec %(key)s is not in aggregate.", { 'host_state': host_state, 'key': key }) return False for aggregate_val in aggregate_vals: if extra_specs_ops.match(aggregate_val, req): break else: LOG.debug( "%(host_state)s fails instance_type extra_specs " "requirements. '%(aggregate_vals)s' do not " "match '%(req)s'", { 'host_state': host_state, 'req': req, 'aggregate_vals': aggregate_vals }) return False return True
def host_passes(self, host_state, filter_properties): """Return a list of hosts that can create instance_type Check that the extra specs associated with the instance type match the metadata provided by aggregates. If not present return False. """ instance_type = filter_properties.get("instance_type") if "extra_specs" not in instance_type: return True metadata = utils.aggregate_metadata_get_by_host(host_state) for key, req in instance_type["extra_specs"].iteritems(): # Either not scope format, or aggregate_instance_extra_specs scope scope = key.split(":", 1) if len(scope) > 1: if scope[0] != _SCOPE: continue else: del scope[0] key = scope[0] aggregate_vals = metadata.get(key, None) if not aggregate_vals: LOG.debug( "%(host_state)s fails instance_type extra_specs " "requirements. Extra_spec %(key)s is not in aggregate.", {"host_state": host_state, "key": key}, ) return False for aggregate_val in aggregate_vals: if extra_specs_ops.match(aggregate_val, req): break else: LOG.debug( "%(host_state)s fails instance_type extra_specs " "requirements. '%(aggregate_vals)s' do not " "match '%(req)s'", {"host_state": host_state, "req": req, "aggregate_vals": aggregate_vals}, ) return False return True
def _do_extra_specs_ops_test(self, value, req, matches): assertion = self.assertTrue if matches else self.assertFalse assertion(extra_specs_ops.match(value, req))