vagrant-vcenter 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,12 +20,11 @@ module VagrantPlugins
20
20
  def read_ssh_info(env)
21
21
  return nil if env[:machine].id.nil?
22
22
 
23
- config = env[:machine].provider_config
24
- # FIXME: Raise a correct exception
25
- dc = config.vcenter_cnx.serviceInstance.find_datacenter(
26
- config.datacenter_name) or abort 'datacenter not found'
27
- root_vm_folder = dc.vmFolder
28
- vm = root_vm_folder.findByUuid(env[:machine].id)
23
+ cfg = env[:machine].provider_config
24
+
25
+ vm = cfg.vmfolder.findByUuid(env[:machine].id) or
26
+ fail Errors::VMNotFound,
27
+ :vm_name => env[:machine].name
29
28
 
30
29
  address = vm.guest.ipAddress
31
30
  if not address or address == ''
@@ -1,5 +1,3 @@
1
- require 'log4r'
2
-
3
1
  module VagrantPlugins
4
2
  module VCenter
5
3
  module Action
@@ -21,21 +19,20 @@ module VagrantPlugins
21
19
  return :not_created
22
20
  end
23
21
 
24
- # FIXME: this part needs some cleanup
25
- config = env[:machine].provider_config
26
-
27
- # FIXME: Raise a correct exception
28
- dc = config.vcenter_cnx.serviceInstance.find_datacenter(
29
- config.datacenter_name) or abort 'datacenter not found'
30
-
31
- root_vm_folder = dc.vmFolder
22
+ cfg = env[:machine].provider_config
32
23
 
33
- vm = root_vm_folder.findByUuid(env[:machine].id)
24
+ vm = cfg.vmfolder.findByUuid(env[:machine].id) or
25
+ fail Errors::VMNotFound,
26
+ :vm_name => env[:machine].name
34
27
 
35
28
  # @logger.debug("Current power state: #{vm.runtime.powerState}")
36
29
  vm_name = env[:machine].name
37
30
 
38
- if vm.runtime.powerState == 'poweredOff'
31
+ if vm.nil?
32
+ # If the VM has been cloned/moved, the findByUuid call returns nil
33
+ @logger.info("VM [#{vm_name}] state is unknown")
34
+ return :unknown
35
+ elsif vm.runtime.powerState == 'poweredOff'
39
36
  @logger.info("VM [#{vm_name}] is stopped")
40
37
  return :stopped
41
38
  elsif vm.runtime.powerState == 'poweredOn'
@@ -1,5 +1,3 @@
1
- require 'i18n'
2
-
3
1
  module VagrantPlugins
4
2
  module VCenter
5
3
  module Action
@@ -11,12 +9,11 @@ module VagrantPlugins
11
9
  end
12
10
 
13
11
  def call(env)
14
- config = env[:machine].provider_config
15
- # FIXME: Raise a correct exception
16
- dc = config.vcenter_cnx.serviceInstance.find_datacenter(
17
- config.datacenter_name) or abort 'datacenter not found'
18
- root_vm_folder = dc.vmFolder
19
- vm = root_vm_folder.findByUuid(env[:machine].id)
12
+ cfg = env[:machine].provider_config
13
+
14
+ vm = cfg.vmfolder.findByUuid(env[:machine].id) or
15
+ fail Errors::VMNotFound,
16
+ :vm_name => env[:machine].name
20
17
 
21
18
  # Poweroff VM
22
19
  env[:ui].info('Powering on VM...')
@@ -1,5 +1,3 @@
1
- require 'i18n'
2
-
3
1
  module VagrantPlugins
4
2
  module VCenter
5
3
  module Action
@@ -11,12 +9,11 @@ module VagrantPlugins
11
9
  end
12
10
 
13
11
  def call(env)
14
- config = env[:machine].provider_config
15
- # FIXME: Raise a correct exception
16
- dc = config.vcenter_cnx.serviceInstance.find_datacenter(
17
- config.datacenter_name) or abort 'datacenter not found'
18
- root_vm_folder = dc.vmFolder
19
- vm = root_vm_folder.findByUuid(env[:machine].id)
12
+ cfg = env[:machine].provider_config
13
+
14
+ vm = cfg.vmfolder.findByUuid(env[:machine].id) or
15
+ fail Errors::VMNotFound,
16
+ :vm_name => env[:machine].name
20
17
 
