rbvmomi 1.11.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +2 -2
- data/exe/rbvmomish +5 -5
- data/lib/rbvmomi/connection.rb +13 -13
- data/lib/rbvmomi/deserialization.rb +1 -2
- data/lib/rbvmomi/{trollop.rb → optimist.rb} +7 -7
- data/lib/rbvmomi/pbm.rb +1 -1
- data/lib/rbvmomi/sms.rb +1 -1
- data/lib/rbvmomi/sso.rb +313 -0
- data/lib/rbvmomi/trivial_soap.rb +8 -5
- data/lib/rbvmomi/type_loader.rb +1 -1
- data/lib/rbvmomi/utils/deploy.rb +1 -1
- data/lib/rbvmomi/version.rb +2 -2
- data/lib/rbvmomi/vim/Folder.rb +1 -1
- data/lib/rbvmomi/vim/HostSystem.rb +2 -2
- data/lib/rbvmomi/vim/ManagedObject.rb +1 -1
- data/lib/rbvmomi/vim/OvfManager.rb +1 -1
- data/lib/rbvmomi/vim/VirtualMachine.rb +9 -11
- data/lib/rbvmomi/vim.rb +9 -10
- data/lib/rbvmomi.rb +11 -9
- data/vmodl.db +0 -0
- metadata +45 -61
- data/.gitignore +0 -13
- data/.travis.yml +0 -11
- data/.yardopts +0 -6
- data/CONTRIBUTORS.md +0 -42
- data/Gemfile +0 -10
- data/Rakefile +0 -16
- data/devel/analyze-vim-declarations.rb +0 -217
- data/devel/analyze-xml.rb +0 -49
- data/devel/benchmark.rb +0 -121
- data/devel/collisions.rb +0 -22
- data/devel/merge-internal-vmodl.rb +0 -63
- data/devel/merge-manual-vmodl.rb +0 -36
- data/examples/annotate.rb +0 -57
- data/examples/cached_ovf_deploy.rb +0 -124
- data/examples/clone_vm.rb +0 -88
- data/examples/create_vm-1.9.rb +0 -97
- data/examples/create_vm.rb +0 -97
- data/examples/extraConfig.rb +0 -57
- data/examples/lease_tool.rb +0 -106
- data/examples/logbundle.rb +0 -66
- data/examples/logtail.rb +0 -63
- data/examples/nfs_datastore.rb +0 -99
- data/examples/power.rb +0 -62
- data/examples/readme-1.rb +0 -38
- data/examples/readme-2.rb +0 -54
- data/examples/run.sh +0 -41
- data/examples/screenshot.rb +0 -51
- data/examples/vdf.rb +0 -84
- data/examples/vm_drs_behavior.rb +0 -80
- data/rbvmomi.gemspec +0 -33
    
        data/examples/clone_vm.rb
    DELETED
    
    | @@ -1,88 +0,0 @@ | |
| 1 | 
            -
            #!/usr/bin/env ruby
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            # Copyright (c) 2011-2017 VMware, Inc.  All Rights Reserved.
         | 
| 4 | 
            -
            # SPDX-License-Identifier: MIT
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            require 'trollop'
         | 
| 7 | 
            -
            require 'rbvmomi'
         | 
| 8 | 
            -
            require 'rbvmomi/trollop'
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            VIM = RbVmomi::VIM
         | 
| 11 | 
            -
             | 
| 12 | 
            -
            opts = Trollop.options do
         | 
| 13 | 
            -
              banner <<-EOS
         | 
| 14 | 
            -
            Clone a VM.
         | 
| 15 | 
            -
             | 
| 16 | 
            -
            Usage:
         | 
| 17 | 
            -
                clone_vm.rb [options] source_vm dest_vm
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            VIM connection options:
         | 
| 20 | 
            -
                EOS
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                rbvmomi_connection_opts
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                text <<-EOS
         | 
| 25 | 
            -
             | 
| 26 | 
            -
            VM location options:
         | 
| 27 | 
            -
                EOS
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                rbvmomi_datacenter_opt
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                text <<-EOS
         | 
| 32 | 
            -
             | 
| 33 | 
            -
            Other options:
         | 
| 34 | 
            -
              EOS
         | 
| 35 | 
            -
             | 
| 36 | 
            -
              opt :linked_clone, "Use a linked clone instead of a full clone"
         | 
| 37 | 
            -
            end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
            Trollop.die("must specify host") unless opts[:host]
         | 
| 40 | 
            -
            ARGV.size == 2 or abort "must specify VM source name and VM target name"
         | 
| 41 | 
            -
            vm_source = ARGV[0]
         | 
| 42 | 
            -
            vm_target = ARGV[1]
         | 
| 43 | 
            -
             | 
| 44 | 
            -
            vim = VIM.connect opts
         | 
| 45 | 
            -
            dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
         | 
| 46 | 
            -
            vm = dc.find_vm(vm_source) or abort "VM not found"
         | 
| 47 | 
            -
             | 
| 48 | 
            -
            if opts[:linked_clone]
         | 
| 49 | 
            -
              # The API for linked clones is quite strange. We can't create a linked
         | 
| 50 | 
            -
              # straight from any VM. The disks of the VM for which we can create a
         | 
| 51 | 
            -
              # linked clone need to be read-only and thus VC demands that the VM we
         | 
