Skip to content

Commit

Permalink
Better resourceref flexibility (#1034)
Browse files Browse the repository at this point in the history
Merged PR #1034.
  • Loading branch information
rambleraptor authored and modular-magician committed Dec 14, 2018
1 parent f2e5088 commit 0424fdd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build/ansible
Submodule ansible updated 64 files
+9 −1 lib/ansible/module_utils/gcp_utils.py
+5 −6 lib/ansible/modules/cloud/google/gcp_compute_address.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_address_facts.py
+6 −6 lib/ansible/modules/cloud/google/gcp_compute_backend_service.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_backend_service_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_compute_disk.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_disk_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_compute_firewall.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_firewall_facts.py
+21 −24 lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule_facts.py
+16 −18 lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py
+3 −3 lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_compute_image.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_image_facts.py
+22 −24 lib/ansible/modules/cloud/google/gcp_compute_instance.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_instance_facts.py
+11 −13 lib/ansible/modules/cloud/google/gcp_compute_instance_group.py
+2 −2 lib/ansible/modules/cloud/google/gcp_compute_instance_group_facts.py
+8 −8 lib/ansible/modules/cloud/google/gcp_compute_instance_group_manager.py
+2 −2 lib/ansible/modules/cloud/google/gcp_compute_instance_group_manager_facts.py
+24 −26 lib/ansible/modules/cloud/google/gcp_compute_instance_template.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_instance_template_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_compute_interconnect_attachment.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_interconnect_attachment_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_compute_region_disk.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_region_disk_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_compute_route.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_route_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_compute_router.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_router_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_compute_subnetwork.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_subnetwork_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_compute_target_http_proxy.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_target_http_proxy_facts.py
+11 −13 lib/ansible/modules/cloud/google/gcp_compute_target_https_proxy.py
+2 −2 lib/ansible/modules/cloud/google/gcp_compute_target_https_proxy_facts.py
+12 −13 lib/ansible/modules/cloud/google/gcp_compute_target_pool.py
+2 −2 lib/ansible/modules/cloud/google/gcp_compute_target_pool_facts.py
+12 −13 lib/ansible/modules/cloud/google/gcp_compute_target_ssl_proxy.py
+2 −2 lib/ansible/modules/cloud/google/gcp_compute_target_ssl_proxy_facts.py
+6 −6 lib/ansible/modules/cloud/google/gcp_compute_target_tcp_proxy.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_target_tcp_proxy_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_compute_target_vpn_gateway.py
+1 −1 lib/ansible/modules/cloud/google/gcp_compute_target_vpn_gateway_facts.py
+24 −26 lib/ansible/modules/cloud/google/gcp_compute_url_map.py
+4 −4 lib/ansible/modules/cloud/google/gcp_compute_url_map_facts.py
+11 −12 lib/ansible/modules/cloud/google/gcp_compute_vpn_tunnel.py
+2 −2 lib/ansible/modules/cloud/google/gcp_compute_vpn_tunnel_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_container_node_pool.py
+5 −6 lib/ansible/modules/cloud/google/gcp_container_node_pool_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_dns_resource_record_set.py
+5 −6 lib/ansible/modules/cloud/google/gcp_dns_resource_record_set_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_iam_service_account_key.py
+5 −6 lib/ansible/modules/cloud/google/gcp_pubsub_subscription.py
+1 −1 lib/ansible/modules/cloud/google/gcp_pubsub_subscription_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_spanner_database.py
+5 −6 lib/ansible/modules/cloud/google/gcp_spanner_database_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_sql_database.py
+5 −6 lib/ansible/modules/cloud/google/gcp_sql_database_facts.py
+5 −6 lib/ansible/modules/cloud/google/gcp_sql_user.py
+5 −6 lib/ansible/modules/cloud/google/gcp_sql_user_facts.py
+10 −12 lib/ansible/modules/cloud/google/gcp_storage_bucket.py
+5 −6 lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py
2 changes: 1 addition & 1 deletion provider/ansible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def python_type(prop)
if prop.is_a? Api::Type::ResourceRef
return 'str' if prop.resource_ref.readonly

return 'dict'
return nil
end
PYTHON_TYPE_FROM_MM_TYPE.fetch(prop.class.to_s, 'str')
end
Expand Down
11 changes: 5 additions & 6 deletions provider/ansible/documentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def documentation_for_property(prop)
# Builds out the RETURNS for a property.
# This will eventually be converted to YAML
def returns_for_property(prop)
type = python_type(prop)
type = python_type(prop) || 'str'
# Type is a valid AnsibleModule type, but not a valid return type
type = 'str' if type == 'path'
# Complex types only mentioned in reference to RETURNS YAML block
Expand Down Expand Up @@ -102,11 +102,10 @@ def resourceref_description(prop)
[
"This field represents a link to a #{prop.resource_ref.name} resource in GCP.",
'It can be specified in two ways.',
"You can add `register: name-of-resource` to a #{module_name(prop.resource_ref)} task",
"and then set this #{prop.name.underscore} field to \"{{ name-of-resource }}\"",
"Alternatively, you can set this #{prop.name.underscore} to a dictionary",
"with the #{prop.imports} key",
"where the value is the #{prop.imports} of your #{prop.resource_ref.name}"
"First, you can place in the #{prop.imports} of the resource here as a string",
'Alternatively, you can add `register: name-of-resource` to a',
"#{module_name(prop.resource_ref)} task",
"and then set this #{prop.name.underscore} field to \"{{ name-of-resource }}\""
].join(' ')
end

Expand Down
10 changes: 9 additions & 1 deletion provider/ansible/gcp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ansible.module_utils.basic import AnsibleModule, env_fallback
from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_text
import ast
import os


Expand Down Expand Up @@ -60,8 +61,15 @@ def replace_resource_dict(item, value):
else:
if not item:
return item
return item.get(value)
if isinstance(item, dict):
return item.get(value)

# Item could be a string or a string representing a dictionary.
try:
new_item = ast.literal_eval(item)
return replace_resource_dict(new_item, value)
except ValueError:
return new_item

# Handles all authentation and HTTP sessions for GCP API calls.
class GcpSession(object):
Expand Down
4 changes: 2 additions & 2 deletions provider/ansible/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def prop_options(prop, _object, spaces)
('required=True' if prop.required && !prop.default_value),
("default=#{python_literal(prop.default_value)}" \
if prop.default_value),
"type=#{quote_string(python_type(prop))}",
("type=#{quote_string(python_type(prop))}" if python_type(prop)),
(choices_enum(prop, spaces) if prop.is_a? Api::Type::Enum),
("elements=#{quote_string(python_type(prop.item_type))}" \
if prop.is_a? Api::Type::Array),
if prop.is_a?(Api::Type::Array) && python_type(prop.item_type)),
("aliases=[#{prop.aliases.map { |x| quote_string(x) }.join(', ')}]" \
if prop.aliases)
].compact
Expand Down

0 comments on commit 0424fdd

Please sign in to comment.