Пример #1
0
        public IDictionary <string, string> VssBackup(IEnumerable <string> vmNames, VmNameType nameType, Options options,
                                                      ILogger logger)
        {
            _cancel = false;
            var vmNamesMap = GetVMNames(vmNames, options.Exclude, nameType);

            if (vmNamesMap.Count > 0)
            {
                if (options.SingleSnapshot)
                {
                    BackupSubset(vmNamesMap, options, logger);
                }
                else
                {
                    foreach (var kv in vmNamesMap)
                    {
                        var vmNamesMapSubset = new Dictionary <string, string> {
                            { kv.Key, kv.Value }
                        };
                        BackupSubset(vmNamesMapSubset, options, logger);
                    }
                }
            }

            return(vmNamesMap);
        }
Пример #2
0
 private static void CheckRequiredVMs(IEnumerable <string> vmNames, VmNameType nameType, IDictionary <string, string> vmNamesMap)
 {
     if (vmNames != null)
     {
         foreach (var vmName in vmNames)
         {
             if (nameType == VmNameType.SystemName && !vmNamesMap.Keys.Contains(vmName, StringComparer.OrdinalIgnoreCase) ||
                 nameType == VmNameType.ElementName && !vmNamesMap.Values.Contains(vmName, StringComparer.OrdinalIgnoreCase))
             {
                 System.Console.WriteLine($"WARNING: \"{vmName}\" not found");
             }
         }
     }
 }
Пример #3
0
        private static bool CheckRequiredVMs(IEnumerable <string> vmNames, VmNameType nameType, IDictionary <string, string> vmNamesMap)
        {
            var withErrors = false;

            if (vmNames != null)
            {
                foreach (var vmName in vmNames)
                {
                    if (nameType == VmNameType.SystemName && !vmNamesMap.Keys.Contains(vmName, StringComparer.OrdinalIgnoreCase) ||
                        nameType == VmNameType.ElementName && !vmNamesMap.Values.Contains(vmName, StringComparer.OrdinalIgnoreCase))
                    {
                        _logger.Error($"\"{vmName}\" not found");
                        withErrors = true;
                    }
                }
            }

            return(!withErrors);
        }
Пример #4
0
        IDictionary <string, string> GetVMNames(IEnumerable <string> vmNames, VmNameType nameType)
        {
            IDictionary <string, string> d = new Dictionary <string, string>();

            string query;
            string vmIdField;

            if (UseWMIV2NameSpace)
            {
                query =
                    "SELECT VirtualSystemIdentifier, ElementName FROM Msvm_VirtualSystemSettingData WHERE VirtualSystemType = 'Microsoft:Hyper-V:System:Realized'";
                vmIdField = "VirtualSystemIdentifier";
            }
            else
            {
                query     = "SELECT SystemName, ElementName FROM Msvm_VirtualSystemSettingData WHERE SettingType = 3";
                vmIdField = "SystemName";
            }

            var inField = nameType == VmNameType.ElementName ? "ElementName" : vmIdField;

            var scope = new ManagementScope(GetWMIScope());

            if (vmNames != null && vmNames.Any())
            {
                query += $" AND ({GetORStr(inField, vmNames)})";
            }

            using (var searcher = new ManagementObjectSearcher(scope, new ObjectQuery(query)))
            {
                using (var moc = searcher.Get())
                    foreach (var mo in moc)
                    {
                        using (mo)
                            d.Add((string)mo[vmIdField], (string)mo["ElementName"]);
                    }
            }

            return(d);
        }
Пример #5
0
 private static void CheckRequiredVMs(IEnumerable<string> vmNames, VmNameType nameType, IDictionary<string, string> vmNamesMap)
 {
     if (vmNames != null)
         foreach (var vmName in vmNames)
             if (nameType == VmNameType.SystemName && !vmNamesMap.Keys.Contains(vmName, StringComparer.OrdinalIgnoreCase) ||
                nameType == VmNameType.ElementName && !vmNamesMap.Values.Contains(vmName, StringComparer.OrdinalIgnoreCase))
             {
                 System.Console.WriteLine($"WARNING: \"{vmName}\" not found");
             }
 }
Пример #6
0
        IDictionary<string, string> GetVMNames(IEnumerable<string> vmNames, VmNameType nameType)
        {
            IDictionary<string, string> d = new Dictionary<string, string>();

            string query;
            string vmIdField;

            if (UseWMIV2NameSpace)
            {
                query = "SELECT VirtualSystemIdentifier, ElementName FROM Msvm_VirtualSystemSettingData WHERE VirtualSystemType = 'Microsoft:Hyper-V:System:Realized'";
                vmIdField = "VirtualSystemIdentifier";
            }
            else
            {
                query = "SELECT SystemName, ElementName FROM Msvm_VirtualSystemSettingData WHERE SettingType = 3";
                vmIdField = "SystemName";
            }

            var inField = nameType == VmNameType.ElementName ? "ElementName" : vmIdField;

            var scope = new ManagementScope(GetWMIScope());

            if (vmNames != null && vmNames.Count() > 0)
                query += string.Format(" AND ({0})", GetORStr(inField, vmNames));

            using (var searcher = new ManagementObjectSearcher(scope, new ObjectQuery(query)))
            {
                using (var moc = searcher.Get())
                    foreach (var mo in moc)
                        using (mo)
                            d.Add((string)mo[vmIdField], (string)mo["ElementName"]);
            }

            return d;
        }
Пример #7
0
        public IDictionary<string, string> VssBackup(IEnumerable<string> vmNames, VmNameType nameType, Options options)
        {
            _cancel = false;
            var vmNamesMap = GetVMNames(vmNames, nameType);

            if (vmNamesMap.Count > 0)
            {
                if (options.SingleSnapshot)
                    BackupSubset(vmNamesMap, options);
                else
                    foreach (var kv in vmNamesMap)
                    {
                        var vmNamesMapSubset = new Dictionary<string, string> { { kv.Key, kv.Value } };
                        BackupSubset(vmNamesMapSubset, options);
                    }
            }

            return vmNamesMap;
        }