Sha256: 05a0a6a633858fbea0e6c4730edd3c3a51bccb750209f9ccefa9bf9a311310e6

Contents?: true

Size: 1.9 KB

Versions: 15

Compression:

Stored size: 1.9 KB

Contents

#!/usr/bin/env ruby

# Copyright (c) 2011-2017 VMware, Inc.  All Rights Reserved.
# SPDX-License-Identifier: MIT

require 'trollop'
require 'rbvmomi'
require 'rbvmomi/trollop'

VIM = RbVmomi::VIM

opts = Trollop.options do
  banner <<-EOS
Create a VM.

Usage:
    create_vm-1.9.rb [options]

VIM connection options:
    EOS

    rbvmomi_connection_opts

    text <<-EOS

VM location options:
    EOS

    rbvmomi_datacenter_opt

    text <<-EOS

Other options:
  EOS
end

Trollop.die("must specify host") unless opts[:host]
vm_name = ARGV[0] or abort "must specify VM name"

vim = VIM.connect opts
dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
vmFolder = dc.vmFolder
hosts = dc.hostFolder.children
rp = hosts.first.resourcePool

vm_cfg = {
  name: vm_name,
  guestId: 'otherGuest',
  files: { vmPathName: '[datastore1]' },
  numCPUs: 1,
  memoryMB: 128,
  deviceChange: [
    {
      operation: :add,
      device: VIM.VirtualLsiLogicController(
        key: 1000,
        busNumber: 0,
        sharedBus: :noSharing,
      )
    }, {
      operation: :add,
      fileOperation: :create,
      device: VIM.VirtualDisk(
        key: 0,
        backing: VIM.VirtualDiskFlatVer2BackingInfo(
          fileName: '[datastore1]',
          diskMode: :persistent,
          thinProvisioned: true,
        ),
        controllerKey: 1000,
        unitNumber: 0,
        capacityInKB: 4000000,
      )
    }, {
      operation: :add,
      device: VIM.VirtualE1000(
        key: 0,
        deviceInfo: {
          label: 'Network Adapter 1',
          summary: 'VM Network',
        },
        backing: VIM.VirtualEthernetCardNetworkBackingInfo(
          deviceName: 'VM Network',
        ),
        addressType: 'generated'
      )
    }
  ],
  extraConfig: [
    {
      key: 'bios.bootOrder',
      value: 'ethernet0'
    }
  ]
}

vmFolder.CreateVM_Task(:config => vm_cfg, :pool => rp).wait_for_completion

Version data entries

15 entries across 13 versions & 2 rubygems

Version Path
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/rbvmomi-1.13.0/examples/create_vm-1.9.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rbvmomi-1.13.0/examples/create_vm-1.9.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/rbvmomi-1.13.0/examples/create_vm-1.9.rb
rbvmomi-1.13.0 examples/create_vm-1.9.rb
rbvmomi-1.12.0 examples/create_vm-1.9.rb
rbvmomi-1.11.7 examples/create_vm-1.9.rb
rbvmomi-1.11.6 examples/create_vm-1.9.rb
rbvmomi-1.11.5 examples/create_vm-1.9.rb
rbvmomi-1.11.4 examples/create_vm-1.9.rb
rbvmomi-1.11.3 examples/create_vm-1.9.rb
rbvmomi-1.11.2 examples/create_vm-1.9.rb
rbvmomi-1.11.1 examples/create_vm-1.9.rb
rbvmomi-1.11.0 examples/create_vm-1.9.rb
rbvmomi-1.10.0 examples/create_vm-1.9.rb
rbvmomi-1.9.5 examples/create_vm-1.9.rb