VMware Cloud Community
MicheleMarcon
Contributor
Contributor

How to programmatically shutdown a Cluster with HA and Java SDK

I'm porting a script that performs a graceful shutdown of a HA cluster to Java, but I have a couple of issues:

1) Can't change DSR behavior. This is my code:

            ManagedEntity[] clusterEntities = new InventoryNavigator(rootFolder).searchManagedEntities("ClusterComputeResource");

            for (ManagedEntity m : clusterEntities) {

                if (m.getName().equals(clusterName)) {

                    System.out.println("Found cluster to shutdown: " + clusterName);

                    ClusterComputeResource ccr = (ClusterComputeResource) m;

                    ClusterDrsConfigInfo Drscfg=ccr.getConfiguration().getDrsConfig();

                    Drscfg.setDefaultVmBehavior(DrsBehavior.partiallyAutomated);

                    ccr.getConfiguration().setDrsConfig(Drscfg);

                    ccr.refreshRecommendation();

                    System.out.println("correct: DSR "+Drscfg.getDefaultVmBehavior());

                    System.out.println("unchanged! DSR "+ccr.getConfiguration().getDrsConfig().getDefaultVmBehavior());

               }

        }

Drscfg gets changed to partiallyAutomated, but the actual cluster still remains on fullyAutomated! Why is that?

2) I need to shutdown an Host for which I have a ManagedObjectReference. However, shutdown is only possible for HostSystem, which is a ManagedEntity. So:

How do I shutdonw a ManagedEntityReference (which points to a HostSystem)

OR

How do I get the ManagedEntity from a ManagedEntityReference?

Thanks!

Tags (1)
0 Kudos
0 Replies