-
Notifications
You must be signed in to change notification settings - Fork 898
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 methods to conversion_host to build virt-v2v wrapper options #18033
Add methods to conversion_host to build virt-v2v wrapper options #18033
Conversation
@miq-bot add-label transformation, technical debt |
e6f0a70
to
8a918cb
Compare
app/models/conversion_host.rb
Outdated
|
||
def active_tasks | ||
ServiceTemplateTransformationPlanTask.where(:state => 'active').select do |task| | ||
task.conversion_host == self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move this to a relation so that we don't need to loop over tasks and it looks like .conversion_host
is itself a different db query with an options hash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we do that ? Simply add has_many :service_template_transformation_plan_task
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would mean a schema change on miq_request_tasks
, wouldn't it ? So too late for hammer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The relation between conversion_host and tasks is probably not that trivial. Currently, the ServiceTemplateTransformationPlanTask class is a sub-sub-class of MiqRequestTask, so the relationship would imply add a conversion_host_id
in miq_request_tasks
.
From a semantic point of view, this wouldn't make sense, as the conversion host is specific to ServiceTemplateTransformationPlanTask. But technically, it's pretty easy and can be safely ignore by other sub-classes of MiqRequestTask.
What do you think @agrare ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fdupont-redhat for starters this ServiceTemplateTransformationPlanTask
should be belongs_to :conversion_host
and yes we'd need to add a schema reference to the base class to do that.
Then this just becomes ConversionHost has_many :service_template_transformation_plan_tasks
(just haha that's a mouthful)
From a semantic point of view, this wouldn't make sense, as the conversion host is specific to ServiceTemplateTransformationPlanTask
yeah that's how STI works, all columns for all sub-classes go in the same table. I wish there was a better way
This way is going to perform really badly compared to a pure db query approach, though I guess no worse than the existing automate approach.
If we need to keep this for backport purposes I'm okay with that but lets put in the schema changes to get this right going forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agrare Here is the PR for schema change: ManageIQ/manageiq-schema#281.
Anyway, we're too late for Hammer, aren't we ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we had a window after they branched but before the first build but afaik @simaishi has cut a beta-1 tag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay @fdupont-redhat now that the schema change is in we can do this with a has_many and if you add a scope on :state => "active"
to MiqRequestTask
we can do the active tasks with -> { active }
app/models/conversion_host.rb
Outdated
return 'ssh' if ssh_transport_supported | ||
end | ||
|
||
def conversion_options(task) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do change the task to a true relationship, then this method could probably be replaced with a number of delegate methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely. What release are we targeting there ? Hammer or I-release ? Given that we're past code freeze for Hammer, I'd say, we're aiming I-release, unless we've got a derogation 😜
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the relationship is made so task belongs to conversion_host. Then, I'm not sure how I can delegate from conversion_host to task, as it has many tasks. That would require that the task is passed to the conversion. Is there a way to do it ? I'm a delegation newbie.
8a918cb
to
289c53f
Compare
9eafeab
to
02b51cc
Compare
app/models/conversion_host.rb
Outdated
options.merge(source_provider_options).merge(destination_provider_options) | ||
end | ||
|
||
def conversion_options_source_provider_vmwarews_vddk(vm, _storage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fdupont-redhat should these below methods be on the conversion_task model? What from the conversion_host do they use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, they should be in the task... And that also answers #18033 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 awesome, if there is anything that the task needs from the conversion_host we can delegate those to the conversion_host as @blomquisg said above
…d fingerprint for host
@agrare I have added a method to Host class to retrieve the host fingerprint. However, I'm not sure how to stub that, so I wouldn't say no to some help. |
app/models/host.rb
Outdated
@@ -500,6 +500,24 @@ def mac_addresses | |||
hardware.nil? ? [] : hardware.mac_addresses | |||
end | |||
|
|||
def fingerprint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fdupont-redhat is this specific to an esx host? If so I think we have a method in VMwareWebService to get this let me look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we do this here which you can access through the vdlVcConnection
.
This returns the actual vddk connection but we could split it up to add an API method to return the thumb print in its own method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably not necessary to have a dedicated method, even though authentication shouldn't be required to get the thumbprint.
@gmcculloug @agrare @JPrause |
app/models/host.rb
Outdated
@@ -500,6 +501,10 @@ def mac_addresses | |||
hardware.nil? ? [] : hardware.mac_addresses | |||
end | |||
|
|||
def thumbprint_sha1 | |||
ESXThumbPrint.new(ipaddress, authentication_userid, authentication_password).to_sha1 | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 much better, this should go to the vmware specific host model though: https://github.com/ManageIQ/manageiq-providers-vmware/blob/master/app/models/manageiq/providers/vmware/infra_manager/host_esx.rb since this doesn't make sense for all hosts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/models/conversion_host.rb
Outdated
has_many :service_template_transformation_plan_tasks, :dependent => :nullify | ||
|
||
def active_tasks | ||
service_template_transformation_plan_tasks { active } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to define the scope in miq_request_task:
scope :active, -> { where(:state => "active") }
Then here it will look like:
has_many :active_tasks, -> { active }, :class_name => ServiceTemplateTransformationPlanTask
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried it but it fails during tests.
}, | ||
send("conversion_options_source_provider_#{source_ems.emstype}_#{source_transport_method}", source_storage), | ||
send("conversion_options_destination_provider_#{destination_ems.emstype}", destination_cluster, destination_storage) | ||
].inject(&:merge) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The array and inject(&:merge)
is more complicated than it needs to be
Can you keep it simple?
conversion_options_source_provider_meth = "conversion_options_source_provider_#{source_ems.emstype}_#{source_transport_method}"
conversion_options_dest_provider_meth = "conversion_options_destination_provider_#{destination_ems.emstype}"
options = {
:source _disks => source_disks.map { |disk| disk[:path] },
:network_mappings => network_mappings
}
options.merge(send(conversion_options_source_provider_meth, source_storage))
options.merge(send(conversion_options_dest_provider_meth, destination_cluster, destination_storage))
options
It might not be as slick but it takes less brainpower to figure out what is going on if you're just scanning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to look smart ;). Reverted.
:scheme => destination_ems.security_protocol == 'non-ssl' ? 'http' : 'https', | ||
:host => destination_ems.hostname, | ||
:port => destination_ems.port, | ||
:path => destination_ems.api_version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed for this PR but seeing this twice (once for vmware and once for openstack) I wonder if we should put this as a generic method on the endpoint so you could do something like dest_ems.default_endpoint.uri
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice. Should it be an abstract method in InfraManager overridden in each provider ?
app/models/conversion_host.rb
Outdated
|
||
def eligible? | ||
return true if concurrent_transformation_limit.nil? | ||
puts "Active tasks: #{active_tasks}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably left in accidentally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Checked commits fabiendupont/manageiq@289c53f~...5f683be with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@agrare I've added extra checks for eligibility (and more to come in another PR). However, I'm not really happy with the spec:
An expert eye would be welcome. |
…t_from_automate Add methods to conversion_host to build virt-v2v wrapper options (cherry picked from commit fcd7161) https://bugzilla.redhat.com/show_bug.cgi?id=1634029
Hammer backport details:
|
When developing initial code for V2V, the conversion host object didn't exist, so an implementation was made in Automate to interact with oVirt hosts. Now that the ConversionHost class has been implemented, it would be better to move that code into the ConversionHost class, hence this PR.
Due to coupling between conversion host and task, it appeared that some methods from /Transformation/Common/AssessTransformation would also be useful in the ServiceTemplateTransformationPlanTask class, so I added them.
The methods for ServiceTemplateTransformationPlanTask will probably have to be exposed in Automate Model. This is still to be defined.
Depends on:
Associated RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1634029