Skip to content

Commit 08ee5d0

Browse files
committed
Add ability to create Resource Pools fog#253
1 parent 1e3bd2a commit 08ee5d0

File tree

4 files changed

+899
-0
lines changed

4 files changed

+899
-0
lines changed

lib/fog/vsphere/compute.rb

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class Compute < Fog::Service
7171
request :get_cluster
7272
request :list_resource_pools
7373
request :get_resource_pool
74+
request :create_resource_pool
75+
# request :update_resource_pool
76+
# request :destroy_resource_pool
7477
request :list_networks
7578
request :get_network
7679
request :list_datastores
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
module Fog
2+
module Vsphere
3+
class Compute
4+
class Real
5+
def create_resource_pool(attributes = {})
6+
cluster = get_raw_cluster(attributes[:cluster], attributes[:datacenter])
7+
8+
root_resource_pool = if attributes[:root_resource_pool_name]
9+
cluster.resourcePool.find attributes[:root_resource_pool_name]
10+
else
11+
cluster.resourcePool
12+
end
13+
14+
unless root_resource_pool
15+
raise ArgumentError, "Root resource pool #{attributes[:root_resource_pool_name]} could not be found!"
16+
end
17+
18+
root_resource_pool.CreateResourcePool(
19+
name: attributes[:name],
20+
spec: get_resource_pool_spec(attributes)
21+
)
22+
23+
get_resource_pool(attributes[:name], attributes[:cluster], attributes[:datacenter])
24+
end
25+
26+
private
27+
28+
def get_resource_pool_spec(attributes = {})
29+
cpu_shares_level = attributes.fetch(:cpu_shares_level, 'normal')
30+
cpu_reservation = attributes.fetch(:cpu_reservation, 0)
31+
cpu_expandable_reservation = attributes.fetch(:cpu_expandable_reservation, false)
32+
cpu_limit = attributes.fetch(:cpu_limit, -1)
33+
cpu_shares = attributes.fetch(:cpu_shares, 0)
34+
35+
memory_shares_level = attributes.fetch(:memory_shares_level, 'normal')
36+
memory_reservation = attributes.fetch(:memory_reservation, 0)
37+
memory_expandable_reservation = attributes.fetch(:memory_expandable_reservation, false)
38+
memory_limit = attributes.fetch(:memory_limit, -1)
39+
memory_shares = attributes.fetch(:memory_shares, 0)
40+
41+
RbVmomi::VIM.ResourceConfigSpec(
42+
cpuAllocation: RbVmomi::VIM.ResourceAllocationInfo(
43+
reservation: cpu_reservation,
44+
limit: cpu_limit,
45+
expandableReservation: cpu_expandable_reservation,
46+
shares: RbVmomi::VIM.SharesInfo(
47+
level: RbVmomi::VIM.SharesLevel(cpu_shares_level),
48+
shares: cpu_shares
49+
)
50+
),
51+
memoryAllocation: RbVmomi::VIM.ResourceAllocationInfo(
52+
reservation: memory_reservation,
53+
limit: memory_limit,
54+
expandableReservation: memory_expandable_reservation,
55+
shares: RbVmomi::VIM.SharesInfo(
56+
level: RbVmomi::VIM.SharesLevel(memory_shares_level),
57+
shares: memory_shares
58+
)
59+
)
60+
)
61+
end
62+
end
63+
64+
class Mock
65+
def create_resource_pool(attributes = {}); end
66+
end
67+
end
68+
end
69+
end

0 commit comments

Comments
 (0)