summaryrefslogtreecommitdiffstats
path: root/cli/objects
diff options
context:
space:
mode:
Diffstat (limited to 'cli/objects')
-rw-r--r--cli/objects/images.py74
1 files changed, 71 insertions, 3 deletions
diff --git a/cli/objects/images.py b/cli/objects/images.py
index 2f9f879..3bed476 100644
--- a/cli/objects/images.py
+++ b/cli/objects/images.py
@@ -116,12 +116,13 @@ class OgImage():
help='Image name')
parser.add_argument('--desc',
nargs='?',
- required=False,
- help='Image description (for new images)')
+ required=True,
+ help='Image description')
parser.add_argument('--repo-id',
nargs='?',
default=1,
- help='Images repository id')
+ type=int,
+ help='Images repository id (Default: 1)')
group = parser.add_argument_group('clients', 'Client selection args')
group.add_argument('--client-ip',
action='append',
@@ -152,3 +153,70 @@ class OgImage():
payload['repository_id'] = parsed_args.repo_id
rest.post('/image/create', payload=payload)
+
+ @staticmethod
+ def update_image(rest, args):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--disk',
+ nargs='?',
+ required=True,
+ help='Disk')
+ parser.add_argument('--part',
+ nargs='?',
+ required=True,
+ help='Partition')
+ parser.add_argument('--id',
+ nargs='?',
+ required=True,
+ help='Image id')
+ parser.add_argument('--repo-id',
+ nargs='?',
+ default=1,
+ type=int,
+ help='Images repository id (Default: 1)')
+ group = parser.add_argument_group('clients', 'Client selection args')
+ group.add_argument('--client-ip',
+ action='append',
+ default=[],
+ required=True,
+ help='Specific client IP')
+ parsed_args = parser.parse_args(args)
+
+ r = rest.get('/client/info', payload={'client': parsed_args.client_ip})
+ center_id = r.json()['center']
+
+ r = rest.get('/client/setup',
+ payload={'client': parsed_args.client_ip})
+ if r.status_code == 200:
+ part_info = list(filter(lambda x: x['disk'] == int(parsed_args.disk) and
+ x['partition'] == int(parsed_args.part),
+ r.json()['partitions']))
+ if not part_info:
+ print('Partition not found.')
+ return
+ fs_code = list(part_info)[0]['code']
+
+ r = rest.get('/images')
+ image_name = None
+ if r.status_code == 200:
+ for image in r.json()['images']:
+ if image['id'] == int(parsed_args.id):
+ image_name = image['name']
+ break
+
+ if not image_name:
+ print('Image not found')
+ return
+ else:
+ print(f'Updating {image_name} image')
+
+ payload = {'clients': parsed_args.client_ip,
+ 'disk': parsed_args.disk,
+ 'center_id': center_id,
+ 'partition': parsed_args.part,
+ 'code': str(fs_code),
+ 'id': parsed_args.id,
+ 'name': image_name,
+ 'repository_id': parsed_args.repo_id}
+
+ rest.post('/image/create', payload=payload)