Esempio n. 1
0
        private bool DiskOk(DiskDescription disk, VBD vbd)
        {
            if (vbd == null)
            {
                return(false);
            }

            VDI vdi = Connection.Resolve(vbd.VDI);

            return(vdi != null && disk.Disk.SR.opaque_ref == vdi.SR.opaque_ref);
        }
Esempio n. 2
0
 private VBD GetDiskVBD(DiskDescription disk, List <VBD> vbds)
 {
     foreach (VBD vbd in vbds)
     {
         if (disk.Device.userdevice == vbd.userdevice)
         {
             return(vbd);
         }
     }
     return(null);
 }
Esempio n. 3
0
        private VDI CreateVdi(DiskDescription disk, double progress1, double progress2)
        {
            VDI vdi = new VDI();

            vdi.name_label       = disk.Disk.name_label;
            vdi.name_description = disk.Disk.name_description;
            vdi.read_only        = false;
            vdi.sharable         = false;
            vdi.SR           = disk.Disk.SR;
            vdi.type         = disk.Disk.type;
            vdi.virtual_size = disk.Disk.virtual_size;

            RelatedTask = XenAPI.VDI.async_create(Session, vdi);
            PollToCompletion(progress1, progress2);
            return(Connection.WaitForCache(new XenRef <VDI>(Result)));
        }
Esempio n. 4
0
        /// <summary>
        /// Create a VDI/disk.
        /// If disk type is existing use the VDI in disk description
        /// Otherwise create a new disk (provision it from the SR)
        /// </summary>
        /// <param name="disk"></param>
        /// <param name="progress"></param>
        /// <param name="step"></param>
        /// <returns></returns>
        private VDI CreateDisk(DiskDescription disk, double progress, double step)
        {
            VDI  vdi;
            bool bootable = false;

            if (disk.Type == DiskDescription.DiskType.Existing)
            {
                vdi = disk.Disk;
            }
            else
            {
                vdi      = CreateVdi(disk, progress, progress + 0.75 * step);
                bootable = IsDeviceAtPositionZero(disk) && InsMethod != InstallMethod.CD;
            }

            AddVMHint(vdi);
            CreateVbd(disk, vdi, progress + 0.75 * step, progress + step, bootable);
            return(vdi);
        }
Esempio n. 5
0
        private VDI MoveDisk(DiskDescription disk, VBD vbd, double progress, double step)
        {
            string old_vdi_ref = vbd.VDI.opaque_ref;

            RelatedTask = XenAPI.VDI.async_copy(Session, vbd.VDI.opaque_ref, disk.Disk.SR.opaque_ref);
            PollToCompletion(progress, progress + 0.25 * step);
            AddVMHint(Connection.WaitForCache(new XenRef <VDI>(Result)));


            VDI new_vdi = Connection.Resolve(new XenRef <VDI>(Result));

            RelatedTask = XenAPI.VBD.async_destroy(Session, vbd.opaque_ref);
            PollToCompletion(progress + 0.25 * step, progress + 0.5 * step);

            RelatedTask = XenAPI.VDI.async_destroy(Session, old_vdi_ref);
            PollToCompletion(progress + 0.5 * step, progress + 0.75 * step);

            CreateVbd(disk, new_vdi, progress + 0.75 * step, progress + step, IsDeviceAtPositionZero(disk));
            return(new_vdi);
        }
Esempio n. 6
0
        /// <summary>
        /// Create a VBD
        ///
        /// ** vbd.bootable **
        /// 1. Windows ignores bootable flag
        /// 2. Eliloader changes the device "0" to bootable when booting linux
        /// </summary>
        /// <param name="disk"></param>
        /// <param name="vdi"></param>
        /// <param name="progress1"></param>
        /// <param name="progress2"></param>
        /// <param name="bootable">Set VBD.bootable to this value - see comments above</param>
        private void CreateVbd(DiskDescription disk, VDI vdi, double progress1, double progress2, bool bootable)
        {
            List <string> devices = AllowedVBDs;

            if (devices.Count == 0)
            {
                throw new Exception(Messages.NO_MORE_USERDEVICES);
            }
            VBD vbd = new VBD();

            vbd.SetIsOwner(true);
            vbd.bootable    = bootable;
            vbd.empty       = false;
            vbd.unpluggable = true;
            vbd.mode        = vbd_mode.RW;
            vbd.type        = vbd_type.Disk;
            vbd.userdevice  = devices.Contains(disk.Device.userdevice) ? disk.Device.userdevice : devices[0];
            vbd.device      = "";
            vbd.VM          = new XenRef <VM>(VM.opaque_ref);
            vbd.VDI         = new XenRef <VDI>(vdi.opaque_ref);
            RelatedTask     = VBD.async_create(Session, vbd);
            PollToCompletion(progress1, progress2);
            Connection.WaitForCache(new XenRef <VBD>(Result));
        }
Esempio n. 7
0
 /// <summary>
 /// Helper: Check if the disk is at the zeroth position in the VBD list
 /// </summary>
 /// <param name="disk"></param>
 /// <returns></returns>
 private bool IsDeviceAtPositionZero(DiskDescription disk)
 {
     return(disk.Device.userdevice == "0");
 }