21
18
  # Poweroff VM
22
19
  env[:ui].info('Suspending VM...')
@@ -51,7 +51,7 @@ module VagrantPlugins
51
51
  # Virtual Data Center to be used
52
52
  #
53
53
  # @return [String]
54
- attr_accessor :computer_name
54
+ attr_accessor :compute_name
55
55
 
56
56
  # Virtual Data Center Network to be used
57
57
  #
@@ -105,11 +105,37 @@ module VagrantPlugins
105
105
  attr_accessor :memory
106
106
 
107
107
  ##
108
- ## vCenter config runtime values
108
+ ## vCenter config runtime values
109
109
  ##
110
110
 
111
111
  # connection handle
112
112
  attr_accessor :vcenter_cnx
113
+
114
+ # Datacenter object
115
+ attr_accessor :datacenter
116
+
117
+ # Compute object
118
+ attr_accessor :compute
119
+
120
+ # Compute resource pool object
121
+ attr_accessor :compute_rp
122
+
123
+ # Datastore object
124
+ attr_accessor :datastore
125
+
126
+ # Network (dv)portgroup object
127
+ attr_accessor :network
128
+
129
+ # VM Folder object
130
+ attr_accessor :vmfolder
131
+
132
+ # Template object
133
+ attr_accessor :template
134
+
135
+ # Template folder object
136
+ attr_accessor :template_folder
137
+
138
+ # Template ID, not sure if used ... verify
113
139
  attr_accessor :template_id
114
140
 
115
141
  def initialize
@@ -122,22 +148,22 @@ module VagrantPlugins
122
148
 
123
149
  # TODO: add blank?
124
150
  errors <<
125
- I18n.t('vagrant_vcenter.config.hostname') if hostname.nil?
151
+ I18n.t('vagrant_vcenter.config.hostname') if hostname.nil?
126
152
  errors <<
127
- I18n.t('vagrant_vcenter.config.username') if username.nil?
153
+ I18n.t('vagrant_vcenter.config.username') if username.nil?
128
154
  errors <<
129
- I18n.t('vagrant_vcenter.config.password') if password.nil?
155
+ I18n.t('vagrant_vcenter.config.password') if password.nil?
130
156
  errors <<
131
- I18n.t('vagrant_vcenter.config.datastore_name') if datastore_name.nil?
157
+ I18n.t('vagrant_vcenter.config.datastore_name') if datastore_name.nil?
132
158
  errors <<
133
- I18n.t('vagrant_vcenter.config.datacenter_name') if datacenter_name.nil?
159
+ I18n.t('vagrant_vcenter.config.datacenter_name') if datacenter_name.nil?
134
160
  errors <<
135
- I18n.t('vagrant_vcenter.config.computer_name') if computer_name.nil?
161
+ I18n.t('vagrant_vcenter.config.compute_name') if compute_name.nil?
136
162
  errors <<
137
- I18n.t('vagrant_vcenter.config.network_name') if network_name.nil?
163
+ I18n.t('vagrant_vcenter.config.network_name') if network_name.nil?
138
164
  if enable_vm_customization
139
165
  errors <<
140
- I18n.t('vagrant_vcenter.config.no_prep_type') if prep_type.downcase != 'linux' && prep_type.downcase != 'windows'
166
+ I18n.t('vagrant_vcenter.config.no_prep_type') if prep_type.downcase != 'linux' && prep_type.downcase != 'windows'
141
167
  end
142
168
  { 'vCenter Provider' => errors }
143
169
  end
@@ -83,6 +83,34 @@ module VagrantPlugins
83
83
  class SyncError < VCenterError
84
84
  error_key(:sync_error)
85
85
  end
