Hello,

Attached Python shell extension (just drop attached file into ~/.VirtualBox/shexts/ directory and perform 'reloadExt' command) which demonstrates how to create and remove hard disks. Likely will get integrated into future versions of shell (for shell extensions to work at least 3.0.4 shell is required).

Thanks,
    Nikolay.

Klaus Espenlaub wrote:
Frédéric SOSSON wrote:
Hello,

I try to create hard disk and to use createBaseStorage...

Do you have a small sample ?

The usual "sample" is VBoxManage. The total tool is relatively big, but each subcommand is usually pretty straightforward.

Klaus


_______________________________________________
vbox-dev mailing list
[email protected]
http://vbox.innotek.de/mailman/listinfo/vbox-dev

def createHdd(ctx,args):
   if (len(args) < 3):
      print "usage: createHdd sizeM location type"
      return 0

   size = int(args[1])
   loc = args[2]
   if len(args) > 3:
      format = args[3]
   else:
      format = "vdi"

   hdd = ctx['vb'].createHardDisk(format, loc)
   progress = hdd.createBaseStorage(size, 
ctx['global'].constants.HardDiskVariant_Standard)
   ctx['progressBar'](progress)

   if not hdd.id:
      print "cannot create disk (file %s exist?)" %(loc)
      return 0
   
   print "created HDD with id: %s" %(hdd.id)

   return 0

def removeHdd(ctx,args):
   if (len(args) != 2):
      print "usage: removeHdd path"
      return 0

   vb = ctx['vb']

   loc = args[1]
   try:
      hdd = vb.findHardDisk(loc)
   except:
      print "no hdd with path %s registered" %(loc)
      return 0
      
   progress = hdd.deleteStorage() # or use close() if you'll need this file
   ctx['progressBar'](progress)

   return 0

commands = {
    'createHdd': ['Create virtual HDD', createHdd],
    'removeHdd': ['Remove virtual HDD', removeHdd]
}
_______________________________________________
vbox-dev mailing list
[email protected]
http://vbox.innotek.de/mailman/listinfo/vbox-dev

Reply via email to