Skip to content

Commit f121960

Browse files
committed
Add ability to create update and delete Resource Pools fog#253
1 parent 1e3bd2a commit f121960

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-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,49 @@
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+
root_resource_pool.CreateResourcePool(
15+
name: attributes[:name],
16+
spec: get_resource_pool_spec(attributes)
17+
)
18+
19+
get_resource_pool(attributes[:name], attributes[:cluster], attributes[:datacenter])
20+
end
21+
22+
private
23+
24+
def get_resource_pool_spec(attributes = {})
25+
RbVmomi::VIM.ResourceConfigSpec(
26+
cpuAllocation: get_resource_pool_allocation_spec(attributes[:cpu]),
27+
memoryAllocation: get_resource_pool_allocation_spec(attributes[:memory])
28+
)
29+
end
30+
31+
def get_resource_pool_allocation_spec(attributes = {})
32+
RbVmomi::VIM.ResourceAllocationInfo(
33+
reservation: attributes.fetch(:reservation, 0),
34+
limit: attributes.fetch(:limit, -1),
35+
expandableReservation: attributes.fetch(:expandable_reservation, false),
36+
shares: RbVmomi::VIM.SharesInfo(
37+
level: RbVmomi::VIM.SharesLevel(attributes.fetch(:shares_level, 'normal')),
38+
shares: attributes.fetch(:shares, 0)
39+
)
40+
)
41+
end
42+
end
43+
44+
class Mock
45+
def create_resource_pool(attributes = {}); end
46+
end
47+
end
48+
end
49+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Fog
2+
module Vsphere
3+
class Compute
4+
class Real
5+
def destroy_resource_pool(attributes = {})
6+
get_raw_resource_pool_by_ref(attributes).Destroy_Task().wait_for_completion
7+
end
8+
end
9+
10+
class Mock
11+
def destroy_resource_pool(attributes = {}); end
12+
end
13+
end
14+
end
15+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Fog
2+
module Vsphere
3+
class Compute
4+
class Real
5+
def update_resource_pool(attributes = {})
6+
raw_resource_pool = get_raw_resource_pool_by_ref(attributes)
7+
8+
raw_resource_pool.UpdateConfig(
9+
name: attributes[:name],
10+
config: get_resource_pool_spec(attributes)
11+
)
12+
13+
get_resource_pool(attributes[:name], attributes[:cluster], attributes[:datacenter])
14+
end
15+
16+
private
17+
18+
def get_raw_resource_pool_by_ref(attributes = {})
19+
dc = find_raw_datacenter(attributes[:datacenter])
20+
cluster = dc.find_compute_resource(attributes[:cluster])
21+
22+
list_raw_resource_pools(cluster).detect { |rp| rp._ref == attributes[:ref] }
23+
end
24+
end
25+
26+
class Mock
27+
def update_resource_pool(attributes = {}); end
28+
end
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)