summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2022-10-18 17:07:04 +0200
committerJose M. Guisado <jguisado@soleta.eu>2022-10-20 12:25:10 +0200
commitdff298d421afcbe2bdd2246be961d5e963b7fdd0 (patch)
tree8bef16b6ed461d29690304ebfd4b6bc9c49355a5 /cli
parent0c1a747a31b32a068078c27fb81bc158b2ea8af5 (diff)
create image: split into create and updatev0.2
Image creation example: ogcli create image --disk --part 1 --name 18oct2 --desc 18oct2 --repo-id 1 --client-ip 192.168.56.11 Image update example: ogcli update image --disk 1 --part 1 --id 20 --client-ip 192.168.56.11
Diffstat (limited to 'cli')
-rw-r--r--cli/cli.py9
-rw-r--r--cli/objects/images.py74
2 files changed, 80 insertions, 3 deletions
diff --git a/cli/cli.py b/cli/cli.py
index 7d3142d..6837852 100644
--- a/cli/cli.py
+++ b/cli/cli.py
@@ -125,3 +125,12 @@ class OgCLI():
if parsed_args.setup_obj == 'disk':
OgDisk.setup_disk(self.rest, args[1:])
+
+ def update(self, args):
+ choices = ['image']
+ parser = argparse.ArgumentParser(prog='ogcli update')
+ parser.add_argument('update_obj', choices=choices)
+ parsed_args = parser.parse_args([args[0]])
+
+ if parsed_args.update_obj == 'image':
+ OgImage.update_image(self.rest, args[1:])
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)