This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Auto-start all VMs on a host using local storage after reboot
Skip to end of metadata
Go to start of metadata

Created by Kraig Amador, 2012

This code requires the classes @ API Signing, Python

#!/ usr/bin/env python
# By: Kraig Amador, 2012

import hashlib, hmac, string, base64, urllib
import json, urllib, socket, sys

our_ip = socket.gethostbyname(socket.gethostname())
api = CloudStack(api_url, apiKey, secret)

host = None
# First, find the CS host for this machine
request = {'listall': 'true'}
for h in api.listHosts(request)['host']:
    if h['ipaddress'] == our_ip:
        host = h

if host is None:
  print "This node isn't a CS host"

# we filter the volumes because the hostid filter doesn't seem to work
volumes = []
request = {'listall': 'true', 'hostid': host['id'], 'isrecursive': 'true'}
for volume in api.listVolumes(request)['volume']:
  if volume['storage'] != host['name']:
  if volume['vmstate'] == 'Stopped':

print "Found %d inactive volumes" % len(volumes)

# For each volume, find the VM, start it up.
for volume in volumes:
  request = {'listall': 'true', 'name': volume['vmname'], 'id': volume['virtualmachineid'], 'isrecursive': 'true'}
  result = api.listVirtualMachines(request)
  if result['count'] < 1:
  for vm in result['virtualmachine']:
    print "Starting up %s" % vm['name']
    request = {'id': vm['id']}
    result = api.startVirtualMachine(request)
  • No labels