| 52 | 
            -
              # are cloning from uses delta-disks. Only then it will allow us to
         | 
| 53 | 
            -
              # share the base disk.
         | 
| 54 | 
            -
              #
         | 
| 55 | 
            -
              # Thus, this code first create a delta disk on top of the base disk for
         | 
| 56 | 
            -
              # the to-be-cloned VM, if delta disks aren't used already.
         | 
| 57 | 
            -
              disks = vm.config.hardware.device.grep(VIM::VirtualDisk)
         | 
| 58 | 
            -
              disks.select { |x| x.backing.parent == nil }.each do |disk|
         | 
| 59 | 
            -
                spec = {
         | 
| 60 | 
            -
                  :deviceChange => [
         | 
| 61 | 
            -
                    {
         | 
| 62 | 
            -
                      :operation => :remove,
         | 
| 63 | 
            -
                      :device => disk
         | 
| 64 | 
            -
                    },
         | 
| 65 | 
            -
                    {
         | 
| 66 | 
            -
                      :operation => :add,
         | 
| 67 | 
            -
                      :fileOperation => :create,
         | 
| 68 | 
            -
                      :device => disk.dup.tap { |x|
         | 
| 69 | 
            -
                        x.backing = x.backing.dup
         | 
| 70 | 
            -
                        x.backing.fileName = "[#{disk.backing.datastore.name}]"
         | 
| 71 | 
            -
                        x.backing.parent = disk.backing
         | 
| 72 | 
            -
                      },
         | 
| 73 | 
            -
                    }
         | 
| 74 | 
            -
                  ]
         | 
| 75 | 
            -
                }
         | 
| 76 | 
            -
                vm.ReconfigVM_Task(:spec => spec).wait_for_completion
         | 
| 77 | 
            -
              end
         | 
| 78 | 
            -
             | 
| 79 | 
            -
              relocateSpec = VIM.VirtualMachineRelocateSpec(:diskMoveType => :moveChildMostDiskBacking)
         | 
| 80 | 
            -
            else
         | 
| 81 | 
            -
              relocateSpec = VIM.VirtualMachineRelocateSpec
         | 
| 82 | 
            -
            end
         | 
| 83 | 
            -
             | 
| 84 | 
            -
            spec = VIM.VirtualMachineCloneSpec(:location => relocateSpec,
         | 
| 85 | 
            -
                                               :powerOn => false,
         | 
| 86 | 
            -
                                               :template => false)
         | 
| 87 | 
            -
             | 
| 88 | 
            -
            vm.CloneVM_Task(:folder => vm.parent, :name => vm_target, :spec => spec).wait_for_completion
         | 
    
        data/examples/create_vm-1.9.rb
    DELETED
    
    | @@ -1,97 +0,0 @@ | |
| 1 | 
            -
            #!/usr/bin/env ruby
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            # Copyright (c) 2011-2017 VMware, Inc.  All Rights Reserved.
         | 
| 4 | 
            -
            # SPDX-License-Identifier: MIT
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            require 'trollop'
         | 
| 7 | 
            -
            require 'rbvmomi'
         | 
| 8 | 
            -
            require 'rbvmomi/trollop'
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            VIM = RbVmomi::VIM
         | 
| 11 | 
            -
             | 
| 12 | 
            -
            opts = Trollop.options do
         | 
| 13 | 
            -
              banner <<-EOS
         | 
| 14 | 
            -
            Create a VM.
         | 
| 15 | 
            -
             | 
| 16 | 
            -
            Usage:
         | 
| 17 | 
            -
                create_vm-1.9.rb [options]
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            VIM connection options:
         | 
| 20 | 
            -
                EOS
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                rbvmomi_connection_opts
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                text <<-EOS
         | 
| 25 | 
            -
             | 
| 26 | 
            -
            VM location options:
         | 
| 27 | 
            -
                EOS
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                rbvmomi_datacenter_opt
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                text <<-EOS
         | 
| 32 | 
            -
             | 
| 33 | 
            -
            Other options:
         | 
| 34 | 
            -
              EOS
         | 
| 35 | 
            -
            end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
            Trollop.die("must specify host") unless opts[:host]
         | 
| 38 | 
            -
            vm_name = ARGV[0] or abort "must specify VM name"
         | 
| 39 | 
            -
             | 
| 40 | 
            -
            vim = VIM.connect opts
         | 
| 41 | 
            -
            dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
         | 
| 42 | 
            -
            vmFolder = dc.vmFolder
         | 
| 43 | 
            -
            hosts = dc.hostFolder.children
         | 
| 44 | 
            -
            rp = hosts.first.resourcePool
         | 
| 45 | 
            -
             | 
