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 VM specific customisations to vApp orchestration #12273

Merged

Conversation

gberginc
Copy link
Contributor

@gberginc gberginc commented Oct 28, 2016

Previously users were only allowed to modify the name of the provisioned vApp and parameters that control the power state of the vApp.

With this change we are adding support for changing the name of the instance as well as the ability to select a different VDC network to which instances may be connected.

Currently we are focusing on the UI part of the changes. I am also adding the spec file for these kinds of tests (it's not complete yet as more different cases are needed). The spec file was previously not used because I was mainly following other orchestration templates.

@miq-bot add_label providers/vmware/cloud, enhancement, ui, wip

screen shot 2016-10-28 at 15 46 07

:name => "vdc_network-#{vm_id}",
:label => "Network",
:data_type => "string",
:default_value => "(default)",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am still not sure whether I should be using i18n here or not. Other templates will output whatever there is in the template itself, but this is a special case and I believe we could use it...

Copy link
Member

Choose a reason for hiding this comment

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

If it will show up on the UI I'd put _() around the string to be safe

return "(default)" if cloud_networks.empty?

# Get network names.
vdc_network_names = cloud_networks.collect(&:name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I am only collecting names of the networks, however I'd rather see if I could create key,value pairs. The list of names is used here and converted into the actual dialog field in OrchestrationTemplateDialogService class.

What I am thinking is if it would be possible to change the code so that it would allow setting up key, value and the corresponding code would use keys if they exist, otherwise it would use the same logic as today.

Copy link
Member

Choose a reason for hiding this comment

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

@gberginc I like the idea but what keys were you thinking of using and what would it make simpler? I could see :default => "(default)" instead of using the string directly.
We'll want to check with @bzwei about changing OrchestrationParameterAllowed to support this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@agrare currently I can only return the names of the VDC networks that are to be displayed in the dropdown. The logic that will create the actual request to the VMware API I'll need to find the IDs of these networks so I thought that the dropdown would have the ability to set these from the code, i.e. {nil => (default), id1 => VDC net 1, ...}.

If we just pass ["(default)", "VDC net 1", ...], the code would work exactly as it does now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@agrare this class is what I am referring to in my previous comments. This class receives values from the form shown in the above screenshot and uses those values to construct provider-specific options struct.

Currently, this class uses only those parameters in "Options". In this class I'd like to get IDs (ems_id), instead of network names so that I don't need to lookup in the database for these IDs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am ok to change OrchestrationParameterAllowed to be a hash rather than an array. We may accept both formats for backward comparability purpose.

expect(orchestration_template.content.include?('ovf:Envelope')).to be_truthy
end

it "is parsed using MmeiqXml" do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooops :-). The typo will be fixed.

@agrare agrare self-assigned this Nov 1, 2016
@gberginc gberginc force-pushed the add_vmware_cloud_orchestration_customisation branch from 8f5e4f2 to 1b2aef5 Compare November 7, 2016 19:15
@miq-bot
Copy link
Member

miq-bot commented Nov 9, 2016

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@gberginc gberginc force-pushed the add_vmware_cloud_orchestration_customisation branch 2 times, most recently from e4000aa to c2c2eb3 Compare November 11, 2016 10:17
@gberginc gberginc force-pushed the add_vmware_cloud_orchestration_customisation branch from c2c2eb3 to edce1c1 Compare November 29, 2016 10:44
@gberginc gberginc force-pushed the add_vmware_cloud_orchestration_customisation branch 2 times, most recently from 3c05d8c to 507408b Compare November 29, 2016 11:00
}
options[:vdc_id] = @dialog_options['dialog_availability_zone'] if @dialog_options.key?("dialog_availability_zone") && !@dialog_options["dialog_availability_zone"].nil? && !@dialog_options["dialog_availability_zone"].empty?
Copy link
Contributor

Choose a reason for hiding this comment

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

can be simplified as

options[:vdc_id] = @dialog_options['dialog_availability_zone'] unless @dialog_options['dialog_availability_zone'].blank?

network_config = {}
source_vms = []

vm_params.each do |vm_id, vm_opts|
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer source_vms = vm_params.collect

end

