forked from fog/fog-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to create update and delete Resource Pools fog#253
- Loading branch information
1 parent
1e3bd2a
commit 8d197e6
Showing
6 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module Fog | ||
module Vsphere | ||
class Compute | ||
class Real | ||
def create_resource_pool(attributes = {}) | ||
cluster = get_raw_cluster(attributes[:cluster], attributes[:datacenter]) | ||
|
||
root_resource_pool = if attributes[:root_resource_pool_name] | ||
cluster.resourcePool.find attributes[:root_resource_pool_name] | ||
else | ||
cluster.resourcePool | ||
end | ||
|
||
root_resource_pool.CreateResourcePool( | ||
name: attributes[:name], | ||
spec: get_resource_pool_spec(attributes) | ||
) | ||
|
||
get_resource_pool(attributes[:name], attributes[:cluster], attributes[:datacenter]) | ||
end | ||
|
||
private | ||
|
||
def get_resource_pool_spec(attributes = {}) | ||
cpu_shares_level = attributes.fetch(:cpu_shares_level, 'normal') | ||
cpu_reservation = attributes.fetch(:cpu_reservation, 0) | ||
cpu_expandable_reservation = attributes.fetch(:cpu_expandable_reservation, false) | ||
cpu_limit = attributes.fetch(:cpu_limit, -1) | ||
cpu_shares = attributes.fetch(:cpu_shares, 0) | ||
|
||
memory_shares_level = attributes.fetch(:memory_shares_level, 'normal') | ||
memory_reservation = attributes.fetch(:memory_reservation, 0) | ||
memory_expandable_reservation = attributes.fetch(:memory_expandable_reservation, false) | ||
memory_limit = attributes.fetch(:memory_limit, -1) | ||
memory_shares = attributes.fetch(:memory_shares, 0) | ||
|
||
RbVmomi::VIM.ResourceConfigSpec( | ||
cpuAllocation: RbVmomi::VIM.ResourceAllocationInfo( | ||
reservation: cpu_reservation, | ||
limit: cpu_limit, | ||
expandableReservation: cpu_expandable_reservation, | ||
shares: RbVmomi::VIM.SharesInfo( | ||
level: RbVmomi::VIM.SharesLevel(cpu_shares_level), | ||
shares: cpu_shares | ||
) | ||
), | ||
memoryAllocation: RbVmomi::VIM.ResourceAllocationInfo( | ||
reservation: memory_reservation, | ||
limit: memory_limit, | ||
expandableReservation: memory_expandable_reservation, | ||
shares: RbVmomi::VIM.SharesInfo( | ||
level: RbVmomi::VIM.SharesLevel(memory_shares_level), | ||
shares: memory_shares | ||
) | ||
) | ||
) | ||
end | ||
end | ||
|
||
class Mock | ||
def create_resource_pool(attributes = {}); end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Fog | ||
module Vsphere | ||
class Compute | ||
class Real | ||
def destroy_resource_pool(attributes = {}) | ||
get_raw_resource_pool_by_ref(attributes).Destroy_Task().wait_for_completion | ||
end | ||
end | ||
|
||
class Mock | ||
def destroy_resource_pool(attributes = {}); end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Fog | ||
module Vsphere | ||
class Compute | ||
class Real | ||
def update_resource_pool(attributes = {}) | ||
raw_resource_pool = get_raw_resource_pool_by_ref(attributes) | ||
|
||
raw_resource_pool.UpdateConfig( | ||
name: attributes[:name], | ||
config: get_resource_pool_spec(attributes) | ||
) | ||
|
||
get_resource_pool(attributes[:name], attributes[:cluster], attributes[:datacenter]) | ||
end | ||
|
||
private | ||
|
||
def get_raw_resource_pool_by_ref(attributes = {}) | ||
dc = find_raw_datacenter(attributes[:datacenter]) | ||
cluster = dc.find_compute_resource(attributes[:cluster]) | ||
|
||
list_raw_resource_pools(cluster).detect { |rp| rp._ref == attributes[:ref] } | ||
end | ||
end | ||
|
||
class Mock | ||
def update_resource_pool(attributes = {}); end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require_relative '../../test_helper' | ||
|
||
describe Fog::Vsphere::Compute::Real do | ||
include Fog::Vsphere::TestHelper | ||
|
||
before { Fog.unmock! } | ||
after { Fog.mock! } | ||
|
||
let(:compute) { prepare_compute } | ||
|
||
describe '#create_resource_pool' do | ||
let(:resource_pool_name) { 'ResourcePool' } | ||
|
||
it 'creates resource pool' do | ||
with_webmock_cassette('create_resource_pool') do | ||
resource_pool = compute.create_resource_pool( | ||
datacenter: 'DC1', | ||
cluster: 'vc-qa-DC1-cluster1', | ||
name: resource_pool_name, | ||
cpu_reservation: '2000', | ||
cpu_shares_level: 'normal', | ||
cpu_expandable_reservation: false, | ||
cpu_limit: -1, | ||
cpu_shares: 0, | ||
memory_reservation: '512', | ||
memory_shares_level: 'normal', | ||
memory_expandable_reservation: false, | ||
memory_limit: -1, | ||
memory_shares: 0 | ||
) | ||
assert_equal(resource_pool[:name], resource_pool_name) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require_relative '../../test_helper' | ||
|
||
describe Fog::Vsphere::Compute::Real do | ||
include Fog::Vsphere::TestHelper | ||
|
||
before { Fog.unmock! } | ||
after { Fog.mock! } | ||
|
||
let(:compute) { prepare_compute } | ||
|
||
describe '#update_resource_pool' do | ||
let(:resource_pool_name) { 'ResourcePool1' } | ||
|
||
it 'updates resource pool' do | ||
with_webmock_cassette('update_resource_pool') do | ||
resource_pool = compute.update_resource_pool( | ||
datacenter: 'DC1', | ||
cluster: 'vc-qa-DC1-cluster1', | ||
name: resource_pool_name, | ||
cpu_reservation: '3000', | ||
memory_reservation: '1024', | ||
ref: 'resgroup-5764' | ||
) | ||
assert_equal(resource_pool[:name], resource_pool_name) | ||
end | ||
end | ||
end | ||
end |