fog-vsphere 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/fog/vsphere/models/compute/folder.rb +3 -2
- data/lib/fog/vsphere/models/compute/servers.rb +15 -2
- data/lib/fog/vsphere/requests/compute/create_vm.rb +1 -1
- data/lib/fog/vsphere/requests/compute/get_folder.rb +5 -1
- data/lib/fog/vsphere/requests/compute/get_virtual_machine.rb +19 -12
- data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +24 -6
- data/lib/fog/vsphere/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96a65cbc2b8dff64e149f6e108ef19d5ddaa5011
|
4
|
+
data.tar.gz: a531b24b12fe6410476a4532f9c4c5584125bb12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a323cdbb8d6541a7a9597e9bf7628b71e13993a322334ed4beeec504ac68ec87a4d7342a850213c2f6b0f352fceb5343cddab989f5cb05556aba748795c0e834
|
7
|
+
data.tar.gz: d52f7e564b586cd2eb5727b260f5e51c2394486175d55a975a69d72fd3591acf727a85032bf92ef272d06224b1b15f8431c4e7c1bdebf5c5105b61c38d5d5a3c
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## v0.5.0 1/18/2016
|
2
|
+
|
3
|
+
* Fix wrong string assignment in storage pods
|
4
|
+
* Pass what we know about the VM from the folder to VM creation
|
5
|
+
* Improve performance of recursive get_vm_by_name
|
6
|
+
* Ensure folder.vms only searches the VMs in that folder
|
7
|
+
* Add recursive parameter to folder.vms to search recursively
|
8
|
+
|
1
9
|
## v0.4.0 12/15/2015
|
2
10
|
|
3
11
|
* Fix cannot create vm on "Resources" resource pool
|
@@ -10,9 +10,10 @@ module Fog
|
|
10
10
|
attribute :path
|
11
11
|
attribute :type
|
12
12
|
|
13
|
-
|
13
|
+
# Pass :recursive => true to get a Servers object that searches for VM names recursively
|
14
|
+
def vms(options = {})
|
14
15
|
return [] if type.to_s != 'vm'
|
15
|
-
service.servers(:folder => path, :datacenter => datacenter)
|
16
|
+
service.servers(:folder => path, :datacenter => datacenter, :recursive => options[:recursive])
|
16
17
|
end
|
17
18
|
|
18
19
|
def to_s
|
@@ -10,6 +10,7 @@ module Fog
|
|
10
10
|
attr_accessor :cluster
|
11
11
|
attr_accessor :resource_pool
|
12
12
|
attr_accessor :folder
|
13
|
+
attr_accessor :recursive
|
13
14
|
|
14
15
|
# 'folder' => '/Datacenters/vm/Jeff/Templates' will be MUCH faster.
|
15
16
|
# than simply listing everything.
|
@@ -19,17 +20,29 @@ module Fog
|
|
19
20
|
:cluster => cluster,
|
20
21
|
:network => network,
|
21
22
|
:resource_pool => resource_pool,
|
22
|
-
:folder => folder
|
23
|
+
:folder => folder,
|
24
|
+
:recursive => recursive,
|
23
25
|
}.merge(filters)
|
24
26
|
|
25
27
|
load service.list_virtual_machines(f)
|
26
28
|
end
|
27
29
|
|
28
30
|
def get(id, datacenter = nil)
|
29
|
-
new service.get_virtual_machine id, datacenter
|
31
|
+
new service.get_virtual_machine id, datacenter, folder, recursive
|
30
32
|
rescue Fog::Compute::Vsphere::NotFound
|
31
33
|
nil
|
32
34
|
end
|
35
|
+
|
36
|
+
# Pass attributes we know about down to any VM we're creating
|
37
|
+
def new(attributes = {})
|
38
|
+
super({
|
39
|
+
:datacenter => datacenter,
|
40
|
+
:path => folder,
|
41
|
+
:cluster => cluster,
|
42
|
+
:resource_pool => resource_pool,
|
43
|
+
}.merge(attributes))
|
44
|
+
end
|
45
|
+
|
33
46
|
end
|
34
47
|
end
|
35
48
|
end
|
@@ -53,9 +53,13 @@ module Fog
|
|
53
53
|
:parent => folder.parent.name,
|
54
54
|
:datacenter => datacenter_name,
|
55
55
|
:type => folder_type(folder),
|
56
|
-
:path =>
|
56
|
+
:path => folder_path(folder),
|
57
57
|
}
|
58
58
|
end
|
59
|
+
|
60
|
+
def folder_path(folder)
|
61
|
+
"/"+folder.path.map(&:last).join('/')
|
62
|
+
end
|
59
63
|
|
60
64
|
def folder_type(folder)
|
61
65
|
types = folder.childType
|
@@ -2,14 +2,14 @@ module Fog
|
|
2
2
|
module Compute
|
3
3
|
class Vsphere
|
4
4
|
class Real
|
5
|
-
def get_virtual_machine(id, datacenter_name = nil)
|
5
|
+
def get_virtual_machine(id, datacenter_name = nil, folder = nil, recursive = false)
|
6
6
|
# The larger the VM list the longer it will take if not searching based on UUID.
|
7
|
-
convert_vm_mob_ref_to_attr_hash(get_vm_ref(id, datacenter_name))
|
7
|
+
convert_vm_mob_ref_to_attr_hash(get_vm_ref(id, datacenter_name, folder, recursive))
|
8
8
|
end
|
9
9
|
|
10
10
|
protected
|
11
11
|
|
12
|
-
def get_vm_ref(id, dc = nil)
|
12
|
+
def get_vm_ref(id, dc = nil, folder = nil, recursive = false)
|
13
13
|
raw_datacenter = find_raw_datacenter(dc) if dc
|
14
14
|
vm = case is_uuid?(id)
|
15
15
|
# UUID based
|
@@ -20,29 +20,36 @@ module Fog
|
|
20
20
|
else
|
21
21
|
# try to find based on VM name
|
22
22
|
if dc
|
23
|
-
get_vm_by_name(id, dc)
|
23
|
+
get_vm_by_name(id, dc, folder, recursive)
|
24
24
|
else
|
25
|
-
raw_datacenters.map { |d| get_vm_by_name(id, d["name"])}.compact.first
|
25
|
+
raw_datacenters.map { |d| get_vm_by_name(id, d["name"], folder, recursive)}.compact.first
|
26
26
|
end
|
27
27
|
end
|
28
28
|
vm ? vm : raise(Fog::Compute::Vsphere::NotFound, "#{id} was not found")
|
29
29
|
end
|
30
30
|
|
31
|
-
def get_vm_by_name(name, dc)
|
32
|
-
|
31
|
+
def get_vm_by_name(name, dc, folder, recursive)
|
32
|
+
if folder
|
33
|
+
# This returns an Enumerator, which when called with .find will
|
34
|
+
# search only until it finds the VM we're looking for
|
35
|
+
vms = raw_list_all_virtual_machines_in_folder(folder, dc, recursive)
|
36
|
+
else
|
37
|
+
vms = raw_list_all_virtual_machines(dc)
|
38
|
+
end
|
33
39
|
|
34
|
-
|
40
|
+
if name.include?('/')
|
35
41
|
folder = File.dirname(name)
|
36
42
|
basename = File.basename(name)
|
37
|
-
vms.
|
43
|
+
vms.find { |v| v["name"] == basename && v.parent.pretty_path.include?(folder) }
|
38
44
|
else
|
39
|
-
vms.
|
45
|
+
vms.find { |v| v["name"] == name }
|
40
46
|
end
|
41
|
-
end
|
47
|
+
end
|
48
|
+
|
42
49
|
end
|
43
50
|
|
44
51
|
class Mock
|
45
|
-
def get_virtual_machine(id, datacenter_name = nil)
|
52
|
+
def get_virtual_machine(id, datacenter_name = nil, folder = nil, recursive = false)
|
46
53
|
if is_uuid?(id)
|
47
54
|
vm = list_virtual_machines({ 'instance_uuid' => id, 'datacenter' => datacenter_name }).first
|
48
55
|
else
|
@@ -11,7 +11,7 @@ module Fog
|
|
11
11
|
if options['instance_uuid'] then
|
12
12
|
[get_virtual_machine(options['instance_uuid'])]
|
13
13
|
elsif options[:folder] && options[:datacenter] then
|
14
|
-
list_all_virtual_machines_in_folder(options[:folder], options[:datacenter])
|
14
|
+
list_all_virtual_machines_in_folder(options[:folder], options[:datacenter], options[:recursive])
|
15
15
|
else
|
16
16
|
list_all_virtual_machines(options)
|
17
17
|
end
|
@@ -20,15 +20,33 @@ module Fog
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
def list_all_virtual_machines_in_folder(path, datacenter_name)
|
24
|
-
|
25
|
-
|
26
|
-
vms = folder.children.grep(RbVmomi::VIM::VirtualMachine)
|
23
|
+
def list_all_virtual_machines_in_folder(path, datacenter_name, recursive)
|
24
|
+
vms = raw_list_all_virtual_machines_in_folder(path, datacenter_name, recursive).to_a
|
27
25
|
# remove all template based virtual machines
|
28
26
|
vms.delete_if { |v| v.config.nil? or v.config.template }
|
29
27
|
vms.map(&method(:convert_vm_mob_ref_to_attr_hash))
|
30
28
|
end
|
31
|
-
|
29
|
+
|
30
|
+
def raw_list_all_virtual_machines_in_folder(path, datacenter_name, recursive)
|
31
|
+
folder = get_raw_vmfolder(path, datacenter_name)
|
32
|
+
folder_enumerator(folder, recursive)
|
33
|
+
end
|
34
|
+
|
35
|
+
# An enumerator for a folder. Enumerates all the VMs in the folder, recursively if
|
36
|
+
# passed recursive=true
|
37
|
+
def folder_enumerator(raw_folder, recursive)
|
38
|
+
Enumerator.new do |yielder|
|
39
|
+
raw_folder.children.each do |child|
|
40
|
+
case child
|
41
|
+
when RbVmomi::VIM::Folder
|
42
|
+
folder_enumerator(child, true).each {|item| yielder.yield item} if recursive
|
43
|
+
when RbVmomi::VIM::VirtualMachine
|
44
|
+
yielder.yield child
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
32
50
|
def list_all_virtual_machines(options = { })
|
33
51
|
raw_vms = raw_list_all_virtual_machines(options[:datacenter])
|
34
52
|
vms = convert_vm_view_to_attr_hash(raw_vms)
|
data/lib/fog/vsphere/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-vsphere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- J.R. Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-core
|
@@ -281,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
281
|
version: '0'
|
282
282
|
requirements: []
|
283
283
|
rubyforge_project:
|
284
|
-
rubygems_version: 2.
|
284
|
+
rubygems_version: 2.5.1
|
285
285
|
signing_key:
|
286
286
|
specification_version: 4
|
287
287
|
summary: Module for the 'fog' gem to support VMware vSphere.
|