Skip to content

Instantly share code, notes, and snippets.

@e0ne
Created July 30, 2015 14:42
Show Gist options
  • Save e0ne/aab147326ecb6e9ea079 to your computer and use it in GitHub Desktop.
Save e0ne/aab147326ecb6e9ea079 to your computer and use it in GitHub Desktop.
Create fake volumes in Cinder DB
""" Usage example:
python create_volumes.py --config-file /etc/cinder/cinder.conf vol_count user_id tenant_id
"""
import sys
from oslo_config import cfg
from cinder import context
from cinder.db import api
from cinder import objects
from cinder import version
CONF = cfg.CONF
def main():
objects.register_all()
CONF([], project='cinder',
version=version.version_string())
cxt = context.get_admin_context()
total = sys.argv[3]
for i in xrange(int(total)):
print('Creating volume #%s of #%s' % (i, total))
volume_properties = {
'size': 1,
'user_id': sys.argv[4],
'project_id': sys.argv[5],
'status': 'available',
'attach_status': 'detached',
'display_description': 'description' + str(i),
'display_name': 'name' + str(i),
'host': 'host',
'availability_zone': 'availability_zone',
'volume_type_id': None,
'metadata': None,
'bootable': False
}
api.volume_create(cxt, volume_properties)
print('Volume #%s created' % i)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment