Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add best fit logic for transformations moving vms to openstack #17880

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/models/transformation_mapping/cloud_best_fit.rb
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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agrare Are there any other attributes that we need to match up?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bdunne flavors just have a total number of CPUs so cpu_total_cores is the correct attribute 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agrare Do we need to worry about root disk or any of those attributes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh thought you meant specifically about CPUs. I don't know how/if the flavor's root_disk_size is used by the virt-v2v migration tool. @aufi @fdupont-redhat do you know?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @aufi @mansam @fdupont-redhat do you guy know what is required re: target flavor

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we have this information from fleecing the VM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So worst case, if we pick a flavor that has a root disk that is smaller than the VM that we're migrating from will the conversion fail?

/cc @rwmjones if you're reading this :D @fdupont-redhat because I know you get notifications

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agrare TBH, I don't know. We should test it.
@rwjones do you have an environment to test it ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bdunne I say we merge this as-is with cpu/memory and come back and revisit after we get clarity on the disk size issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, it's easy to add more later once we know what the right answer is.

: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
37 changes: 37 additions & 0 deletions spec/models/transformation_mapping/cloud_best_fit_spec.rb
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