Ejemplo n.º 1
0
 /// <summary>
 /// Comverts an ova.xml V 0.1 from a XenServer 3 export into an OVF Xml String
 /// </summary>
 /// <param name="vhdExports">DiskInfo[] an array of disk names / identifiers</param>
 /// <param name="ovaxmlFileName">ova xml file name</param>
 /// <param name="ovfName">OVF Name</param>
 /// <param name="lang"></param>
 /// <returns>OVF Xml String</returns>
 public string ConvertXVAv1toOVF(DiskInfo[] vhdExports, string ovaxmlFileName, string ovfName, string lang)
 {
     XcAppliance xca = Tools.LoadOldOvaXml(ovaxmlFileName);
     EnvelopeType env = ConvertFromXenOVAv1(xca, vhdExports, ovfName, lang);
     return Tools.Serialize(env, typeof(EnvelopeType), Tools.LoadNamespaces());
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Converts an ova.xml (version 2) file from an XenServer Export *.xva into and OVF xml string.
 /// </summary>
 /// <param name="vhdExports">DiskInfo[] an array of disk names / identifiers</param>
 /// <param name="ovaxml">ova.xml data in a string</param>
 /// <param name="ovfFilePath">OVF file Path</param>
 /// <param name="ovfName">Name of the OVF</param>
 /// <param name="lang">Language to use</param>
 /// <returns>OVF XML String</returns>
 public string ConvertXVAtoOVF(DiskInfo[] vhdExports, string ovaxml, string ovfFilePath, string ovfName, string lang)
 {
     XenXva xenobj = Tools.DeserializeOvaXml(ovaxml);
     EnvelopeType env = ConvertFromXenOVA(xenobj, vhdExports, ovfFilePath, ovfName, lang);
     string xmlstring = Tools.Serialize(env, typeof(EnvelopeType), Tools.LoadNamespaces());
     log.Debug("OVF.ConvertXVAtoOVF completed");
     return xmlstring;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Comverts an ova.xml V 0.1 from a XenServer 3 export into an OVF Xml String
 /// </summary>
 /// <param name="vhdExports">DiskInfo[] an array of disk names / identifiers</param>
 /// <param name="ovaxmlFileName">ova xml file name</param>
 /// <param name="ovfName">OVF Name</param>
 /// <returns>OVF Xml String</returns>
 public string ConvertXVAv1toOVF(DiskInfo[] vhdExports, string ovaxmlFileName, string ovfName)
 {
     return ConvertXVAv1toOVF(vhdExports, ovaxmlFileName, ovfName, Properties.Settings.Default.Language);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="vhdExports"></param>
 /// <param name="pathToOvf"></param>
 /// <param name="ovfName"></param>
 /// <returns></returns>
 public EnvelopeType ConvertPhysicaltoOVF(DiskInfo[] vhdExports, string pathToOvf, string ovfName)
 {
     return ConvertPhysicaltoOVF(vhdExports, pathToOvf, ovfName, Properties.Settings.Default.Language);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="vhdExports"></param>
 /// <param name="pathToOvf"></param>
 /// <param name="ovfName"></param>
 /// <param name="lang"></param>
 /// <returns></returns>
 public EnvelopeType ConvertPhysicaltoOVF(DiskInfo[] vhdExports, string pathToOvf, string ovfName, string lang)
 {
     CollectInformation();
     var env = CreateEnvelope(ovfName, lang);
     string vmUuid = AddVirtualSystem(env, lang, ovfName);
     string vhsId = AddVirtualHardwareSection(env, vmUuid, lang);
     AddVssd(env, vmUuid, vhsId);
     AddCPUs(env, vmUuid);
     AddMemory(env, vmUuid);
     AddNetworks(env, vmUuid, lang);
     CreateConnectedDevices(env, vmUuid, vhdExports);
     #region CREATE PVP ENTRIES
     foreach (DiskInfo di in vhdExports)
     {
         string pvpFilename = string.Format(@"{0}.pvp", Path.GetFileNameWithoutExtension(di.VhdFileName));
         string pvpPathWithFilename = Path.Combine(pathToOvf, pvpFilename);
         if (File.Exists(pvpPathWithFilename))
         {
             AddExternalFile(env, pvpFilename, null);
         }
     }
     #endregion
     FinalizeEnvelope(env);
     log.DebugFormat("OVF.Create completed, {0}", ovfName);
     return env;
 }
Ejemplo n.º 6
0
 private void TransformXvaOvf_VDI(EnvelopeType env, string vsId, string lang, string refId, DiskInfo di, XenStruct vmstruct)
 {
     string instanceId = null;
     if (mappings.ContainsKey(refId))
     {
         instanceId = string.Format(@"Xen:{0}/{1}", vsId, mappings[refId]);
     }
     else
     {
         instanceId = string.Format(@"Xen:{0}/{1}", vsId, Guid.NewGuid().ToString());
     }
     string description = null;
     string vhdfilename = di.VhdFileName;
     ulong filesize = 0;
     ulong capacity = 0;
     ulong freespace = 0;
     foreach (XenMember n in vmstruct.xenmember)
     {
         if (n.xenname.ToLower().Equals("virtual_size"))
         {
             capacity = Convert.ToUInt64(n.xenvalue);
         }
         else if (n.xenname.ToLower().Equals("physical_utilisation"))
         {
             filesize = Convert.ToUInt64(n.xenvalue);
         }
     }
     freespace = capacity - filesize;
     UpdateDisk(env, vsId, instanceId, description, vhdfilename, filesize, capacity, freespace);
     log.DebugFormat("OVF.TransformXvaOvf_VDI completed {0}", vsId);
 }
Ejemplo n.º 7
0
        private void CreateConnectedDevices(EnvelopeType ovfEnv, string vsId, string lang, DiskInfo[] vhdExports)
        {
            //VirtualHardwareSection_Type vhs = FindVirtualHardwareSection(ovfEnv, vsId);
            bool guessPosition = true;
            int i = 0;
            #region IDE
            if (Win32_IDEController != null && Win32_IDEController.Count > 0)
            {
                foreach (ManagementObject mo in Win32_IDEController)
                {
                    #region FIND BY PROPERTIES NOT EXPLICID
                    string deviceid = null;
                    foreach (PropertyData pd in mo.Properties)
                    {
                        if (pd.Name.ToLower().Equals("deviceid") && pd.Value != null)
                        {
                            deviceid = (string)pd.Value;
                        }
                    }
                    #endregion

                    if (deviceid == null)
                    {
                        traceLog.Debug("No device id defined, continuing");
                        continue;
                    }
                    List<ManagementObject> ControllerAssociations = FindDeviceReferences("Win32_IDEControllerDevice", deviceid);
                    string controllerInstanceId = Guid.NewGuid().ToString();

                    AddController(ovfEnv, vsId, DeviceType.IDE, controllerInstanceId, i++);
                    foreach (ManagementObject ca in ControllerAssociations)
                    {
                        #region FIND BY PROPERTIES NOT EXPLICID
                        string _dependent = null;
                        foreach (PropertyData pd in ca.Properties)
                        {
                            if (pd.Name.ToLower().Equals("dependent") && pd.Value != null)
                            {
                                _dependent = (string)pd.Value;
                            }
                        }
                        if (_dependent == null)
                        {
                            traceLog.Debug("PCI Association not available, continuing.");
                            continue;
                        }
                        #endregion
                        string[] dependent = _dependent.Split(new char[] { '=' });
                        string dependentId = dependent[dependent.Length - 1].Replace("\"", "");
                        dependentId = dependentId.Replace(@"\", "");
                        string startswith = dependentId; //.Replace(@"\", "");

                        if (startswith.ToUpper().StartsWith(@"IDEDISK"))
                        {
                            log.Debug("OVF.CreateConnectedDevices Checking IDEDISK");
                            foreach (ManagementObject md in Win32_DiskDrive)
                            {
                                #region FIND BY PROPERTIES NOT EXPLICID
                                string _deviceid = null;
                                string _pnpdeviceid = null;
                                UInt64 _size = 0;
                                foreach (PropertyData pd in md.Properties)
                                {
                                    if (pd.Name.ToLower().Equals("deviceid") && pd.Value != null)
                                    {
                                        _deviceid = (string)pd.Value;
                                    }
                                    else if (pd.Name.ToLower().Equals("pnpdeviceid") && pd.Value != null)
                                    {
                                        _pnpdeviceid = (string)pd.Value;
                                    }
                                    else if (pd.Name.ToLower().Equals("size") && pd.Value != null)
                                    {
                                        _size = (UInt64)pd.Value;
                                    }

                                }
                                #endregion

                                _pnpdeviceid = _pnpdeviceid.Replace(@"\", "");
                                if (_pnpdeviceid.Equals(dependentId))
                                {
                                    foreach (DiskInfo di in vhdExports)
                                    {
                                        if (_deviceid.Contains(di.DriveId))
                                        {
                                            try
                                            {
                                                log.DebugFormat("OVF.CreateConnectedDevices: Dependent: {0}  Device: {1}", dependentId, _deviceid);
                                                string diskInstanceId = Guid.NewGuid().ToString();
                                                int lastAmp = dependentId.LastIndexOf('&');
                                                if (lastAmp < 0) lastAmp = 0;
                                                string[] tmp = dependentId.Substring(lastAmp + 1).Split(new char[] { '.' });
                                                string address = null;
                                                if (tmp.Length >= 2)
                                                {
                                                    address = tmp[1];
                                                }
                                                else
                                                {
                                                    address = (guessPosition) ? "0" : "1";
                                                    guessPosition = !guessPosition;
                                                }
                                                address = address.Replace("&", "_");
                                                bool bootable = IsBootDisk(di.DriveId);
                                                AddDisk(ovfEnv, vsId, diskInstanceId, lang, di.VhdFileName, bootable,
                                                        _ovfrm.GetString("RASD_19_CAPTION"),
                                                        _ovfrm.GetString("RASD_19_DESCRIPTION"),
                                                        Convert.ToUInt64(di.PhysicalSize), Convert.ToUInt64(di.CapacitySize));
                                                AddDeviceToController(ovfEnv, vsId, diskInstanceId, controllerInstanceId, address);
                                                di.Added = true;
                                                log.DebugFormat("OVF.CreateConnectedDevices: {0} ({1}) added to {2}", di.DriveId, di.VhdFileName, dependentId);
                                            }
                                            catch (Exception ex)
                                            {
                                                string msg = string.Format("{0} [{1}] controller connection could not be identified.", "IDEDISK", _pnpdeviceid);
                                                log.ErrorFormat("OVF.CreateConnectedDevices: {0}", msg);
                                                throw new Exception(msg, ex);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else if (startswith.ToUpper().StartsWith(@"IDECDROM"))
                        {
                            log.Debug("OVF.CreateConnectedDevices Checking IDECDROM");
                            foreach (ManagementObject md in Win32_CDROMDrive)
                            {
                                #region FIND BY PROPERTIES NOT EXPLICID
                                string _pnpdeviceid = null;
                                foreach (PropertyData pd in md.Properties)
                                {
                                    if (pd.Name.ToLower().Equals("pnpdeviceid") && pd.Value != null)
                                    {
                                        _pnpdeviceid = (string)pd.Value;
                                    }
                                }
                                if (_pnpdeviceid == null)
                                {
                                    traceLog.Debug("PNPDeviceID not available, continuing.");
                                    continue;
                                }
                                #endregion
                                _pnpdeviceid = _pnpdeviceid.Replace(@"\", "");
                                if (_pnpdeviceid.Equals(dependentId))
                                {
                                    log.DebugFormat("OVF.CreateConnectedDevices: Dependent: {0}  Device: {1}", dependentId, _pnpdeviceid);
                                    try
                                    {
                                        string diskInstanceId = Guid.NewGuid().ToString();
                                        int lastAmp = dependentId.LastIndexOf('&');
                                        if (lastAmp < 0) lastAmp = 0;
                                        string[] tmp = dependentId.Substring(lastAmp + 1).Split(new char[] { '.' });
                                        //string[] tmp = dependentId.Split(new char[] { '.' });
                                        string address = tmp[1];
                                        int idetest = Convert.ToInt32(address);
                                        if (idetest != 0 && idetest != 1)
                                        {
                                            address = "0";
                                        }
                                        AddCDROM(ovfEnv, vsId, diskInstanceId, _ovfrm.GetString("RASD_16_CAPTION"), _ovfrm.GetString("RASD_16_ELEMENTNAME"));
                                        AddDeviceToController(ovfEnv, vsId, diskInstanceId, controllerInstanceId, address);
                                        log.DebugFormat("OVF.CreateConnectedDevices: CDROM added to {0}", dependentId);
                                    }
                                    catch
                                    {
                                        log.WarnFormat("OVF.CreateConnectedDevices: CDROM [{0}] controller connection could not be identified, skipped.", _pnpdeviceid);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                log.Info("OVF.CreateConnectedDevices NO IDE controllers detected.");
            }
            log.Debug("OVF.CreateConnectedDevices IDE Controllers completed.");
            #endregion

            #region SCSI
            if (Win32_SCSIController != null && Win32_SCSIController.Count > 0)
            {
                foreach (ManagementObject device in Win32_SCSIController)
                {
                    #region FIND BY PROPERTIES NOT EXPLICID
                    string _deviceid = null;
                    foreach (PropertyData pd in device.Properties)
                    {
                        if (pd.Name.ToLower().Equals("deviceid") && pd.Value != null)
                        {
                            _deviceid = (string)pd.Value;
                        }
                    }
                    if (_deviceid == null)
                    {
                        traceLog.Debug("SCSI DeviceID not available, continuing.");
                        continue;
                    }
                    #endregion
                    List<ManagementObject> ControllerAssociations = FindDeviceReferences("Win32_SCSIControllerDevice", _deviceid);
                    string controllerInstanceId = Guid.NewGuid().ToString();

                    if (ControllerAssociations == null || ControllerAssociations.Count <= 0)
                    {
                        traceLog.DebugFormat("No Controller associations for {0}", _deviceid);
                        continue;
                    }

                    AddController(ovfEnv, vsId, DeviceType.SCSI, controllerInstanceId, i++);
                    foreach (ManagementObject ca in ControllerAssociations)
                    {
                        #region FIND BY PROPERTIES NOT EXPLICID
                        string _dependent = null;
                        foreach (PropertyData pd in ca.Properties)
                        {
                            if (pd.Name.ToLower().Equals("dependent") && pd.Value != null)
                            {
                                _dependent = (string)pd.Value;
                            }
                        }
                        if (_dependent == null)
                        {
                            traceLog.Debug("SCSI Association not available, continuing.");
                            continue;
                        }
                        #endregion

                        string[] dependent = _dependent.Split(new char[] { '=' });
                        string dependentId = dependent[dependent.Length - 1].Replace("\"", "");
                        dependentId = dependentId.Replace(@"\", "");
                        string startswith = dependentId; //.Replace(@"\", "");

                        if (startswith.ToUpper().StartsWith(@"SCSIDISK"))
                        {
                            foreach (ManagementObject md in Win32_DiskDrive)
                            {
                                #region FIND BY PROPERTIES NOT EXPLICID
                                string __deviceid = null;
                                string __pnpdeviceid = null;
                                UInt32 __scsibus = 0;
                                UInt16 __scsilogicalunit = 0;
                                UInt16 __scsiport = 0;
                                UInt16 __scsitargetid = 0;
                                UInt64 __size = 0;
                                foreach (PropertyData pd in md.Properties)
                                {
                                    if (pd.Name.ToLower().Equals("deviceid") && pd.Value != null)
                                    {
                                        __deviceid = (string)pd.Value;
                                    }
                                    if (pd.Name.ToLower().Equals("pnpdeviceid") && pd.Value != null)
                                    {
                                        __pnpdeviceid = (string)pd.Value;
                                    }
                                    if (pd.Name.ToLower().Equals("scsibus") && pd.Value != null)
                                    {
                                        __scsibus = (UInt32)pd.Value;
                                    }
                                    if (pd.Name.ToLower().Equals("scsilogicalunit") && pd.Value != null)
                                    {
                                        __scsilogicalunit = (UInt16)pd.Value;
                                    }
                                    if (pd.Name.ToLower().Equals("scsiport") && pd.Value != null)
                                    {
                                        __scsiport = (UInt16)pd.Value;
                                    }
                                    if (pd.Name.ToLower().Equals("scsitargetid") && pd.Value != null)
                                    {
                                        __scsitargetid = (UInt16)pd.Value;
                                    }
                                    if (pd.Name.ToLower().Equals("size") && pd.Value != null)
                                    {
                                        __size = (UInt64)pd.Value;
                                    }
                                }
                                if (__deviceid == null)
                                {
                                    traceLog.Debug("SCSI DeviceID not available, continuing.");
                                    continue;
                                }
                                #endregion

                                __pnpdeviceid = __pnpdeviceid.Replace(@"\", "");
                                if (__pnpdeviceid.Equals(dependentId))
                                {
                                    foreach (DiskInfo di in vhdExports)
                                    {
                                        if (__deviceid.Contains(di.DriveId))
                                        {
                                            string diskInstanceId = Guid.NewGuid().ToString();
                                            string _description = string.Format(_ovfrm.GetString("RASD_CONTROLLER_SCSI_DESCRIPTION"), __scsibus, __scsilogicalunit, __scsiport, __scsitargetid);
                                            bool bootable = IsBootDisk(di.DriveId);
                                            AddDisk(ovfEnv, vsId, diskInstanceId, lang, di.VhdFileName, bootable, _ovfrm.GetString("RASD_19_CAPTION"), _description, Convert.ToUInt64(di.PhysicalSize), Convert.ToUInt64(di.CapacitySize));
                                            AddDeviceToController(ovfEnv, vsId, diskInstanceId, controllerInstanceId, Convert.ToString(__scsiport));
                                            di.Added = true;
                                            log.DebugFormat("CreateConnectedDevices: {0} ({1}) added to {2}", di.DriveId, di.VhdFileName, dependentId);
                                        }
                                    }
                                }
                            }
                        }
                        else if (startswith.ToUpper().StartsWith(@"SCSICDROM"))
                        {
                            foreach (ManagementObject md in Win32_CDROMDrive)
                            {
                                #region FIND BY PROPERTIES NOT EXPLICID
                                string __deviceid = null;
                                string __pnpdeviceid = null;
                                UInt32 __scsibus = 0;
                                UInt16 __scsilogicalunit = 0;
                                UInt16 __scsiport = 0;
                                UInt16 __scsitargetid = 0;
                                foreach (PropertyData pd in md.Properties)
                                {
                                    if (pd.Name.ToLower().Equals("deviceid") && pd.Value != null)
                                    {
                                        __deviceid = (string)pd.Value;
                                    }
                                    if (pd.Name.ToLower().Equals("pnpdeviceid") && pd.Value != null)
                                    {
                                        __pnpdeviceid = (string)pd.Value;
                                    }
                                    if (pd.Name.ToLower().Equals("scsibus") && pd.Value != null)
                                    {
                                        __scsibus = (UInt32)pd.Value;
                                    }
                                    if (pd.Name.ToLower().Equals("scsilogicalunit") && pd.Value != null)
                                    {
                                        __scsilogicalunit = (UInt16)pd.Value;
                                    }
                                    if (pd.Name.ToLower().Equals("scsiport") && pd.Value != null)
                                    {
                                        __scsiport = (UInt16)pd.Value;
                                    }
                                    if (pd.Name.ToLower().Equals("scsitargetid") && pd.Value != null)
                                    {
                                        __scsitargetid = (UInt16)pd.Value;
                                    }
                                }
                                if (__deviceid == null)
                                {
                                    traceLog.Debug("SCSI DeviceID not available, continuing.");
                                    continue;
                                }
                                #endregion
                                __pnpdeviceid = __pnpdeviceid.Replace(@"\", "");
                                if (__pnpdeviceid.Equals(dependentId))
                                {
                                    string diskInstanceId = Guid.NewGuid().ToString();
                                    string caption = string.Format(_ovfrm.GetString("RASD_CONTROLLER_SCSI_DESCRIPTION"), __scsibus, __scsilogicalunit, __scsiport, __scsitargetid);
                                    AddCDROM(ovfEnv, vsId, diskInstanceId, caption, _ovfrm.GetString("RASD_16_DESCRIPTION"));
                                    AddDeviceToController(ovfEnv, vsId, diskInstanceId, controllerInstanceId, Convert.ToString(__scsiport));
                                    log.DebugFormat("CreateConnectedDevices: CDROM added to {0}", dependentId);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                log.Info("OVF.CreateConnectedDevices no SCSI Controllers detected.");
            }
            log.DebugFormat("OVF.CreateConnectedDevices SCSI Controllers completed {0} ", vsId);
            #endregion

            #region OTHER CONTROLLER DISKS
            // These are disks that were not found on an IDE or SCSI, but exist and wish to be exported.
            // these could be USB, 1394 etc.
            foreach (DiskInfo di in vhdExports)
            {
                if (!di.Added)
                {
                    UInt64 _size = 0;
                    string diskInstanceId = Guid.NewGuid().ToString();
                    string _deviceid = null;
                    string _mediatype = null;
                    foreach (ManagementObject md in Win32_DiskDrive)
                    {
                        #region FIND BY PROPERTIES NOT EXPLICID
                        foreach (PropertyData pd in md.Properties)
                        {
                            if (pd.Name.ToLower().Equals("deviceid") && pd.Value != null)
                            {
                                _deviceid = (string)pd.Value;
                            }
                            else if (pd.Name.ToLower().Equals("mediatype") && pd.Value != null)
                            {
                                _mediatype = (string)pd.Value;
                            }
                            else if (pd.Name.ToLower().Equals("size") && pd.Value != null)
                            {
                                _size = (UInt64)pd.Value;
                            }

                        }
                        #endregion
                    }

                    bool bootable = IsBootDisk(di.DriveId);
                    AddDisk(ovfEnv, vsId, diskInstanceId, lang, di.VhdFileName, bootable, _ovfrm.GetString("RASD_19_CAPTION"), _mediatype, Convert.ToUInt64(di.PhysicalSize), Convert.ToUInt64(di.CapacitySize));
                    di.Added = true;
                    log.DebugFormat("CreateConnectedDevices: {0} ({1}) added to {2}", di.DriveId, di.VhdFileName, _mediatype);
                }
            }
            log.DebugFormat("OVF.CreateConnectedDevices OTHER Controllers completed {0} ", vsId);
            #endregion

            #region CHECK ALL DISKS WERE DEFINED
            foreach (DiskInfo di in vhdExports)
            {
                if (!di.Added)
                {
                    AddDisk(ovfEnv, vsId, Guid.NewGuid().ToString(), lang, di.VhdFileName, false, _ovfrm.GetString("RASD_19_CAPTION"), _ovfrm.GetString("RASD_19_DESCRIPTION"), Convert.ToUInt64(di.PhysicalSize), Convert.ToUInt64(di.CapacitySize));
                    di.Added = true;
                    log.Warn("CreateConnectedDevices: MANUAL Update of OVF REQUIRED TO DEFINE: Disk Size and Capacity");
                    log.WarnFormat("CreateConnectedDevices: {0} ({1}) NOT FOUND, added as Unknown with 0 Size", di.DriveId, di.VhdFileName);
                }
            }
            #endregion

            log.DebugFormat("OVF.CreateConnectedDevices completed {0} ", vsId);
        }
Ejemplo n.º 8
0
 private void CreateConnectedDevices(EnvelopeType ovfEnv, string vsId, DiskInfo[] vhdExports)
 {
     CreateConnectedDevices(ovfEnv, vsId, Properties.Settings.Default.Language, vhdExports);
 }
Ejemplo n.º 9
0
        private EnvelopeType ConvertFromXenOVAv1(XcAppliance xenxva, DiskInfo[] vhdExports, string ovfname, string lang)
        {
            mappings.Clear();
            if (ovfname == null ||
                xenxva == null ||
                xenxva.vm == null ||
                xenxva.vm.config == null ||
                xenxva.vm.hacks == null ||
                xenxva.vm.vbd == null ||
                xenxva.vm.label == null ||
                xenxva.vm.label.Length <= 0 ||
                vhdExports == null ||
                vhdExports.Length <= 0)
                throw new NullReferenceException("Invalid/Null argument");

            EnvelopeType env = CreateEnvelope(ovfname, lang);
            string vsId = AddVirtualSystem(env, lang, ovfname);
            string vhsId = AddVirtualHardwareSection(env, vsId, lang);
            ulong mem = 0;
            if (xenxva.vm.config.memset != 0)
            {
                mem = xenxva.vm.config.memset / MB;
                SetMemory(env, vsId, mem, "MB");
            }
            if (xenxva.vm.config.vcpus != 0)
            {
                SetCPUs(env, vsId, xenxva.vm.config.vcpus);
            }
            if (xenxva.vm.hacks.isHVM)
            {
                AddVirtualSystemSettingData(env, vsId, vhsId, xenxva.vm.label.Trim(), xenxva.vm.label.Trim() , _ovfrm.GetString("CONVERT_XVA_VSSD_CAPTION"), Guid.NewGuid().ToString(), Properties.Settings.Default.xenDefaultVirtualSystemType);
                AddOtherSystemSettingData(env, vsId, lang, "HVM_boot_policy", Properties.Settings.Default.xenBootOptions, _ovfrm.GetString("XENSERVER_SPECIFIC_DESCRIPTION"));
                AddOtherSystemSettingData(env, vsId, lang, "HVM_boot_params", Properties.Settings.Default.xenBootOrder, _ovfrm.GetString("XENSERVER_SPECIFIC_DESCRIPTION"));
                AddOtherSystemSettingData(env, vsId, lang, "platform", Properties.Settings.Default.xenPlatformSetting, _ovfrm.GetString("XENSERVER_PLATFORM_DESCRIPTION"));

            }
            else
            {
                AddVirtualSystemSettingData(env, vsId, vhsId, xenxva.vm.label.Trim(), xenxva.vm.label.Trim(), _ovfrm.GetString("CONVERT_XVA_VSSD_CAPTION"), Guid.NewGuid().ToString(), Properties.Settings.Default.xenDefaultPVVirtualSystemType);
                AddOtherSystemSettingData(env, vsId, lang, "PV_bootloader", Properties.Settings.Default.xenPVBootloader, _ovfrm.GetString("XENSERVER_SPECIFIC_DESCRIPTION"));
                AddOtherSystemSettingData(env, vsId, lang, "PV_kernel", Properties.Settings.Default.xenKernelOptions, _ovfrm.GetString("XENSERVER_SPECIFIC_DESCRIPTION"));
                AddOtherSystemSettingData(env, vsId, lang, "platform", Properties.Settings.Default.xenPVPlatformSetting, _ovfrm.GetString("XENSERVER_PLATFORM_DESCRIPTION"));
            }
            UpdateVirtualSystemName(env, vsId, lang, xenxva.vm.label.Trim());
            AddNetwork(env, vsId, lang, _ovfrm.GetString("RASD_10_CAPTION"),  _ovfrm.GetString("RASD_10_DESCRIPTION"), null);
            string contollerId = Guid.NewGuid().ToString();
            AddController(env, vsId, DeviceType.IDE, contollerId, 0);
            int i = 0;
            foreach (DiskInfo di in vhdExports)
            {
                if (di.PhysicalSize == null) di.PhysicalSize = "0";
                if (di.CapacitySize == null) di.CapacitySize = "0";
                AddDisk(env, vsId, di.DriveId, lang, di.VhdFileName, true, _ovfrm.GetString("RASD_19_CAPTION"), _ovfrm.GetString("RASD_19_DESCRIPTION"), Convert.ToUInt64(di.PhysicalSize), Convert.ToUInt64(di.CapacitySize));
                AddDeviceToController(env, vsId, di.DriveId, contollerId, Convert.ToString(i++));
            }

            FinalizeEnvelope(env);
            log.DebugFormat("OVF.ConvertFromXenOVAv1 completed {0}", ovfname);
            mappings.Clear();
            return env;
        }
Ejemplo n.º 10
0
        private EnvelopeType ConvertFromXenOVA(XenXva xenxva, DiskInfo[] vhdExports, string ovfFilePath, string ovfname, string lang)
        {
            mappings.Clear();
            EnvelopeType env = CreateEnvelope(ovfname, lang);
            string vsId = AddVirtualSystem(env, lang, ovfname);
            string vhsId = AddVirtualHardwareSection(env, vsId, lang);
            // Do this because it isn't defined yet this will allow for
            // it to update in any order.
            UpdateVirtualSystemSettingData(env, vsId, "VirtualSystemType", "hvm");
            foreach (XenMember xm in xenxva.xenstruct.xenmember)
            {
                if (xm.xenname.ToLower().Equals("objects"))
                {
                    foreach (object obj in ((XenArray)xm.xenvalue).xendata.xenvalue)
                    {
                        if (obj is XenStruct)
                        {
                            bool AtVM = false;
                            bool AtVBD = false;
                            bool AtVIF = false;
                            bool AtNetwork = false;
                            bool AtVDI = false;
                            bool AtSR = false;
                            bool IsReferenced = false;
                            string reference = null;
                            foreach (XenMember xmm in ((XenStruct)obj).xenmember)
                            {
                                #region SET AREA
                                if (xmm.xenname.ToLower().Equals("class") &&
                                    xmm.xenvalue != null &&
                                    xmm.xenvalue is string &&
                                    ((string)xmm.xenvalue).Length > 0 &&
                                    ((string)xmm.xenvalue).ToLower().Equals("vm"))
                                {
                                    AtVM = true;
                                }
                                else if (xmm.xenname.ToLower().Equals("class") &&
                                    xmm.xenvalue != null &&
                                    xmm.xenvalue is string &&
                                    ((string)xmm.xenvalue).Length > 0 &&
                                    ((string)xmm.xenvalue).ToLower().Equals("vbd"))
                                {
                                    AtVBD = true;
                                }

                                else if (xmm.xenname.ToLower().Equals("class") &&
                                    xmm.xenvalue != null &&
                                    xmm.xenvalue is string &&
                                    ((string)xmm.xenvalue).Length > 0 &&
                                    ((string)xmm.xenvalue).ToLower().Equals("vif"))
                                {
                                    AtVIF = true;
                                }
                                else if (xmm.xenname.ToLower().Equals("class") &&
                                    xmm.xenvalue != null &&
                                    xmm.xenvalue is string &&
                                    ((string)xmm.xenvalue).Length > 0 &&
                                    ((string)xmm.xenvalue).ToLower().Equals("network"))
                                {
                                    AtNetwork = true;
                                }
                                else if (xmm.xenname.ToLower().Equals("class") &&
                                    xmm.xenvalue != null &&
                                    xmm.xenvalue is string &&
                                    ((string)xmm.xenvalue).Length > 0 &&
                                    ((string)xmm.xenvalue).ToLower().Equals("vdi"))
                                {
                                    AtVDI = true;
                                }
                                else if (xmm.xenname.ToLower().Equals("class") &&
                                    xmm.xenvalue != null &&
                                    xmm.xenvalue is string &&
                                    ((string)xmm.xenvalue).Length > 0 &&
                                    ((string)xmm.xenvalue).ToLower().Equals("sr"))
                                {
                                    AtSR = true;
                                }
                                #endregion

                                #region CHECK REFERENCE
                                if (xmm.xenname.ToLower().Equals("id") &&
                                   xmm.xenvalue != null &&
                                   xmm.xenvalue is string)
                                {
                                    string curid = (string)(xmm.xenvalue);
                                    if (mappings.ContainsKey(curid))
                                    {
                                        IsReferenced = true;
                                        reference = curid;
                                    }
                                    else
                                    {
                                        IsReferenced = false;
                                    }
                                }
                                #endregion

                                #region GET DATA
                                if (xmm.xenname.ToLower().Equals("snapshot") &&
                                    xmm.xenvalue != null &&
                                    xmm.xenvalue is XenStruct)
                                {
                                    if (AtVM)
                                    {
                                        TransformXvaOvf_VM(env, vsId, lang, (XenStruct)xmm.xenvalue);
                                        AtVM = false;
                                    }
                                    else if (AtVBD)
                                    {
                                        TransformXvaOvf_VBD(env, vsId, lang, (XenStruct)xmm.xenvalue);
                                        AtVBD = false;
                                    }
                                    else if (AtVIF)
                                    {
                                        TransformXvaOvf_VIF(env, vsId, lang, (XenStruct)xmm.xenvalue);
                                        AtVIF = false;
                                    }
                                    else if (AtNetwork && IsReferenced)
                                    {
                                        TransformXvaOvf_Network(env, vsId, lang, reference, (XenStruct)xmm.xenvalue);
                                        AtNetwork = false;
                                    }
                                    else if (AtVDI && IsReferenced)
                                    {
                                        DiskInfo diskDetails = null;
                                        foreach (DiskInfo di in vhdExports)
                                        {
                                            if (di.DriveId.ToLower().Equals(reference.ToLower()))
                                            {
                                                diskDetails = di;
                                                break;
                                            }
                                        }
                                        if (diskDetails != null)
                                        {
                                            TransformXvaOvf_VDI(env, vsId, lang, reference, diskDetails, (XenStruct)xmm.xenvalue);
                                            string pvpFilename = string.Format(@"{0}.pvp", Path.GetFileNameWithoutExtension(diskDetails.VhdFileName));
                                            string pvpFileWithPath = Path.Combine(ovfFilePath, pvpFilename);
                                            if (File.Exists(pvpFileWithPath))
                                            {
                                                AddExternalFile(env, pvpFilename, null);
                                            }
                                        }
                                        else
                                        {
                                            log.ErrorFormat("Could not find the details for disk, {0}", reference);
                                        }
                                        AtVDI = false;
                                    }
                                    else if (AtSR && IsReferenced)
                                    {
                                        TransformXvaOvf_SR(env, vsId, lang, (XenStruct)xmm.xenvalue);
                                        AtSR = false;
                                    }
                                    IsReferenced = false;
                                }
                                #endregion
                            }
                        }
                    }
                }
            }
            FinalizeEnvelope(env);
            log.DebugFormat("OVF.ConvertFromXenOVA completed {0}", ovfname);
            mappings.Clear();
            return env;
        }