86
+ # Set key for DatacenterNotFound errors.
87
+ class DatacenterNotFound < VCenterError
88
+ error_key(:datacenter_not_found)
89
+ end
90
+ # Set key for ComputeNotFound errors.
91
+ class ComputeNotFound < VCenterError
92
+ error_key(:compute_not_found)
93
+ end
94
+ # Set key for DatastoreNotFound errors.
95
+ class DatastoreNotFound < VCenterError
96
+ error_key(:datastore_not_found)
97
+ end
98
+ # Set key for NetworkNotFound errors.
99
+ class NetworkNotFound < VCenterError
100
+ error_key(:network_not_found)
101
+ end
102
+ # Set key for MachineNotRunning errors.
103
+ class MachineNotRunning < VCenterError
104
+ error_key(:machine_not_running)
105
+ end
106
+ # Set key for VMNotFound errors.
107
+ class VMNotFound < VCenterError
108
+ error_key(:vm_not_found)
109
+ end
110
+ # Set key for GuestCustomNotSupported
111
+ class GuestCustomNotSupported < VCenterError
112
+ error_key(:guest_custom_not_supported)
113
+ end
86
114
  end
87
115
  end
88
116
  end
@@ -48,8 +48,10 @@ module VagrantPlugins
48
48
  end
49
49
 
50
50
  def self.setup_i18n
51
- I18n.load_path << File.expand_path('locales/en.yml',
52
- VCenter.source_root)
51
+ I18n.load_path << File.expand_path(
52
+ 'locales/en.yml',
53
+ VCenter.source_root
54
+ )
53
55
  I18n.reload!
54
56
  end
55
57
 
@@ -1,6 +1,6 @@
1
1
  module VagrantPlugins
2
2
  # Set version for vagrant-vcenter gem.
3
3
  module VCenter
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.3'
5
5
  end
6
6
  end
@@ -1,4 +1,4 @@
1
- en:
1
+ en:
2
2
  vagrant_vcenter:
3
3
  power:
4
4
  vm_not_created: |-
@@ -9,7 +9,7 @@ en:
9
9
  VM is already running
10
10
  vm_halted_cannot_suspend: |-
11
11
  VM is not running or already suspended, cannot suspend it.
12
- config:
12
+ config:
13
13
  hostname: |-
14
14
  Configuration must specify a vCenter hostname
15
15
  username: |-
@@ -20,7 +20,7 @@ en:
20
20
  Configuration must specify a Datastore (for the VM templates images)
21
21
  datacenter_name: |-
22
22
  Configuration must specify a vCenter Datacenter
23
- computer_name: |-
23
+ compute_name: |-
24
24
  Configuration must specify a compute resource name
25
25
  network_name: |-
26
26
  Configuration must specify a resource pool name
@@ -34,7 +34,7 @@ en:
34
34
  Configuration must specify a gateway
35
35
  netmask: |-
36
36
  Configuration must specify a netmask
37
- states:
37
+ states:
38
38
  not_created: |-
39
39
  The environment has not yet been created. Run `vagrant up` to
40
40
  create the environment. If a machine is not created, only the
@@ -50,3 +50,31 @@ en:
50
50
  shut it down forcefully, or you can run `vagrant suspend` to simply
51
51
  suspend the virtual machine. In either case, to restart it again,
52
52
  simply run `vagrant up`.
53
+ unknown: |-
54
+ The VM state cannot be retrieved from vCenter. Please contact your
55
+ vCenter administrator for more informations.
56
+ errors:
57
+ datacenter_not_found: |-
58
+ The Datacenter '%{datacenter_name}' was not found in this environment.
59
+ Verify that your Vagrantfile settings are correct.
60
+ compute_not_found: |-
61
+ The Cluster or Host '%{compute_name}' was not found in this environment.
62
+ Verify that your Vagrantfile settings are correct.
63
+ datastore_not_found: |-
64
+ The Datastore %{datastore_name} was not found in this environment.
65
+ Verify that your Vagrantfile settings are correct.
66
+ network_not_found: |-
67
+ The Network %{network_name} was not found in this environment.
68
+ Verify that your Vagrantfile settings are correct.
69
+ machine_not_running: |-
70
+ The Machine %{machine_name} is not currently running...
71
+ To start the VM you can simply run `vagrant up %{machine_name}`
72
+ vm_not_found: |-
73
+ The Virtual Machine %{vm_name} was not found in this environment.
74
+ This should not happen, please log an issue on Github
75
+ guest_custom_not_supported: |-
76
+ The Guest Customization process for %{type} is not supported.
77
+
78
+
79
+
80
+
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
3
  require 'vagrant-vcenter/version'
