|
| 1 | +"""Create a CDN domain mapping.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | + |
| 4 | +import click |
| 5 | + |
| 6 | +import SoftLayer |
| 7 | +from SoftLayer.CLI import environment |
| 8 | +from SoftLayer.CLI import exceptions |
| 9 | +from SoftLayer.CLI import formatting |
| 10 | + |
| 11 | + |
| 12 | +@click.command(cls=SoftLayer.CLI.command.SLCommand, ) |
| 13 | +@click.option('--hostname', required=True, help="To route requests to your website, enter the hostname for your" |
| 14 | + "website, for example, www.example.com or app.example.com.") |
| 15 | +@click.option('--origin', required=True, help="Your server IP address or hostname.") |
| 16 | +@click.option('--origin-type', default="server", type=click.Choice(['server', 'storage']), show_default=True, |
| 17 | + help="The origin type. Note: If OriginType is storage then OriginHost is take as Endpoint") |
| 18 | +@click.option('--http', help="Http port") |
| 19 | +@click.option('--https', help="Https port") |
| 20 | +@click.option('--bucket-name', help="Bucket name") |
| 21 | +@click.option('--cname', help="Enter a globally unique subdomain. The full URL becomes the CNAME we use to configure" |
| 22 | + " your DNS. If no value is entered, we will generate a CNAME for you.") |
| 23 | +@click.option('--header', help="The edge server uses the host header in the HTTP header to communicate with the" |
| 24 | + " Origin host. It defaults to Hostname.") |
| 25 | +@click.option('--path', help="Give a path relative to the domain provided, which can be used to reach this Origin." |
| 26 | + " For example, 'articles/video' => 'www.example.com/articles/video") |
| 27 | +@click.option('--ssl', default="dvSan", type=click.Choice(['dvSan', 'wilcard']), help="A DV SAN Certificate allows" |
| 28 | + " HTTPS traffic over your personal domain, but it requires a domain validation to prove ownership." |
| 29 | + " A wildcard certificate allows HTTPS traffic only when using the CNAME given.") |
| 30 | +@environment.pass_env |
| 31 | +def cli(env, hostname, origin, origin_type, http, https, bucket_name, cname, header, path, ssl): |
| 32 | + """Create a CDN domain mapping.""" |
| 33 | + if not http and not https: |
| 34 | + raise exceptions.CLIAbort('Is needed http or https options') |
| 35 | + |
| 36 | + manager = SoftLayer.CDNManager(env.client) |
| 37 | + cdn = manager.create_cdn(hostname, origin, origin_type, http, https, bucket_name, cname, header, path, ssl) |
| 38 | + |
| 39 | + table = formatting.Table(['Name', 'Value']) |
| 40 | + table.add_row(['CDN Unique ID', cdn.get('uniqueId')]) |
| 41 | + if bucket_name: |
| 42 | + table.add_row(['Bucket Name', cdn.get('bucketName')]) |
| 43 | + table.add_row(['Hostname', cdn.get('domain')]) |
| 44 | + table.add_row(['Header', cdn.get('header')]) |
| 45 | + table.add_row(['IBM CNAME', cdn.get('cname')]) |
| 46 | + table.add_row(['Akamai CNAME', cdn.get('akamaiCname')]) |
| 47 | + table.add_row(['Origin Host', cdn.get('originHost')]) |
| 48 | + table.add_row(['Origin Type', cdn.get('originType')]) |
| 49 | + table.add_row(['Protocol', cdn.get('protocol')]) |
| 50 | + table.add_row(['Http Port', cdn.get('httpPort')]) |
| 51 | + table.add_row(['Https Port', cdn.get('httpsPort')]) |
| 52 | + table.add_row(['Certificate Type', cdn.get('certificateType')]) |
| 53 | + table.add_row(['Provider', cdn.get('vendorName')]) |
| 54 | + table.add_row(['Path', cdn.get('path')]) |
| 55 | + |
| 56 | + env.fout(table) |
0 commit comments