Last active
May 23, 2016 12:18
-
-
Save tamirko/ad63db8d132f0c24e79c6a22deb74590 to your computer and use it in GitHub Desktop.
Restart a VM by using Cfy Workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following should be defined in your blueprint : | |
node_templates: # or node_types if you specify this on a type | |
my_vm: | |
type: ... | |
... | |
interfaces: | |
... | |
my_custom_interface: | |
restart_linux_vm: scripts/restart_my_vm.sh | |
restart_windows_vm: scripts/restart_my_vm.ps1 | |
... | |
plugins: | |
utils-plugin: | |
# This will make it run on the Cloudify manager VM | |
executor: central_deployment_agent | |
source: utils-plugin | |
workflows: | |
restart_vms: | |
mapping: utils-plugin.vms.tasks.restart_vms | |
parameters: | |
node_id: {} | |
node_instance_id: null | |
-------------------------------------------------------------------------------------- | |
# Then this should be in a workflow (Python). | |
# It should be mapped to a Cloudify plugin whose code will run on the Cludify manager. | |
@workflow | |
def restart_vms(node_id, node_instance_id=None, my_input=None ,**kwargs): | |
node = ctx.get_node(current_node_id) | |
for instance in node.instances: | |
# This is for restarting Windows VMs : | |
instance.execute_operation("my_custom_interface.restart_windows_vm",kwargs={'process': {'args': [my_input]}}) | |
# This is for restarting Linux VMs : | |
instance.execute_operation("my_custom_interface.restart_linux_vm",kwargs={'process': {'args': [my_input]}}) | |
-------------------------------------------------------------------------------------- | |
# In restart_my_vm.sh, you should have something like : | |
ctx logger info "This is my_input $1" | |
COMMAND="sudo reboot" | |
ctx logger info "Running ${COMMAND}" | |
sudo nohup ${COMMAND} > /dev/null 2>&1 & | |
-------------------------------------------------------------------------------------- | |
# Then, this workflow can be invoked by running (will restart all the instances of my_vm: | |
cfy executions start -d myDeploymentNa,e -w restart_vms -p '{ "node_id" :"my_vm"} | |
# This can be invoked by running (will restart only the instance whose id my_vm_a2345 and istance of my_vm node : | |
cfy executions start -d myDeploymentNa,e -w restart_vms -p '{ "node_id" :"my_vm", "node_instance_id": "my_vm_a2345"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment