public static VolumeObjectTO ParseJson(dynamic json)
        {
            VolumeObjectTO result = null;

            if (json == null)
            {
                return(result);
            }

            dynamic volumeObjectTOJson = json[CloudStackTypes.VolumeObjectTO];

            if (volumeObjectTOJson != null)
            {
                result = new VolumeObjectTO()
                {
                    dataStore = volumeObjectTOJson.dataStore,
                    format    = ((string)volumeObjectTOJson.format),
                    name      = (string)volumeObjectTOJson.name,
                    uuid      = (string)volumeObjectTOJson.uuid
                };
                result.primaryDataStore = PrimaryDataStoreTO.ParseJson(volumeObjectTOJson.dataStore);

                // Assert
                if (result.dataStore == null || result.primaryDataStore == null)
                {
                    String errMsg = "VolumeObjectTO missing primary dataStore in spec " + volumeObjectTOJson.ToString();
                    logger.Error(errMsg);
                    throw new ArgumentNullException(errMsg);
                }

                GuessFileExtension(result);
            }
            return(result);
        }
Beispiel #2
0
        private static void GuessFileExtension(VolumeObjectTO volInfo)
        {
            if (String.IsNullOrEmpty(volInfo.format))
            {
                logger.Info("No image format in VolumeObjectTO, going to use format from first file that matches " + volInfo.FullFileName);

                string path = null;
                if (volInfo.primaryDataStore != null)
                {
                    if (volInfo.primaryDataStore.isLocal)
                    {
                        path = volInfo.primaryDataStore.Path;
                    }
                    else
                    {
                        path = volInfo.primaryDataStore.UncPath;
                    }
                }
                else if (volInfo.nfsDataStore != null)
                {
                    path = volInfo.nfsDataStore.UncPath;
                    if (volInfo.path != null)
                    {
                        path += @"\" + volInfo.path;
                    }
                }
                else
                {
                    String errMsg = "VolumeObjectTO missing dataStore in spec " + Utils.CleanString(volInfo.ToString());
                    logger.Error(errMsg);
                    throw new ArgumentNullException(errMsg);
                }

                path = Utils.NormalizePath(path);
                if (Directory.Exists(path))
                {
                    string[] choices = choices = Directory.GetFiles(path, volInfo.uuid + ".vhd*");
                    if (choices.Length != 1)
                    {
                        String errMsg = "Tried to guess file extension, but cannot find file corresponding to " +
                                        Path.Combine(volInfo.primaryDataStore.Path, volInfo.uuid);
                        logger.Debug(errMsg);
                    }
                    else
                    {
                        string[] splitFileName = choices[0].Split(new char[] { '.' });
                        volInfo.format = splitFileName[splitFileName.Length - 1];
                    }
                }
                logger.Debug("Going to use file " + volInfo.FullFileName);
            }
        }
Beispiel #3
0
        public static DiskTO ParseJson(dynamic json)
        {
            DiskTO result = null;

            if (json != null)
            {
                result = new DiskTO()
                {
                    templateObjectTO = TemplateObjectTO.ParseJson(json.data),
                    volumeObjectTO   = VolumeObjectTO.ParseJson(json.data),
                    type             = (string)json.type,
                    diskSequence     = json.diskSeq
                };
            }

            return(result);
        }
        private static void GuessFileExtension(VolumeObjectTO volInfo)
        {
            if (String.IsNullOrEmpty(volInfo.format))
            {
                logger.Info("No image format in VolumeObjectTO, going to use format from first file that matches " + volInfo.FullFileName);

                string[] choices = Directory.GetFiles(volInfo.primaryDataStore.path, volInfo.name + ".vhd*");

                if (choices.Length != 1)
                {
                    String errMsg = "Tried to guess file extension, but cannot find file corresponding to " + Path.Combine(volInfo.primaryDataStore.path, volInfo.name); // format being guessed.
                    logger.Debug(errMsg);
                }
                else
                {
                    string[] splitFileName = choices[0].Split(new char[] { '.' });
                    volInfo.format = splitFileName[splitFileName.Length - 1];
                }
                logger.Debug("Going to use file " + volInfo.FullFileName);
            }
        }
        private static void GuessFileExtension(VolumeObjectTO volInfo)
        {
            if (String.IsNullOrEmpty(volInfo.format))
            {
                logger.Info("No image format in VolumeObjectTO, going to use format from first file that matches " + volInfo.FullFileName);

                string path = null;
                if (volInfo.primaryDataStore != null)
                {
                    if (volInfo.primaryDataStore.isLocal)
                    {
                        path = volInfo.primaryDataStore.Path;
                    }
                    else
                    {
                        path = volInfo.primaryDataStore.UncPath;
                    }
                }
                else if (volInfo.nfsDataStore != null)
                {
                    path = volInfo.nfsDataStore.UncPath;
                    if (volInfo.path != null)
                    {
                        path += @"\" + volInfo.path;
                    }
                }
                else
                {
                    String errMsg = "VolumeObjectTO missing dataStore in spec " + Utils.CleanString(volInfo.ToString());
                    logger.Error(errMsg);
                    throw new ArgumentNullException(errMsg);
                }

                path = Utils.NormalizePath(path);
                if (Directory.Exists(path))
                {
                    string[] choices = Directory.GetFiles(path, volInfo.uuid + ".vhd*");
                    if (choices.Length != 1)
                    {
                        String errMsg = "Tried to guess file extension, but cannot find file corresponding to " +
                            Path.Combine(volInfo.primaryDataStore.Path, volInfo.uuid);
                        logger.Debug(errMsg);
                    }
                    else
                    {
                        string[] splitFileName = choices[0].Split(new char[] { '.' });
                        volInfo.format = splitFileName[splitFileName.Length - 1];
                    }
                }
                logger.Debug("Going to use file " + volInfo.FullFileName);
            }
        }
        public static VolumeObjectTO ParseJson(dynamic json)
        {
            VolumeObjectTO result = null;

            if (json == null)
            {
                return result;
            }

            dynamic volumeObjectTOJson = json[CloudStackTypes.VolumeObjectTO];
            if (volumeObjectTOJson != null)
            {
                result = new VolumeObjectTO()
                {
                    dataStore = volumeObjectTOJson.dataStore,
                    format = ((string)volumeObjectTOJson.format),
                    name = (string)volumeObjectTOJson.name,
                    path = volumeObjectTOJson.path,
                    uuid = (string)volumeObjectTOJson.uuid,
                    size = (ulong)volumeObjectTOJson.size
                };
                result.primaryDataStore = PrimaryDataStoreTO.ParseJson(volumeObjectTOJson.dataStore);
                result.nfsDataStore = NFSTO.ParseJson(volumeObjectTOJson.dataStore);

                // Assert
                if (result.dataStore == null || (result.primaryDataStore == null && result.nfsDataStore == null))
                {
                    String errMsg = "VolumeObjectTO missing dataStore in spec " + Utils.CleanString(volumeObjectTOJson.ToString());
                    logger.Error(errMsg);
                    throw new ArgumentNullException(errMsg);
                }

                GuessFileExtension(result);
            }
            return result;
        }
        private static void GuessFileExtension(VolumeObjectTO volInfo)
        {
            if (String.IsNullOrEmpty(volInfo.format))
            {
                logger.Info("No image format in VolumeObjectTO, going to use format from first file that matches " + volInfo.FullFileName);

                string path = volInfo.primaryDataStore.Path;
                if (!volInfo.primaryDataStore.isLocal)
                {
                    path = volInfo.primaryDataStore.UncPath;
                }

                string[] choices = choices = Directory.GetFiles(path, volInfo.name + ".vhd*");
                if (choices.Length != 1)
                {
                    String errMsg = "Tried to guess file extension, but cannot find file corresponding to " + Path.Combine(volInfo.primaryDataStore.Path, volInfo.name); // format being guessed.
                    logger.Debug(errMsg);
                }
                else
                {
                    string[] splitFileName = choices[0].Split(new char[] { '.' });
                    volInfo.format = splitFileName[splitFileName.Length - 1];
                }
                logger.Debug("Going to use file " + volInfo.FullFileName);
            }
        }
Beispiel #8
0
        public static VolumeObjectTO ParseJson(dynamic json)
        {
            VolumeObjectTO result = null;

            if (json == null)
            {
                return result;
            }

            dynamic volumeObjectTOJson = json[CloudStackTypes.VolumeObjectTO];
            if (volumeObjectTOJson != null)
            {
                result = new VolumeObjectTO()
                {
                    dataStore = volumeObjectTOJson.dataStore,
                    formatExtension = ((string)volumeObjectTOJson.format),
                    name = (string)volumeObjectTOJson.name,
                    uuid = (string)volumeObjectTOJson.uuid
                };
                result.formatExtension = !String.IsNullOrEmpty(result.formatExtension) ? result.formatExtension.ToLowerInvariant() : result.formatExtension;
            }
            return result;
        }