diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-06-05 15:19:42 +0200 |
---|---|---|
committer | lupoDharkael <izhe@hotmail.es> | 2024-07-04 16:14:20 +0200 |
commit | 6f9da3fdbb2905d79151e2e4b6a00b0d35a64d18 (patch) | |
tree | 28c949f1beb04cd12eca45254373abc9d5b2ed7c | |
parent | f53a60129b39aeee35261b3a4c185386cc50bfb4 (diff) |
objects: fix restore image default repo value
Obtain the image's repository from the API REST.
Don't send 127.0.0.1 as image server when --repo is not defined.
-rw-r--r-- | cli/objects/images.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/cli/objects/images.py b/cli/objects/images.py index 67bbf45..21f727c 100644 --- a/cli/objects/images.py +++ b/cli/objects/images.py @@ -9,6 +9,23 @@ from urllib.parse import urlparse from cli.utils import * import argparse +import requests + +def get_repository(repository_id, rest): + repositories = get_repositories(rest) + if not repositories: + return None + [repository] = [repository for repository in repositories + if repository['id'] == repository_id] + return repository + + +def get_repositories(rest): + r = rest.get('/repositories') + if not r or r.status_code != requests.codes.ok: + return None + repositories = r.json()['repositories'] + return repositories class OgImage(): @@ -43,7 +60,7 @@ class OgImage(): help='Transfer method. (Default: tiptorrent)') parser.add_argument('--repo', nargs='?', - default=urlparse(rest.URL).netloc.split(':')[0], + required=False, help='Repository IP address') group = parser.add_argument_group('clients', 'Client selection args') group.add_argument('--center-id', @@ -92,6 +109,13 @@ class OgImage(): else: found_image = found_image[0] + if not parsed_args.repo: + repository = get_repository(found_image['repo_id'], rest) + if not repository: + print(f'Could not find repository for image {found_image["name"]}') + return + parsed_args.repo = repository['ip'] + payload = {'disk': parsed_args.disk, 'partition': parsed_args.part, 'id': str(parsed_args.id), 'name': found_image['name'], 'profile': str(found_image['software_id']), |