|
| 1 | +"""Import an image.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | + |
| 4 | +import SoftLayer |
| 5 | +from SoftLayer.CLI import environment |
| 6 | +from SoftLayer.CLI import exceptions |
| 7 | +from SoftLayer.CLI import formatting |
| 8 | + |
| 9 | + |
| 10 | +import click |
| 11 | + |
| 12 | + |
| 13 | +@click.command() |
| 14 | +@click.argument('name') |
| 15 | +@click.argument('uri') |
| 16 | +@click.option('--note', default="", |
| 17 | + help="The note to be applied to the imported template") |
| 18 | +@click.option('--osrefcode', default="", |
| 19 | + help="The referenceCode of the operating system software" |
| 20 | + " description for the imported VHD") |
| 21 | +@environment.pass_env |
| 22 | +def cli(env, name, note, osrefcode, uri): |
| 23 | + """Import an image.""" |
| 24 | + |
| 25 | + image_mgr = SoftLayer.ImageManager(env.client) |
| 26 | + data = {} |
| 27 | + output = [] |
| 28 | + if name: |
| 29 | + data['name'] = name |
| 30 | + if note: |
| 31 | + data['note'] = note |
| 32 | + if osrefcode: |
| 33 | + data['operatingSystemReferenceCode'] = osrefcode |
| 34 | + if uri: |
| 35 | + data['uri'] = uri |
| 36 | + |
| 37 | + # not sure if u should validate here or not |
| 38 | + # if uri.endswith(".vhd") and osrefcode == "": |
| 39 | + # raise exceptions.CLIAbort("Please specify osrefcode for .vhdImage") |
| 40 | + |
| 41 | + result = image_mgr.import_image_from_uri(data) |
| 42 | + |
| 43 | + if not result: |
| 44 | + raise exceptions.CLIAbort("Failed to import Image") |
| 45 | + |
| 46 | + table = formatting.KeyValueTable(['name', 'value']) |
| 47 | + table.align['name'] = 'r' |
| 48 | + table.align['value'] = 'l' |
| 49 | + table.add_row(['name', result['name']]) |
| 50 | + table.add_row(['id', result['id']]) |
| 51 | + table.add_row(['created', result['createDate']]) |
| 52 | + table.add_row(['guid', result['globalIdentifier']]) |
| 53 | + output.append(table) |
| 54 | + return output |
0 commit comments