# add by ttx
def
check_compute_host_is_available(self , context, instance_opts, image, host, nextSearchFlag=
False
):
elevated = context.elevated()
compute_node_info = db.compute_node_get_by_host(elevated, host)
nova_volumes_free = compute_node_info.nova_volumes_free
nova_volumes_size = compute_node_info.nova_volumes_size
mem_instance_used = compute_node_info.mem_instance_used
memory_mb = compute_node_info.memory_mb
memory_mb_used = compute_node_info.memory_mb_used
memory_mb_free = memory_mb - mem_instance_used
image_size = image.get(
'size'
)
image_size_mb = image_size/
1024
/
1024
save_volumes_G = FLAGS.save_volumes_G
# save 30G space ,and next the variable can use the configuration item
if
FLAGS.use_block:
if
image_size_mb > nova_volumes_free - save_volumes_G *
1024
:
if
nextSearchFlag:
LOG.debug(_(
'%s nova -volumes space is not enongh, the all nova-volume space is %sG, the nova-volume free space is %sG, and the nova-volume must save %sG, but the image_size need is %sG'
%(host, nova_volumes_size/
1024
, nova_volumes_free/
1024
, save_volumes_G , image_size_mb/
1024
)))
return
False
else
:
msg = _(
'%s nova -volumes space is not enongh, the all nova-volume space is %sG, the nova-volume free space is %sG, and the nova-volume must save %sG, but the image_size need is %sG'
%(host, nova_volumes_size/
1024
, nova_volumes_free/
1024
, save_volumes_G , image_size_mb/
1024
))
raise
exception.NoValidHost(reason=msg)
if
mem_instance_used + instance_opts[
'memory_mb'
] > memory_mb * FLAGS.mem_use_rate:
if
nextSearchFlag:
LOG.debug(_(
'%s instances has use %smb memory,the all has % smb memory, is not enough to launch the instance(%smb)...'
%(host, mem_instance_used, memory_mb, instance_opts[
'memory_mb'
])))
return
False
#next to search the appropriate host to launch the instance
else
:
msg = _(
'%s instances has use %smb memory,the all has %smb memory, is not enough to launch the instance(%smb)...'
%(host, mem_instance_used, memory_mb, instance_opts[
'memory_mb'
]))
raise
exception.NoValidHost(reason=msg)
return
True
1、内存控制:在创建虚拟机时、查看已经生成的实例所分配的内存总量(包括暂停的虚拟机)再加上当前正在创建的虚拟机所需要的内存、再将该值与物理机的实际内存做比较
、假若超过实际内存的90%
(可配置)、则在调度算法提示内存不足、不让创建虚拟机。
下图为计算节点无虚拟机时,计算节点资源使用情况:内存使用率=2.856%(说明空闲时间基本不占用内存)
k
2、磁盘控制:vgdispaly查看卷的使用情况(nova-volumes名字从配置文件读取)、动态控制创建虚拟机的附加卷磁盘是否有足够可用的磁盘空间。(预留20G,
可配置)
3、将内存信息和磁盘信息保存在数据库里面(创建虚拟机时实时刷新)
4、数据库设计:在现有的数据库表compute_nodes中增加字段:
nova_volumes_size:
nova_volumes_free:
mem_instance_used:
由于jddc_host_info与compute_info两个数据库表有冗余、所以将用于spice控制的host数据库表合并到此表,在以后升级,将废除jddc_host_info数据库表、直接使用compute_nodes表。
因此在compute_info表中加入hostname、ip、befin_port、end_port字段
以下为现有的jddc_host_info数据库表:
以下为现有的compute_info数据库表:
5、具体资源调度控制实现:
在nova的调度算法里面、进行资源判断、若资源不满足创建需求则、抛出错误信息,创建终止;否则生成虚拟机。
1、内存控制:在创建虚拟机时、查看已经生成的实例所分配的内存总量(包括暂停的虚拟机)再加上当前正在创建的虚拟机所需要的内存、再将该值与物理机的实际内存做比较
、假若超过实际内存的90%?(可配置)、则页面提示内存不足、不让创建虚拟机。(
是否应该考虑实际剩余的内存?)
下图为计算节点无虚拟机时,计算节点资源使用情况:内存使用率=2.856%(说明空闲时间基本不占用内存)
k
2、磁盘控制:vgdispaly查看卷的使用情况(nova-volumes名字配置文件读取)、动态控制创建虚拟机的附加卷磁盘(image的size)。(预留20G,可配置)(
df查看卷组的使用情况、动态控制创建虚拟机的磁盘。instance的拷贝?,其中不同实例假若用的是同一个镜像、则差异文件保存在nova-volumes里面?)
3、将内存信息和磁盘信息保存在数据库里面(创建虚拟机时实时刷新)
创建单独的数据库:node_info(设计参考service)
id:
host:
created_at:
updated_at:
physic_core:
instance_used_core:
physic_all_mem:
physic_free_mem:
instance_used_mem:
nova_volumes_size:
nova_volumes_free:
avg_load:(保存系统最近15分钟内平均负载,即uptime的最后一个数值)
instance_num:
instance_disk_all:(记录可供instance使用的磁盘总存储空间_base???)
instance_disk_free:(记录instance的磁盘存储剩余空间???)
4、cpu核数要做控制???
top
uptime
vmstat 1
def getNodeInfo():
result = {}
if_str = execute('grep cores /proc/cpuinfo | head -n 1 | cut -d ":" -f2',shell=True)
physic_core = int(if_str[0].split()[0])
result['physic_core'] = physic_core
if_str = execute("free |grep Mem | awk '{print $2}'",shell=True)
physic_all_mem = int(if_str[0].split()[0])
result['physic_all_mem'] = physic_all_mem
if_str = execute("free |grep Mem | awk '{print $4}'",shell=True)
physic_free_mem = int(if_str[0].split()[0])
result['physic_free_mem'] = physic_free_mem
if_str = execute("vgdisplay nova-volumes | grep Alloc | awk '{print $7}'",shell=True)
nova_volumes_size = float((if_str[0].split()[0]))
result['nova_volumes_size'] = nova_volumes_size
if_str = execute("vgdisplay nova-volumes | grep Free | awk '{print $7}'",shell=True)
nova_volumes_free = float(if_str[0].split()[0])
result['nova_volumes_free'] = nova_volumes_free
if_str = execute("uptime | awk '{print $12}'",shell=True)
avg_load = float(if_str[0].split()[0])
result['avg_load'] = avg_load
result['instance_disk_all'] = None
result['instance_disk_free'] = None
print result