Esempio n. 8
0
        private VDI MoveDisk(DiskDescription disk, VBD vbd, double progress, double step)
        {
            string old_vdi_ref = vbd.VDI.opaque_ref;

            RelatedTask = XenAPI.VDI.async_copy(Session, vbd.VDI.opaque_ref, disk.Disk.SR.opaque_ref);
            PollToCompletion(progress, progress + 0.25 * step);
            AddVMHint(Connection.WaitForCache(new XenRef<VDI>(Result)));

            VDI new_vdi = Connection.Resolve(new XenRef<VDI>(Result));

            RelatedTask = XenAPI.VBD.async_destroy(Session, vbd.opaque_ref);
            PollToCompletion(progress + 0.25 * step, progress + 0.5 * step);

            RelatedTask = XenAPI.VDI.async_destroy(Session, old_vdi_ref);
            PollToCompletion(progress + 0.5 * step, progress + 0.75 * step);

            CreateVbd(disk, new_vdi, progress + 0.75 * step, progress + step, IsDeviceAtPositionZero(disk));
            return new_vdi;
        }
Esempio n. 9
0
 /// <summary>
 /// Helper: Check if the disk is at the zeroth position in the VBD list
 /// </summary>
 /// <param name="disk"></param>
 /// <returns></returns>
 private bool IsDeviceAtPositionZero(DiskDescription disk)
 {
     return disk.Device.userdevice == "0";
 }
Esempio n. 10
0
 private VBD GetDiskVBD(DiskDescription disk, List<VBD> vbds)
 {
     foreach (VBD vbd in vbds)
     {
         if (disk.Device.userdevice == vbd.userdevice)
             return vbd;
     }
     return null;
 }
Esempio n. 11
0
        private bool DiskOk(DiskDescription disk, VBD vbd)
        {
            if (vbd == null)
                return false;

            VDI vdi = Connection.Resolve(vbd.VDI);

            return vdi != null && disk.Disk.SR.opaque_ref == vdi.SR.opaque_ref;
        }
Esempio n. 12
0
        private VDI CreateVdi(DiskDescription disk, double progress1, double progress2)
        {
            VDI vdi = new VDI();
            vdi.name_label = disk.Disk.name_label;
            vdi.name_description = disk.Disk.name_description;
            vdi.read_only = false;
            vdi.sharable = false;
            vdi.SR = disk.Disk.SR;
            vdi.type = disk.Disk.type;
            vdi.virtual_size = disk.Disk.virtual_size;

            RelatedTask = XenAPI.VDI.async_create(Session, vdi);
            PollToCompletion(progress1, progress2);
            return Connection.WaitForCache(new XenRef<VDI>(Result));
        }
Esempio n. 13
0
 /// <summary>
 /// Create a VBD
 /// 
 /// ** vbd.bootable **
 /// 1. Windows ignores bootable flag
 /// 2. Eliloader changes the device "0" to bootable when booting linux
 /// </summary>
 /// <param name="disk"></param>
 /// <param name="vdi"></param>
 /// <param name="progress1"></param>
 /// <param name="progress2"></param>
 /// <param name="bootable">Set VBD.bootable to this value - see comments above</param>
 private void CreateVbd(DiskDescription disk, VDI vdi, double progress1, double progress2, bool bootable)
 {
     List<string> devices = AllowedVBDs;
     if (devices.Count == 0)
         throw new Exception(Messages.NO_MORE_USERDEVICES);
     VBD vbd = new VBD();
     vbd.IsOwner = true;
     vbd.bootable = bootable;
     vbd.empty = false;
     vbd.unpluggable = true;
     vbd.mode = vbd_mode.RW;
     vbd.type = vbd_type.Disk;
     vbd.userdevice = devices.Contains(disk.Device.userdevice) ? disk.Device.userdevice : devices[0];
     vbd.device = "";
     vbd.VM = new XenRef<VM>(VM.opaque_ref);
     vbd.VDI = new XenRef<VDI>(vdi.opaque_ref);
     RelatedTask = VBD.async_create(Session, vbd);
     PollToCompletion(progress1, progress2);
     Connection.WaitForCache(new XenRef<VBD>(Result));
 }
Esempio n. 14
0
        /// <summary>
        /// Create a VDI/disk. 
        /// If disk type is existing use the VDI in disk description 
        /// Otherwise create a new disk (provision it from the SR)
        /// </summary>
        /// <param name="disk"></param>
        /// <param name="progress"></param>
        /// <param name="step"></param>
        /// <returns></returns>
        private VDI CreateDisk(DiskDescription disk, double progress, double step)
        {
            VDI vdi;
            bool bootable = false;
            if(disk.Type == DiskDescription.DiskType.Existing)
                vdi = disk.Disk;
            else
            {
                vdi = CreateVdi(disk, progress, progress + 0.75 * step);
                bootable = IsDeviceAtPositionZero(disk);
            }

            AddVMHint(vdi);
            CreateVbd(disk, vdi, progress + 0.75 * step, progress + step, bootable);
            return vdi;
        }