| 46 | 
            -
            vm_cfg = {
         | 
| 47 | 
            -
              name: vm_name,
         | 
| 48 | 
            -
              guestId: 'otherGuest',
         | 
| 49 | 
            -
              files: { vmPathName: '[datastore1]' },
         | 
| 50 | 
            -
              numCPUs: 1,
         | 
| 51 | 
            -
              memoryMB: 128,
         | 
| 52 | 
            -
              deviceChange: [
         | 
| 53 | 
            -
                {
         | 
| 54 | 
            -
                  operation: :add,
         | 
| 55 | 
            -
                  device: VIM.VirtualLsiLogicController(
         | 
| 56 | 
            -
                    key: 1000,
         | 
| 57 | 
            -
                    busNumber: 0,
         | 
| 58 | 
            -
                    sharedBus: :noSharing,
         | 
| 59 | 
            -
                  )
         | 
| 60 | 
            -
                }, {
         | 
| 61 | 
            -
                  operation: :add,
         | 
| 62 | 
            -
                  fileOperation: :create,
         | 
| 63 | 
            -
                  device: VIM.VirtualDisk(
         | 
| 64 | 
            -
                    key: 0,
         | 
| 65 | 
            -
                    backing: VIM.VirtualDiskFlatVer2BackingInfo(
         | 
| 66 | 
            -
                      fileName: '[datastore1]',
         | 
| 67 | 
            -
                      diskMode: :persistent,
         | 
| 68 | 
            -
                      thinProvisioned: true,
         | 
| 69 | 
            -
                    ),
         | 
| 70 | 
            -
                    controllerKey: 1000,
         | 
| 71 | 
            -
                    unitNumber: 0,
         | 
| 72 | 
            -
                    capacityInKB: 4000000,
         | 
| 73 | 
            -
                  )
         | 
| 74 | 
            -
                }, {
         | 
| 75 | 
            -
                  operation: :add,
         | 
| 76 | 
            -
                  device: VIM.VirtualE1000(
         | 
| 77 | 
            -
                    key: 0,
         | 
| 78 | 
            -
                    deviceInfo: {
         | 
| 79 | 
            -
                      label: 'Network Adapter 1',
         | 
| 80 | 
            -
                      summary: 'VM Network',
         | 
| 81 | 
            -
                    },
         | 
| 82 | 
            -
                    backing: VIM.VirtualEthernetCardNetworkBackingInfo(
         | 
| 83 | 
            -
                      deviceName: 'VM Network',
         | 
| 84 | 
            -
                    ),
         | 
| 85 | 
            -
                    addressType: 'generated'
         | 
| 86 | 
            -
                  )
         | 
| 87 | 
            -
                }
         | 
| 88 | 
            -
              ],
         | 
| 89 | 
            -
              extraConfig: [
         | 
| 90 | 
            -
                {
         | 
| 91 | 
            -
                  key: 'bios.bootOrder',
         | 
| 92 | 
            -
                  value: 'ethernet0'
         | 
| 93 | 
            -
                }
         | 
| 94 | 
            -
              ]
         | 
| 95 | 
            -
            }
         | 
| 96 | 
            -
             | 
| 97 | 
            -
            vmFolder.CreateVM_Task(:config => vm_cfg, :pool => rp).wait_for_completion
         | 
    
        data/examples/create_vm.rb
    DELETED
    
    | @@ -1,97 +0,0 @@ | |
| 1 | 
            -
            #!/usr/bin/env ruby
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            # Copyright (c) 2011-2017 VMware, Inc.  All Rights Reserved.
         | 
| 4 | 
            -
            # SPDX-License-Identifier: MIT
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            require 'trollop'
         | 
| 7 | 
            -
            require 'rbvmomi'
         | 
| 8 | 
            -
            require 'rbvmomi/trollop'
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            VIM = RbVmomi::VIM
         | 
| 11 | 
            -
             | 
| 12 | 
            -
            opts = Trollop.options do
         | 
| 13 | 
            -
              banner <<-EOS
         | 
| 14 | 
            -
            Create a VM.
         | 
| 15 | 
            -
             | 
| 16 | 
            -
            Usage:
         | 
| 17 | 
            -
                create_vm.rb [options]
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            VIM connection options:
         | 
| 20 | 
            -
                EOS
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                rbvmomi_connection_opts
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                text <<-EOS
         | 
| 25 | 
            -
             | 
| 26 | 
            -
            VM location options:
         | 
| 27 | 
            -
                EOS
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                rbvmomi_datacenter_opt
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                text <<-EOS
         | 
| 32 | 
            -
             | 
| 33 | 
            -
            Other options:
         | 
| 34 | 
            -
              EOS
         | 
| 35 | 
            -
            end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
            Trollop.die("must specify host") unless opts[:host]
         | 
| 38 | 
            -
            vm_name = ARGV[0] or abort "must specify VM name"
         | 
| 39 | 
            -
             | 
| 40 | 
            -
            vim = VIM.connect opts
         | 
| 41 | 
            -
            dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
         | 
| 42 | 
            -
            vmFolder = dc.vmFolder
         | 
| 43 | 
            -
            hosts = dc.hostFolder.children
         | 
| 44 | 
            -
            rp = hosts.first.resourcePool
         | 
| 45 | 
            -
             | 
