Sha256: ee76895b2d2851e23f28a22b600cda119efe8d4ff8d02618d9aef1bbe48086ab

Contents?: true

Size: 1.96 KB

Versions: 7

Compression:

Stored size: 1.96 KB

Contents

module Fog
  module Compute
    class Vsphere
      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

7 entries across 5 versions & 2 rubygems

Version Path
fog-vsphere-2.5.0 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-2.4.0 lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-2.3.0 lib/fog/vsphere/requests/compute/create_group.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-vsphere-2.2.0/lib/fog/vsphere/requests/compute/create_group.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-vsphere-2.2.0/lib/fog/vsphere/requests/compute/create_group.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-vsphere-2.2.0/lib/fog/vsphere/requests/compute/create_group.rb
fog-vsphere-2.2.0 lib/fog/vsphere/requests/compute/create_group.rb