如何在openstack中创建镜像 for Juno

云计算 OpenStack
当前在OpenStack中没有提供一个方便快捷的方法去创建镜像,需要运维人员使用KVM制作,这无疑提高了对运维人员和环境(需要一个安装了KVM的linux)的要求,因此我觉得OpenStack还是不适应于私有云的,它是为公有云而生。

当前在OpenStack中没有提供一个方便快捷的方法去创建镜像,需要运维人员使用KVM制作,这无疑提高了对运维人员和环境(需要一个安装了KVM的linux)的要求,因此我觉得OpenStack还是不适应于私有云的,它是为公有云而生。

如何在openstack中创建镜像 for Juno

本文介绍一种利用Horizon和ISO格式的安装盘来创建镜像的方法,其原理为:

1. 创建一个新的磁盘作为root disk

2. 从Glance下载ISO作为第二块磁盘

3. 从Glance下载virtio作为第三块磁盘

4. 从ISO启动虚拟机,比将系统安装到root disk

5. 创建image并保持到Glance

1.添加一种disk类型newos

  1. 'mapping': a dict contains the storage device mapping. 
  2.  
  3.  
  4.    For the default disk types it will contain the following 
  5.    keys & values: 
  6.  
  7.  
  8.       'disk' -> disk_info 
  9.       'disk.rescue' -> disk_info 
  10.       'disk.local' -> disk_info 
  11.       'disk.swap' -> disk_info 
  12.       'disk.config' -> disk_info 
  13.       'disk.newos' -> disk_info 
  14. disk_info指的是: 
  15. 'disk_info': a tuple specifying disk configuration 
  16.  
  17.  
  18.    It contains the following 3 fields 
  19.  
  20.  
  21.       (disk bus, disk dev, device type) 
  22.  
  23.  
  24.  * 'disk_bus': the guest bus type ('ide''virtio''scsi', etc) 
  25.  
  26.  
  27.  * 'disk_dev': the device name 'vda''hdc''sdf''xvde' etc 
  28.  
  29.  
  30.  * 'device_type': type of device eg 'disk''cdrom''floppy' 

2 设置磁盘顺序

在blockinfo.py中,调用逻辑是:

spawn-->get_disk_info -->get_disk_mapping :

  1. if image_meta and image_meta.get('disk_format') == 'iso'
  2.     root_disk_bus = disk_bus 
  3.     #创建虚拟机时如果image_meta中的disk_format为iso, 则认为是创建新image的操作,那么进行如下操作 
  4.  
  5.     #设置disk.newos为root device 
  6.     root_device_type = 'disk' 
  7.  
  8.     root_info = get_next_disk_info(mapping, 
  9.                                    root_disk_bus, 
  10.                                    root_device_type) 
  11.     mapping['root'] = root_info 
  12.     mapping['disk.newos'] = root_info 
  13.  
  14.     #设置disk(iso)为第二个device 
  15.     image_device_type = 'cdrom' 
  16.     image_device_bus = cdrom_bus 
  17.     cdrom_info = get_next_disk_info(mapping, 
  18.                                    image_device_bus, 
  19.                                    image_device_type) 
  20.     mapping['disk'] = cdrom_info 
  21.  
  22.     #s设置disk.virtio作为第三个设备,为需要virtio的时候提供virtio驱动程序 
  23.     virtio_device_type = 'cdrom' 
  24.     virtio_device_bus = cdrom_bus 
  25.     virtio_device_info = get_next_disk_info(mapping, 
  26.                                    virtio_device_bus, 
  27.                                    virtio_device_type) 
  28.     mapping['disk.virtio'] = virtio_device_info 
  29.     return mapping 

#p#

3 创建磁盘

