'Make sure a custom resource class exists.
First attempt to PUT the resource class using microversion 1.7. If
this results in a 406, fail over to a GET and POST with version 1.2.
Returns the name of the resource class if it was successfully
created or already exists. Otherwise None.
:param name: String name of the resource class to check/create.
:raises: `exception.InvalidResourceClass` upon error.'

@safe_connect
def _ensure_resource_class(self, name):

    response = self.put(('/resource_classes/%s' % name), None, version='1.7')
    if (200 <= response.status_code < 300):
        return name
    elif (response.status_code == 406):
        LOG.debug('Falling    back    to    placement    API    microversion    1.2    for    resource    class    management.')
        return self._get_or_create_resource_class(name)
    else:
        msg = _LE('Failed    to    ensure    resource    class    record    with    placement    API    for    resource    class    %(rc_name)s.    Got    %(status_code)d:    %(err_text)s.')
        args = {'rc_name': name, 'status_code': response.status_code, 'err_text': response.text}
        LOG.error(msg, args)
        raise exception.InvalidResourceClass(resource_class=name)
