Esempio n. 1
0
def initalize_hypervisor(hypervisor):
  conn = hypervisor.get_connection(True)
  if conn:
    # get a list of existing storage pools
    for pool in conn.listStoragePools():
      storagepool = conn.storagePoolLookupByName(pool)
      xml = minidom.parseString(storagepool.XMLDesc(0))
      items = xml.getElementsByTagName('name')
      name = items[0].childNodes[0].data
      items = xml.getElementsByTagName('path')
      path = items[0].childNodes[0].data
      (new_pool, created) = StoragePool.objects.get_or_create(
        name=name,
        path=path,
        hypervisor=hypervisor
      )
      pool = new_pool.get_storagepool()
      if pool:
        # get a list of volumes
        for vol in pool.listVolumes():
          if match_vol.search(vol):
            vol = vol.replace('.qcow2', '')
            (new_vol, created) = Volume.objects.get_or_create(
              name=vol,
              storagepool=new_pool
            )
            if created: new_vol.save()
            new_vol.update()
        
    # get a list of existing installation disks
    task_id = node.send_command(hypervisor, 'installationdisk_list', 
      {'path': hypervisor.install_medium_path})
    now = time.time()
    while True:
      time.sleep(2.5)
      status = node.check_command(hypervisor, task_id)
      print status
      if status['state'] == 'SUCCESS':
        print status['args']['disks']
        for disk in status['args']['disks']:
          print disk
          (installationdisk, created) = InstallationDisk.objects.get_or_create(
            name=disk['filename'],
            hypervisor=hypervisor,
            url='Unknown',
            filename=disk['filename'],
            total_bytes=disk['total_bytes'],
            user=User.objects.all()[0] # not brilliant..
          )
          if created: installationdisk.save()
        break
      elif status['state'] == 'FAILED' or status['state'] == 'ERROR' or time.time() - now > 60:
        break 
Esempio n. 2
0
  def get_status(self):
    status = node.check_command(self.hypervisor, self.task_id)
    print status
    if 'args' in status:
      args = status['args']
      if args:
        if 'total_bytes_dl' in args:
          self.total_bytes_dl = args['total_bytes_dl']
        if 'total_bytes' in args:
          self.total_bytes = args['total_bytes']
        if 'percent' in args:
          self.percent = args['percent']

    self.state = status['state']
    self.save()
Esempio n. 3
0
def initalize_hypervisor(hypervisor):
  conn = hypervisor.get_connection(True)
  if conn:
    # get a list of existing storage pools
    for pool in conn.listDefinedStoragePools() + conn.listStoragePools():
      storagepool = conn.storagePoolLookupByName(pool)
      xml = minidom.parseString(storagepool.XMLDesc(0))
      items = xml.getElementsByTagName('name')
      name = items[0].childNodes[0].data
      items = xml.getElementsByTagName('path')
      path = items[0].childNodes[0].data
      (new_pool, created) = StoragePool.objects.get_or_create(
        name=name,
        path=path,
        hypervisor=hypervisor
      )
      if created: new_pool.save()
      new_pool.update(True) 

    try:
      initalize_hypervisor_instances(hypervisor)
    except Exception as e:
      print "Initalize hypervisor instances error: %s" % (e)

    print "HELLO"
        
    # get a list of existing installation disks
    task_id = node.send_command(hypervisor, 'installationdisk_list', 
      {'path': hypervisor.install_medium_path})
    print task_id
    now = time.time()
    while True:
      time.sleep(2.5)
      status = node.check_command(hypervisor, task_id)
      if status['state'] == 'SUCCESS':
        for disk in status['args']['disks']:
          (installationdisk, created) = InstallationDisk.objects.get_or_create(
            name=disk['filename'],
            hypervisor=hypervisor,
            url='Unknown',
            filename=disk['filename'],
            total_bytes=disk['total_bytes'],
            user=User.objects.all()[0] # not brilliant..
          )
          if created: installationdisk.save()
        break
      elif status['state'] == 'FAILED' or status['state'] == 'ERROR' or time.time() - now > 60:
        break 
Esempio n. 4
0
 def delete(self, request=None):
   task_id = node.send_command(self.hypervisor, 'installationdisk_delete', {
     'path': os.path.join(self.hypervisor.install_medium_path, self.filename)})
   now = time.time()
   while True:
     time.sleep(2.5)
     status = node.check_command(self.hypervisor, task_id)
     print status
     if status['state'] == 'SUCCESS':
       if request:
         messages.add_message(request, persistent_messages.SUCCESS, 'Deleted Installation Disk %s on %s' % (self.name, self.hypervisor))
       super(InstallationDisk, self).delete()
       break
     elif status['state'] == 'FAILED' or status['state'] == 'ERROR':
       if request:
         msg = "N/A"
         if 'args' in status:
           msg = status['args']['msg']
         messages.add_message(request, persistent_messages.ERROR, 'Unable to delete Installation Disk %s on %s: %s' % (self.name, self.hypervisor, msg))
       break