Skip to content

Commit

Permalink
fix: add remote to all modules
Browse files Browse the repository at this point in the history
  • Loading branch information
kmpm committed Dec 1, 2024
1 parent 74ee0e9 commit d1c9652
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
11 changes: 7 additions & 4 deletions plugins/module_utils/incuscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def __init__(self, remote='local', project='default', target=None, debug=False,
if not self._incus_cmd:
raise IncusClientException("incus command not found in PATH")

def _remoteCmd(self, cmd):
"""Return the command with the remote set."""
return [cmd, self.remote + ':']

def _parseErr(self, returncode, stderr):
err_params = {"rc": returncode}
if self.debug:
Expand Down Expand Up @@ -70,7 +74,8 @@ def query_raw(self, method, url, payload=None, url_params=None, ok_errors=None):
url = url + '&' + urlencode(url_params)
else:
url = url + '?' + urlencode(url_params)

if self.remote != 'local':
url = self.remote + ':' + url
args = ['query', '-X', method, url, '--wait', '--raw']
if self.debug:
self.logs.append(args)
Expand Down Expand Up @@ -167,9 +172,7 @@ def list(self, filter=''):
Returns a list of instances in a dict.
"""
# syntax: incus list [<remote>:] [<filter>...] [flags]
args=['list',]
if self.remote:
args.extend([self.remote + ':',])
args = self._remoteCmd('list')
if filter:
args.extend([filter, ]),
args.extend(['--project', self.project, '--format', 'json'])
Expand Down
11 changes: 11 additions & 0 deletions plugins/modules/incus_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
- Name of an instance.
type: str
required: true
remote:
description: The remote to use for the Incus CLI.
type: str
default: local
description:
description:
- Description of the instance
Expand Down Expand Up @@ -387,6 +391,8 @@ def __init__(self, module):
self.module = module
self.name = self.module.params['name']
self.project = self.module.params['project']
self.description = self.module.params['description']
self.remote = self.module.params['remote']
self._build_config()

self.state = self.module.params['state']
Expand All @@ -405,6 +411,7 @@ def __init__(self, module):
try:
self.client = IncusClient(
project=self.project,
remote=self.remote,
debug=self.debug
)
except IncusClientException as e:
Expand Down Expand Up @@ -683,6 +690,10 @@ def main():
type='str',
required=True,
),
remote=dict(
type='str',
default='local',
),
description=dict(
type='str',
),
Expand Down
8 changes: 7 additions & 1 deletion plugins/modules/incus_instance_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
- Name of the instance. If empty all instances will be returned.
type: str
required: false
remote:
description: The remote to use for the Incus CLI.
type: str
default: local
project:
description:
- Project to get network information from
Expand Down Expand Up @@ -89,10 +93,11 @@ class IncusInstanceInfo(object):
def __init__(self, module):
self.module = module
self.name = module.params['name']
self.remote = module.params['remote']
self.project = module.params['project']
self.target = module.params['target']

self.client = IncusClient(project=self.project, target=self.target)
self.client = IncusClient(project=self.project, target=self.target, remote=self.remote)
self.api_endpoint = '/1.0/instances'
self.logs = []

Expand Down Expand Up @@ -152,6 +157,7 @@ def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(type='str', required=False),
remote=dict(type='str', default='local'),
project=dict(type='str', default='default'),
target=dict(type='str', required=False),
),
Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/incus_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
- Name of the network
type: str
required: true
remote:
description: The remote to use for the Incus CLI.
type: str
default: local
project:
description:
- Project to manage the network in
Expand Down Expand Up @@ -259,6 +263,7 @@ def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(type='str', required=True),
remote=dict(type='str', default='local'),
project=dict(type='str', default='default'),
description=dict(type='str', required=False),
config=dict(type='dict', required=False),
Expand Down
8 changes: 7 additions & 1 deletion plugins/modules/incus_network_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
- Name of the network. If empty all networks will be returned.
type: str
required: false
remote:
description: The remote to use for the Incus CLI.
type: str
default: local
project:
description:
- Project to get network information from
Expand Down Expand Up @@ -84,8 +88,9 @@ def __init__(self, module):
self.name = module.params['name']
self.project = module.params['project']
self.target = module.params['target']
self.remote = module.params['remote']

self.client = IncusClient(project=self.project, target=self.target)
self.client = IncusClient(project=self.project, target=self.target, remote=self.remote)
self.api_endpoint = '/1.0/networks'
self.logs = []

Expand Down Expand Up @@ -145,6 +150,7 @@ def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(type='str', required=False),
remote=dict(type='str', default='local'),
project=dict(type='str', default='default'),
target=dict(type='str', required=False),
),
Expand Down
11 changes: 9 additions & 2 deletions plugins/modules/incus_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
- Name of the profile
type: str
required: true
remote:
description: The remote to use for the Incus CLI.
type: str
default: local
project:
description:
- Project to manage the profile in
Expand Down Expand Up @@ -86,13 +90,15 @@ def clean_resource(resource, **defaults):
class IncusProfileManagement(object):
def __init__(self, module):
self.module = module
self.client = IncusClient(module.params['project'])

self.remote = self.module.params['remote']
self.project = module.params['project']
self.name = self.module.params['name']
self.description = self.module.params['description']
self.config = self.module.params['config']
self.devices = self.module.params['devices']
self.state = self.module.params['state']

self.client = IncusClient(project=self.project, remote=self.remote)
self.actions = []

def _get_current(self):
Expand Down Expand Up @@ -175,6 +181,7 @@ def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(type='str', required=True),
remote=dict(type='str', default='local'),
project=dict(type='str', default='default'),
description=dict(type='str', required=False),
config=dict(type='dict', required=False, default={}),
Expand Down

0 comments on commit d1c9652

Please sign in to comment.