bosh_vsphere_cpi 1.2865.0 → 1.2881.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61901cfb3ea1b5238cfea27df709f21128b701d0
4
- data.tar.gz: fb1532f1e12449573b112c958706370f7248f29c
3
+ metadata.gz: 709f8ea4d8fdcbce3a60c83d718666dfcb5b0405
4
+ data.tar.gz: f2b312d3746cce0b6c08d7d9e973abc23553b653
5
5
  SHA512:
6
- metadata.gz: 3f977fff415d9170c4ed358273bada7dbd455a0ae4b631a2bb67e8def4d7f0c1fe8c34673c33d078e80d75cb791c51b33d7dec64dff5b388f06e910db3f191cc
7
- data.tar.gz: 6caff7a89146bf0166397eb8d4d0c8da35ceeb6752347801d017637f3608cc4be3000589376007fe8b0b712e9307e50b18b8d9ec47b06e3d6ad5335758f70b1e
6
+ metadata.gz: 1fbc8f30dc769f5727ad279240b59aacd9ca3b2370ff0be575cfc2fe6edd34fb049e0909e18895486903c9ff9e2ee02273bf1582e38e133f3895deb1f00dc71f
7
+ data.tar.gz: f1fbc214c332fc82e17633becfd900aee187530667a87e6a1dae2886e6ecb6ee30738e798e2fdf294589db71752c01e6ee834aed96664296ccdd7896c6e4e3d1
data/bin/vsphere_cpi CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'yaml'
5
- require 'sequel'
6
5
  require 'logger'
7
6
  require 'cloud'
8
7
  require 'cloud/vsphere'
@@ -11,26 +10,11 @@ require 'tmpdir'
11
10
  require 'bosh/cpi'
12
11
  require 'bosh/cpi/cli'
13
12
 
14
- Sequel.extension(:migration)
15
-
16
13
  cpi_config = YAML.load_file(ARGV.shift)
17
- db_config = cpi_config.fetch('db')
18
-
19
- require 'sequel/adapters/sqlite' if db_config['adapter'] == 'sqlite'
20
-
21
- connection_options = db_config.delete('connection_options') { {} }
22
- db_config.delete_if { |_, v| v.to_s.empty? }
23
- db_config = db_config.merge(connection_options)
24
-
25
- db = Sequel.connect(db_config)
26
-
27
- db_migrations_path = File.expand_path('../../db/migrations', __FILE__)
28
- Sequel::TimestampMigrator.new(db, db_migrations_path, {table: 'vsphere_cpi_schema'}).run
29
14
 
30
15
  Bosh::Clouds::Config.configure(OpenStruct.new(
31
16
  logger: Logger.new(STDERR),
32
17
  task_checkpoint: nil,
33
- db: db,
34
18
  ))
35
19
 
36
20
  cloud_properties = cpi_config['cloud']['properties']
@@ -8,17 +8,10 @@ end
8
8
  require 'yaml'
9
9
 
10
10
  require 'pry'
11
- require 'sequel'
12
- require 'sequel/adapters/sqlite'
13
11
  require 'cloud'
14
12
  require 'cloud/vsphere'
15
13
 
16
- db = Sequel.sqlite
17
- Sequel.extension :migration
18
-
19
- Sequel::TimestampMigrator.new(db, File.expand_path('../../db/migrations', __FILE__), {}).run
20
-
21
- bosh_director_config = OpenStruct.new(logger: Logger.new(STDOUT), uuid: 'uuid', task_checkpoint: nil, db: Sequel.sqlite)
14
+ bosh_director_config = OpenStruct.new(logger: Logger.new(STDOUT), uuid: 'uuid', task_checkpoint: nil)
22
15
 
23
16
  Bosh::Clouds::Config.configure(bosh_director_config)
24
17
 
@@ -32,4 +25,4 @@ puts "You are connected to #{vsphere_properties['vcenters'].first['host']}"
32
25
  # Welcome to the vSphere console!
33
26
  # you can access the cpi through the 'cpi' object
34
27
 
35
- Pry.start binding
28
+ Pry.start binding
@@ -70,8 +70,8 @@ module VSphereCloud
70
70
  end
71
71
  end
72
72
 
73
- def power_off_vm(vm)
74
- task = vm.power_off
73
+ def power_off_vm(vm_mob)
74
+ task = vm_mob.power_off
75
75
  wait_for_task(task)
76
76
  end
77
77
 
@@ -92,43 +92,26 @@ module VSphereCloud
92
92
  end
93
93
 
94
94
  def delete_disk(datacenter, path)
95
- tasks = []
95
+ base_path = path.chomp(File.extname(path))
96
96
  [".vmdk", "-flat.vmdk"].each do |extension|
