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

Allow VMware provision without needing to specify a host #11437

Merged
merged 10 commits into from
Sep 27, 2016

Conversation

agrare
Copy link
Member

@agrare agrare commented Sep 21, 2016

This will allow a user to provision a VM to a VMware DRS-enabled cluster without having to specify a specific host. This aligns MIQ provision workflow with the VMware cloning workflow when you have a DRS cluster.

https://bugzilla.redhat.com/show_bug.cgi?id=1377975

end

def dest_folder
folder_id = get_option(:placement_folder_name)
return EmsFolder.find_by(:id => folder_id) if folder_id

host_dc = dest_host.parent_datacenter || dest_host.ems_cluster.parent_datacenter
dc = dest_cluster ? dest_cluster.parent_datacenter : dest_host.parent_datacenter
Copy link
Member Author

@agrare agrare Sep 22, 2016

Choose a reason for hiding this comment

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

A host always has at least a ComputeResource but for some reason we only inventory ClusterComputeResource
This line could be simplified to just dc = dest_cluster.parent_datacenter if we change that, might revisit later.

Copy link
Member

Choose a reason for hiding this comment

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

same simplification

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@agrare agrare force-pushed the vmware_infra_provision_no_host branch from 008c857 to 2845e48 Compare September 22, 2016 15:54
@gmcculloug
Copy link
Member

@bdunne Please review

datastore = selected_placement_obj(:placement_ds_name, Storage)

raise MiqException::MiqProvisionError, "Destination placement_ds_name not provided" if datastore.nil?
raise MiqException::MiqProvisionError, "Destination placement_host_name and placement_cluster_name not provided" if host.nil? && cluster.nil?
Copy link
Member Author

Choose a reason for hiding this comment

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

One test relies on this method raising an exception if these are missing, not sure if its better to do the checks here or in prepare_for_clone_task though

Copy link
Member

Choose a reason for hiding this comment

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

The selected_placement_obj method used by both the manual_placement and automatic_placement methods use to raise an error if the object was not defined. Now the manual_placement method is checking here and the automatic_placement will not catch the error until prepare_for_clone_task.

Can we consolidate these checks in the placement method above? I would move the new raise logic in prepare_for_clone_task and do that in the placement method as well. It makes more sense to do all our placement checking in that one place.

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved all new checks to placement

@@ -54,18 +57,17 @@ def dest_resource_pool
resource_pool = ResourcePool.find_by(:id => respool_id) unless respool_id.nil?
return resource_pool unless resource_pool.nil?

cluster = dest_host.owning_cluster
cluster ? cluster.default_resource_pool : dest_host.default_resource_pool
dest_cluster ? dest_cluster.default_resource_pool : dest_host.default_resource_pool
Copy link
Member

Choose a reason for hiding this comment

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

Could be simplified to:

dest_cluster.try(:default_resource_pool) || dest_host.default_resource_pool

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

end

def dest_folder
folder_id = get_option(:placement_folder_name)
return EmsFolder.find_by(:id => folder_id) if folder_id

host_dc = dest_host.parent_datacenter || dest_host.ems_cluster.parent_datacenter
dc = dest_cluster ? dest_cluster.parent_datacenter : dest_host.parent_datacenter
Copy link
Member

Choose a reason for hiding this comment

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

same simplification

host_ids = if clone_options[:host]
clone_options[:host].id
else
clone_options[:cluster].hosts.collect(&:id)
Copy link
Member

Choose a reason for hiding this comment

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

Is .hosts an ActiveRecord Collection? If so, pluck(:id) would be slightly more efficient.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

datastore ||= selected_placement_obj(:placement_ds_name, Storage)
return host, datastore
cluster = selected_placement_obj(:placement_cluster_name, EmsCluster) || (host.ems_cluster if host)
Copy link
Member

Choose a reason for hiding this comment

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

Prefer host.try(:ems_cluster) over (host.ems_cluster if host)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -435,7 +435,7 @@
:auto_select_single: false
:description: Name
:required_method: :validate_placement
:required: true
:required: false
Copy link
Member

Choose a reason for hiding this comment

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

Since this is no longer required, the :required_method: will not run. I would suggest changing it to a validation_method and verify that validate_placement returns the expected result with and without a host selected.

Copy link
Member Author

Choose a reason for hiding this comment

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

@gmcculloug mentioned not wanting this in here at all yet so it might be moot

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest creating a separate PR for the dialog/workflow validation changes. I suggested this change to @agrare for local testing but did not expect it to be part of the PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah my misunderstanding didn't realize it was for local dev, removed.

@agrare agrare force-pushed the vmware_infra_provision_no_host branch 2 times, most recently from 562db92 to a10e83c Compare September 22, 2016 19:55
@agrare
Copy link
Member Author

agrare commented Sep 22, 2016

Got rid of a VIM API call here now that we have dvSwitches in VMDB 😄

How bad would it be to have allowed_vlans return [lan.id, lan.name] in options[:network] similar to hosts/clusters/folders? Right now it just passes the name, that way we could avoid having to do this lookup

@agrare agrare changed the title [WIP] Allow VMware provision without needing to specify a host Allow VMware provision without needing to specify a host Sep 26, 2016
@agrare
Copy link
Member Author

agrare commented Sep 26, 2016

@gmcculloug can you review?

@miq-bot remove-label wip

@miq-bot miq-bot removed the wip label Sep 26, 2016
Copy link
Member

