How to create a VM on a specified host with openstack

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xjtuse_mal/article/details/7901744

如果用devstack安装的openstack cluster,那么所有的source code都在/opt/stack下面。


如果用户想创建一个VM在特定的机器上,openstack提供了一种hack的方法,具体可以这样做,在通过"nova boot"创建instance的时候,使用availability_zone来制定目标机器,格式为“xxx:targethost”,xxx可以是任意的字符串,和targethost使用冒号分开。


root@devstack12:~# nova boot
 
usage: nova boot [--flavor <flavor>] [--image <image>] [--meta <key=value>]
                 [--file <dst-path=src-path>] [--key_name <key_name>]
                 [--user_data <user-data>]
                 [--availability_zone <availability-zone>]
                 [--security_groups <security_groups>]
                 [--block_device_mapping <dev_name=mapping>]
                 [--hint <key=value>]
                 [--nic <net-id=net-uuid,v4-fixed-ip=ip-addr>]
                 [--config-drive <value>] [--poll]
                 <name>
error: too few arguments
Try 'nova help boot' for more information.
root@devstack12:~# nova image-list
+--------------------------------------+---------------------------------+--------+--------+
| ID                                   | Name                            | Status | Server |
+--------------------------------------+---------------------------------+--------+--------+
| 4bca2cad-3d3e-4526-983c-0d4b0d1110e0 | cirros-0.3.0-x86_64-uec         | ACTIVE |        |
| ab22c6d4-dba6-460d-afbe-7c4f62b138cb | cirros-0.3.0-x86_64-uec-kernel  | ACTIVE |        |
| d014fd1f-549c-4732-931d-58f18b151b68 | cirros-0.3.0-x86_64-uec-ramdisk | ACTIVE |        |
+--------------------------------------+---------------------------------+--------+--------+
 
root@devstack12:~#
root@devstack12:~# nova boot --image  4bca2cad-3d3e-4526-983c-0d4b0d1110e0 --flavor 1--availability_zone xx:devstack13 server1

以上的命令可以保证用户新创建的instance会在devstack13上边。


从代码上也可以看出来,以下这段代码来自于:/opt/stack/nova/nova/compute/api.py:_create_instance()

# NOTE(vish): We have a legacy hack to allow admins to specify hosts
#             via az using az:host. It might be nice to expose an
#             api to specify specific hosts to force onto, but for
#             now it just supports this legacy hack.
host = None
if availability_zone:
      availability_zone, _x, host = availability_zone.partition(':')
if not availability_zone:
      availability_zone = FLAGS.default_schedule_zone
if context.is_admin and host:
      filter_properties = {'force_hosts': [host]}
else:
      filter_properties = {}

filter_properties['scheduler_hints'] = scheduler_hints



展开阅读全文

没有更多推荐了,返回首页