ia64/xen-unstable

changeset 13601:072ce22bcc91

[XENAPI] Update test scripts to move from VBD.image to creating VDI's
with the uri attribute.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Wed Jan 24 15:48:58 2007 +0000 (2007-01-24)
parents 665be23d7fe9
children 85250ca1df56
files tools/python/scripts/test_vm_create.py tools/python/scripts/xapi.py
line diff
     1.1 --- a/tools/python/scripts/test_vm_create.py	Wed Jan 24 15:47:31 2007 +0000
     1.2 +++ b/tools/python/scripts/test_vm_create.py	Wed Jan 24 15:48:58 2007 +0000
     1.3 @@ -47,7 +47,8 @@ vdi_cfg = {
     1.4      'virtual_size': 100 * 1024,
     1.5      'sector_size': 1024,
     1.6      'type': 'system',
     1.7 -    'parent': '',    
     1.8 +    'parent': '',
     1.9 +    'SR_name': 'QCoW',
    1.10      'sharable': False,
    1.11      'read_only': False,
    1.12  }
    1.13 @@ -61,6 +62,19 @@ vbd_cfg = {
    1.14      'driver': 'paravirtualised',
    1.15  }
    1.16  
    1.17 +local_vdi_cfg = {
    1.18 +    'name_label': 'gentoo.amd64.img',
    1.19 +    'name_description': '',
    1.20 +    'uri': 'file:/root/gentoo.amd64.img',
    1.21 +    'virtual_size': 0,
    1.22 +    'sector_size': 0,
    1.23 +    'type': 'system',
    1.24 +    'parent': '',
    1.25 +    'SR_name': 'Local',
    1.26 +    'sharable': False,
    1.27 +    'read_only': False,
    1.28 +}    
    1.29 +
    1.30  local_vbd_cfg = {
    1.31      'VDI': '',
    1.32      'VM': '',
    1.33 @@ -68,7 +82,6 @@ local_vbd_cfg = {
    1.34      'mode': 'RW',
    1.35      'type': 'disk',
    1.36      'driver': 'paravirtualised',
    1.37 -    'image': 'file:/root/gentoo.amd64.img'
    1.38  }
    1.39  
    1.40  vif_cfg = {
    1.41 @@ -90,6 +103,7 @@ def test_vm_create():
    1.42      server, session = connect()
    1.43      vm_uuid = None
    1.44      vdi_uuid = None
    1.45 +    local_vdi_uuid = None
    1.46      local_vbd_uuid = None
    1.47      vbd_uuid = None
    1.48      vif_uuid = None
    1.49 @@ -102,9 +116,14 @@ def test_vm_create():
    1.50          vm_names.append(vm_record['name_label'])
    1.51  
    1.52      # Get default SR
    1.53 -    sr_list = execute(server, 'SR.get_by_name_label', (session, 'Local'))
    1.54 +    sr_list = execute(server, 'SR.get_by_name_label', (session,
    1.55 +                                                       vdi_cfg['SR_name']))
    1.56      sr_uuid = sr_list[0]
    1.57  
    1.58 +    local_sr_list = execute(server, 'SR.get_by_name_label',
    1.59 +                            (session, local_vdi_cfg['SR_name']))
    1.60 +    local_sr_uuid = local_sr_list[0]
    1.61 +
    1.62      # Get default network
    1.63      net_list = execute(server, 'network.get_all', (session,))
    1.64      net_uuid = net_list[0]
    1.65 @@ -121,13 +140,18 @@ def test_vm_create():
    1.66          vbd_cfg['VM'] = vm_uuid
    1.67          vbd_cfg['VDI'] = vdi_uuid
    1.68          vbd_uuid = execute(server, 'VBD.create', (session, vbd_cfg))
    1.69 -
    1.70 +        
    1.71 +        # Create a new VDI (Local)
    1.72 +        local_vdi_cfg['SR'] = local_sr_uuid
    1.73 +        local_vdi_uuid = execute(server, 'VDI.create',
    1.74 +                                 (session, local_vdi_cfg))
    1.75 + 
    1.76          # Create a new VBD (Local)
    1.77          local_vbd_cfg['VM'] = vm_uuid
    1.78 -        local_vbd_cfg['VDI'] = ''
    1.79 +        local_vbd_cfg['VDI'] = local_vdi_uuid
    1.80          local_vbd_uuid = execute(server, 'VBD.create',
    1.81                                   (session, local_vbd_cfg))
    1.82 -        
    1.83 +
    1.84          # Create a new VIF
    1.85          vif_cfg['network'] = net_uuid
    1.86          vif_cfg['VM'] = vm_uuid
    1.87 @@ -138,13 +162,15 @@ def test_vm_create():
    1.88  
    1.89          time.sleep(30)
    1.90  
    1.91 -        print 'Suspending VM..'
    1.92 -        execute(server, 'VM.suspend', (session, vm_uuid))
    1.93 -        print 'Suspended VM.'
    1.94 -        time.sleep(5)
    1.95 -        print 'Resuming VM ...'
    1.96 -        execute(server, 'VM.resume', (session, vm_uuid, False))
    1.97 -        print 'Resumed VM.'
    1.98 +        test_suspend = True
    1.99 +        if test_suspend:
   1.100 +            print 'Suspending VM..'
   1.101 +            execute(server, 'VM.suspend', (session, vm_uuid))
   1.102 +            print 'Suspended VM.'
   1.103 +            time.sleep(5)
   1.104 +            print 'Resuming VM ...'
   1.105 +            execute(server, 'VM.resume', (session, vm_uuid, False))
   1.106 +            print 'Resumed VM.'
   1.107  
   1.108          # Wait for user to say we're good to shut it down
   1.109          while True:
   1.110 @@ -156,12 +182,17 @@ def test_vm_create():
   1.111          # Clean up
   1.112          if vif_uuid:
   1.113              execute(server, 'VIF.destroy', (session, vif_uuid))
   1.114 +            
   1.115          if local_vbd_uuid:
   1.116              execute(server, 'VBD.destroy', (session, local_vbd_uuid))
   1.117 +        if local_vdi_uuid:
   1.118 +            execute(server, 'VDI.destroy', (session, local_vdi_uuid))
   1.119 +            
   1.120          if vbd_uuid:
   1.121              execute(server, 'VBD.destroy', (session, vbd_uuid))
   1.122          if vdi_uuid:
   1.123              execute(server, 'VDI.destroy', (session, vdi_uuid))
   1.124 +        
   1.125          if vm_uuid:
   1.126              try:
   1.127                  execute(server, 'VM.hard_shutdown', (session, vm_uuid))
     2.1 --- a/tools/python/scripts/xapi.py	Wed Jan 24 15:47:31 2007 +0000
     2.2 +++ b/tools/python/scripts/xapi.py	Wed Jan 24 15:48:58 2007 +0000
     2.3 @@ -37,7 +37,7 @@ SR_LIST_FORMAT = '%(name_label)-18s %(uu
     2.4                   '%(type)-10s'
     2.5  VDI_LIST_FORMAT = '%(name_label)-18s %(uuid)-36s %(virtual_size)-8s '\
     2.6                    '%(sector_size)-8s'
     2.7 -VBD_LIST_FORMAT = '%(device)-6s %(uuid)-36s %(VDI)-8s %(image)-8s'
     2.8 +VBD_LIST_FORMAT = '%(device)-6s %(uuid)-36s %(VDI)-8s'
     2.9  TASK_LIST_FORMAT = '%(name_label)-18s %(uuid)-36s %(status)-8s %(progress)-4s'
    2.10  VIF_LIST_FORMAT = '%(name)-8s %(device)-7s %(uuid)-36s %(MAC)-10s'
    2.11  
    2.12 @@ -85,25 +85,28 @@ OPTIONS = {
    2.13                                           'action': 'store_true'})],
    2.14      
    2.15      'vdi-create': [(('--name-label',), {'help': 'Name for VDI'}),
    2.16 -                   (('--description',), {'help': 'Description for VDI'}),
    2.17 +                   (('--name-description',), {'help': 'Description for VDI'}),
    2.18                     (('--sector-size',), {'type': 'int',
    2.19 -                                         'help': 'Sector size'}),
    2.20 +                                         'help': 'Sector size',
    2.21 +                                         'default': 0}),
    2.22                     (('--virtual-size',), {'type': 'int',
    2.23 +                                          'default': 0,
    2.24                                            'help': 'Size of VDI in sectors'}),
    2.25                     (('--type',), {'choices': ['system', 'user', 'ephemeral'],
    2.26 +                                  'default': 'system',
    2.27                                    'help': 'VDI type'}),
    2.28                     (('--sharable',), {'action': 'store_true',
    2.29                                        'help': 'VDI sharable'}),
    2.30                     (('--read-only',), {'action': 'store_true',
    2.31 -                                       'help': 'Read only'})],
    2.32 +                                       'help': 'Read only'}),
    2.33 +                   (('--sr',), {})],
    2.34      
    2.35      'vbd-create': [(('--VDI',), {'help': 'UUID of VDI to attach to.'}),
    2.36                     (('--mode',), {'choices': ['RO', 'RW'],
    2.37                                    'help': 'device mount mode'}),
    2.38                     (('--driver',), {'choices':['paravirtualised', 'ioemu'],
    2.39                                      'help': 'Driver for VBD'}),
    2.40 -                   (('--device',), {'help': 'Device name on guest domain'}),
    2.41 -                   (('--image',), {'help': 'Location of drive image.'})]
    2.42 +                   (('--device',), {'help': 'Device name on guest domain'})]
    2.43                     
    2.44  }
    2.45  
    2.46 @@ -464,8 +467,7 @@ def xapi_vbd_list(args, async = False):
    2.47      
    2.48      print VBD_LIST_FORMAT % {'device': 'Device',
    2.49                               'uuid' : 'UUID',
    2.50 -                             'VDI': 'VDI',
    2.51 -                             'image': 'Image'}
    2.52 +                             'VDI': 'VDI'}
    2.53      
    2.54      for vbd in vbds:
    2.55          vbd_struct = execute(server, 'VBD.get_record', (session, vbd))
    2.56 @@ -547,7 +549,12 @@ def xapi_vdi_create(args, async = False)
    2.57          cfg[opt] = val
    2.58  
    2.59      server, session = connect()
    2.60 -    srs = execute(server, 'SR.get_all', (session,))
    2.61 +    srs = []
    2.62 +    if cfg.get('SR'):    
    2.63 +        srs = execute(server, 'SR.get_by_name_label', (session, cfg['SR']))
    2.64 +    else:
    2.65 +        srs = execute(server, 'SR.get_all', (session,))
    2.66 +
    2.67      sr = srs[0]
    2.68      cfg['SR'] = sr
    2.69