3
4
 
@@ -7,19 +8,20 @@ Gem::Specification.new do |s|
7
8
  s.platform = Gem::Platform::RUBY
8
9
  s.authors = 'Fabio Rapposelli'
9
10
  s.email = 'fabio@gosddc.com'
10
- s.homepage = 'https://github.com/gosddc/vagrant-vcenter'
11
+ s.homepage = 'https://github.com/frapposelli/vagrant-vcenter'
11
12
  s.license = 'MIT'
12
13
  s.summary = 'VMware vCenter® Vagrant provider'
13
14
  s.description = 'Enables Vagrant to manage machines with VMware vCenter®.'
14
15
 
15
16
  s.add_runtime_dependency 'vagrant-rbvmomi', '~> 1.8.1'
16
17
  s.add_runtime_dependency 'log4r', '~> 1.1.10'
17
- s.add_runtime_dependency 'pry'
18
18
 
19
+ s.add_development_dependency 'bundler'
19
20
  s.add_development_dependency 'rake'
20
21
  s.add_development_dependency 'rspec-core', '~> 2.12.2'
21
22
  s.add_development_dependency 'rspec-expectations', '~> 2.12.1'
22
23
  s.add_development_dependency 'rspec-mocks', '~> 2.12.1'
24
+ s.add_development_dependency 'rubocop'
23
25
 
24
26
  s.files = `git ls-files`.split($RS)
25
27
  s.executables = s.files.grep(/^bin/) { |f| File.basename(f) }
metadata CHANGED
@@ -1,121 +1,136 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-vcenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Rapposelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-15 00:00:00.000000000 Z
11
+ date: 2016-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vagrant-rbvmomi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.8.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.8.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: log4r
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.1.10
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.1.10
41
41
  - !ruby/object:Gem::Dependency
42
- name: pry
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- type: :runtime
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-core
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 2.12.2
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.12.2
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec-expectations
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 2.12.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 2.12.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec-mocks
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: 2.12.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 2.12.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: Enables Vagrant to manage machines with VMware vCenter®.
112
126
  email: fabio@gosddc.com
113
127
  executables: []
114
128
  extensions: []
115
129
  extra_rdoc_files: []
116
130
  files:
117
- - .gitignore
118
- - .rubocop.yml
131
+ - ".gitignore"
132
+ - ".rubocop.yml"
133
+ - ".ruby-version"
119
134
  - Gemfile
120
135
  - LICENSE
121
136
  - README.md
@@ -153,7 +168,7 @@ files:
153
168
  - lib/vagrant-vcenter/version.rb
154
169
  - locales/en.yml
155
170
  - vagrant-vcenter.gemspec
156
- homepage: https://github.com/gosddc/vagrant-vcenter
171
+ homepage: https://github.com/frapposelli/vagrant-vcenter
157
172
  licenses:
158
173
  - MIT
159
174
  metadata: {}
@@ -163,19 +178,18 @@ require_paths:
163
178
  - lib
164
179
  required_ruby_version: !ruby/object:Gem::Requirement
165
180
  requirements:
166
- - - '>='
181
+ - - ">="
167
182
  - !ruby/object:Gem::Version
168
183
  version: '0'
169
184
  required_rubygems_version: !ruby/object:Gem::Requirement
170
185
  requirements:
171
- - - '>='
186
+ - - ">="
172
187
  - !ruby/object:Gem::Version
173
188
  version: '0'
174
189
  requirements: []
175
190
  rubyforge_project:
176
- rubygems_version: 2.1.8
191
+ rubygems_version: 2.4.5.1
177
192
  signing_key:
178
193
  specification_version: 4
179
194
  summary: VMware vCenter® Vagrant provider
180
195
  test_files: []
181
- has_rdoc: