Sha256: 0b813f5f1410564b1f864eda939e755e9939fa196ed26e9d783c6f02feb53838

Contents?: true

Size: 1.96 KB

Versions: 23

Compression:

Stored size: 1.96 KB

Contents

module Fog
  module Vsphere
    class Compute
      class Real
        def create_group(attributes = {})
          cluster = get_raw_cluster(attributes[:cluster], attributes[:datacenter])
          group = cluster.configurationEx.group.find { |n| n[:name] == attributes[:name] }
          if group
            raise ArgumentError, "Group #{attributes[:name]} already exists!"
          end
          spec = get_group_spec attributes
          cluster_spec = RbVmomi::VIM.ClusterConfigSpecEx(groupSpec: [
                                                            RbVmomi::VIM.ClusterGroupSpec(
                                                              operation: RbVmomi::VIM.ArrayUpdateOperation('add'),
                                                              info: spec
                                                            )
                                                          ])
          cluster.ReconfigureComputeResource_Task(spec: cluster_spec, modify: true).wait_for_completion
          group = cluster.configurationEx.group.find { |n| n[:name] == attributes[:name] }
          if group
            return group[:name]
          else
            raise Fog::Vsphere::Errors::ServiceError, "Unknown error creating group #{attributes[:name]}"
          end
        end

        private

        def get_group_spec(attributes = {})
          if attributes[:type].to_s == 'ClusterVmGroup'
            vms = attributes[:vm_ids].to_a.map { |id| get_vm_ref(id, attributes[:datacenter]) }
            attributes[:type].new(
              name: attributes[:name],
              vm: vms
            )
          elsif attributes[:type].to_s == 'ClusterHostGroup'
            attributes[:type].new(
              name: attributes[:name],
              host: attributes[:host_refs]
            )
          end
        end
      end

      class Mock
        def create_group(attributes = {})
          data[:groups][attributes[:name]] = attributes
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
fog-vsphere-3.7.0 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.6.8 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.6.7 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.6.6 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.6.5 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.6.4 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.6.3 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.6.2 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.5.3 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.6.0 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.5.2 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.5.1 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.5.0 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.4.0 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.3.1 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.3.0 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.2.5 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.2.2 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.2.1 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-3.2.0 lib/fog/vsphere/requests/compute/create_group.rb