| 46 | 
            -
            vm_cfg = {
         | 
| 47 | 
            -
              :name => vm_name,
         | 
| 48 | 
            -
              :guestId => 'otherGuest',
         | 
| 49 | 
            -
              :files => { :vmPathName => '[datastore1]' },
         | 
| 50 | 
            -
              :numCPUs => 1,
         | 
| 51 | 
            -
              :memoryMB => 128,
         | 
| 52 | 
            -
              :deviceChange => [
         | 
| 53 | 
            -
                {
         | 
| 54 | 
            -
                  :operation => :add,
         | 
| 55 | 
            -
                  :device => VIM.VirtualLsiLogicController(
         | 
| 56 | 
            -
                    :key => 1000,
         | 
| 57 | 
            -
                    :busNumber => 0,
         | 
| 58 | 
            -
                    :sharedBus => :noSharing
         | 
| 59 | 
            -
                  )
         | 
| 60 | 
            -
                }, {
         | 
| 61 | 
            -
                  :operation => :add,
         | 
| 62 | 
            -
                  :fileOperation => :create,
         | 
| 63 | 
            -
                  :device => VIM.VirtualDisk(
         | 
| 64 | 
            -
                    :key => 0,
         | 
| 65 | 
            -
                    :backing => VIM.VirtualDiskFlatVer2BackingInfo(
         | 
| 66 | 
            -
                      :fileName => '[datastore1]',
         | 
| 67 | 
            -
                      :diskMode => :persistent,
         | 
| 68 | 
            -
                      :thinProvisioned => true
         | 
| 69 | 
            -
                    ),
         | 
| 70 | 
            -
                    :controllerKey => 1000,
         | 
| 71 | 
            -
                    :unitNumber => 0,
         | 
| 72 | 
            -
                    :capacityInKB => 4000000
         | 
| 73 | 
            -
                  )
         | 
| 74 | 
            -
                }, {
         | 
| 75 | 
            -
                  :operation => :add,
         | 
| 76 | 
            -
                  :device => VIM.VirtualE1000(
         | 
| 77 | 
            -
                    :key => 0,
         | 
| 78 | 
            -
                    :deviceInfo => {
         | 
| 79 | 
            -
                      :label => 'Network Adapter 1',
         | 
| 80 | 
            -
                      :summary => 'VM Network'
         | 
| 81 | 
            -
                    },
         | 
| 82 | 
            -
                    :backing => VIM.VirtualEthernetCardNetworkBackingInfo(
         | 
| 83 | 
            -
                      :deviceName => 'VM Network'
         | 
| 84 | 
            -
                    ),
         | 
| 85 | 
            -
                    :addressType => 'generated'
         | 
| 86 | 
            -
                  )
         | 
| 87 | 
            -
                }
         | 
| 88 | 
            -
              ],
         | 
| 89 | 
            -
              :extraConfig => [
         | 
| 90 | 
            -
                {
         | 
| 91 | 
            -
                  :key => 'bios.bootOrder',
         | 
| 92 | 
            -
                  :value => 'ethernet0'
         | 
| 93 | 
            -
                }
         | 
| 94 | 
            -
              ]
         | 
| 95 | 
            -
            }
         | 
| 96 | 
            -
             | 
| 97 | 
            -
            vmFolder.CreateVM_Task(:config => vm_cfg, :pool => rp).wait_for_completion
         | 
    
        data/examples/extraConfig.rb
    DELETED
    
    | @@ -1,57 +0,0 @@ | |
| 1 | 
            -
            # Copyright (c) 2011-2017 VMware, Inc.  All Rights Reserved.
         | 
| 2 | 
            -
            # SPDX-License-Identifier: MIT
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            require 'trollop'
         | 
| 5 | 
            -
            require 'rbvmomi'
         | 
| 6 | 
            -
            require 'rbvmomi/trollop'
         | 
| 7 | 
            -
             | 
| 8 | 
            -
            VIM = RbVmomi::VIM
         | 
| 9 | 
            -
            CMDS = %w(list set)
         | 
| 10 | 
            -
             | 
| 11 | 
            -
            opts = Trollop.options do
         | 
| 12 | 
            -
              banner <<-EOS
         | 
| 13 | 
            -
            View and modify VM extraConfig options.
         | 
| 14 | 
            -
             | 
| 15 | 
            -
            Usage:
         | 
| 16 | 
            -
                extraConfig.rb [options] VM list
         | 
| 17 | 
            -
                extraConfig.rb [options] VM set key=value [key=value...]
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            Commands: #{CMDS * ' '}
         | 
| 20 | 
            -
             | 
| 21 | 
            -
            VIM connection options:
         | 
| 22 | 
            -
                EOS
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                rbvmomi_connection_opts
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                text <<-EOS
         | 
| 27 | 
            -
             | 
| 28 | 
            -
            VM location options:
         | 
| 29 | 
            -
                EOS
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                rbvmomi_datacenter_opt
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                text <<-EOS
         | 
| 34 | 
            -
             | 
| 35 | 
            -
            Other options:
         | 
| 36 | 
            -
              EOS
         | 
| 37 | 
            -
             | 
| 38 | 
            -
              stop_on CMDS
         | 
| 39 | 
            -
            end
         | 
| 40 | 
            -
             | 
| 41 | 
            -
            vm_name = ARGV[0] or Trollop.die("no VM name given")
         | 
| 42 | 
            -
            cmd = ARGV[1] or Trollop.die("no command given")
         | 
| 43 | 
            -
            abort "invalid command" unless CMDS.member? cmd
         | 
| 44 | 
            -
            Trollop.die("must specify host") unless opts[:host]
         | 
| 45 | 
            -
             | 
| 46 | 
            -
            vim = VIM.connect opts
         | 
| 47 | 
            -
             | 
| 48 | 
            -
            dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
         | 
| 49 | 
            -
            vm = dc.find_vm(vm_name) or abort "VM not found"
         | 
