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

Container Registry #134

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ action_groups:
- bare_metal
- block_storage
- block_storage_info
- container_registry
- container_registry_info
- container_registry_region_info
- container_registry_repository
- container_registry_repository_info
- dns_domain
- dns_domain_info
- dns_record
Expand All @@ -19,6 +24,7 @@ action_groups:
- object_storage_cluster_info
- object_storage_info
- os_info
- plan_container_registry_info
- plan_info
- plan_metal_info
- region_info
Expand Down
27 changes: 20 additions & 7 deletions plugins/module_utils/vultr_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(
resource_create_param_keys=None,
resource_update_param_keys=None,
resource_update_method="PATCH",
response_in_list=True,
):
self.module = module
self.namespace = namespace
Expand All @@ -96,7 +97,7 @@ def __init__(
# The name key of the resource, usually 'name'
self.resource_key_name = resource_key_name

# The name key of the resource, usually 'id'
# The id key of the resource, usually 'id'
self.resource_key_id = resource_key_id

# Some resources need an additional GET request to get all attributes
Expand All @@ -111,6 +112,9 @@ def __init__(
# Some resources have PUT, many have PATCH
self.resource_update_method = resource_update_method

# Some resources return objects as the top level, not in an array
self.response_in_list = response_in_list

self.result = {
"changed": False,
namespace: dict(),
Expand Down Expand Up @@ -237,8 +241,9 @@ def query_filter_list_by_name(
get_details=False,
fail_not_found=False,
skip_transform=True,
param_value=None,
):
param_value = self.module.params.get(param_key or key_name)
param_value = param_value or self.module.params.get(param_key or key_name)

found = dict()
for resource in self.query_list(path=path, result_key=result_key, query_params=query_params):
Expand Down Expand Up @@ -275,7 +280,7 @@ def query_filter_list_by_name(
return dict()

def query_filter_list(self):
# Returns a single dict representing the resource queryied by name
# Returns a single dict representing the resource queried by name
return self.query_filter_list_by_name(
key_name=self.resource_key_name,
key_id=self.resource_key_id,
Expand All @@ -295,10 +300,14 @@ def query_by_id(self, resource_id=None, path=None, result_key=None, skip_transfo
)

if resource:
if skip_transform:
return resource[result_key]
else:
if self.response_in_list:
if skip_transform:
return resource[result_key]
return self.transform_resource(resource[result_key])
else:
if skip_transform:
return resource
return self.transform_resource(resource)

return dict()

Expand All @@ -316,6 +325,7 @@ def query_list(self, path=None, result_key=None, query_params=None):
query_params=query_params,
result_key=result_key,
)

return resources[result_key] if resources else []

def wait_for_state(self, resource, key, states, cmp="=", retries=60, skip_wait=False):
Expand Down Expand Up @@ -370,7 +380,10 @@ def create(self):
method="POST",
data=data,
)
return resource.get(self.ressource_result_key_singular) if resource else dict()

if self.response_in_list:
return resource.get(self.ressource_result_key_singular) if resource else dict()
return resource if resource else dict()

def is_diff(self, param, resource):
value = self.module.params.get(param)
Expand Down
Loading
Loading