1"""Capture virtual server image."""
2# :license: MIT, see LICENSE for more details.
3
4import click
5
6import SoftLayer
7from SoftLayer.CLI import environment
8from SoftLayer.CLI import formatting
9from SoftLayer.CLI import helpers
10
11
12# pylint: disable=redefined-builtin
13
14@click.command(short_help="Capture SoftLayer image.")
15@click.argument('identifier')
16@click.option('--name', '-n', required=True, help="Name of the image")
17@click.option('--all', help="Capture all disks belonging to the VS")
18@click.option('--note', help="Add a note to be associated with the image")
19@environment.pass_env
20def cli(env, identifier, name, all, note):
21    """Capture one or all disks from a virtual server to a SoftLayer image."""
22
23    vsi = SoftLayer.VSManager(env.client)
24    vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS')
25
26    capture = vsi.capture(vs_id, name, all, note)
27
28    table = formatting.KeyValueTable(['name', 'value'])
29    table.align['name'] = 'r'
30    table.align['value'] = 'l'
31
32    table.add_row(['vs_id', capture['guestId']])
33    table.add_row(['date', capture['createDate'][:10]])
34    table.add_row(['time', capture['createDate'][11:19]])
35    table.add_row(['transaction', formatting.transaction_status(capture)])
36    table.add_row(['transaction_id', capture['id']])
37    table.add_row(['all_disks', all])
38    env.fout(table)
39