| 50 | 
            -
             | 
| 51 | 
            -
            case cmd
         | 
| 52 | 
            -
            when 'list'
         | 
| 53 | 
            -
              vm.config.extraConfig.each { |x| puts "#{x.key}: #{x.value}" }
         | 
| 54 | 
            -
            when 'set'
         | 
| 55 | 
            -
              extraConfig = ARGV[2..-1].map { |x| x.split("=", 2) }.map { |k,v| { :key => k, :value => v } }
         | 
| 56 | 
            -
              vm.ReconfigVM_Task(:spec => VIM.VirtualMachineConfigSpec(:extraConfig => extraConfig)).wait_for_completion
         | 
| 57 | 
            -
            end
         | 
    
        data/examples/lease_tool.rb
    DELETED
    
    | @@ -1,106 +0,0 @@ | |
| 1 | 
            -
            #!/usr/bin/env ruby
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            # Copyright (c) 2012-2017 VMware, Inc.  All Rights Reserved.
         | 
| 4 | 
            -
            # SPDX-License-Identifier: MIT
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            require 'trollop'
         | 
| 7 | 
            -
            require 'rbvmomi'
         | 
| 8 | 
            -
            require 'rbvmomi/trollop'
         | 
| 9 | 
            -
            require 'rbvmomi/utils/leases'
         | 
| 10 | 
            -
            require 'yaml'
         | 
| 11 | 
            -
             | 
| 12 | 
            -
            VIM = RbVmomi::VIM
         | 
| 13 | 
            -
            CMDS = ['set_lease_on_leaseless_vms', 'show_expired_vms', 
         | 
| 14 | 
            -
                    'show_soon_expired_vms', 'kill_expired_vms']
         | 
| 15 | 
            -
             | 
| 16 | 
            -
            opts = Trollop.options do
         | 
| 17 | 
            -
              banner <<-EOS
         | 
| 18 | 
            -
            Tool for managing leases on VMs where leases are stored in YAML on VM annotations.
         | 
| 19 | 
            -
             | 
| 20 | 
            -
            Usage:
         | 
| 21 | 
            -
                lease_tool.rb [options] <cmd>
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            Commands: #{CMDS * ' '}
         | 
| 24 | 
            -
             | 
| 25 | 
            -
            VIM connection options:
         | 
| 26 | 
            -
                EOS
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                rbvmomi_connection_opts
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                text <<-EOS
         | 
| 31 | 
            -
             | 
| 32 | 
            -
            VM location options:
         | 
| 33 | 
            -
                EOS
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                rbvmomi_datacenter_opt
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                text <<-EOS
         | 
| 38 | 
            -
             | 
| 39 | 
            -
            Other options:
         | 
| 40 | 
            -
              EOS
         | 
| 41 | 
            -
             | 
| 42 | 
            -
              opt :vm_folder_path, "Path to VM folder to deploy VM into", :type => :string
         | 
| 43 | 
            -
              opt :force, "Really perform VMs. Used with kill_expired_vms"
         | 
| 44 | 
            -
             | 
| 45 | 
            -
              stop_on CMDS
         | 
| 46 | 
            -
            end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
            Trollop.die("must specify host") unless opts[:host]
         | 
| 49 | 
            -
            cmd = ARGV[0] or Trollop.die("no command given")
         | 
| 50 | 
            -
            Trollop.die("no vm folder path given") unless opts[:vm_folder_path]
         | 
| 51 | 
            -
             | 
| 52 | 
            -
            vim = VIM.connect opts
         | 
| 53 | 
            -
            dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
         | 
| 54 | 
            -
             | 
| 55 | 
            -
            root_vm_folder = dc.vmFolder
         | 
| 56 | 
            -
            vm_folder = root_vm_folder.traverse(opts[:vm_folder_path], VIM::Folder)
         | 
| 57 | 
            -
             | 
| 58 | 
            -
            lease_tool = LeaseTool.new
         | 
| 59 | 
            -
            vms_props_list = (['runtime.powerState'] + lease_tool.vms_props_list).uniq
         | 
| 60 | 
            -
            inventory = vm_folder.inventory_flat('VirtualMachine' => vms_props_list) 
         | 
| 61 | 
            -
            inventory = inventory.select{|obj, props| obj.is_a?(VIM::VirtualMachine)}
         | 
| 62 | 
            -
            case cmd
         | 
| 63 | 
            -
            when 'set_lease_on_leaseless_vms'
         | 
| 64 | 
            -
              lease_tool.set_lease_on_leaseless_vms(
         | 
| 65 | 
            -
                inventory.keys, inventory,
         | 
| 66 | 
            -
                :lease_minutes => 3 * 24 * 60 * 60 # 3 days
         | 
| 67 | 
            -
              )
         | 
| 68 | 
            -
            when 'show_expired_vms'
         | 
| 69 | 
            -
              vms = lease_tool.filter_expired_vms inventory.keys, inventory
         | 
| 70 | 
            -
              vms.each do |vm, time_to_expiration|
         | 
| 71 | 
            -
                puts "VM '#{inventory[vm]['name']}' is expired"
         | 
| 72 | 
            -
              end  
         | 
| 73 | 
            -
            when 'kill_expired_vms'
         | 