driver.py中的调逻辑是:spawn--> _create_image

  1. newos_size_gb = CONF.os_root_disk_size 
  2. if 'disk.newos' in disk_mapping: 
  3.     fname = "newos_%s_%s" % (newos_size_gb, os_type_with_default) 
  4.     size = newos_size_gb * 1024 * 1024 * 1024 
  5.     image('disk.newos').cache(fetch_func=self._create_newos, 
  6.                               filename=fname, 
  7.                               size=size, 
  8.                               newos_size=newos_size_gb) 
  9.  
  10. virtio_image_id = CONF.virtio_image_id 
  11. virtio_images = {'image_id': virtio_image_id} 
  12. virtio_fname = imagecache.get_cache_fname(virtio_images, 'image_id'
  13. image('disk.virtio').cache(fetch_func=libvirt_utils.fetch_image, 
  14.                         context=context, 
  15.                         filename=virtio_fname, 
  16.                         size=size, 
  17.                         image_id=virtio_image_id, 
  18.                         user_id=instance['user_id'], 
  19.                         project_id=instance['project_id'])
  1. @staticmethod 
  2. def _create_newos(target, newos_size): 
  3.     #self._create_local(target, newos_size) 
  4.     unit='G' 
  5.     libvirt_utils.create_image('qcow2', target, 
  6.                                '%d%c' % (newos_size, unit)) 

4. 将磁盘配置写入XML文件中

driver.py中的调逻辑是:spawn-->get_guest_xml--> get_guest_config-->_get_guest_storage_config

  1. if rescue: 
  2.         diskrescue = self.get_guest_disk_config(instance, 
  3.                                                 'disk.rescue'
  4.                                                 disk_mapping, 
  5.                                                 inst_type) 
  6.         devices.append(diskrescue) 
  7.  
  8.         diskos = self.get_guest_disk_config(instance, 
  9.                                             'disk'
  10.                                             disk_mapping, 
  11.                                             inst_type) 
  12.         devices.append(diskos) 
  13.     else
  14.         #添加device 
  15.         if 'disk.newos' in disk_mapping: 
  16.             disknewos = self.get_guest_disk_config(instance, 
  17.                                                    'disk.newos'
  18.                                                    disk_mapping, 
  19.                                                    inst_type) 
  20.             devices.append(disknewos) 
  21.  
  22.             diskcdrom = self.get_guest_disk_config(instance, 
  23.                                                 'disk'
  24.                                                 disk_mapping, 
  25.                                                 inst_type) 
  26.             devices.append(diskcdrom) 
  27.  
  28.             diskvirtio = self.get_guest_disk_config(instance, 
  29.                                                 'disk.virtio'
  30.                                                 disk_mapping, 
  31.                                                 inst_type) 
  32.             devices.append(diskvirtio) 
  33.             ### 
  34.         else
  35.             if 'disk' in disk_mapping: 
  36.                 diskos = self.get_guest_disk_config(instance, 
  37.                                                     'disk'
  38.                                                      disk_mapping, 
  39.                                                      inst_type) 
  40.                 devices.append(diskos) 

参考:http://www.ibm.com/developerworks/cn/cloud/library/cl-openstack-images/

博文出处:http://blog.csdn.net/epugv/article/details/44856439

责任编辑:Ophira 来源: epugv的专栏
相关推荐

2019-08-27 08:00:10

OpenStack命令虚拟机

2015-02-06 09:39:16

OpenStack j云主机创建

2015-10-10 10:21:26

OpenStackRegion多Region

2019-08-12 14:04:51

2011-05-04 09:11:30

RPM包Linux

2019-05-14 11:00:07

LinuxSSH别名

2020-07-13 07:00:21

Kubernetes

2023-02-06 17:49:35

Linux符号链接

2009-11-23 20:05:29

ibmdwLotus

2022-03-15 07:55:09

JavaScript线性仪表图开发

2020-07-20 07:00:00

KubernetesHostPath

2023-09-27 23:24:50

C++链表

2018-01-26 09:02:30

LinuxPDF创建视频

2022-11-11 09:01:08

SwiftUI条形图子视图

2019-07-30 10:33:01

2015-03-09 13:41:08

DevStackOpenStackOpenStack J

2015-10-23 17:29:24

AtomicOpenStack 应用部署

2021-02-18 17:00:52

Linux归档文件

2022-04-01 07:35:45

IDEAJavaWeb 项目

2020-07-09 13:10:42

GIMP曲线文本应用
点赞
收藏

51CTO技术栈公众号