fog-vsphere 0.1.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.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.travis.yml +32 -0
  4. data/CONTRIBUTING.md +18 -0
  5. data/CONTRIBUTORS.md +59 -0
  6. data/Gemfile +5 -0
  7. data/LICENSE.md +20 -0
  8. data/README.md +31 -0
  9. data/Rakefile +8 -0
  10. data/fog-vsphere.gemspec +32 -0
  11. data/gemfiles/Gemfile.1.9.2+ +8 -0
  12. data/gemfiles/Gemfile.1.9.2- +11 -0
  13. data/lib/fog/vsphere.rb +41 -0
  14. data/lib/fog/vsphere/compute.rb +473 -0
  15. data/lib/fog/vsphere/models/compute/cluster.rb +28 -0
  16. data/lib/fog/vsphere/models/compute/clusters.rb +22 -0
  17. data/lib/fog/vsphere/models/compute/customfield.rb +16 -0
  18. data/lib/fog/vsphere/models/compute/customfields.rb +23 -0
  19. data/lib/fog/vsphere/models/compute/customvalue.rb +14 -0
  20. data/lib/fog/vsphere/models/compute/customvalues.rb +33 -0
  21. data/lib/fog/vsphere/models/compute/datacenter.rb +44 -0
  22. data/lib/fog/vsphere/models/compute/datacenters.rb +19 -0
  23. data/lib/fog/vsphere/models/compute/datastore.rb +21 -0
  24. data/lib/fog/vsphere/models/compute/datastores.rb +21 -0
  25. data/lib/fog/vsphere/models/compute/folder.rb +24 -0
  26. data/lib/fog/vsphere/models/compute/folders.rb +23 -0
  27. data/lib/fog/vsphere/models/compute/interface.rb +91 -0
  28. data/lib/fog/vsphere/models/compute/interfaces.rb +66 -0
  29. data/lib/fog/vsphere/models/compute/interfacetype.rb +22 -0
  30. data/lib/fog/vsphere/models/compute/interfacetypes.rb +34 -0
  31. data/lib/fog/vsphere/models/compute/network.rb +18 -0
  32. data/lib/fog/vsphere/models/compute/networks.rb +22 -0
  33. data/lib/fog/vsphere/models/compute/process.rb +17 -0
  34. data/lib/fog/vsphere/models/compute/resource_pool.rb +19 -0
  35. data/lib/fog/vsphere/models/compute/resource_pools.rb +22 -0
  36. data/lib/fog/vsphere/models/compute/scsicontroller.rb +16 -0
  37. data/lib/fog/vsphere/models/compute/server.rb +325 -0
  38. data/lib/fog/vsphere/models/compute/servers.rb +36 -0
  39. data/lib/fog/vsphere/models/compute/servertype.rb +36 -0
  40. data/lib/fog/vsphere/models/compute/servertypes.rb +23 -0
  41. data/lib/fog/vsphere/models/compute/snapshot.rb +35 -0
  42. data/lib/fog/vsphere/models/compute/snapshots.rb +27 -0
  43. data/lib/fog/vsphere/models/compute/template.rb +11 -0
  44. data/lib/fog/vsphere/models/compute/templates.rb +19 -0
  45. data/lib/fog/vsphere/models/compute/volume.rb +99 -0
  46. data/lib/fog/vsphere/models/compute/volumes.rb +53 -0
  47. data/lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb +65 -0
  48. data/lib/fog/vsphere/requests/compute/create_folder.rb +22 -0
  49. data/lib/fog/vsphere/requests/compute/create_vm.rb +169 -0
  50. data/lib/fog/vsphere/requests/compute/current_time.rb +18 -0
  51. data/lib/fog/vsphere/requests/compute/get_cluster.rb +25 -0
  52. data/lib/fog/vsphere/requests/compute/get_compute_resource.rb +41 -0
  53. data/lib/fog/vsphere/requests/compute/get_datacenter.rb +31 -0
  54. data/lib/fog/vsphere/requests/compute/get_datastore.rb +30 -0
  55. data/lib/fog/vsphere/requests/compute/get_folder.rb +74 -0
  56. data/lib/fog/vsphere/requests/compute/get_interface_type.rb +15 -0
  57. data/lib/fog/vsphere/requests/compute/get_network.rb +59 -0
  58. data/lib/fog/vsphere/requests/compute/get_resource_pool.rb +26 -0
  59. data/lib/fog/vsphere/requests/compute/get_server_type.rb +32 -0
  60. data/lib/fog/vsphere/requests/compute/get_template.rb +16 -0
  61. data/lib/fog/vsphere/requests/compute/get_virtual_machine.rb +57 -0
  62. data/lib/fog/vsphere/requests/compute/get_vm_first_scsi_controller.rb +26 -0
  63. data/lib/fog/vsphere/requests/compute/list_child_snapshots.rb +71 -0
  64. data/lib/fog/vsphere/requests/compute/list_clusters.rb +72 -0
  65. data/lib/fog/vsphere/requests/compute/list_compute_resources.rb +92 -0
  66. data/lib/fog/vsphere/requests/compute/list_customfields.rb +21 -0
  67. data/lib/fog/vsphere/requests/compute/list_datacenters.rb +53 -0
  68. data/lib/fog/vsphere/requests/compute/list_datastores.rb +40 -0
  69. data/lib/fog/vsphere/requests/compute/list_folders.rb +44 -0
  70. data/lib/fog/vsphere/requests/compute/list_interface_types.rb +25 -0
  71. data/lib/fog/vsphere/requests/compute/list_networks.rb +38 -0
  72. data/lib/fog/vsphere/requests/compute/list_processes.rb +40 -0
  73. data/lib/fog/vsphere/requests/compute/list_resource_pools.rb +38 -0
  74. data/lib/fog/vsphere/requests/compute/list_server_types.rb +54 -0
  75. data/lib/fog/vsphere/requests/compute/list_templates.rb +48 -0
  76. data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +80 -0
  77. data/lib/fog/vsphere/requests/compute/list_vm_customvalues.rb +20 -0
  78. data/lib/fog/vsphere/requests/compute/list_vm_interfaces.rb +63 -0
  79. data/lib/fog/vsphere/requests/compute/list_vm_snapshots.rb +66 -0
  80. data/lib/fog/vsphere/requests/compute/list_vm_volumes.rb +52 -0
  81. data/lib/fog/vsphere/requests/compute/modify_vm_interface.rb +59 -0
  82. data/lib/fog/vsphere/requests/compute/modify_vm_volume.rb +25 -0
  83. data/lib/fog/vsphere/requests/compute/revert_to_snapshot.rb +30 -0
  84. data/lib/fog/vsphere/requests/compute/set_vm_customvalue.rb +17 -0
  85. data/lib/fog/vsphere/requests/compute/vm_clone.rb +727 -0
  86. data/lib/fog/vsphere/requests/compute/vm_config_vnc.rb +45 -0
  87. data/lib/fog/vsphere/requests/compute/vm_destroy.rb +23 -0
  88. data/lib/fog/vsphere/requests/compute/vm_execute.rb +47 -0
  89. data/lib/fog/vsphere/requests/compute/vm_migrate.rb +33 -0
  90. data/lib/fog/vsphere/requests/compute/vm_power_off.rb +39 -0
  91. data/lib/fog/vsphere/requests/compute/vm_power_on.rb +26 -0
  92. data/lib/fog/vsphere/requests/compute/vm_reboot.rb +31 -0
  93. data/lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb +23 -0
  94. data/lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb +24 -0
  95. data/lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb +23 -0
  96. data/lib/fog/vsphere/requests/compute/vm_take_snapshot.rb +37 -0
  97. data/lib/fog/vsphere/version.rb +5 -0
  98. data/tests/compute_tests.rb +53 -0
  99. data/tests/helper.rb +8 -0
  100. data/tests/helpers/mock_helper.rb +9 -0
  101. data/tests/helpers/succeeds_helper.rb +9 -0
  102. data/tests/models/compute/server_tests.rb +70 -0
  103. data/tests/models/compute/servers_tests.rb +15 -0
  104. data/tests/requests/compute/current_time_tests.rb +12 -0
  105. data/tests/requests/compute/get_network_tests.rb +50 -0
  106. data/tests/requests/compute/list_child_snapshots_tests.rb +10 -0
  107. data/tests/requests/compute/list_clusters_tests.rb +11 -0
  108. data/tests/requests/compute/list_virtual_machines_tests.rb +38 -0
  109. data/tests/requests/compute/list_vm_snapshots_tests.rb +10 -0
  110. data/tests/requests/compute/revert_to_snapshot_tests.rb +15 -0
  111. data/tests/requests/compute/set_vm_customvalue_tests.rb +20 -0
  112. data/tests/requests/compute/vm_clone_tests.rb +50 -0
  113. data/tests/requests/compute/vm_config_vnc_tests.rb +19 -0
  114. data/tests/requests/compute/vm_destroy_tests.rb +17 -0
  115. data/tests/requests/compute/vm_migrate_tests.rb +16 -0
  116. data/tests/requests/compute/vm_power_off_tests.rb +26 -0
  117. data/tests/requests/compute/vm_power_on_tests.rb +17 -0
  118. data/tests/requests/compute/vm_reboot_tests.rb +26 -0
  119. data/tests/requests/compute/vm_reconfig_cpus_tests.rb +19 -0
  120. data/tests/requests/compute/vm_reconfig_hardware_tests.rb +19 -0
  121. data/tests/requests/compute/vm_reconfig_memory_tests.rb +19 -0
  122. data/tests/requests/compute/vm_take_snapshot_tests.rb +19 -0
  123. metadata +289 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cfe6e1cbbfc4227977c73a8745a21b95dc3620bb
