|
5 | 5 |
|
6 | 6 | import SoftLayer |
7 | 7 | from SoftLayer.CLI import environment |
8 | | - |
9 | | -# pylint: disable=redefined-builtin |
| 8 | +from SoftLayer.CLI import exceptions |
| 9 | +from SoftLayer.CLI import formatting |
10 | 10 |
|
11 | 11 |
|
12 | 12 | @click.command() |
13 | | -@click.argument('account_id') |
14 | | -@click.argument('content_url') |
15 | | -@click.option('--type', |
16 | | - help='The media type for this mapping (http, flash, wm, ...)', |
| 13 | +@click.argument('unique_id') |
| 14 | +@click.argument('origin') |
| 15 | +@click.argument('path') |
| 16 | +@click.option('--origin-type', '-t', |
| 17 | + type=click.Choice(['server', 'storage']), |
| 18 | + help='The origin type.', |
| 19 | + default='server', |
| 20 | + show_default=True) |
| 21 | +@click.option('--header', '-H', |
| 22 | + type=click.STRING, |
| 23 | + help='The host header to communicate with the origin.') |
| 24 | +@click.option('--bucket-name', '-b', |
| 25 | + type=click.STRING, |
| 26 | + help="The name of the available resource [required if --origin-type=storage]") |
| 27 | +@click.option('--port', '-p', |
| 28 | + type=click.INT, |
| 29 | + help="The http port number.", |
| 30 | + default=80, |
| 31 | + show_default=True) |
| 32 | +@click.option('--protocol', '-P', |
| 33 | + type=click.STRING, |
| 34 | + help="The protocol used by the origin.", |
17 | 35 | default='http', |
18 | 36 | show_default=True) |
19 | | -@click.option('--cname', |
20 | | - help='An optional CNAME to attach to the mapping') |
| 37 | +@click.option('--optimize-for', '-o', |
| 38 | + type=click.Choice(['web', 'video', 'file']), |
| 39 | + help="Performance configuration", |
| 40 | + default='web', |
| 41 | + show_default=True) |
| 42 | +@click.option('--extensions', '-e', |
| 43 | + type=click.STRING, |
| 44 | + help="File extensions that can be stored in the CDN, example: 'jpg, png, pdf'") |
| 45 | +@click.option('--cache-query', '-c', |
| 46 | + type=click.STRING, |
| 47 | + help="Cache query rules with the following formats:\n" |
| 48 | + "'ignore-all', 'include: <query-names>', 'ignore: <query-names>'", |
| 49 | + default="include-all", |
| 50 | + show_default=True) |
21 | 51 | @environment.pass_env |
22 | | -def cli(env, account_id, content_url, type, cname): |
23 | | - """Create an origin pull mapping.""" |
| 52 | +def cli(env, unique_id, origin, path, origin_type, header, |
| 53 | + bucket_name, port, protocol, optimize_for, extensions, cache_query): |
| 54 | + """Create an origin path for an existing CDN mapping. |
| 55 | +
|
| 56 | + For more information see the following documentation: \n |
| 57 | + https://cloud.ibm.com/docs/infrastructure/CDN?topic=CDN-manage-your-cdn#adding-origin-path-details |
| 58 | + """ |
24 | 59 |
|
25 | 60 | manager = SoftLayer.CDNManager(env.client) |
26 | | - manager.add_origin(account_id, type, content_url, cname) |
| 61 | + |
| 62 | + if origin_type == 'storage' and not bucket_name: |
| 63 | + raise exceptions.ArgumentError('[-b | --bucket-name] is required when [-t | --origin-type] is "storage"') |
| 64 | + |
| 65 | + result = manager.add_origin(unique_id, origin, path, origin_type=origin_type, |
| 66 | + header=header, port=port, protocol=protocol, |
| 67 | + bucket_name=bucket_name, file_extensions=extensions, |
| 68 | + optimize_for=optimize_for, cache_query=cache_query) |
| 69 | + |
| 70 | + table = formatting.Table(['Item', 'Value']) |
| 71 | + table.align['Item'] = 'r' |
| 72 | + table.align['Value'] = 'r' |
| 73 | + |
| 74 | + table.add_row(['CDN Unique ID', result['mappingUniqueId']]) |
| 75 | + |
| 76 | + if origin_type == 'storage': |
| 77 | + table.add_row(['Bucket Name', result['bucketName']]) |
| 78 | + |
| 79 | + table.add_row(['Origin', result['origin']]) |
| 80 | + table.add_row(['Origin Type', result['originType']]) |
| 81 | + table.add_row(['Path', result['path']]) |
| 82 | + table.add_row(['Port', result['httpPort']]) |
| 83 | + table.add_row(['Configuration', result['performanceConfiguration']]) |
| 84 | + table.add_row(['Status', result['status']]) |
| 85 | + |
| 86 | + env.fout(table) |
0 commit comments