|
| 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