4
+ data.tar.gz: b8affb28c374525ca1c7672b8ba41b872dffd46a
5
+ SHA512:
6
+ metadata.gz: 42468d362477c2f717de36467569278bbd9d6936f6f56809d2c6e968da8e206f73dc051d8dde82c0308645a0aed406f0bfbfac4aecaaecc19e55a72942e5469e
7
+ data.tar.gz: 8d7dfb60c5849b2bd1865a1ffd8e5823e6a3904d578682d3c8e4e922a17625591db912458b2a27f210d6d8e7d966320a50d133f859b84dbcad56015431c4519f
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ gemfiles/*.lock
data/.travis.yml ADDED
@@ -0,0 +1,32 @@
1
+ language: ruby
2
+ sudo: false
3
+ before_install: gem install bundler
4
+ matrix:
5
+ allow_failures:
6
+ - rvm: jruby-head
7
+ fast_finish: true
8
+ include:
9
+ - rvm: 1.8.7
10
+ gemfile: gemfiles/Gemfile.1.9.2-
11
+ - rvm: 1.9.3
12
+ gemfile: gemfiles/Gemfile.1.9.2+
13
+ - rvm: 2.0.0
14
+ gemfile: Gemfile
15
+ - rvm: 2.1.0
16
+ gemfile: Gemfile
17
+ - rvm: 2.1.1
18
+ gemfile: Gemfile
19
+ - rvm: 2.2.0
20
+ gemfile: Gemfile
21
+ - rvm: jruby-18mode
22
+ gemfile: gemfiles/Gemfile.1.9.2-
23
+ - rvm: jruby-19mode
24
+ gemfile: gemfiles/Gemfile.1.9.2+
25
+ - rvm: jruby-head
26
+ gemfile: Gemfile
27
+ notifications:
28
+ email: false
29
+ addons:
30
+ code_climate:
31
+ repo_token: 44bcd04b60228fc94f2be3a5e0346441b5ea156e94e89a17fc24c5d3de483721
32
+
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,18 @@
1
+ ## Getting Involved
2
+
3
+ New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another.
4
+
5
+ ### Coding
6
+
7
+ * Pick a task:
8
+ * Offer feedback on open [pull requests](https://github.com/fog/fog-vsphere/pulls).
9
+ * Review open [issues](https://github.com/fog/fog-vsphere/issues) for things to help on.
10
+ * [Create an issue](https://github.com/fog/fog-vsphere/issues/new) to start a discussion on additions or features.
11
+ * Fork the project, add your changes and tests to cover them in a topic branch.
12
+ * Commit your changes and rebase against `fog/fog-vsphere` to ensure everything is up to date.
13
+ * [Submit a pull request](https://github.com/fog/fog-vsphere/compare/)
14
+
15
+ ### Non-Coding
16
+
17
+ * Offer feedback on open [issues](https://github.com/fog/fog-vsphere/issues).
18
+ * Organize or volunteer at events.
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,59 @@
1
+ * Ahmed Elsabbahy <aelsabbahy@promnetwork.com>
2
+ * Alan Sebastian <asebastian2@gmail.com>
3
+ * Carl Caum <carl@carlcaum.com>
4
+ * Carlos Sanchez <csanchez@maestrodev.com>
5
+ * Chris Thompson <chris.thompson@govdelivery.com>
6
+ * Chris Thompson <teaforthecat@gmail.com>
7
+ * Cyrus Team <cyrusteam@cyruslists.com>
8
+ * Darren Foo <stonith@users.noreply.github.com>
9
+ * Dominic Cleal <dcleal@redhat.com>
10
+ * Eric Stonfer <ericstonfer@yahoo.com>
11
+ * Ewoud Kohl van Wijngaarden <ewoud@kohlvanwijngaarden.nl>
12
+ * Francois Herbert <F.Herbert@massey.ac.nz>
13
+ * Francois Herbert <fherbert@oss.co.nz>
14
+ * Francois Herbert <francois@herbert.org.nz>
15
+ * Ivan Nečas <inecas@redhat.com>
16
+ * Ivo Reznicek <ireznice@googlemail.com>
17
+ * James Herdman <james.herdman@me.com>
18
+ * Jeff McCune <jeff@puppetlabs.com>
19
+ * Justin Clayton <justin.clayton@gettyimages.com>
20
+ * Justin Pratt <github@justinpratt.me>
21
+ * Justin Pratt <jpratt@liveramp.com>
22
+ * Karan Misra <karan@erodov.com>
23
+ * Kelsey Hightower <kelsey@puppetlabs.com>
24
+ * Kevin Menard <kevin@nirvdrum.com>
25
+ * Kevin Menard <nirvdrum@gmail.com>
26
+ * Lance Ivy <lance@cainlevy.net>
27
+ * Lukas Zapletal <lzap+git@redhat.com>
28
+ * Marc Grimme <grimme@atix.de>
29
+ * Marc Grimme <marc.grimme@googlemail.com>
30
+ * Martin Matuska <martin@matuska.org>
31
+ * Matt Darby <matt.darby@rackspace.com>
32
+ * Matthew Black <matthew.black@sap.com>
33
+ * Matthew Black <matthewblack@successfactors.com>
34
+ * Michael Moll <kvedulv@kvedulv.de>
35
+ * Mick Pollard <aussielunix@gmail.com>
36
+ * Ming Jin <skyairmj@gmail.com>
37
+ * Nick Huanca <nhuanca@pingidentity.com>
38
+ * Nick Huanca <nick.huanca@gmail.com>
39
+ * Nick Huanuca <nhuanca@pingidentity.com>
40
+ * Ohad Levy <ohadlevy@gmail.com>
41
+ * Ohad Levy <ohadlevy@redhat.com>
42
+ * Oscar Elfving <sofam84@gmail.com>
43
+ * Paul Thornthwaite <paul@brightbox.co.uk>
44
+ * Paul Thornthwaite <tokengeek@gmail.com>
45
+ * Rich Lane <rlane@club.cc.cmu.edu>
46
+ * Samuel Keeley <samuel@dropbox.com>
47
+ * Shlomi Zadok <shlomi@ben-hanna.com>
48
+ * Simon Josi <me@yokto.net>
49
+ * Tejas Ravindra Mandke <tejas@identified.com>
50
+ * Timur Alperovich <timur@maginatics.com>
51
+ * Wesley Beary <geemus+github@gmail.com>
52
+ * Wesley Beary <geemus@gmail.com>
53
+ * Xavier Fontrodona <xavier.fontrodona@safelayer.com>
54
+ * alan <asebastian2@gmail.com>
55
+ * endzyme <nick.huanca@gmail.com>
56
+ * geemus <geemus@gmail.com>
57
+ * karmab <karimboumedhel@gmail.com>
58
+ * slivik <jakub.sliva@gmail.com>
59
+ * tipt0e <topo-2@charter.net>
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'codeclimate-test-reporter', group: :test, require: nil
4
+
5
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2015 [CONTRIBUTORS.md](CONTRIBUTORS.md)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Fog::Vsphere
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fog-vsphere.svg)](http://badge.fury.io/rb/fog-vsphere) [![Build Status](https://travis-ci.org/fog/fog-vsphere.svg?branch=master)](https://travis-ci.org/fog/fog-vsphere) [![Dependency Status](https://gemnasium.com/fog/fog-vsphere.svg)](https://gemnasium.com/fog/fog-vsphere) [![Test Coverage](https://codeclimate.com/github/fog/fog-vsphere/badges/coverage.svg)](https://codeclimate.com/github/fog/fog-vsphere/coverage) [![Code Climate](https://codeclimate.com/github/fog/fog-vsphere.png)](https://codeclimate.com/github/fog/fog-vsphere) [![Stories in Ready](https://badge.waffle.io/fog/fog-vsphere.png?label=ready&title=Ready)](https://waffle.io/fog/fog-vsphere)
4
+
5
+ TODO: Write a gem description
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'fog-vsphere'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fog-vsphere
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/fog/fog-vsphere/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ mock = ENV['FOG_MOCK'] || 'true'
4
+ task :test do
5
+ sh("export FOG_MOCK=#{mock} && bundle exec shindont")
6
+ end
7
+
8
+ task(:default => [:test])
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fog/vsphere/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fog-vsphere'
8
+ spec.version = Fog::Vsphere::VERSION
9
+ spec.authors = ['J.R. Garcia']
10
+ spec.email = ['jrg@vmware.com']
11
+
12
+ spec.summary = "Module for the 'fog' gem to support VMware vSphere."
13
+ spec.description = 'This library can be used as a module for `fog` or as standalone provider to use vSphere in applications.'
14
+ spec.homepage = 'https://github.com/fog/fog-vsphere'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.test_files = spec.files.grep(%r{^tests\/})
19
+
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.required_ruby_version = '>= 1.8.7'
23
+
24
+ spec.add_runtime_dependency 'fog-core', '~> 1.32'
25
+ spec.add_runtime_dependency 'rbvmomi', '~> 1.8'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.10'
28
+ spec.add_development_dependency 'pry', '~> 0.10'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rubocop', '~> 0.34'
31
+ spec.add_development_dependency 'shindo', '~> 0.3'
32
+ end
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'codeclimate-test-reporter', group: :test, require: nil
4
+
5
+ gem 'net-ssh', '~> 2.9'
6
+ gem 'rubocop', '~> 0.34'
7
+
8
+ gemspec :path => '..'
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'mime-types', '~> 1.25'
4
+ gem 'net-ssh', '~> 2.9'
5
+ gem 'nokogiri', '~> 1.5.11'
6
+ gem 'rainbow', '~> 1.99'
7
+ gem 'rest-client', '~> 1.6.8'
8
+ gem 'rubocop', '~> 0.5.0'
9
+ gem 'tins', '~> 1.6.0'
10
+
11
+ gemspec :path => '..'
@@ -0,0 +1,41 @@
1
+ require 'fog/core'
2
+
3
+ module Fog
4
+ module Vsphere
5
+ autoload :Compute, File.expand_path('../vsphere/compute', __FILE__)
6
+
7
+ extend Fog::Provider
8
+
9
+ module Errors
10
+ class ServiceError < Fog::Errors::Error; end
11
+ class SecurityError < ServiceError; end
12
+ class NotFound < ServiceError; end
13
+ end
14
+
15
+ service(:compute, 'Compute')
16
+
17
+ # This helper was originally added as Fog.class_as_string and moved to core but only used here
18
+ def self.class_from_string classname, defaultpath=""
19
+ if classname and classname.is_a? String then
20
+ chain = classname.split("::")
21
+ klass = Kernel
22
+ chain.each do |klass_string|
23
+ klass = klass.const_get klass_string
24
+ end
25
+ if klass.is_a? Class then
26
+ klass
27
+ elsif defaultpath != nil then
28
+ class_from_string((defaultpath.split("::")+chain).join("::"), nil)
29
+ else
30
+ nil
31
+ end
32
+ elsif classname and classname.is_a? Class then
33
+ classname
34
+ else
35
+ nil
36
+ end
37
+ rescue NameError
38
+ defaultpath != nil ? class_from_string((defaultpath.split("::")+chain).join("::"), nil) : nil
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,473 @@
1
+ require 'digest/sha2'
2
+
3
+ module Fog
4
+ module Compute
5
+ class Vsphere < Fog::Service
6
+ requires :vsphere_username, :vsphere_password, :vsphere_server
7
+ recognizes :vsphere_port, :vsphere_path, :vsphere_ns
8
+ recognizes :vsphere_rev, :vsphere_ssl, :vsphere_expected_pubkey_hash
9
+ recognizes :vsphere_debug
10
+
11
+ model_path 'fog/vsphere/models/compute'
12
+ model :server
13
+ collection :servers
14
+ model :servertype
15
+ collection :servertypes
16
+ model :datacenter
17
+ collection :datacenters
18
+ model :interface
19
+ collection :interfaces
20
+ model :interfacetype
21
+ collection :interfacetypes
22
+ model :volume
23
+ collection :volumes
24
+ model :snapshot
25
+ collection :snapshots
26
+ model :template
27
+ collection :templates
28
+ model :cluster
29
+ collection :clusters
30
+ model :resource_pool
31
+ collection :resource_pools
32
+ model :network
33
+ collection :networks
34
+ model :datastore
35
+ collection :datastores
36
+ model :folder
37
+ collection :folders
38
+ model :customvalue
39
+ collection :customvalues
40
+ model :customfield
41
+ collection :customfields
42
+ model :scsicontroller
43
+ model :process
44
+
45
+ request_path 'fog/vsphere/requests/compute'
46
+ request :current_time
47
+ request :cloudinit_to_customspec
48
+ request :list_virtual_machines
49
+ request :vm_power_off
50
+ request :vm_power_on
51
+ request :vm_reboot
52
+ request :vm_clone
53
+ request :vm_destroy
54
+ request :vm_migrate
55
+ request :vm_execute
56
+ request :list_datacenters
57
+ request :get_datacenter
58
+ request :list_clusters
59
+ request :get_cluster
60
+ request :list_resource_pools
61
+ request :get_resource_pool
62
+ request :list_networks
63
+ request :get_network
64
+ request :list_datastores
65
+ request :get_datastore
66
+ request :list_compute_resources
67
+ request :get_compute_resource
68
+ request :list_templates
69
+ request :get_template
70
+ request :get_folder
71
+ request :list_folders
72
+ request :create_vm
73
+ request :list_vm_interfaces
74
+ request :modify_vm_interface
75
+ request :modify_vm_volume
76
+ request :list_vm_volumes
77
+ request :get_virtual_machine
78
+ request :vm_reconfig_hardware
79
+ request :vm_reconfig_memory
80
+ request :vm_reconfig_cpus
81
+ request :vm_config_vnc
82
+ request :create_folder
83
+ request :list_server_types
84
+ request :get_server_type
85
+ request :list_interface_types
86
+ request :get_interface_type
87
+ request :list_vm_customvalues
88
+ request :list_customfields
89
+ request :get_vm_first_scsi_controller
90
+ request :set_vm_customvalue
91
+ request :vm_take_snapshot
92
+ request :list_vm_snapshots
93
+ request :list_child_snapshots
94
+ request :revert_to_snapshot
95
+ request :list_processes
96
+
97
+ module Shared
98
+ attr_reader :vsphere_is_vcenter
99
+ attr_reader :vsphere_rev
100
+ attr_reader :vsphere_server
101
+ attr_reader :vsphere_username
102
+
103
+ protected
104
+
105
+ ATTR_TO_PROP = {
106
+ :id => 'config.instanceUuid',
107
+ :name => 'name',
108
+ :uuid => 'config.uuid',
109
+ :template => 'config.template',
110
+ :parent => 'parent',
111
+ :hostname => 'summary.guest.hostName',
112
+ :operatingsystem => 'summary.guest.guestFullName',
113
+ :ipaddress => 'guest.ipAddress',
114
+ :power_state => 'runtime.powerState',
115
+ :connection_state => 'runtime.connectionState',
116
+ :hypervisor => 'runtime.host',
117
+ :tools_state => 'guest.toolsStatus',
118
+ :tools_version => 'guest.toolsVersionStatus',
119
+ :memory_mb => 'config.hardware.memoryMB',
120
+ :cpus => 'config.hardware.numCPU',
121
+ :corespersocket => 'config.hardware.numCoresPerSocket',
122
+ :overall_status => 'overallStatus',
123
+ :guest_id => 'config.guestId',
124
+ :hardware_version => 'config.version',
125
+ :cpuHotAddEnabled => 'config.cpuHotAddEnabled',
126
+ :memoryHotAddEnabled => 'config.memoryHotAddEnabled',
127
+ :firmware => 'config.firmware',
128
+ }
129
+
130
+ def convert_vm_view_to_attr_hash(vms)
131
+ vms = @connection.serviceContent.propertyCollector.collectMultiple(vms,*ATTR_TO_PROP.values.uniq)
132
+ vms.map { |vm| props_to_attr_hash(*vm) }
133
+ end
134
+
135
+ # Utility method to convert a VMware managed object into an attribute hash.
136
+ # This should only really be necessary for the real class.
137
+ # This method is expected to be called by the request methods
138
+ # in order to massage VMware Managed Object References into Attribute Hashes.
139
+ def convert_vm_mob_ref_to_attr_hash(vm_mob_ref)
140
+ return nil unless vm_mob_ref
141
+
142
+ props = vm_mob_ref.collect!(*ATTR_TO_PROP.values.uniq)
143
+ props_to_attr_hash vm_mob_ref, props
144
+ end
145
+
146
+ def props_to_attr_hash vm_mob_ref, props
147
+ # NOTE: Object.tap is in 1.8.7 and later.
148
+ # Here we create the hash object that this method returns, but first we need
149
+ # to add a few more attributes that require additional calls to the vSphere
150
+ # API. The hypervisor name and mac_addresses attributes may not be available
151
+ # so we need catch any exceptions thrown during lookup and set them to nil.
152
+ #
153
+ # The use of the "tap" method here is a convenience, it allows us to update the
154
+ # hash object without explicitly returning the hash at the end of the method.
155
+ Hash[ATTR_TO_PROP.map { |k,v| [k.to_s, props[v]] }].tap do |attrs|
156
+ attrs['id'] ||= vm_mob_ref._ref
157
+ attrs['mo_ref'] = vm_mob_ref._ref
158
+ # The name method "magically" appears after a VM is ready and
159
+ # finished cloning.
160
+ if attrs['hypervisor'].kind_of?(RbVmomi::VIM::HostSystem)
161
+ host = attrs['hypervisor']
162
+ attrs['datacenter'] = Proc.new { parent_attribute(host.path, :datacenter)[1] rescue nil }
163
+ attrs['cluster'] = Proc.new { parent_attribute(host.path, :cluster)[1] rescue nil }
164
+ attrs['hypervisor'] = Proc.new { host.name rescue nil }
165
+ attrs['resource_pool'] = Proc.new {(vm_mob_ref.resourcePool || host.resourcePool).name rescue nil}
166
+ end
167
+ # This inline rescue catches any standard error. While a VM is
168
+ # cloning, a call to the macs method will throw and NoMethodError
169
+ attrs['mac_addresses'] = Proc.new {vm_mob_ref.macs rescue nil}
170
+ # Rescue nil to catch testing while vm_mob_ref isn't reaL??
171
+ attrs['path'] = "/"+attrs['parent'].path.map(&:last).join('/') rescue nil
172
+ end
173
+ end
174
+ # returns the parent object based on a type
175
+ # provides both real RbVmomi object and its name.
176
+ # e.g.
177
+ #[Datacenter("datacenter-2"), "dc-name"]
178
+ def parent_attribute path, type
179
+ element = case type
180
+ when :datacenter
181
+ RbVmomi::VIM::Datacenter
182
+ when :cluster
183
+ RbVmomi::VIM::ClusterComputeResource
184
+ when :host
185
+ RbVmomi::VIM::HostSystem
186
+ else
187
+ raise "Unknown type"
188
+ end
189
+ path.select {|x| x[0].is_a? element}.flatten
190
+ rescue
191
+ nil
192
+ end
193
+
194
+ # returns vmware managed obj id string
195
+ def managed_obj_id obj
196
+ obj.to_s.match(/\("([^"]+)"\)/)[1]
197
+ end
198
+
199
+ def is_uuid?(id)
200
+ !(id =~ /[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/).nil?
201
+ end
202
+ end
203
+
204
+ class Mock
205
+ include Shared
206
+
207
+ def self.data
208
+ @data ||= Hash.new do |hash, key|
209
+ hash[key] = {
210
+ :servers => {
211
+ "5032c8a5-9c5e-ba7a-3804-832a03e16381" => {
212
+ "resource_pool" => "Resources",
213
+ "memory_mb" => 2196,
214
+ "mac_addresses" => { "Network adapter 1" => "00:50:56:a9:00:28" },
215
+ "power_state" => "poweredOn",
216
+ "cpus" => 1,
217
+ "hostname" => "dhcp75-197.virt.bos.redhat.com",
218
+ "mo_ref" => "vm-562",
219
+ "connection_state" => "connected",
220
+ "overall_status" => "green",
221
+ "datacenter" => "Solutions",
222
+ "volumes" =>
223
+ [{
224
+ "id" => "6000C29c-a47d-4cd9-5249-c371de775f06",
225
+ "datastore" => "Storage1",
226
+ "mode" => "persistent",
227
+ "size" => 8388608,
228
+ "thin" => true,
229
+ "name" => "Hard disk 1",
230
+ "filename" => "[Storage1] rhel6-mfojtik/rhel6-mfojtik.vmdk",
231
+ "size_gb" => 8
232
+ }],
233
+ "interfaces" =>
234
+ [{"mac" => "00:50:56:a9:00:28",
235
+ "network" => "VM Network",
236
+ "name" => "Network adapter 1",
237
+ "status" => "ok",
238
+ "summary" => "VM Network",
239
+ }],
240
+ "hypervisor" => "gunab.puppetlabs.lan",
241
+ "guest_id" => "rhel6_64Guest",
242
+ "tools_state" => "toolsOk",
243
+ "cluster" => "Solutionscluster",
244
+ "name" => "rhel64",
245
+ "operatingsystem" => "Red Hat Enterprise Linux 6 (64-bit)",
246
+ "path" => "/Datacenters/Solutions/vm",
247
+ "uuid" => "4229f0e9-bfdc-d9a7-7bac-12070772e6dc",
248
+ "instance_uuid" => "5032c8a5-9c5e-ba7a-3804-832a03e16381",
249
+ "id" => "5032c8a5-9c5e-ba7a-3804-832a03e16381",
250
+ "tools_version" => "guestToolsUnmanaged",
251
+ "ipaddress" => "192.168.100.184",
252
+ "template" => false
253
+ },
254
+ "502916a3-b42e-17c7-43ce-b3206e9524dc" => {
255
+ "resource_pool" => "Resources",
256
+ "memory_mb" => 512,
257
+ "power_state" => "poweredOn",
258
+ "mac_addresses" => { "Network adapter 1" => "00:50:56:a9:00:00" },
259
+ "hostname" => nil,
260
+ "cpus" => 1,
261
+ "connection_state" => "connected",
262
+ "mo_ref" => "vm-621",
263
+ "overall_status" => "green",
264
+ "datacenter" => "Solutions",
265
+ "volumes" =>
266
+ [{"thin" => false,
267
+ "size_gb" => 10,
268
+ "datastore" => "datastore1",
269
+ "filename" => "[datastore1] i-1342439683/i-1342439683.vmdk",
270
+ "size" => 10485762,
271
+ "name" => "Hard disk 1",
272
+ "mode" => "persistent",
273
+ "id" => "6000C29b-f364-d073-8316-8e98ac0a0eae" }],
274
+ "interfaces" =>
275
+ [{ "summary" => "VM Network",
276
+ "mac" => "00:50:56:a9:00:00",
277
+ "status" => "ok",
278
+ "network" => "VM Network",
279
+ "name" => "Network adapter 1" }],
280
+ "hypervisor" => "gunab.puppetlabs.lan",
281
+ "guest_id" => nil,
282
+ "cluster" => "Solutionscluster",
283
+ "tools_state" => "toolsNotInstalled",
284
+ "name" => "i-1342439683",
285
+ "operatingsystem" => nil,
286
+ "path" => "/",
287
+ "tools_version" => "guestToolsNotInstalled",
288
+ "uuid" => "4229e0de-30cb-ceb2-21f9-4d8d8beabb52",
289
+ "instance_uuid" => "502916a3-b42e-17c7-43ce-b3206e9524dc",
290
+ "id" => "502916a3-b42e-17c7-43ce-b3206e9524dc",
291
+ "ipaddress" => nil,
292
+ "template" => false
293
+ },
294
+ "5029c440-85ee-c2a1-e9dd-b63e39364603" => {
295
+ "resource_pool" => "Resources",
296
+ "memory_mb" => 2196,
297
+ "power_state" => "poweredOn",
298
+ "mac_addresses" => { "Network adapter 1" => "00:50:56:b2:00:af" },
299
+ "hostname" => "centos56gm.localdomain",
300
+ "cpus" => 1,
301
+ "connection_state" => "connected",
302
+ "mo_ref" => "vm-715",
303
+ "overall_status" => "green",
304
+ "datacenter" => "Solutions",
305
+ "hypervisor" => "gunab.puppetlabs.lan",
306
+ "guest_id" => "rhel6_64Guest",
307
+ "cluster" => "Solutionscluster",
308
+ "tools_state" => "toolsOk",
309
+ "name" => "jefftest",
310
+ "operatingsystem" => "Red Hat Enterprise Linux 6 (64-bit)",
311
+ "path" => "/",
312
+ "tools_version" => "guestToolsUnmanaged",
313
+ "ipaddress" => "192.168.100.187",
314
+ "uuid" => "42329da7-e8ab-29ec-1892-d6a4a964912a",
315
+ "instance_uuid" => "5029c440-85ee-c2a1-e9dd-b63e39364603",
316
+ "id" => "5029c440-85ee-c2a1-e9dd-b63e39364603",
317
+ "template" => false
318
+ }
319
+ },
320
+ :datacenters => {
321
+ "Solutions" => {:name => "Solutions", :status => "grey"}
322
+ },
323
+ :clusters =>
324
+ [{:id => "1d4d9a3f-e4e8-4c40-b7fc-263850068fa4",
325
+ :name => "Solutionscluster",
326
+ :num_host => "4",
327
+ :num_cpu_cores => "16",
328
+ :overall_status => "green",
329
+ :datacenter => "Solutions",
330
+ :klass => "RbVmomi::VIM::ComputeResource"
331
+ },
332
+ {:id => "e4195973-102b-4096-bbd6-5429ff0b35c9",
333
+ :name => "Problemscluster",
334
+ :num_host => "4",
335
+ :num_cpu_cores => "32",
336
+ :overall_status => "green",
337
+ :datacenter => "Solutions",
338
+ :klass => "RbVmomi::VIM::ComputeResource"
339
+ },
340
+ {
341
+ :klass => "RbVmomi::VIM::Folder",
342
+ :clusters => [{:id => "03616b8d-b707-41fd-b3b5-The first",
343
+ :name => "Problemscluster",
344
+ :num_host => "4",
345
+ :num_cpu_cores => "32",
346
+ :overall_status => "green",
347
+ :datacenter => "Solutions",
348
+ :klass => "RbVmomi::VIM::ComputeResource"
349
+ },
350
+ {:id => "03616b8d-b707-41fd-b3b5-the Second",
351
+ :name => "Lastcluster",
352
+ :num_host => "8",
353
+ :num_cpu_cores => "32",
354
+ :overall_status => "green",
355
+ :datacenter => "Solutions",
356
+ :klass => "RbVmomi::VIM::ComputeResource"}
357
+ ]
358
+ }
359
+ ]
360
+ }
361
+ end
362
+ end
363
+
364
+ def initialize(options={})
365
+ require 'rbvmomi'
366
+ @vsphere_username = options[:vsphere_username]
367
+ @vsphere_password = 'REDACTED'
368
+ @vsphere_server = options[:vsphere_server]
369
+ @vsphere_expected_pubkey_hash = options[:vsphere_expected_pubkey_hash]
370
+ @vsphere_is_vcenter = true
371
+ @vsphere_rev = '4.0'
372
+ end
373
+
374
+ def data
375
+ self.class.data[@vsphere_username]
376
+ end
377
+
378
+ def reset_data
379
+ self.class.data.delete(@vsphere_username)
380
+ end
381
+ end
382
+
383
+ class Real
384
+ include Shared
385
+
386
+ def initialize(options={})
387
+ require 'rbvmomi'
388
+ @vsphere_username = options[:vsphere_username]
389
+ @vsphere_password = options[:vsphere_password]
390
+ @vsphere_server = options[:vsphere_server]
391
+ @vsphere_port = options[:vsphere_port] || 443
392
+ @vsphere_path = options[:vsphere_path] || '/sdk'
393
+ @vsphere_ns = options[:vsphere_ns] || 'urn:vim25'
394
+ @vsphere_rev = options[:vsphere_rev] || '4.0'
395
+ @vsphere_ssl = options[:vsphere_ssl] || true
396
+ @vsphere_debug = options[:vsphere_debug] || false
397
+ @vsphere_expected_pubkey_hash = options[:vsphere_expected_pubkey_hash]
398
+ @vsphere_must_reauthenticate = false
399
+ @vsphere_is_vcenter = nil
400
+ @connection = nil
401
+ connect
402
+ negotiate_revision(options[:vsphere_rev])
403
+ authenticate
404
+ end
405
+
406
+ def reload
407
+ connect
408
+ # Check if the negotiation was ever run
409
+ if @vsphere_is_vcenter.nil?
410
+ negotiate
411
+ end
412
+ authenticate
413
+ end
414
+
415
+ private
416
+ def negotiate_revision(revision = nil)
417
+ # Negotiate the API revision
418
+ if not revision
419
+ rev = @connection.serviceContent.about.apiVersion
420
+ @connection.rev = [ rev, ENV['FOG_VSPHERE_REV'] || '4.1' ].min
421
+ end
422
+
423
+ @vsphere_is_vcenter = @connection.serviceContent.about.apiType == "VirtualCenter"
424
+ @vsphere_rev = @connection.rev
425
+ end
426
+
427
+ def connect
428
+ # This is a state variable to allow digest validation of the SSL cert
429
+ bad_cert = false
430
+ loop do
431
+ begin
432
+ @connection = RbVmomi::VIM.new :host => @vsphere_server,
433
+ :port => @vsphere_port,
434
+ :path => @vsphere_path,
435
+ :ns => @vsphere_ns,
436
+ :rev => @vsphere_rev,
437
+ :ssl => @vsphere_ssl,
438
+ :insecure => bad_cert,
439
+ :debug => @vsphere_debug
440
+ break
441
+ rescue OpenSSL::SSL::SSLError
442
+ raise if bad_cert
443
+ bad_cert = true
444
+ end
445
+ end
446
+
447
+ if bad_cert then
448
+ validate_ssl_connection
449
+ end
450
+ end
451
+
452
+ def authenticate
453
+ begin
454
+ @connection.serviceContent.sessionManager.Login :userName => @vsphere_username,
455
+ :password => @vsphere_password
456
+ rescue RbVmomi::VIM::InvalidLogin => e
457
+ raise Fog::Vsphere::Errors::ServiceError, e.message
458
+ end
459
+ end
460
+
461
+ # Verify a SSL certificate based on the hashed public key
462
+ def validate_ssl_connection
463
+ pubkey = @connection.http.peer_cert.public_key
464
+ pubkey_hash = Digest::SHA2.hexdigest(pubkey.to_s)
465
+ expected_pubkey_hash = @vsphere_expected_pubkey_hash
466
+ if pubkey_hash != expected_pubkey_hash then
467
+ raise Fog::Vsphere::Errors::SecurityError, "The remote system presented a public key with hash #{pubkey_hash} but we're expecting a hash of #{expected_pubkey_hash || '<unset>'}. If you are sure the remote system is authentic set vsphere_expected_pubkey_hash: <the hash printed in this message> in ~/.fog"
468
+ end
469
+ end
470
+ end
471
+ end
472
+ end
473
+ end