forked from ManageIQ/manageiq
-
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 best fit logic for transformations moving vms to openstack
- Loading branch information
Showing
2 changed files
with
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class TransformationMapping | ||
class CloudBestFit | ||
attr_reader :source_vm, :destination_manager | ||
def initialize(source_vm, destination_manager) | ||
@source_vm = source_vm | ||
@destination_manager = destination_manager | ||
end | ||
|
||
def available_fit_flavors | ||
@available_fit_flavors ||= destination_manager.flavors.where( | ||
:cpus => source_vm.cpu_total_cores..Float::INFINITY, | ||
:memory => (source_vm.hardware.memory_mb * 1.megabyte)..Float::INFINITY | ||
).order(:cpus, :memory) | ||
end | ||
|
||
def best_fit_flavor | ||
available_fit_flavors.first | ||
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,37 @@ | ||
describe TransformationMapping::CloudBestFit do | ||
let(:ems) { FactoryGirl.create(:ems_openstack) } | ||
let(:vm) { FactoryGirl.create(:vm_vmware, :hardware => vm_hardware) } | ||
let(:vm_hardware) { FactoryGirl.create(:hardware, :cpu1x2, :ram1GB) } | ||
|
||
subject { described_class.new(vm, ems) } | ||
|
||
it "no flavors on the provider" do | ||
expect(subject.available_fit_flavors).to match_array([]) | ||
expect(subject.best_fit_flavor).to be_nil | ||
end | ||
|
||
it "no flavors match" do | ||
ems.flavors.create!(:cpus => 1, :memory => 512.megabytes) | ||
|
||
expect(subject.available_fit_flavors).to match_array([]) | ||
expect(subject.best_fit_flavor).to be_nil | ||
end | ||
|
||
it "one flavor matches" do | ||
ems.flavors.create!(:cpus => 2, :memory => 512.megabytes) | ||
flavor = ems.flavors.create!(:cpus => 2, :memory => 1.gigabyte) | ||
|
||
expect(subject.available_fit_flavors).to match_array([flavor]) | ||
expect(subject.best_fit_flavor).to eq(flavor) | ||
end | ||
|
||
it "multiple flavors match" do | ||
ems.flavors.create!(:cpus => 2, :memory => 512.megabytes) | ||
flavor1 = ems.flavors.create!(:cpus => 2, :memory => 1.gigabyte) | ||
flavor2 = ems.flavors.create!(:cpus => 2, :memory => 2.gigabytes) | ||
flavor3 = ems.flavors.create!(:cpus => 4, :memory => 1.gigabyte) | ||
|
||
expect(subject.available_fit_flavors).to match_array([flavor1, flavor2, flavor3]) | ||
expect(subject.best_fit_flavor).to eq(flavor1) | ||
end | ||
end |