Skip to content

Commit

Permalink
bugfix to code in Calling External Services, and added a NOTE to Serv…
Browse files Browse the repository at this point in the history
…ice Dialogs
  • Loading branch information
Peter McGowan committed Aug 24, 2017
1 parent 45ae3ae commit cc1881c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
30 changes: 15 additions & 15 deletions calling_external_services/chapter.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ The method is called in a loop, passing an IP address into the +body_hash+ argum

The _fog_ gem is a multipurpose cloud services library that supports connectivity to a number of cloud providers.

The follow code uses the fog gem to retrieve OpenStack networks from Neutron, and present them as a dynamic drop-down dialog list. The code filters networks that match a tenant's name, and assumes that the ManageIQ user has a +tenant+ tag containing the same name:
The follow code uses the fog gem to retrieve OpenStack networks from Neutron, and present them as a dynamic drop-down dialog list. The code filters networks that match a tenant's name, and assumes that the CloudForms/ManageIQ user's group has a +tenant+ tag containing the same name:

[source,ruby]
----
require 'fog'
require 'fog/openstack'
begin
tenant_name = $evm.root['user'].current_group.tags(:tenant).first
$evm.log(:info, "Tenant name: #{tenant_name}")
tenant = $evm.root['user'].current_group.tags(:tenant).first
$evm.log(:info, "Tenant name: #{tenant}")
dialog_field = $evm.object
dialog_field["sort_by"] = "value"
Expand All @@ -90,20 +90,20 @@ begin
ems = $evm.vmdb('ems').find_by_name("OpenStack DC01")
raise "ems not found" if ems.nil?
neutron_service = Fog::Network.new({
:provider => 'OpenStack',
:openstack_api_key => ems.authentication_password,
neutron_service = Fog::Network::OpenStack.new({
:openstack_api_key => ems.authentication_password,
:openstack_username => ems.authentication_userid,
:openstack_auth_url => "http://#{ems.hostname}:35357/v2.0/tokens",
:openstack_tenant => tenant_name
:openstack_auth_url => "https://#{ems.hostname}:#{ems.port}/v2.0/tokens",
:openstack_tenant => tenant,
:connection_options => {:ssl_verify_peer => false}
})
keystone_service = Fog::Identity.new({
:provider => 'OpenStack',
:openstack_api_key => ems.authentication_password,
keystone_service = Fog::Identity::OpenStack.new({
:openstack_api_key => ems.authentication_password,
:openstack_username => ems.authentication_userid,
:openstack_auth_url => "http://#{ems.hostname}:35357/v2.0/tokens",
:openstack_tenant => tenant_name
:openstack_auth_url => "https://#{ems.hostname}:#{ems.port}/v2.0/tokens",
:openstack_tenant => tenant,
:connection_options => {:ssl_verify_peer => false}
})
tenant_id = keystone_service.current_tenant["id"]
Expand Down
12 changes: 12 additions & 0 deletions service_dialogs/chapter.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ Here is another, more real-world example of the versatility of dynamic elements:

This example populates a dynamic drop-down list with infrastructure lifecycle environments into which a user can provision a new virtual machine. If the user is a member of group containing the string "administrators", then a further two environments: "Pre-Production" and "Production" are added to the list.

[NOTE]
====
If an element is marked as *Required* then using '!' as the default return on the prompt value will satisfy the 'required' stipulation without the user necessarily selecting anything from the presented drop-down list. This may not be desirable. For *Required* elements a preferred option would be to use +nil+ as the default return, for example:
[source,ruby]
----
values_hash[nil] = '-- select from list --'
----
This would then not satisfy the 'required' stipulation, and so force the user to select a presented 'real' value from the drop-down list.
====

=== Read-Only and Protected Elements

CloudForms 3.1/ManageIQ _Anand_ added the ability to mark a text box as protected, which results in any input being obfuscated. This is particularly useful for inputting passwords (see <<i3>>).
Expand Down

0 comments on commit cc1881c

Please sign in to comment.