97
- tasks << @service_content.file_manager.delete_file("#{path}#{extension}", datacenter)
98
- end
99
- tasks.each do |task|
100
- begin
101
- wait_for_task(task)
102
- rescue => e
103
- unless e.message =~ /File .* was not found/
104
- raise e
105
- end
106
- end
97
+ delete_path(datacenter, "#{base_path}#{extension}")
107
98
  end
108
99
  end
109
100
 
110
101
  def move_disk(source_datacenter, source_path, dest_datacenter, dest_path)
111
102
  tasks = []
103
+ base_source_path = source_path.chomp(File.extname(source_path))
104
+ base_dest_path = source_path.chomp(File.extname(dest_path))
112
105
  [".vmdk", "-flat.vmdk"].each do |extension|
113
106
  tasks << @service_content.file_manager.move_file(
114
- "#{source_path}#{extension}", source_datacenter,
115
- "#{dest_path}#{extension}", dest_datacenter, false
107
+ "#{base_source_path}#{extension}", source_datacenter,
108
+ "#{base_dest_path}#{extension}", dest_datacenter, false
116
109
  )
117
110
  end
118
111
 
119
112
  tasks.each { |task| wait_for_task(task) }
120
113
  end
121
114
 
122
- def copy_disk(source_datacenter, source_path, dest_datacenter, dest_path)
123
- tasks = []
124
- [".vmdk", "-flat.vmdk"].each do |extension|
125
- tasks << @service_content.file_manager.copy_file("#{source_path}#{extension}", source_datacenter,
126
- "#{dest_path}#{extension}", dest_datacenter, false)
127
- end
128
-
129
- tasks.each { |task| wait_for_task(task) }
130
- end
131
-
132
115
  def create_datastore_folder(folder_path, datacenter)
133
116
  @service_content.file_manager.make_directory(folder_path, datacenter, true)
134
117
  end
@@ -152,22 +135,6 @@ module VSphereCloud
152
135
  wait_for_task(task)
153
136
  end
154
137
 
155
- def has_disk?(disk_path, disk_datacenter)
156
- datacenter = find_by_inventory_path(disk_datacenter)
157
-
158
- [".vmdk", "-flat.vmdk"].each do |extension|
159
- begin
160
- uuid = @service_content.virtual_disk_manager.query_virtual_disk_uuid(
161
- "#{disk_path}#{extension}", datacenter
162
- )
163
- return true if uuid
164
- rescue VimSdk::SoapError
165
- end
166
- end
167
-
168
- false
169
- end
170
-
171
138
  def find_by_inventory_path(path)
172
139
  full_path = Array(path).join("/")
173
140
  @service_content.search_index.find_by_inventory_path(full_path)
@@ -245,8 +212,38 @@ module VSphereCloud
245
212
  result
246
213
  end
247
214
 
215
+ def find_disk(disk_cid, datastore, disk_folder)
216
+ disk_path = "[#{datastore.name}] #{disk_folder}/#{disk_cid}.vmdk"
217
+ disk_size_in_mb = find_disk_size_using_browser(datastore, disk_cid, disk_folder)
218
+ disk_size_in_mb.nil? ? nil : Resources::Disk.new(disk_cid, disk_size_in_mb, datastore, disk_path)
219
+ end
220
+
248
221
  private
249
222
 
223
+ def find_disk_size_using_browser(datastore, disk_cid, disk_folder)
224
+ search_spec_details = VimSdk::Vim::Host::DatastoreBrowser::FileInfo::Details.new
225
+ search_spec_details.file_type = true # actually return VmDiskInfos not FileInfos
226
+
227
+ query_details = VimSdk::Vim::Host::DatastoreBrowser::VmDiskQuery::Details.new
228
+ query_details.capacity_kb = true
229
+
230
+ query = VimSdk::Vim::Host::DatastoreBrowser::VmDiskQuery.new
231
+ query.details = query_details
232
+
233
+ search_spec = VimSdk::Vim::Host::DatastoreBrowser::SearchSpec.new
234
+ search_spec.details = search_spec_details
235
+ search_spec.match_pattern = ["#{disk_cid}.vmdk"]
236
+ search_spec.query = [query]
237
+
238
+ vm_disk_infos = wait_for_task(datastore.mob.browser.search("[#{datastore.name}] #{disk_folder}", search_spec)).file
239
+
240
+ return nil if vm_disk_infos.empty?
241
+
242
+ vm_disk_infos.first.capacity_kb / 1024
243
+ rescue VimSdk::SoapError
244
+ nil
245
+ end
246
+
250
247
  def find_perf_metric_names(mob, names)
251
248
  @lock.synchronize do
252
249
  unless @metrics_cache.has_key?(mob.class)