class SISFC::DataCenter
Attributes
dcid[R]
location_id[R]
Public Class Methods
new(id:, location_id:, name:, type:, **opts)
click to toggle source
# File lib/sisfc/data_center.rb, line 14 def initialize(id:, location_id:, name:, type:, **opts) @dcid = id @location_id = location_id @vms = {} @vm_type_count = {} @name = name @type = type raise ArgumentError, "Unsupported type!" unless [ :private, :public ].include?(@type) @availability_check_proc = opts[:maximum_vm_capacity] end
Public Instance Methods
add_vm(vm, component_name)
click to toggle source
returns false in case no more VMs can be allocated
# File lib/sisfc/data_center.rb, line 26 def add_vm(vm, component_name) @vms[component_name] ||= [] @vm_type_count[vm.size] ||= 0 raise 'Error! VM is already present!' if @vms[component_name].include? vm # defer availablility check to user specified procedure if @availability_check_proc return false unless @availability_check_proc.call(@vm_type_count) end # allocate VM @vms[component_name] << vm @vm_type_count[vm.size] += 1 end
get_random_vm(component_name)
click to toggle source
returns nil in case no VM
for component component_name is running
# File lib/sisfc/data_center.rb, line 51 def get_random_vm(component_name) if @vms.has_key? component_name @vms[component_name].sample end end
private?()
click to toggle source
# File lib/sisfc/data_center.rb, line 62 def private? @type == :private end
public?()
click to toggle source
# File lib/sisfc/data_center.rb, line 66 def public? @type == :public end
remove_vm(vm, component_name)
click to toggle source
# File lib/sisfc/data_center.rb, line 42 def remove_vm(vm, component_name) if @vms.has_key? component_name and @vms[component_name].include? vm raise 'Error! Inconsistent number of VMs!' unless @vm_type_count[vm.size] >= 1 @vm_type_count[vm.size] += 1 @vms.delete(vm) end end
to_s()
click to toggle source
# File lib/sisfc/data_center.rb, line 57 def to_s "Data center #{@dcid}, with VMs:" + @vms.inject("") {|s,(k,v)| s += " (#{k}: #{v.size})" } end