前面有篇《nova boot from volume代码分析》http://iceyao.blog.51cto.com/9426658/1770927,今天这里看下针对nova boot from volume无法注入密码的简单hack。
nova/virt/libvirt/driver.py中_inject_data函数部分代码
if any((key, net, metadata, admin_pass, files)): injection_p_w_picpath = self.p_w_picpath_backend.p_w_picpath( instance, 'disk' + suffix, p_w_picpath_type) img_id = instance.p_w_picpath_ref if not injection_p_w_picpath.check_p_w_picpath_exists(): LOG.warn(_LW('Image %s not found on disk storage. ' 'Continue without injecting data'), injection_p_w_picpath.path, instance=instance) return
其实主要问题是,nova boot from rbd volume的时候,虚拟机的系统盘是在云硬盘那里的,所以必须先定位云硬盘的位置,才可以注入密码。默认情况下boot from p_w_picpath,系统盘名字是<instance-uuid>_disk,boot from volume名字是volume-<volume-uuid>。
nova/virt/libvirt/p_w_picpathbackend.py
class Rbd(Image): SUPPORTS_CLONE = True def __init__(self, instance=None, disk_name=None, path=None, **kwargs): super(Rbd, self).__init__("block", "rbd", is_block_dev=False) if path: try: self.rbd_name = path.split('/')[1] except IndexError: raise exception.InvalidDevicePath(path=path) else: self.rbd_name = '%s_%s' % (instance.uuid, disk_name) if not CONF.libvirt.p_w_picpaths_rbd_pool: raise RuntimeError(_('You should specify' ' p_w_picpaths_rbd_pool' ' flag to use rbd p_w_picpaths.')) self.pool = CONF.libvirt.p_w_picpaths_rbd_pool self.discard_mode = CONF.libvirt.hw_disk_discard self.rbd_user = CONF.libvirt.rbd_user self.ceph_conf = CONF.libvirt.p_w_picpaths_rbd_ceph_conf # 这里的判断逻辑不是很严谨,纯碎演示 if not instance.p_w_picpath_ref: context = nova_context.get_admin_context() # 获取bdms bdms = ( objects.BlockDeviceMappingList.get_by_instance_uuid( context, instance.uuid)) connection_info = jsonutils.loads(bdms[0].connection_info) # 获得系统盘volume-id,cinder rbd pool self.rbd_name = connection_info['data']['name'].split('/')[1] self.pool = connection_info['data']['name'].split('/')[0]
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。