def host_passes(self, host_state, filter_properties): spec = filter_properties.get('request_spec', {}) props = spec.get('instance_properties', {}) availability_zone = props.get('availability_zone') if not availability_zone: return True metadata = utils.aggregate_metadata_get_by_host( host_state, key='availability_zone') if 'availability_zone' in metadata: hosts_passes = availability_zone in metadata['availability_zone'] host_az = metadata['availability_zone'] else: hosts_passes = availability_zone == CONF.default_availability_zone host_az = CONF.default_availability_zone if not hosts_passes: LOG.debug("Availability Zone '%(az)s' requested. " "%(host_state)s has AZs: %(host_az)s", {'host_state': host_state, 'az': availability_zone, 'host_az': host_az}) return hosts_passes
def test_aggregate_metadata_get_by_host_empty_result(self): host_state = fakes.FakeHostState( 'fake', 'node', {'aggregates': []}) metadata = utils.aggregate_metadata_get_by_host(host_state, 'k3') self.assertEqual({}, metadata)
def test_aggregate_metadata_get_by_host_with_key(self): host_state = fakes.FakeHostState( 'fake', 'node', {'aggregates': _AGGREGATE_FIXTURES}) metadata = utils.aggregate_metadata_get_by_host(host_state, 'k1') self.assertIn('k1', metadata) self.assertEqual(set(['1', '3', '7', '6']), metadata['k1'])
def host_passes(self, host_state, filter_properties): """If a host is in an aggregate that has the metadata key "filter_tenant_id" it can only create instances from that tenant(s). A host can be in different aggregates. If a host doesn't belong to an aggregate with the metadata key "filter_tenant_id" it can create instances from all tenants. """ spec = filter_properties.get('request_spec', {}) props = spec.get('instance_properties', {}) tenant_id = props.get('project_id') metadata = utils.aggregate_metadata_get_by_host(host_state, key="filter_tenant_id") if metadata != {}: if tenant_id not in metadata["filter_tenant_id"]: LOG.debug("%s fails tenant id on aggregate", host_state) 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): """Checks a host in an aggregate that metadata key/value match with image properties. """ cfg_namespace = CONF.aggregate_image_properties_isolation_namespace cfg_separator = CONF.aggregate_image_properties_isolation_separator spec = filter_properties.get("request_spec", {}) image_props = spec.get("image", {}).get("properties", {}) metadata = utils.aggregate_metadata_get_by_host(host_state) for key, options in metadata.iteritems(): if cfg_namespace and not key.startswith(cfg_namespace + cfg_separator): continue prop = image_props.get(key) if prop and prop not in options: LOG.debug( "%(host_state)s fails image aggregate properties " "requirements. Property %(prop)s does not " "match %(options)s.", {"host_state": host_state, "prop": prop, "options": options}, ) return False return True
def test_aggregate_metadata_get_by_host_empty_result(self): host_state = fakes.FakeHostState('fake', 'node', {'aggregates': []}) metadata = utils.aggregate_metadata_get_by_host(host_state, 'k3') self.assertEqual({}, metadata)