@gmcculloug gmcculloug left a comment

Choose a reason for hiding this comment

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

@agrare Do not change the return values for allowed_vlans in this PR since that will cause issues for automate users. We can look into doing that in a separate PR where we can focus on backwards compatibility. The details would get lost in this PR and we would also not want to back port that change to the Darga branch.

# Find a host in the cluster that has this storage mounted to get the right ems_ref for this
# datastore in the datacenter
datastore = HostStorage.find_by(:storage_id => clone_options[:datastore].id, :host_id => host_ids)
vim_clone_options[:datastore] = datastore.ems_ref if datastore
Copy link
Member

Choose a reason for hiding this comment

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

Now that this logic is more than a single line it would be clearer to have it in a separate method.

vim_clone_options[:datastore] = datastore_ems_ref(clone_options)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

datastore = selected_placement_obj(:placement_ds_name, Storage)

raise MiqException::MiqProvisionError, "Destination placement_ds_name not provided" if datastore.nil?
raise MiqException::MiqProvisionError, "Destination placement_host_name and placement_cluster_name not provided" if host.nil? && cluster.nil?
Copy link
Member

Choose a reason for hiding this comment

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

The selected_placement_obj method used by both the manual_placement and automatic_placement methods use to raise an error if the object was not defined. Now the manual_placement method is checking here and the automatic_placement will not catch the error until prepare_for_clone_task.

Can we consolidate these checks in the placement method above? I would move the new raise logic in prepare_for_clone_task and do that in the placement method as well. It makes more sense to do all our placement checking in that one place.

@@ -435,7 +435,7 @@
:auto_select_single: false
:description: Name
:required_method: :validate_placement
:required: true
:required: false
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest creating a separate PR for the dialog/workflow validation changes. I suggested this change to @agrare for local testing but did not expect it to be part of the PR.

@agrare agrare force-pushed the vmware_infra_provision_no_host branch 2 times, most recently from a9b0be1 to c557796 Compare September 27, 2016 12:47
@agrare
Copy link
Member Author

agrare commented Sep 27, 2016

@gmcculloug made requested changes and re-tested

@agrare agrare force-pushed the vmware_infra_provision_no_host branch from c557796 to dca8127 Compare September 27, 2016 17:35
@miq-bot
Copy link
Member

miq-bot commented Sep 27, 2016

Checked commits agrare/manageiq@cc6906c~...dca8127 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
6 files checked, 5 offenses detected

app/models/manageiq/providers/vmware/infra_manager/provision/cloning.rb

app/models/manageiq/providers/vmware/infra_manager/provision/placement.rb

spec/models/manageiq/providers/vmware/infra_manager/provision/placement_spec.rb

@gmcculloug
Copy link
Member

@agrare Thanks. The two remaining tasks in the description will be moved to a separate PR, correct?

@bdunne Changes look good to me. Please give this one final review.

@agrare
Copy link
Member Author

agrare commented Sep 27, 2016

@gmcculloug correct, I'll take them out of the TODO list

@bdunne
Copy link
Member

bdunne commented Sep 27, 2016

👍 LGTM

@bdunne bdunne merged commit de4f24f into ManageIQ:master Sep 27, 2016
@bdunne bdunne added this to the Sprint 47 Ending Oct 3, 2016 milestone Sep 27, 2016
@agrare
Copy link
Member Author

agrare commented Sep 27, 2016

Thanks guys!

@agrare agrare deleted the vmware_infra_provision_no_host branch September 27, 2016 18:53
@bdunne
Copy link
Member

bdunne commented Sep 27, 2016

@agrare This needs to go back to the euwe branch, right?

@agrare
Copy link
Member Author

agrare commented Sep 27, 2016

@bdunne yes, there's a 5.6.z clone also (https://bugzilla.redhat.com/show_bug.cgi?id=1378116)

chessbyte pushed a commit that referenced this pull request Sep 29, 2016
Allow VMware provision without needing to specify a host
(cherry picked from commit de4f24f)
@chessbyte
Copy link
Member

Euwe Backport details:

$ git log
commit 92faa3252b44f9b8227537d037349c6ae68fa9b7
Author: Brandon Dunne <brandondunne@hotmail.com>
Date:   Tue Sep 27 14:53:16 2016 -0400

    Merge pull request #11437 from agrare/vmware_infra_provision_no_host

    Allow VMware provision without needing to specify a host
    (cherry picked from commit de4f24f31c66681066a0b85931653d872818c4ab)

@chessbyte
Copy link
Member

@chessbyte
Copy link
Member

This should be backported AFTER #11135

chessbyte pushed a commit that referenced this pull request Oct 11, 2016
Allow VMware provision without needing to specify a host
(cherry picked from commit de4f24f)

https://bugzilla.redhat.com/show_bug.cgi?id=1378116
@chessbyte
Copy link
Member

Darga Backport details:

$ git log
commit a6a212a019cb8191c022dbe97d6496aa20fd482e
Author: Brandon Dunne <brandondunne@hotmail.com>
Date:   Tue Sep 27 14:53:16 2016 -0400

    Merge pull request #11437 from agrare/vmware_infra_provision_no_host

    Allow VMware provision without needing to specify a host
    (cherry picked from commit de4f24f31c66681066a0b85931653d872818c4ab)

    https://bugzilla.redhat.com/show_bug.cgi?id=1378116

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants