¡@

Home 

OpenStack Study: utils.py

OpenStack Index

**** CubicPower OpenStack Study ****

def get_test_admin_context():

    return context.get_admin_context()

**** CubicPower OpenStack Study ****

def create_volume(ctxt,

                  host='test_host',

                  display_name='test_volume',

                  display_description='this is a test volume',

                  status='available',

                  migration_status=None,

                  size=1,

                  availability_zone='fake_az',

                  volume_type_id=None,

                  **kwargs):

    """Create a volume object in the DB."""

    vol = {}

    vol['size'] = size

    vol['host'] = host

    vol['user_id'] = ctxt.user_id

    vol['project_id'] = ctxt.project_id

    vol['status'] = status

    vol['migration_status'] = migration_status

    vol['display_name'] = display_name

    vol['display_description'] = display_description

    vol['attach_status'] = 'detached'

    vol['availability_zone'] = availability_zone

    if volume_type_id:

        vol['volume_type_id'] = volume_type_id

    for key in kwargs:

        vol[key] = kwargs[key]

    return db.volume_create(ctxt, vol)

**** CubicPower OpenStack Study ****

def create_snapshot(ctxt,

                    volume_id,

                    display_name='test_snapshot',

                    display_description='this is a test snapshot',

                    status='creating'):

    vol = db.volume_get(ctxt, volume_id)

    snap = {}

    snap['volume_id'] = volume_id

    snap['user_id'] = ctxt.user_id

    snap['project_id'] = ctxt.project_id

    snap['status'] = status

    snap['volume_size'] = vol['size']

    snap['display_name'] = display_name

    snap['display_description'] = display_description

    return db.snapshot_create(ctxt, snap)