Skip to content

Commit

Permalink
adding ability to set default version
Browse files Browse the repository at this point in the history
  • Loading branch information
rambleraptor committed Jul 17, 2019
1 parent 25eefbc commit 5920954
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions products/mlengine/ansible.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@ overrides: !ruby/object:Overrides::ResourceOverrides
provider_helpers:
- products/mlengine/helpers/ansible/model_decoder.py
Version: !ruby/object:Overrides::Ansible::ResourceOverride
update: |
if module.params.get('is_default') == True:
set_default(module)
post_create: |
if module.params.get('is_default') == True:
set_default(module)
transport: !ruby/object:Overrides::Ansible::Transport
decoder: decode_response
properties:
isDefault: !ruby/object:Overrides::Ansible::PropertyOverride
aliases: ['default']
provider_helpers:
- products/mlengine/helpers/ansible/model_decoder.py
- products/mlengine/helpers/ansible/version_set_default.py
files: !ruby/object:Provider::Config::Files
resource:
<%= lines(indent(compile('provider/ansible/resource~compile.yaml'), 4)) -%>
2 changes: 2 additions & 0 deletions products/mlengine/ansible_version_added.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@
:version_added: '2.9'
:model:
:version_added: '2.9'
:isDefault:
:version_added: '2.9'
3 changes: 3 additions & 0 deletions products/mlengine/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ objects:
resource: Model
imports: name
required: true
- !ruby/object:Api::Type::Boolean
name: 'isDefault'
description: If true, this version will be used to handle prediction requests that do not specify a version
properties:
- !ruby/object:Api::Type::String
name: 'name'
Expand Down
1 change: 1 addition & 0 deletions products/mlengine/examples/ansible/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ task: !ruby/object:Provider::Ansible::Task
model: "{{ model }}"
runtime_version: 1.13
python_version: 3.5
is_default: true
deployment_uri: gs://ansible-cloudml-bucket/
project: <%= ctx[:project] %>
auth_kind: <%= ctx[:auth_kind] %>
Expand Down
20 changes: 20 additions & 0 deletions products/mlengine/helpers/ansible/version_set_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2019 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.

# Sets this version as default.
def set_default(module):
res = {'project': module.params['project'], 'model': replace_resource_dict(module.params['model'], 'name'), 'name': module.params['name']}
link = "https://ml.googleapis.com/v1/projects/{project}/models/{model}/versions/{name}:setDefault".format(**res)

auth = GcpSession(module, 'mlengine')
return_if_object(module, auth.post(link))

0 comments on commit 5920954

Please sign in to comment.