| 74 | 
            -
              vms = lease_tool.filter_expired_vms inventory.keys, inventory
         | 
| 75 | 
            -
              vms.each do |vm, time_to_expiration|
         | 
| 76 | 
            -
                puts "VM '#{inventory[vm]['name']}' is expired"
         | 
| 77 | 
            -
                if !opts[:force]
         | 
| 78 | 
            -
                  puts "NOT killing VM '#{inventory[vm]['name']}' because --force not set"
         | 
| 79 | 
            -
                else
         | 
| 80 | 
            -
                  puts "Killing expired VM '#{inventory[vm]['name']}'"
         | 
| 81 | 
            -
                  # Destroying VMs is very stressful for vCenter, and we aren't in a rush
         | 
| 82 | 
            -
                  # so do one VM at a time
         | 
| 83 | 
            -
                  if inventory[vm]['runtime.powerState'] == 'poweredOn'
         | 
| 84 | 
            -
                    vm.PowerOffVM_Task.wait_for_completion
         | 
| 85 | 
            -
                  end
         | 
| 86 | 
            -
                  vm.Destroy_Task.wait_for_completion
         | 
| 87 | 
            -
                end
         | 
| 88 | 
            -
              end  
         | 
| 89 | 
            -
            when 'show_soon_expired_vms'
         | 
| 90 | 
            -
              vms = lease_tool.filter_expired_vms(
         | 
| 91 | 
            -
                inventory.keys, inventory, 
         | 
| 92 | 
            -
                :time_delta => 3.5 * 24 * 60 * 60, # 3.5 days 
         | 
| 93 | 
            -
              )
         | 
| 94 | 
            -
              # We could send the user emails here, but for this example, just print the
         | 
| 95 | 
            -
              # VMs that will expire within the next 3.5 days
         | 
| 96 | 
            -
              vms.each do |vm, time_to_expiration|
         | 
| 97 | 
            -
                if time_to_expiration > 0
         | 
| 98 | 
            -
                  hours_to_expiration = time_to_expiration / (60.0 * 60.0) 
         | 
| 99 | 
            -
                  puts "VM '%s' expires in %.2fh" % [inventory[vm]['name'], hours_to_expiration]
         | 
| 100 | 
            -
                else
         | 
| 101 | 
            -
                  puts "VM '#{inventory[vm]['name']}' is expired"
         | 
| 102 | 
            -
                end
         | 
| 103 | 
            -
              end  
         | 
| 104 | 
            -
            else
         | 
| 105 | 
            -
              abort "invalid command"
         | 
| 106 | 
            -
            end
         | 
    
        data/examples/logbundle.rb
    DELETED
    
    | @@ -1,66 +0,0 @@ | |
| 1 | 
            -
            # Copyright (c) 2011-2017 VMware, Inc.  All Rights Reserved.
         | 
| 2 | 
            -
            # SPDX-License-Identifier: MIT
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            # @todo Retrieve ESX log bundles when run against VC.
         | 
| 5 | 
            -
            require 'trollop'
         | 
| 6 | 
            -
            require 'rbvmomi'
         | 
| 7 | 
            -
            require 'rbvmomi/trollop'
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            VIM = RbVmomi::VIM
         | 
| 10 | 
            -
            DEFAULT_SERVER_PLACEHOLDER = '0.0.0.0'
         | 
| 11 | 
            -
             | 
| 12 | 
            -
            opts = Trollop.options do
         | 
| 13 | 
            -
              banner <<-EOS
         | 
| 14 | 
            -
            Generate and retrieve a log bundle.
         | 
| 15 | 
            -
             | 
| 16 | 
            -
            Usage:
         | 
| 17 | 
            -
                logbundle.rb [options] dest
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            dest must be a directory.
         | 
| 20 | 
            -
             | 
| 21 | 
            -
            VIM connection options:
         | 
| 22 | 
            -
                EOS
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                rbvmomi_connection_opts
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                text <<-EOS
         | 
| 27 | 
            -
             | 
| 28 | 
            -
            Other options:
         | 
| 29 | 
            -
              EOS
         | 
| 30 | 
            -
            end
         | 
| 31 | 
            -
             | 
| 32 | 
            -
            Trollop.die("must specify host") unless opts[:host]
         | 
| 33 | 
            -
            dest = ARGV[0] or abort("must specify destination directory")
         | 
| 34 | 
            -
             | 
| 35 | 
            -
            abort "destination is not a directory" unless File.directory? dest
         | 
| 36 | 
            -
             | 
| 37 | 
            -
            vim = VIM.connect opts
         | 
| 38 | 
            -
            is_vc = vim.serviceContent.about.apiType == 'VirtualCenter'
         | 
| 39 | 
            -
            diagMgr = vim.serviceContent.diagnosticManager
         | 
| 40 | 
            -
             | 
| 41 | 
            -
            bundles =
         | 
| 42 | 
            -
              begin
         | 
| 43 | 
            -
                diagMgr.GenerateLogBundles_Task(includeDefault: true).wait_for_completion
         | 
| 44 | 
            -
              rescue VIM::TaskInProgress
         | 
| 45 | 
            -
                $!.task.wait_for_completion
         | 
| 46 | 
            -
              end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
            bundles.each do |b|
         | 
