'This code is needed in Pike to prevent problems where an operator
has already adjusted their flavors to add the custom resource class to
extra_specs. Since existing ironic instances will not have this in
their extra_specs, they will only have allocations against
VCPU/RAM/disk. By adding just the custom RC to the existing flavor
extra_specs, the periodic call to update_available_resources() will add
an allocation against the custom resource class, and prevent placement
from thinking that that node is available. This code can be removed in
Queens, and will need to be updated to also alter extra_specs to
zero-out the old-style standard resource classes of VCPU, MEMORY_MB,
and DISK_GB.'

def _pike_flavor_migration(self, host):

    ctx = nova_context.get_admin_context()
    for node in six.itervalues(self.node_cache):
        if (not node.instance_uuid):
            continue
        if (not node.resource_class):
            LOG.warning('Node    %(node)s    does    not    have    its    resource_class    set.', {'node': node.uuid})
            continue
        rc = obj_fields.ResourceClass.normalize_name(node.resource_class)
        instance = objects.Instance.get_by_uuid(ctx, node.instance_uuid, expected_attrs=['flavor'])
        specs = instance.flavor.extra_specs
        res_key = ('resources:%s' % rc)
        if (res_key in specs):
            continue
        specs[res_key] = 1
        instance.save()
        LOG.debug("The    flavor    extra_specs    for    Ironic    instance    %(inst)s    have    been    updated    for    custom    resource    class    '%(rc)s'.", {'inst': instance.uuid, 'rc': rc})
    return
