支持windows虛擬機和linux虛擬機分區調度

有一個新裝的環境測試報windows,linux分區調度不支持

測試前提條件:

  • Openstack Pike
  • image文件配置了metadata。openstack image set –property os_type=windows image_id
  • 主機組也配置了metadate。nova aggregate-set-metadata aggregate_id os_type=windows

用該image生成的vm,沒有被nova-scheduler調度到windows主機組。

分析原因,首先想到的是nova的配置文件filter選項有沒有配置對應的filter。

# vim /etc/nova/nova.conf

scheduler_default_filters果然沒有配置AggregateImagePropertiesIsolation

AggregateImagePropertiesIsolation的作用:Checks a host in an aggregate that metadata key/value match with image properties.

將AggregateImagePropertiesIsolation加上,重啓openstack-nova-scheduler.service但生成的vm仍舊不能被調度到windows主機組。

查看日誌文件/var/log/nova/nova-scheduler.log:發現有這句話:Filter AggregateImagePropertiesIsolation returned 5 host(s) get_filtered_objects /usr/lib/python2.7/site-packages/nova/filters.py:104

說明filter:AggregateImagePropertiesIsolation生效了,但是卻不能識別出windows主機組,返回了5 host(s),該環境一共就5個計算節點。

查看代碼邏輯:

# vim /lib/python2.7/site-packages/nova/scheduler/filters/aggregate_image_properties_isolation.py
class AggregateImagePropertiesIsolation(filters.BaseHostFilter):
    """AggregateImagePropertiesIsolation works with image properties."""

    # Aggregate data and instance type does not change within a request
    run_filter_once_per_request = True

    def host_passes(self, host_state, spec_obj):
        """Checks a host in an aggregate that metadata key/value match        with image properties.        """
        cfg_namespace = (CONF.filter_scheduler.
            aggregate_image_properties_isolation_namespace)
        cfg_separator = (CONF.filter_scheduler.
            aggregate_image_properties_isolation_separator)

        image_props = spec_obj.image.properties if spec_obj.image else {}
        LOG.debug("##### image_props: %s #####" % image_props)
        metadata = utils.aggregate_metadata_get_by_host(host_state)

        for key, options in metadata.items():
            if (cfg_namespace and
                    not key.startswith(cfg_namespace + cfg_separator)):
                continue
            prop = None
            try:
                prop = image_props.get(key)
            except AttributeError:
                LOG.warning(_LW("Host '%(host)s' has a metadata key '%(key)s' "
                                "that is not present in the image metadata."),
                            {"host": host_state.host, "key": key})
                continue

            # NOTE(sbauza): Aggregate metadata is only strings, we need to
            # stringify the property to match with the option
            # TODO(sbauza): Fix that very ugly pattern matching
            if prop and str(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

通過代碼得知,只有一種情況下才會返回False,其他情況都是返回True。False就是計算節點被過濾掉,True是沒被過濾掉。現在的實際情況是沒有被過濾,全部計算節點返回的是True。期望的是隻有metadate被設置爲windows的主機返回True,其他應該都是False。現在來分析原因。

看代碼,返回False只有一種情況:主機的某一個metadata和image的metadata不匹配。返回True,除了主機的所有metadata和image的metadata都匹配會返回;還有一種情況在代碼的continue語句中,即在except中,該異常是AttributeError。就是說主機的所有metadata只要是或者和image的metadata都匹配或者不存在於image的metadata中,就會執行完所有的while循環,返回True。

檢查不期望被filter通過的主機的metadata,nova aggregate-show aggregate_id 發現其他主機組沒有配置os_type。用命令nova aggregate-set-metadatew aggregate_id給其他主機組添加屬性:os_type=linux

再用該image生成vm,可以被正確調度到windows主機組。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章