| 49 | 
            -
              uri = URI.parse(b.url.sub('*', DEFAULT_SERVER_PLACEHOLDER))
         | 
| 50 | 
            -
              dest_path = File.join(dest, File.basename(uri.path))
         | 
| 51 | 
            -
              puts "downloading bundle #{b.url} to #{dest_path}"
         | 
| 52 | 
            -
              if uri.host == DEFAULT_SERVER_PLACEHOLDER
         | 
| 53 | 
            -
                vim.http.request_get(uri.path) do |res|
         | 
| 54 | 
            -
                  File.open dest_path, 'w' do |io|
         | 
| 55 | 
            -
                    res.read_body do |data|
         | 
| 56 | 
            -
                      io.write data
         | 
| 57 | 
            -
                      $stdout.write '.'
         | 
| 58 | 
            -
                      $stdout.flush
         | 
| 59 | 
            -
                    end
         | 
| 60 | 
            -
                  end
         | 
| 61 | 
            -
                  puts
         | 
| 62 | 
            -
                end
         | 
| 63 | 
            -
              else
         | 
| 64 | 
            -
                puts 'not supported yet'
         | 
| 65 | 
            -
              end
         | 
| 66 | 
            -
            end
         | 
    
        data/examples/logtail.rb
    DELETED
    
    | @@ -1,63 +0,0 @@ | |
| 1 | 
            -
            # Copyright (c) 2011-2017 VMware, Inc.  All Rights Reserved.
         | 
| 2 | 
            -
            # SPDX-License-Identifier: MIT
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            # Translation of example 2-2 from the vSphere SDK for Perl Programming Guide
         | 
| 5 | 
            -
            require 'trollop'
         | 
| 6 | 
            -
            require 'rbvmomi'
         | 
| 7 | 
            -
            require 'rbvmomi/trollop'
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            VIM = RbVmomi::VIM
         | 
| 10 | 
            -
             | 
| 11 | 
            -
            opts = Trollop.options do
         | 
| 12 | 
            -
              banner <<-EOS
         | 
| 13 | 
            -
            Follow a log file.
         | 
| 14 | 
            -
             | 
| 15 | 
            -
            Usage:
         | 
| 16 | 
            -
                logtail.rb [options] [logKey]
         | 
| 17 | 
            -
             | 
| 18 | 
            -
            If logKey is not provided the list of available log keys will be printed and
         | 
| 19 | 
            -
            the program will exit.
         | 
| 20 | 
            -
             | 
| 21 | 
            -
            VIM connection options:
         | 
| 22 | 
            -
                EOS
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                rbvmomi_connection_opts
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                text <<-EOS
         | 
| 27 | 
            -
             | 
| 28 | 
            -
            Other options:
         | 
| 29 | 
            -
              EOS
         | 
| 30 | 
            -
            end
         | 
| 31 | 
            -
             | 
| 32 | 
            -
            Trollop.die("must specify host") unless opts[:host]
         | 
| 33 | 
            -
            logKey = ARGV[0]
         | 
| 34 | 
            -
             | 
| 35 | 
            -
            vim = VIM.connect opts
         | 
| 36 | 
            -
            diagMgr = vim.serviceContent.diagnosticManager
         | 
| 37 | 
            -
             | 
| 38 | 
            -
            if not logKey
         | 
| 39 | 
            -
              puts "Available logs:"
         | 
| 40 | 
            -
              diagMgr.QueryDescriptions.each do |desc|
         | 
| 41 | 
            -
                puts "#{desc.key}: #{desc.info.label}"
         | 
| 42 | 
            -
              end
         | 
| 43 | 
            -
              exit 0
         | 
| 44 | 
            -
            end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
            # Obtain the last line of the logfile by setting an arbitrarily large
         | 
| 47 | 
            -
            # line number as the starting point
         | 
| 48 | 
            -
            log = diagMgr.BrowseDiagnosticLog(key: logKey, start: 999999999)
         | 
| 49 | 
            -
            lineEnd = log.lineEnd
         | 
| 50 | 
            -
             | 
| 51 | 
            -
            # Get the last 5 lines of the log first, and then check every 2 seconds
         | 
| 52 | 
            -
            # to see if the log size has increased.
         | 
| 53 | 
            -
            start = lineEnd - 5
         | 
| 54 | 
            -
            while true
         | 
| 55 | 
            -
              log = diagMgr.BrowseDiagnosticLog(key: logKey, start: start)
         | 
| 56 | 
            -
              if log.lineStart != 0
         | 
| 57 | 
            -
                log.lineText.each do |l|
         | 
| 58 | 
            -
                  puts l
         | 
| 59 | 
            -
                end
         | 
| 60 | 
            -
              end
         | 
| 61 | 
            -
              start = log.lineEnd + 1
         | 
| 62 | 
            -
              sleep 2
         | 
| 63 | 
            -
            end
         | 
    
        data/examples/nfs_datastore.rb
    DELETED
    
    | @@ -1,99 +0,0 @@ | |
| 1 | 
            -
            #!/usr/bin/env ruby
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            # Copyright (c) 2011-2017 VMware, Inc.  All Rights Reserved.
         | 
| 4 | 
            -
            # SPDX-License-Identifier: MIT
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            require 'trollop'
         | 
| 7 | 
            -
            require 'rbvmomi'
         | 
