示例#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");
             }
 }
        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;
        }
        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;
        }