src/vsphere_cpi/lib/cloud/vsphere/drs_rules/vm_group.rb
# Delete VM Groups if they are empty
# @param [String[]] vm_group_names - List of VM Groups
Delete VM Groups if they are empty
Delete VM Groups if they are empty
def delete_vm_groups(vm_group_names)
      return if vm_group_names.empty?
      vm_attribute_manager = VMAttributeManager.new(@client.service_content.custom_fields_manager)
      DrsLock.new(vm_attribute_manager, DRS_LOCK_VMGROUP ).with_drs_lock do
        empty_vm_groups = @cluster.configuration_ex.group.select do |group|
          group.is_a?(VimSdk::Vim::Cluster::VmGroup) && vm_group_names.include?(group.name) && group.vm.empty?
        end
        return if empty_vm_groups.empty?
        logger.debug("Deleting empty VmGroups: #{empty_vm_groups.map(&:name)}")
        group_specs = empty_vm_groups.map do |vm_group|
          vm_group_spec = VimSdk::Vim::Cluster::VmGroup.new
          vm_group_spec.name = vm_group.name
          group_spec = VimSdk::Vim::Cluster::GroupSpec.new
          group_spec.info = vm_group_spec
          group_spec.operation =  VimSdk::Vim::Option::ArrayUpdateSpec::Operation::REMOVE
          group_spec.remove_key = vm_group.name
          group_spec
        end
        config_spec = VimSdk::Vim::Cluster::ConfigSpecEx.new
        config_spec.group_spec = group_specs
        @client.wait_for_task do
          @cluster.reconfigure_ex(config_spec, true)
        end
      end
    end
def delete_vm_groups ( vm_group_names ) return if vm_group_names . empty? vm_attribute_manager = VMAttributeManager . new ( @client . service_content . custom_fields_manager ) DrsLock . new ( vm_attribute_manager , DRS_LOCK_VMGROUP ) . with_drs_lock do empty_vm_groups = @cluster . configuration_ex . group . select do | group | group . is_a? ( VimSdk :: Vim :: Cluster :: VmGroup ) && vm_group_names . include? ( group . name ) && group . vm . empty? end return if empty_vm_groups . empty? logger . debug ( "Deleting empty VmGroups: #{empty_vm_groups.map(&:name)}" ) group_specs = empty_vm_groups . map do | vm_group | vm_group_spec = VimSdk :: Vim :: Cluster :: VmGroup . new vm_group_spec . name = vm_group . name group_spec = VimSdk :: Vim :: Cluster :: GroupSpec . new group_spec . info = vm_group_spec group_spec . operation = VimSdk :: Vim :: Option :: ArrayUpdateSpec :: Operation :: REMOVE group_spec . remove_key = vm_group . name group_spec end config_spec = VimSdk :: Vim :: Cluster :: ConfigSpecEx . new config_spec . group_spec = group_specs @client . wait_for_task do @cluster . reconfigure_ex ( config_spec , true ) end end end
Delete VM Groups if they are empty
Delete VM Groups if they are empty
vm_group_names
]
List of VM Groups
List of VM Groups