码迷,mamicode.com
首页 > 其他好文 > 详细

OpenStack启动虚拟机、虚拟机做快照加速

时间:2015-09-25 04:05:03      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:snapshots nova

虚拟机做快照加速:

 [root@controller-39 ~]# vim /usr/lib/python2.7/site-packages/nova/virt/libvirt/driver.py
cfg.StrOpt(‘snapshots_directory‘,
               default=‘$instances_path/snapshots‘,
               help=‘Location where libvirt driver will store snapshots ‘
                    ‘before uploading them to image service‘),
CONF = cfg.CONF
CONF.register_opts(libvirt_opts, ‘libvirt‘)

# 可以看出nova.conf中可以配置虚拟机做快照(默认全量快照),快照上传到glance之前的过渡目录(比如:配置在ssd盘上)。


启动虚拟机加速:

# openstack第一次启动虚拟机的时候会从glance拉镜像到本地(默认是$instances_path/_base)
# 第二次以同样的镜像启动虚拟机的时候就直接从$image_cache_directory_name/_base启动了
# 同样,如果base目录是ssd的话,启动虚拟机快是理所应当的。
# 下面的patch就是把虚拟机的base目录变成一个nova.conf的配置选项。

---
 virt/imagecache.py           |    4 ++++
 virt/libvirt/imagebackend.py |    3 ++-
 virt/libvirt/imagecache.py   |    3 ++-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/virt/imagecache.py b/virt/imagecache.py
index b63013f..593a48e 100644
--- a/virt/imagecache.py
+++ b/virt/imagecache.py
@@ -29,6 +29,10 @@ imagecache_opts = [
                     ‘This is NOT the full path - just a folder name. ‘
                     ‘For per-compute-host cached images, set to _base_$my_ip‘,
                deprecated_name=‘base_dir_name‘),
+    cfg.StrOpt(‘image_cache_directory_name‘,
+               default=‘/var/lib/nova/instances‘,
+               help=‘Where cached images are stored under cache directory. ‘,
+               deprecated_name=‘base_dir‘),
     cfg.BoolOpt(‘remove_unused_base_images‘,
                 default=True,
                 help=‘Should unused base images be removed?‘,
diff --git a/virt/libvirt/imagebackend.py b/virt/libvirt/imagebackend.py
index 6511496..8c0b887 100644
--- a/virt/libvirt/imagebackend.py
+++ b/virt/libvirt/imagebackend.py
@@ -84,6 +84,7 @@ __imagebackend_opts = [
 CONF = cfg.CONF
 CONF.register_opts(__imagebackend_opts, ‘libvirt‘)
 CONF.import_opt(‘image_cache_subdirectory_name‘, ‘nova.virt.imagecache‘)
+CONF.import_opt(‘image_cache_directory_name‘, ‘nova.virt.imagecache‘)
 CONF.import_opt(‘preallocate_images‘, ‘nova.virt.driver‘)
 
 LOG = logging.getLogger(__name__)
@@ -181,7 +182,7 @@ class Image(object):
         def fetch_func_sync(target, *args, **kwargs):
             fetch_func(target=target, *args, **kwargs)
 
-        base_dir = os.path.join(CONF.instances_path,
+        base_dir = os.path.join(CONF.image_cache_directory_name,
                                 CONF.image_cache_subdirectory_name)
         if not os.path.exists(base_dir):
             fileutils.ensure_tree(base_dir)
diff --git a/virt/libvirt/imagecache.py b/virt/libvirt/imagecache.py
index 5320bad..e1453de 100644
--- a/virt/libvirt/imagecache.py
+++ b/virt/libvirt/imagecache.py
@@ -72,6 +72,7 @@ CONF = cfg.CONF
 CONF.register_opts(imagecache_opts, ‘libvirt‘)
 CONF.import_opt(‘instances_path‘, ‘nova.compute.manager‘)
 CONF.import_opt(‘image_cache_subdirectory_name‘, ‘nova.virt.imagecache‘)
+CONF.import_opt(‘image_cache_directory_name‘, ‘nova.virt.imagecache‘)
 

 def get_cache_fname(images, key):
@@ -578,7 +579,7 @@ class ImageCacheManager(imagecache.ImageCacheManager):
         # cache to the instance directory. Files ending in _sm are no longer
         # created, but may remain from previous versions.
 
-        base_dir = os.path.join(CONF.instances_path,
+        base_dir = os.path.join(CONF.image_cache_directory_name,
                                 CONF.image_cache_subdirectory_name)
         if not os.path.exists(base_dir):
             LOG.debug(_(‘Skipping verification, no base directory at %s‘),
--


本文出自 “the-way-to-cloud” 博客,请务必保留此出处http://iceyao.blog.51cto.com/9426658/1697988

OpenStack启动虚拟机、虚拟机做快照加速

标签:snapshots nova

原文地址:http://iceyao.blog.51cto.com/9426658/1697988

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!