Add clone vm example
Add clone vm example into mistral-extra Co-Authored-By: Lingxian Kong <anlin.kong@gmail.com> Change-Id: Ibe8558cafb334a25db2455157f22170b725a08d3
This commit is contained in:
parent
d50ce0da4f
commit
d8f4085ef4
|
@ -0,0 +1,55 @@
|
||||||
|
=======================
|
||||||
|
Cloning virtual machine
|
||||||
|
=======================
|
||||||
|
|
||||||
|
Workflow ``clone_vm`` defines the process of creating a new VM based on
|
||||||
|
existing VM which was created using bootable volume (and may have other
|
||||||
|
additional volumes). It's also a good example of using sub-workflows in one
|
||||||
|
workflow.
|
||||||
|
|
||||||
|
To run the example:
|
||||||
|
|
||||||
|
1. Create sub-workflows ``clone_volume.yaml`` and
|
||||||
|
``boot_vm_from_volume.yaml``::
|
||||||
|
|
||||||
|
mistral workflow-create clone_volume.yaml
|
||||||
|
mistral workflow-create boot_vm_from_volume.yaml
|
||||||
|
|
||||||
|
2. Create workflow ``clone_vm.yaml``::
|
||||||
|
|
||||||
|
mistral workflow-create clone_vm.yaml
|
||||||
|
|
||||||
|
3. Create ``input.json`` file containing workflow input parameters as follows::
|
||||||
|
|
||||||
|
{
|
||||||
|
"vm_name": "new_vm",
|
||||||
|
"flavor_ref": "1",
|
||||||
|
"source_root_vol_id": "1969299a-4c45-4900-bfe0-5ac65c1f2211",
|
||||||
|
"root_vol_name": "new_root_vol",
|
||||||
|
"root_vol_size": 1,
|
||||||
|
"additional_volumes": [
|
||||||
|
{
|
||||||
|
"vol_name": "new_user_vol_1",
|
||||||
|
"vol_size": 1,
|
||||||
|
"source_vol_id": "94391f69-a2f7-4406-b602-86e0b421d519"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"vol_name": "new_user_vol_2",
|
||||||
|
"vol_size": 1,
|
||||||
|
"source_vol_id": "262b37ab-86f1-4be5-ada2-645898400584"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
5. Start workflow::
|
||||||
|
|
||||||
|
mistral execution-create clone_vm input.json
|
||||||
|
|
||||||
|
6. Get execution status by using execution id from the previous command
|
||||||
|
output::
|
||||||
|
|
||||||
|
mistral execution-get <execution_id>
|
||||||
|
|
||||||
|
7. Make sure that a virtual machine with a bootable volume and two additional
|
||||||
|
volumes has been created successfully. It can be done by opening Horizon UI
|
||||||
|
or using Nova client (python-novaclient).
|
|
@ -0,0 +1,33 @@
|
||||||
|
---
|
||||||
|
version: '2.0'
|
||||||
|
|
||||||
|
boot_vm_from_volume:
|
||||||
|
description: Create a virtual machine from a bootable volume
|
||||||
|
type: direct
|
||||||
|
|
||||||
|
input:
|
||||||
|
- vm_name
|
||||||
|
- block_device_mapping_v2
|
||||||
|
- flavor_ref
|
||||||
|
- image
|
||||||
|
output:
|
||||||
|
vm_id: <% $.vm_id %>
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
create_server:
|
||||||
|
action: nova.servers_create
|
||||||
|
input:
|
||||||
|
name: <% $.vm_name %>
|
||||||
|
block_device_mapping_v2: <% $.block_device_mapping_v2 %>
|
||||||
|
flavor: <% $.flavor_ref %>
|
||||||
|
image: <% $.image %>
|
||||||
|
publish:
|
||||||
|
vm_id: <% task(create_server).result.id %>
|
||||||
|
on-success:
|
||||||
|
- wait_for_instance
|
||||||
|
|
||||||
|
wait_for_instance:
|
||||||
|
action: nova.servers_find id=<% $.vm_id %> status='ACTIVE'
|
||||||
|
retry:
|
||||||
|
delay: 10
|
||||||
|
count: 5
|
|
@ -0,0 +1,75 @@
|
||||||
|
---
|
||||||
|
version: 2.0
|
||||||
|
|
||||||
|
clone_vm:
|
||||||
|
type: direct
|
||||||
|
description: Create a virtual machine by cloning an existing one. 1.clone system volume 2.set the system volume to bootable 3.create a new instance from the new bootable system volume 4.clone user volumes 5.attach user volumes to the new instance
|
||||||
|
|
||||||
|
input:
|
||||||
|
- vm_name #name of the new instance
|
||||||
|
- flavor_ref #flavor of the new instance
|
||||||
|
- source_root_vol_id #root volume id of the source instance
|
||||||
|
- root_vol_name #root volume name of the new instance
|
||||||
|
- root_vol_size #root volume size of the new instance
|
||||||
|
- additional_volumes:
|
||||||
|
- vol_name #volume name of the new instance
|
||||||
|
- vol_size #volume size of the new instance
|
||||||
|
- source_vol_id #source volume id of the source instance
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
clone_root_volume:
|
||||||
|
description: Create a new volume from root volume of source vm.
|
||||||
|
workflow: clone_volume
|
||||||
|
input:
|
||||||
|
size: <% $.root_vol_size %>
|
||||||
|
source_volid: <% $.source_root_vol_id %>
|
||||||
|
name: <% $.root_vol_name %>
|
||||||
|
publish:
|
||||||
|
new_root_vol_id: <% task(clone_root_volume).result.vol_id %>
|
||||||
|
on-success:
|
||||||
|
- set_volume_bootable
|
||||||
|
|
||||||
|
set_volume_bootable:
|
||||||
|
action: cinder.volumes_set_bootable volume=<% $.new_root_vol_id %> flag=true
|
||||||
|
on-success:
|
||||||
|
- create_new_vm
|
||||||
|
|
||||||
|
create_new_vm:
|
||||||
|
description: Boot a new instance from new bootable volume
|
||||||
|
workflow: boot_vm_from_volume
|
||||||
|
input:
|
||||||
|
image: ""
|
||||||
|
vm_name: <% $.vm_name %>
|
||||||
|
flavor_ref: <% $.flavor_ref %>
|
||||||
|
block_device_mapping_v2:
|
||||||
|
- source_type: "volume"
|
||||||
|
destination_type: "volume"
|
||||||
|
delete_on_termination: "FALSE"
|
||||||
|
boot_index: "0"
|
||||||
|
uuid: <% $.new_root_vol_id %>
|
||||||
|
publish:
|
||||||
|
new_vm_id: <% task(create_new_vm).result.vm_id %>
|
||||||
|
on-success:
|
||||||
|
- clone_additional_volumes
|
||||||
|
|
||||||
|
clone_additional_volumes:
|
||||||
|
description: Create new volumes from existed ones one by one
|
||||||
|
with-items: volume in <% $.additional_volumes %>
|
||||||
|
workflow: clone_volume
|
||||||
|
input:
|
||||||
|
source_volid: <% ($.volume).source_vol_id %>
|
||||||
|
size: <% ($.volume).vol_size %>
|
||||||
|
name: <% ($.volume).vol_name %>
|
||||||
|
publish:
|
||||||
|
additional_vol_ids: <% task(clone_additional_volumes).result.vol_id %>
|
||||||
|
on-success:
|
||||||
|
- attach_volume
|
||||||
|
|
||||||
|
attach_volume:
|
||||||
|
description: Attach additional volumes to the instance
|
||||||
|
with-items: vol_id in <% $.additional_vol_ids %>
|
||||||
|
action: nova.volumes_create_server_volume
|
||||||
|
input:
|
||||||
|
server_id: <% $.new_vm_id %>
|
||||||
|
volume_id: <% $.vol_id %>
|
||||||
|
device: null
|
|
@ -0,0 +1,31 @@
|
||||||
|
---
|
||||||
|
version: '2.0'
|
||||||
|
|
||||||
|
clone_volume:
|
||||||
|
description: Create a new volume by cloning an existing one
|
||||||
|
type: direct
|
||||||
|
|
||||||
|
input:
|
||||||
|
- source_volid # ID of the source volume
|
||||||
|
- name # name of the new volume
|
||||||
|
- size # size of the new volume
|
||||||
|
output:
|
||||||
|
vol_id: <% $.vol_id %>
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
create_volume:
|
||||||
|
action: cinder.volumes_create
|
||||||
|
input:
|
||||||
|
name: <% $.name %>
|
||||||
|
size: <% $.size %>
|
||||||
|
source_volid: <% $.source_volid %>
|
||||||
|
publish:
|
||||||
|
vol_id: <% task(create_volume).result.id %>
|
||||||
|
on-success:
|
||||||
|
- wait_for_volume
|
||||||
|
|
||||||
|
wait_for_volume:
|
||||||
|
action: cinder.volumes_find id=<% $.vol_id %> status='available'
|
||||||
|
retry:
|
||||||
|
delay: 5
|
||||||
|
count: 15
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"vm_name":"new_vm",
|
||||||
|
"flavor_ref":"1",
|
||||||
|
"source_root_vol_id":"1969299a-4c45-4900-bfe0-5ac65c1f2211",
|
||||||
|
"root_vol_name":"new_sys_vol",
|
||||||
|
"root_vol_size":1,
|
||||||
|
"additional_volumes":
|
||||||
|
[{
|
||||||
|
"vol_size":1,
|
||||||
|
"source_vol_id":"94391f69-a2f7-4406-b602-86e0b421d519",
|
||||||
|
"vol_name":"new_user_vol_1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"vol_size":1,
|
||||||
|
"source_vol_id":"262b37ab-86f1-4be5-ada2-645898400584",
|
||||||
|
"vol_name":"new_user_vol_2"
|
||||||
|
}]
|
||||||
|
}
|
Loading…
Reference in New Issue