summaryrefslogtreecommitdiffstats
path: root/cli/objects
diff options
context:
space:
mode:
Diffstat (limited to 'cli/objects')
-rw-r--r--cli/objects/images.py26
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']),