/// <summary>
        /// Method to list all storage recommendation
        /// </summary>
        private void StorageRecommendation()
        {
            string                 podName            = cb.get_option("storagepodname");
            PodStorageDrsEntry     podStorageDrsEntry = null;
            ManagedObjectReference srmRef             = cb._connection._sic.storageResourceManager;
            ManagedObjectReference sdrsMor            = cb._svcUtil.getEntityByName("StoragePod", podName);

            if (sdrsMor != null)
            {
                cb._connection._service.RefreshStorageDrsRecommendation(srmRef, sdrsMor);
                Console.WriteLine("Success: Refresh Cluster Recommendation");
                string[] type = new string[] { "podStorageDrsEntry" };
                podStorageDrsEntry = (PodStorageDrsEntry)cb._svcUtil.GetDynamicProperty(sdrsMor, "podStorageDrsEntry");
                ClusterRecommendation[] clusterrecommendations = podStorageDrsEntry.recommendation;
                if (clusterrecommendations != null)
                {
                    Console.WriteLine("List of Recommnedation");
                    foreach (ClusterRecommendation recommend in clusterrecommendations)
                    {
                        Console.WriteLine(recommend.type + "Reson" + recommend.reason + "target"
                                          + recommend.target.Value);
                    }
                }
                else
                {
                    Console.WriteLine("No recommendations for this storage pod");
                }
            }
            else
            {
                throw new Exception("Failure: StoragePod " + podName
                                    + " not found.");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete VMdk AntiAffinity Rule Spec
        /// </summary>
        /// <param name="podName">string</param>
        /// <param name="ruleName">string</param>
        private void DeleteVmdkAntiAffinityRule(string podName, string ruleName)
        {
            ManagedObjectReference srmRef  = cb._connection._sic.storageResourceManager;
            ManagedObjectReference sdrsMor = cb._svcUtil.getEntityByName("StoragePod", podName);

            if (sdrsMor != null)
            {
                PodStorageDrsEntry       podStorageDrsEntry = (PodStorageDrsEntry)cb._svcUtil.GetDynamicProperty(sdrsMor, "podStorageDrsEntry");
                StorageDrsVmConfigInfo   drsVmConfigInfo    = null;
                StorageDrsConfigSpec     sdrsConfigSpec     = new StorageDrsConfigSpec();
                StorageDrsVmConfigSpec   drsVmConfigSpec    = new StorageDrsVmConfigSpec();
                StorageDrsVmConfigInfo[] sdrsVmConfig       = podStorageDrsEntry.storageDrsConfig.vmConfig;

                foreach (StorageDrsVmConfigInfo vmConfig in sdrsVmConfig)
                {
                    if (vmConfig.intraVmAntiAffinity != null)
                    {
                        if (vmConfig.intraVmAntiAffinity.name.Equals(ruleName))
                        {
                            drsVmConfigInfo = vmConfig;
                        }
                    }
                }

                if (drsVmConfigInfo != null)
                {
                    drsVmConfigInfo.intraVmAntiAffinity = null;
                    drsVmConfigSpec.info        = drsVmConfigInfo;
                    drsVmConfigSpec.operation   = ArrayUpdateOperation.edit;
                    sdrsConfigSpec.vmConfigSpec = new StorageDrsVmConfigSpec[] { drsVmConfigSpec };
                }
                else
                {
                    string msg = "\nFailure: Rule " + ruleName + " not found.";
                    throw new Exception(msg);
                }

                ManagedObjectReference taskmor =
                    cb._connection._service.ConfigureStorageDrsForPod_Task(srmRef,
                                                                           sdrsMor, sdrsConfigSpec, true);
                if (taskmor != null)
                {
                    String status = cb.getServiceUtil().WaitForTask(
                        taskmor);
                    if (status.Equals("sucess"))
                    {
                        Console.WriteLine("Success: Delete VmdkAntiAffinity Rule.");
                    }
                    else
                    {
                        Console.WriteLine("Failure: Delete VmdkAntiAffinity Rule.");
                        throw new Exception(status);
                    }
                }
            }
            else
            {
                throw new Exception("Storage Pod " + podName + "not found");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method to delete VM Anti AffinityRule
        /// </summary>
        /// <param name="podName">string</param>
        /// <param name="ruleName">string</param>
        private void DeleteVmAntiAffinityRule(string podName, string ruleName)
        {
            ManagedObjectReference srmRef  = cb._connection._sic.storageResourceManager;
            ManagedObjectReference sdrsMor = cb._svcUtil.getEntityByName("StoragePod", podName);

            if (sdrsMor != null)
            {
                PodStorageDrsEntry          podStorageDrsEntry     = (PodStorageDrsEntry)cb._svcUtil.GetDynamicProperty(sdrsMor, "podStorageDrsEntry");
                ClusterRuleSpec             ruleSpec               = new ClusterRuleSpec();
                ClusterRuleInfo[]           clusterRuleInfo        = podStorageDrsEntry.storageDrsConfig.podConfig.rule;
                StorageDrsConfigSpec        sdrsConfigSpec         = new StorageDrsConfigSpec();
                StorageDrsPodConfigSpec     podConfigSpec          = new StorageDrsPodConfigSpec();
                ClusterAntiAffinityRuleSpec vmAntiAffinityRuleSpec = null;
                if (clusterRuleInfo != null)
                {
                    foreach (ClusterRuleInfo vmRule in clusterRuleInfo)
                    {
                        if (vmRule.name.Equals(ruleName))
                        {
                            vmAntiAffinityRuleSpec = (ClusterAntiAffinityRuleSpec)vmRule;
                        }
                    }
                    if (vmAntiAffinityRuleSpec != null)
                    {
                        ruleSpec.operation           = ArrayUpdateOperation.remove;
                        ruleSpec.info                = vmAntiAffinityRuleSpec;
                        ruleSpec.removeKey           = vmAntiAffinityRuleSpec.key;
                        podConfigSpec.rule           = new ClusterRuleSpec[] { ruleSpec };
                        sdrsConfigSpec.podConfigSpec = podConfigSpec;
                        ManagedObjectReference taskmor =
                            cb._connection._service.ConfigureStorageDrsForPod_Task(srmRef,
                                                                                   sdrsMor, sdrsConfigSpec, true);
                        if (taskmor != null)
                        {
                            String status = cb.getServiceUtil().WaitForTask(taskmor);
                            if (status.Equals("sucess"))
                            {
                                Console.WriteLine("Success: Delete VmAntiAffinity Rule.");
                            }
                            else
                            {
                                Console.WriteLine("Failure: Delete VmAntiAffinity Rule.");
                                throw new Exception(status);
                            }
                        }
                    }
                    else
                    {
                        string msg = "\nFailure: Rule " + ruleName + " not found.";
                        throw new Exception(msg);
                    }
                }
            }
            else
            {
                throw new Exception("Storage Pod " + podName + "not found");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method to list all rules
        /// </summary>
        /// <param name="podName">string</param>
        private void ListRules(string podName)
        {
            ManagedObjectReference sdrsMor = cb._svcUtil.getEntityByName("StoragePod", podName);

            if (sdrsMor != null)
            {
                PodStorageDrsEntry podStorageDrsEntry = (PodStorageDrsEntry)cb._svcUtil.GetDynamicProperty(sdrsMor, "podStorageDrsEntry");
                Console.WriteLine("List of VM anti-affinity rules: ");
                ClusterRuleInfo[] clusterRuleInfo = podStorageDrsEntry.storageDrsConfig.podConfig.rule;
                if (clusterRuleInfo != null)
                {
                    foreach (ClusterRuleInfo vmRule in clusterRuleInfo)
                    {
                        Console.WriteLine(vmRule.name);
                    }
                }
                else
                {
                    Console.WriteLine("No rule set for VM anti-affinity");
                }
                Console.WriteLine("List of VMDK anti-affinity rules:");
                StorageDrsVmConfigInfo[] vmConfig = podStorageDrsEntry.storageDrsConfig.vmConfig;
                if (vmConfig != null)
                {
                    foreach (StorageDrsVmConfigInfo sdrsVmConfig in vmConfig)
                    {
                        if (sdrsVmConfig.intraVmAntiAffinity != null)
                        {
                            Console.WriteLine(sdrsVmConfig.intraVmAntiAffinity.name);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No rule set for VMDK anti-affinity");
                }
            }
            else
            {
                throw new Exception("Failure: StoragePod" + podName + "not found");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Method to modify VM Anti Affinity Rule
        /// </summary>
        /// <param name="podName">string</param>
        /// <param name="ruleName">string</param>
        /// <param name="newRuleName">string</param>
        /// <param name="enabled">string</param>
        /// <param name="vmList">string array</param>
        private void ModifyVmAntiAffinityRule(string podName, string ruleName,
                                              string newRuleName, string enabled,
                                              string[] vmList)
        {
            ManagedObjectReference srmRef  = cb._connection._sic.storageResourceManager;
            ManagedObjectReference sdrsMor = cb._svcUtil.getEntityByName("StoragePod", podName);

            if (sdrsMor != null)
            {
                PodStorageDrsEntry            podStorageDrsEntry     = (PodStorageDrsEntry)cb._svcUtil.GetDynamicProperty(sdrsMor, "podStorageDrsEntry");
                ClusterRuleInfo[]             clusterRuleInfo        = podStorageDrsEntry.storageDrsConfig.podConfig.rule;
                ClusterRuleSpec               ruleSpec               = new ClusterRuleSpec();
                List <ManagedObjectReference> vmMorefList            = new List <ManagedObjectReference>();
                ManagedObjectReference        vmMoref                = null;
                StorageDrsConfigSpec          sdrsConfigSpec         = new StorageDrsConfigSpec();
                StorageDrsPodConfigSpec       podConfigSpec          = new StorageDrsPodConfigSpec();
                ClusterAntiAffinityRuleSpec   vmAntiAffinityRuleSpec = null;
                foreach (ClusterRuleInfo vmRule in clusterRuleInfo)
                {
                    if (vmRule.name.Equals(ruleName))
                    {
                        vmAntiAffinityRuleSpec = (ClusterAntiAffinityRuleSpec)vmRule;
                    }
                }

                if (vmAntiAffinityRuleSpec != null)
                {
                    if (newRuleName != null)
                    {
                        vmAntiAffinityRuleSpec.name = newRuleName;
                    }

                    if (enabled.Equals("true"))
                    {
                        vmAntiAffinityRuleSpec.enabled          = true;
                        vmAntiAffinityRuleSpec.enabledSpecified = true;
                    }
                    else
                    {
                        vmAntiAffinityRuleSpec.enabled          = false;
                        vmAntiAffinityRuleSpec.enabledSpecified = false;
                    }

                    foreach (string vmname in vmList)
                    {
                        vmMoref = cb._svcUtil.getEntityByName("VirtualMachine", vmname);
                        if (vmMoref != null)
                        {
                            vmMorefList.Add(vmMoref);
                        }
                        else
                        {
                            string message = "Failure: " + vmname + "VM not found";
                            throw new Exception(message);
                        }
                    }
                    vmAntiAffinityRuleSpec.vm = vmMorefList.ToArray();

                    vmAntiAffinityRuleSpec.userCreated          = true;
                    vmAntiAffinityRuleSpec.userCreatedSpecified = true;
                    ruleSpec.info                = vmAntiAffinityRuleSpec;
                    ruleSpec.operation           = ArrayUpdateOperation.edit;
                    podConfigSpec.rule           = new ClusterRuleSpec[] { ruleSpec };
                    sdrsConfigSpec.podConfigSpec = podConfigSpec;
                    ManagedObjectReference taskmor =
                        cb._connection._service.ConfigureStorageDrsForPod_Task(srmRef,
                                                                               sdrsMor, sdrsConfigSpec, true);

                    if (taskmor != null)
                    {
                        String status = cb.getServiceUtil().WaitForTask(
                            taskmor);
                        if (status.Equals("sucess"))
                        {
                            Console.WriteLine("Success: Modifying VmAntiAffinity Rule.");
                        }
                        else
                        {
                            Console.WriteLine("Failure: Modifying VmAntiAffinity Rule.");
                            throw new Exception(status);
                        }
                    }
                }
                else
                {
                    string msg = "\nFailure: Rule " + ruleName + " not found.";
                    throw new Exception(msg);
                }
            }
            else
            {
                throw new Exception("Storage Pod " + podName + "not found");
            }
        }