| 8 | 
            -
            require 'rbvmomi/trollop'
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            VIM = RbVmomi::VIM
         | 
| 11 | 
            -
            CMDS = %w(mount unmount)
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            opts = Trollop.options do
         | 
| 14 | 
            -
              banner <<-EOS
         | 
| 15 | 
            -
            Mount/Unmount an NFS datastore from a cluster or single host system.
         | 
| 16 | 
            -
             | 
| 17 | 
            -
            Usage:
         | 
| 18 | 
            -
                nfs_datastore.rb [options] resource mount nfs-hostname:/remote/path [name]
         | 
| 19 | 
            -
                nfs_datastore.rb [options] resource unmount nfs-hostname:/remote/path [name]
         | 
| 20 | 
            -
             | 
| 21 | 
            -
            Commands: #{CMDS * ' '}
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            VIM connection options:
         | 
| 24 | 
            -
                EOS
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                rbvmomi_connection_opts
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                text <<-EOS
         | 
| 29 | 
            -
             | 
| 30 | 
            -
            VM location options:
         | 
| 31 | 
            -
                EOS
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                rbvmomi_datacenter_opt
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                text <<-EOS
         | 
| 36 | 
            -
             | 
| 37 | 
            -
            Other options:
         | 
| 38 | 
            -
              EOS
         | 
| 39 | 
            -
             | 
| 40 | 
            -
              stop_on CMDS
         | 
| 41 | 
            -
            end
         | 
| 42 | 
            -
             | 
| 43 | 
            -
            Trollop.die("must specify host") unless opts[:host]
         | 
| 44 | 
            -
             | 
| 45 | 
            -
            cr_path = ARGV[0] or Trollop.die("no system name given")
         | 
| 46 | 
            -
            cmd = ARGV[1] or Trollop.die("no command given")
         | 
| 47 | 
            -
            abort "invalid command" unless CMDS.member? cmd
         | 
| 48 | 
            -
            nfs_spec = ARGV[2] or Trollop.die("no nfs path given")
         | 
| 49 | 
            -
            remoteHost, remotePath = nfs_spec.split(":")
         | 
| 50 | 
            -
            localPath = ARGV[3] || remoteHost
         | 
| 51 | 
            -
            mode = "readOnly" #hardcoded.
         | 
| 52 | 
            -
             | 
| 53 | 
            -
            vim = VIM.connect opts
         | 
| 54 | 
            -
            dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
         | 
| 55 | 
            -
            cr = dc.find_compute_resource(cr_path) || dc.hostFolder.children.find(cr_path).first
         | 
| 56 | 
            -
            abort "compute resource not found" unless cr
         | 
| 57 | 
            -
             | 
| 58 | 
            -
            case cr
         | 
| 59 | 
            -
            when VIM::ClusterComputeResource
         | 
| 60 | 
            -
              hosts = cr.host
         | 
| 61 | 
            -
            when VIM::ComputeResource
         | 
| 62 | 
            -
              hosts = [cr]
         | 
| 63 | 
            -
            else
         | 
| 64 | 
            -
              abort "invalid resource"
         | 
| 65 | 
            -
            end
         | 
| 66 | 
            -
             | 
| 67 | 
            -
            hosts.each do |host|
         | 
| 68 | 
            -
              hds = host.configManager.datastoreSystem
         | 
| 69 | 
            -
             | 
| 70 | 
            -
              ds = hds.datastore.select {|ds|
         | 
| 71 | 
            -
                ds.info.respond_to?(:nas) and
         | 
| 72 | 
            -
                ds.info.name == localPath and
         | 
| 73 | 
            -
                ds.info.nas.remoteHost == remoteHost and
         | 
| 74 | 
            -
                ds.info.nas.remotePath == remotePath
         | 
| 75 | 
            -
              }.first
         | 
| 76 | 
            -
             | 
| 77 | 
            -
              case cmd
         | 
| 78 | 
            -
              when 'mount'
         | 
| 79 | 
            -
                if ds
         | 
| 80 | 
            -
                  puts "already mounted on #{host.name} as #{ds.name}"
         | 
| 81 | 
            -
                else
         | 
| 82 | 
            -
                  ds =
         | 
| 83 | 
            -
                    hds.CreateNasDatastore(:spec => VIM.HostNasVolumeSpec(:remoteHost => remoteHost,
         | 
| 84 | 
            -
                                                                          :remotePath => remotePath,
         | 
| 85 | 
            -
                                                                          :localPath  => localPath,
         | 
| 86 | 
            -
                                                                          :accessMode => mode))
         | 
| 87 | 
            -
                  puts "mounted on #{host.name} as #{ds.name}"
         | 
| 88 | 
            -
                end
         | 
| 89 | 
            -
              when 'unmount'
         | 
| 90 | 
            -
                if ds
         | 
| 91 | 
            -
                  hds.RemoveDatastore(:datastore => ds)
         | 
| 92 | 
            -
                  puts "unmounted from #{host.name}"
         | 
| 93 | 
            -
                else
         | 
| 94 | 
            -
                  puts "not mounted on #{host.name}"
         | 
| 95 | 
            -
                end
         | 
| 96 | 
            -
              else
         | 
| 97 | 
            -
                abort "invalid command"
         | 
| 98 | 
            -
              end
         | 
| 99 | 
            -
            end
         |