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

Ansible Redis #1269

Merged
merged 4 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/async.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Operation < Api::Object
def validate
super

check :kind, type: String, required: true
check :kind, type: String
check :path, type: String, required: true
check :base_url, type: String, required: true
check :wait_ms, type: Integer, required: true
Expand Down
40 changes: 40 additions & 0 deletions products/redis/ansible.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

--- !ruby/object:Provider::Ansible::Config
manifest: !ruby/object:Provider::Ansible::Manifest
metadata_version: '1.1'
status:
- preview
supported_by: 'community'
requirements:
- python >= 2.6
- requests >= 2.18.4
- google-auth >= 1.3.0
version_added: '2.8'
author: Google Inc. (@googlecloudplatform)
# This is where custom code would be defined eventually.
datasources: !ruby/object:Overrides::ResourceOverrides
Instance: !ruby/object:Overrides::Ansible::ResourceOverride
version_added: '2.8'
base_url: projects/{{project}}/locations/{{region}}/instances
facts: !ruby/object:Provider::Ansible::FactsOverride
has_filters: false
overrides: !ruby/object:Overrides::ResourceOverrides
Instance: !ruby/object:Overrides::Ansible::ResourceOverride
# TODO(alexstephen): Create update masks and get Redis update support working
input: true
version_added: '2.8'
files: !ruby/object:Provider::Config::Files
compile:
<%= lines(indent(compile('provider/ansible/product~compile.yaml'), 4)) -%>
31 changes: 23 additions & 8 deletions products/redis/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,34 @@ objects:
update_verb: :PATCH
description: |
A Google Cloud Redis instance.
collection_url_response: !ruby/object:Api::Resource::ResponseList
items: 'instances'
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation':
'https://cloud.google.com/memorystore/docs/redis/'
api: 'https://cloud.google.com/memorystore/docs/redis/reference/rest/'
<%=
# Cloud Redis takes a fair bit of time to provision/delete, try six minutes.
indent(compile_file({timeouts: {
insert_sec: 6 * 60,
update_sec: 6 * 60,
delete_sec: 6 * 60 }},
'templates/regional_async.yaml.erb'), 4)
%>
async: !ruby/object:Api::Async
operation: !ruby/object:Api::Async::Operation
path: 'name'
base_url: '{{op_id}}'
wait_ms: 1000
timeouts: !ruby/object:Api::Timeouts
insert_sec: 360
update_sec: 360
delete_sec: 360
result: !ruby/object:Api::Async::Result
path: 'response'
resource_inside_response: true
status: !ruby/object:Api::Async::Status
path: 'done'
complete: true
allowed:
- true
- false
error: !ruby/object:Api::Async::Error
path: 'error'
message: 'message'
parameters:
- !ruby/object:Api::Type::String # TODO: resourceref?
name: 'region'
Expand Down
40 changes: 40 additions & 0 deletions products/redis/examples/ansible/instance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2018 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

--- !ruby/object:Provider::Ansible::Example
dependencies:
- !ruby/object:Provider::Ansible::Task
name: gcp_compute_network
register: network
code:
name: <%= dependency_name('network', 'instance') %>
project: <%= ctx[:project] %>
auth_kind: <%= ctx[:auth_kind] %>
service_account_file: <%= ctx[:service_account_file] %>
task: !ruby/object:Provider::Ansible::Task
name: gcp_redis_instance
code:
name: "instance37"
tier: "STANDARD_HA"
memory_size_gb: 1
region: 'us-central1'
location_id: 'us-central1-a'
redis_version: "REDIS_3_2"
display_name: "Ansible Test Instance"
reserved_ip_range: "192.168.0.0/29"
labels:
my_key: my_val
other_key: other_val
project: <%= ctx[:project] %>
auth_kind: <%= ctx[:auth_kind] %>
service_account_file: <%= ctx[:service_account_file] %>
2 changes: 1 addition & 1 deletion templates/ansible/async.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, <%= op_path -%>)
op_uri = async_op_url(module, {'op_id': op_id})
<% if object.async.status.complete == true -%>
if not status:
while not status:
<% else -%>
while status != <%= python_literal(object.async.status.complete) -%>:
<% end -%>
Expand Down
4 changes: 0 additions & 4 deletions templates/ansible/facts.erb
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ def main():
module.exit_json(**return_value)


<% if object.collection -%>
<%= lines(emit_link('collection', build_url(object.collection), object)) -%>
<% else # object.collection -%>
<%= lines(emit_link('collection', build_url(object.collection_url), object)) -%>
<% end # object.collection -%>


<%= method_decl('fetch_list', ['module', 'link', ('query' if object.facts.has_filters)]) %>
Expand Down
2 changes: 1 addition & 1 deletion templates/ansible/resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def resource_to_request(module):
properties_in_request = [
object&.parameters&.select { |p| p.input },
object.properties.reject(&:output)
].flatten.compact
].flatten.compact.reject(&:url_param_only)
-%>
<%
request_hash = {
Expand Down