# Create options suitable for VMware vCloud provider.
custom_opts = {
Copy link
Contributor

Choose a reason for hiding this comment

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

The hash key naming is very confusing all over this class. Why a mix with CamelCase, camelCase, and snack_case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's how fog library that is used to connect to vCloud names these parameters. I had the same issues, but in the end I wanted to make minimal changes to fog.

next if param_match.nil?

vm_id = param_match.captures.first
vm_params[vm_id] = {} unless vm_params.key?(vm_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

seems to me that you always want to initialize vm_params[vm_id] = {} and in next line set [param] conditionally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bzweil can you explain a bit more? Line 72 creates new empty object in vm_params with vm_id as its key, but only if it wasn't created before. The next line will store specific parameter value for this VM.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gberginc You're right. I misinterpreted it. But this line can be simplified as vm_params[vm_id] ||= {}

@gberginc gberginc force-pushed the add_vmware_cloud_orchestration_customisation branch from 507408b to 17659d6 Compare November 29, 2016 19:01
@gberginc
Copy link
Contributor Author

@bzwei All comments addressed, apart from the one on the hash key names due to the external requirement from the fog library.

@gberginc gberginc force-pushed the add_vmware_cloud_orchestration_customisation branch from 17659d6 to 19bdbee Compare November 29, 2016 21:16
} unless network_config.key?(network_id)

# Add network configuration to the source VM.
src_vm[:networks] = [
Copy link
Contributor

Choose a reason for hiding this comment

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

should it be an array [] or hash {}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has to be an array of objects. Since all elements are :key => value, this implicitly creates an object. Would you prefer that I do it explicitly, so that I create it like

          src_vm[:networks] = [
            {
              :networkName             => network_id,
              :IsConnected             => true,
              :IpAddressAllocationMode => "DHCP"
            }
          ]

Copy link
Contributor

Choose a reason for hiding this comment

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

Your original code is OK. Just want to make sure it is according to design.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean the API takes multiple networks for a single VM but your application limits it to one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are trying to mimic vCloud Director UI, where users seem to be able to only specify a single network.

network_id = vm_opts["vdc_network"]
unless network_id.nil?
# Create new network config if it hasn't been created before.
network_config[network_id] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

network_config[network_id] ||= { and no need for unless check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really appreciate these kind of comments! I will wait for the comment about explicitly storing the object in the array above and then resubmit.

Previously users were only allowed to modify the name of the provisioned
vApp and parameters that control the power state of the vApp.

With this change we are adding support for changing the name of the
instances that are deployed as part of the vApp as well as the ability
to select a different VDC network to which instances may be connected.
Similarly to the vCloud Director, each instance may be connected to a
different network.

Signed-off-by: Gregor Berginc <gregor.berginc@xlab.si>
@gberginc gberginc force-pushed the add_vmware_cloud_orchestration_customisation branch from 19bdbee to 20b9aa3 Compare November 30, 2016 15:53
@miq-bot
Copy link
Member

miq-bot commented Nov 30, 2016

Checked commit xlab-si@20b9aa3 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
5 files checked, 8 offenses detected

app/models/manageiq/providers/vmware/cloud_manager/orchestration_service_option_converter.rb

app/models/manageiq/providers/vmware/cloud_manager/orchestration_template.rb

spec/models/manageiq/providers/vmware/cloud_manager/orchestration_template_spec.rb

@gberginc
Copy link
Contributor Author

@agrare I'was able to test this PR using the existing testbed and works as expected. It properly configures the name of VMs being deployed as part of vApp template instantiation. It also connects VMs to the specified VDC networks.

I am thus removing WIP label.

@miq-bot remove_label wip

@gberginc gberginc changed the title [WIP] Add VM specific customisations to vApp orchestration Add VM specific customisations to vApp orchestration Dec 14, 2016
@agrare agrare removed the wip label Dec 14, 2016
@agrare
Copy link
Member

agrare commented Dec 14, 2016

LGTM 👍

@agrare agrare merged commit cebf291 into ManageIQ:master Dec 14, 2016
@agrare agrare added the euwe/no label Dec 14, 2016
@agrare agrare added this to the Sprint 51 Ending Jan 2, 2017 milestone Dec 14, 2016
@chargio
Copy link
Contributor

chargio commented Dec 15, 2016

Hi @agrare, it looks like a nice enhancement to the provider. Should it not be backported?

@agrare
Copy link
Member

agrare commented Dec 15, 2016

@sergio-ocon generally speaking enhancements aren't backported, if we have a BZ and it gets all ack's for a z-stream clone we'll backport it.

@tadeboro tadeboro deleted the add_vmware_cloud_orchestration_customisation branch March 30, 2018 07:57
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.

6 participants