一个Openstack 系统中通常包括多个计算节点
[email protected]:/etc/nova# nova hypervisor-list +----+---------------------+ | ID | Hypervisor hostname | +----+---------------------+ | 1 | compute | | 2 | network | | 3 | compute2 | +----+---------------------+这就产生了一个问题,当发出创建虚拟机请求时,应该把虚拟机创建到哪个计算节点上呢? nova-scheduler 服务即是实现这个调度工作的,调度算法通过filter 和weight 来实现。filter 用于选择可用的计算节点。weight 用于在可用的计算节点中选择一个最佳的节点。
filter
filter 在nova.conf 中配置,改动须要重新启动nova-scheduler 服务
默认的filter 为(截取icehouse版)
scheduler_default_filters = RetryFilter, AvailabilityZoneFilter, RamFilter,ComputeFilter, ComputeCapabilitiesFilter, ImagePropertiesFilter
以下列出各个filter 的功能
RetryFilter: 剔除上传已经被尝试调度过的计算节点AvailabilityZoneFilter:剔除那些AvailabilityZone 不满足要求的计算节点
ComputeFilter 剔除那些非活动的计算节点
ComputeCapabilitiesFilter 检查计算节点的其它属性
ImagePropertiesFilter 剔除那些硬件架构,Hypervisor,虚拟机模式等属性不满足磁盘镜像要求的节点
filter 类存放在nova/scheduler/filter 文件夹下全部的
[email protected]:/usr/lib/python2.7/dist-packages/nova/scheduler/filters# ll *.pyc -rw-r--r-- 1 root root 7207 Jul 15 09:33 affinity_filter.pyc -rw-r--r-- 1 root root 2400 Jul 15 09:33 aggregate_image_properties_isolation.pyc -rw-r--r-- 1 root root 2399 Jul 15 09:33 aggregate_instance_extra_specs.pyc -rw-r--r-- 1 root root 1896 Jul 15 09:33 aggregate_multitenancy_isolation.pyc -rw-r--r-- 1 root root 807 Jul 15 09:33 all_hosts_filter.pyc -rw-r--r-- 1 root root 1588 Jul 15 09:33 availability_zone_filter.pyc -rw-r--r-- 1 root root 2514 Jul 15 09:33 compute_capabilities_filter.pyc -rw-r--r-- 1 root root 1763 Jul 15 09:33 compute_filter.pyc -rw-r--r-- 1 root root 3671 Jul 15 09:33 core_filter.pyc -rw-r--r-- 1 root root 1900 Jul 15 09:33 disk_filter.pyc -rw-r--r-- 1 root root 2107 Jul 15 09:33 extra_specs_ops.pyc -rw-r--r-- 1 root root 4003 Jul 15 09:33 image_props_filter.pyc -rw-r--r-- 1 root root 2007 Jul 15 09:33 __init__.pyc -rw-r--r-- 1 root root 1641 Jul 15 09:33 io_ops_filter.pyc -rw-r--r-- 1 root root 2300 Jul 15 09:33 isolated_hosts_filter.pyc -rw-r--r-- 1 root root 5435 Jul 15 09:33 json_filter.pyc -rw-r--r-- 1 root root 2021 Jul 15 09:33 metrics_filter.pyc -rw-r--r-- 1 root root 1521 Jul 15 09:33 num_instances_filter.pyc -rw-r--r-- 1 root root 1497 Jul 15 09:33 pci_passthrough_filter.pyc -rw-r--r-- 1 root root 3824 Jul 15 09:33 ram_filter.pyc -rw-r--r-- 1 root root 1448 Jul 15 09:33 retry_filter.pyc -rw-r--r-- 1 root root 9769 Jul 15 09:33 trusted_filter.pyc -rw-r--r-- 1 root root 2237 Jul 15 09:33 type_filter.pyc
affinity_filter.py
这里文件中事实上有四个可用filter,都是关于亲和性的调度策略。分别例如以下:
DifferentHostFilter
创建虚拟机的同一时候能够指定一些虚拟机,要求新的虚拟机不能在这些虚拟机所在主机上创建。
说的简单一点,在host1上执行着vm1,要创建vm2。创建时指定了scheduler_hints->different_host=[vm1]。那么vm2就不会在host1上创建。
SameHostFilter
与上面的filter功能相反,假设创建时指定了scheduler_hints-> same_host=[vm1],那么vm2就能够创建在host1上。
SimpleCIDRAffinityFilter
假设指定了scheduler_hints-> build_near_host_ip,那么仅仅能在host1的管理IP网段内选择主机。
GroupAntiAffinityFilter
功能:指定scheduler_hints-> group_hosts=[host1, host2],那么虚拟机不能创建在这些host上。
core_filter.py
CoreFilter
功能:看host上的vcpu个数是否能满足创建虚拟机的instance_type中的vcpu个数。
依据CONF.cpu_allocation_ratio(默认是16)确定host上当前的vcpus_total。
disk_filter.py
DiskFilter
功能:看host上的disk大小是否能满足创建虚拟机的instance_type中的(root_gb + ephemeral_gb)。
计算disk总量时,会依据CONF.disk_allocation_ratio计算
ram_filter.py
RamFilter
AggregateRamFilter
同CoreFilter同样。
CONF.ram_allocation_ratio=1.5
image_props_filter.py
ImagePropertiesFilter
功能:看虚拟机image->properties中某些属性是否在host的capabilities->supported_instances内。
属性包含:architecture、hypervisor_type、vm_mode。假设image->properties中没有这些属性,则通过过滤;假设有这些属性,而host->capabilities->supported_instances没有,返回False。
io_ops_filter.py
IoOpsFilter
功能:依据主机的IO负载过滤。
IO负载由host->num_io_ops表示,与CONF.max_io_ops_per_host(默认是8)比較。
isolated_hosts_filter.py
IsolatedHostsFilter
功能:假设没有配置CONF.isolated_images,当前host不在CONF.isolated_hosts中,返回True。假设虚拟机image_ref在CONF.isolated_images中,且host在CONF.isolated_hosts中,返回True。其它情况返回False。
測试filter
我的环境眼下启动两个计算节点,horizon中的虚拟机管理器能够看到,compue 上可用资源最多。理论应该创建到compue 上
虚拟机在同样计算节点
改动scheduler_default_filters=SameHostFilter
[email protected]:/etc/nova# cat nova.conf [DEFAULT] scheduler_default_filters=SameHostFilter
或者在原有filter 前面加入 (规则从前到后优先)
scheduler_default_filters = SameHostFilter,RetryFilter, AvailabilityZoneFilter, RamFilter,ComputeFilter, ComputeCapabilitiesFilter, ImagePropertiesFilter
运行创建虚拟机,加入參数same_host=想要指定的虚拟机,6c16999c-e94a-4947-8489-1333d28862f8 为
在network 节点。
[email protected]:/etc/nova# nova show 6c16999c-e94a-4947-8489-1333d28862f8 +--------------------------------------+------------------------------------------------------------+ | Property | Value | +--------------------------------------+------------------------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | nova | | OS-EXT-SRV-ATTR:host | network | | OS-EXT-SRV-ATTR:hypervisor_hostname | network | | OS-EXT-SRV-ATTR:instance_name | instance-00000135 | | OS-EXT-STS:power_state | 1 | | OS-EXT-STS:task_state | - | | OS-EXT-STS:vm_state | active | | OS-SRV-USG:launched_at | 2015-12-25T03:30:35.000000 | | OS-SRV-USG:terminated_at | - | | accessIPv4 | | | accessIPv6 | | | config_drive | | | created | 2015-12-25T03:30:29Z | | flavor | m1 (bbf0b691-2f6a-4781-885c-26511f3f9318) | | hostId | 98b5cba71c2e72f61d0acb210bf7cc01a6ed8a3facabd5b6f4560f2a | | id | 6c16999c-e94a-4947-8489-1333d28862f8 | | image | cirros-0.3.2-x86_64 (d5aab3ac-74b5-4d53-91ee-92a22b48bb61) | | key_name | admin-key | | metadata | {} | | name | vm2 | | os-extended-volumes:volumes_attached | [] | | progress | 0 | | security_groups | default | | sharednet1 network | 192.168.12.116 | | status | ACTIVE | | tenant_id | 2996e46c2519415d8de2b141d6c607ba | | updated | 2015-12-25T03:30:35Z | | user_id | 84ad09b97a7f41d08afdf20afee08daf | +--------------------------------------+------------------------------------------------------------+
nova boot --flavor m1 --image cirros-0.3.2-x86_64 --nic net-id=d691ca44-6ec4-4118-b8dd-76f363a2b53f --security-group default --key-name admin-key vm5 --hint same_host=6c16999c-e94a-4947-8489-1333d28862f8
[email protected]:~# source admin-openrc.sh [email protected]:~# nova boot --flavor m1 --image cirros-0.3.2-x86_64 --nic net-id=d691ca44-6ec4-4118-b8dd-76f363a2b53f --security-group default --key-name admin-key vm5 --hint same_host=6c16999c-e94a-4947-8489-1333d28862f8 +--------------------------------------+------------------------------------------------------------+ | Property | Value | +--------------------------------------+------------------------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | nova | | OS-EXT-SRV-ATTR:host | - | | OS-EXT-SRV-ATTR:hypervisor_hostname | - | | OS-EXT-SRV-ATTR:instance_name | instance-0000013c | | OS-EXT-STS:power_state | 0 | | OS-EXT-STS:task_state | scheduling | | OS-EXT-STS:vm_state | building | | OS-SRV-USG:launched_at | - | | OS-SRV-USG:terminated_at | - | | accessIPv4 | | | accessIPv6 | | | adminPass | LHdQ245ZKktd | | config_drive | | | created | 2015-12-25T07:27:38Z | | flavor | m1 (bbf0b691-2f6a-4781-885c-26511f3f9318) | | hostId | | | id | e9863fe9-effc-475a-b1c1-5925080c8399 | | image | cirros-0.3.2-x86_64 (d5aab3ac-74b5-4d53-91ee-92a22b48bb61) | | key_name | admin-key | | metadata | {} | | name | vm5 | | os-extended-volumes:volumes_attached | [] | | progress | 0 | | security_groups | default | | status | BUILD | | tenant_id | 2996e46c2519415d8de2b141d6c607ba | | updated | 2015-12-25T07:27:39Z | | user_id | 84ad09b97a7f41d08afdf20afee08daf | +--------------------------------------+------------------------------------------------------------+ [email protected]:~# nova show e9863fe9-effc-475a-b1c1-5925080c8399 +--------------------------------------+------------------------------------------------------------+ | Property | Value | +--------------------------------------+------------------------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | nova | | OS-EXT-SRV-ATTR:host | network | | OS-EXT-SRV-ATTR:hypervisor_hostname | network | | OS-EXT-SRV-ATTR:instance_name | instance-0000013c | | OS-EXT-STS:power_state | 1 | | OS-EXT-STS:task_state | - | | OS-EXT-STS:vm_state | active | | OS-SRV-USG:launched_at | 2015-12-25T07:27:46.000000 | | OS-SRV-USG:terminated_at | - | | accessIPv4 | | | accessIPv6 | | | config_drive | | | created | 2015-12-25T07:27:38Z | | flavor | m1 (bbf0b691-2f6a-4781-885c-26511f3f9318) | | hostId | 98b5cba71c2e72f61d0acb210bf7cc01a6ed8a3facabd5b6f4560f2a | | id | e9863fe9-effc-475a-b1c1-5925080c8399 | | image | cirros-0.3.2-x86_64 (d5aab3ac-74b5-4d53-91ee-92a22b48bb61) | | key_name | admin-key | | metadata | {} | | name | vm5 | | os-extended-volumes:volumes_attached | [] | | progress | 0 | | security_groups | default | | sharednet1 network | 192.168.12.122 | | status | ACTIVE | | tenant_id | 2996e46c2519415d8de2b141d6c607ba | | updated | 2015-12-25T07:27:46Z | | user_id | 84ad09b97a7f41d08afdf20afee08daf | +--------------------------------------+------------------------------------------------------------+ [email protected]:~#
查看,新虚拟机又创建到了network 上面