Example #1
0
def cli(env, unique_id, origin_path):
    """Removes an origin path for an existing CDN mapping."""

    manager = SoftLayer.CDNManager(env.client)
    manager.remove_origin(unique_id, origin_path)

    click.secho("Origin with path %s has been deleted" % origin_path, fg='green')
Example #2
0
def cli(env, unique_id, history):
    """Detail a CDN Account."""

    manager = SoftLayer.CDNManager(env.client)

    cdn_mapping = manager.get_cdn(unique_id)
    cdn_metrics = manager.get_usage_metrics(unique_id, history=history)

    # usage metrics
    total_bandwidth = "%s GB" % cdn_metrics['totals'][0]
    total_hits = cdn_metrics['totals'][1]
    hit_ratio = "%s %%" % cdn_metrics['totals'][2]

    table = formatting.KeyValueTable(['name', 'value'])
    table.align['name'] = 'r'
    table.align['value'] = 'l'

    table.add_row(['unique_id', cdn_mapping['uniqueId']])
    table.add_row(['hostname', cdn_mapping['domain']])
    table.add_row(['protocol', cdn_mapping['protocol']])
    table.add_row(['origin', cdn_mapping['originHost']])
    table.add_row(['origin_type', cdn_mapping['originType']])
    table.add_row(['path', cdn_mapping['path']])
    table.add_row(['provider', cdn_mapping['vendorName']])
    table.add_row(['status', cdn_mapping['status']])
    table.add_row(['total_bandwidth', total_bandwidth])
    table.add_row(['total_hits', total_hits])
    table.add_row(['hit_radio', hit_ratio])

    env.fout(table)
Example #3
0
def cli(env, unique_id, origin, path, origin_type, header,
        bucket_name, port, protocol, optimize_for, extensions, cache_query):
    """Create an origin path for an existing CDN mapping.

    For more information see the following documentation: \n
    https://cloud.ibm.com/docs/infrastructure/CDN?topic=CDN-manage-your-cdn#adding-origin-path-details
    """

    manager = SoftLayer.CDNManager(env.client)

    if origin_type == 'storage' and not bucket_name:
        raise exceptions.ArgumentError('[-b | --bucket-name] is required when [-t | --origin-type] is "storage"')

    result = manager.add_origin(unique_id, origin, path, origin_type=origin_type,
                                header=header, port=port, protocol=protocol,
                                bucket_name=bucket_name, file_extensions=extensions,
                                optimize_for=optimize_for, cache_query=cache_query)

    table = formatting.Table(['Item', 'Value'])
    table.align['Item'] = 'r'
    table.align['Value'] = 'r'

    table.add_row(['CDN Unique ID', result['mappingUniqueId']])

    if origin_type == 'storage':
        table.add_row(['Bucket Name', result['bucketName']])

    table.add_row(['Origin', result['origin']])
    table.add_row(['Origin Type', result['originType']])
    table.add_row(['Path', result['path']])
    table.add_row(['Port', result['httpPort']])
    table.add_row(['Configuration', result['performanceConfiguration']])
    table.add_row(['Status', result['status']])

    env.fout(table)
Example #4
0
    def execute(self, args):
        manager = SoftLayer.CDNManager(self.client)
        origins = manager.get_origins(args.get('<account>'))

        table = formatting.Table(['id', 'media_type', 'cname', 'origin_url'])

        for origin in origins:
            table.add_row([
                origin['id'], origin['mediaType'],
                origin.get('cname', formatting.blank()), origin['originUrl']
            ])

        return table
def cli(env, account_id):
    """List origin pull mappings."""

    manager = SoftLayer.CDNManager(env.client)
    origins = manager.get_origins(account_id)

    table = formatting.Table(['id', 'media_type', 'cname', 'origin_url'])

    for origin in origins:
        table.add_row([
            origin['id'], origin['mediaType'],
            origin.get('cname', formatting.blank()), origin['originUrl']
        ])

    env.fout(table)
Example #6
0
def cli(env, unique_id):
    """List origin path for an existing CDN mapping."""

    manager = SoftLayer.CDNManager(env.client)
    origins = manager.get_origins(unique_id)

    table = formatting.Table(['Path', 'Origin', 'HTTP Port', 'Status'])

    for origin in origins:
        table.add_row([origin['path'],
                       origin['origin'],
                       origin['httpPort'],
                       origin['status']])

    env.fout(table)
Example #7
0
    def execute(self, args):
        manager = SoftLayer.CDNManager(self.client)
        accounts = manager.list_accounts()

        table = formatting.Table(
            ['id', 'account_name', 'type', 'created', 'notes'])
        for account in accounts:
            table.add_row([
                account['id'], account['cdnAccountName'],
                account['cdnSolutionName'], account['createDate'],
                account.get('cdnAccountNote', formatting.blank())
            ])

        table.sortby = args['--sortby']
        return table
Example #8
0
def cli(env, identifier, header, http_port, origin, respect_headers, cache,
        performance_configuration):
    """Edit a CDN Account.

       Note: You can use the hostname or uniqueId as IDENTIFIER.
    """

    manager = SoftLayer.CDNManager(env.client)
    cdn_id = helpers.resolve_id(manager.resolve_ids, identifier, 'CDN')

    cache_result = {}
    if cache:
        if len(cache) > 1:
            cache_result['cacheKeyQueryRule'] = cache[0]
            cache_result['description'] = cache[1]
        else:
            cache_result['cacheKeyQueryRule'] = cache[0]

    cdn_result = manager.edit(
        cdn_id,
        header=header,
        http_port=http_port,
        origin=origin,
        respect_headers=respect_headers,
        cache=cache_result,
        performance_configuration=performance_configuration)

    table = formatting.KeyValueTable(['name', 'value'])
    table.align['name'] = 'r'
    table.align['value'] = 'l'

    for cdn in cdn_result:
        table.add_row(['Create Date', cdn.get('createDate')])
        table.add_row(['Header', cdn.get('header')])
        table.add_row(['Http Port', cdn.get('httpPort')])
        table.add_row(['Origin Type', cdn.get('originType')])
        table.add_row(
            ['Performance Configuration',
             cdn.get('performanceConfiguration')])
        table.add_row(['Protocol', cdn.get('protocol')])
        table.add_row(['Respect Headers', cdn.get('respectHeaders')])
        table.add_row(['Unique Id', cdn.get('uniqueId')])
        table.add_row(['Vendor Name', cdn.get('vendorName')])
        table.add_row(['Cache key optimization', cdn.get('cacheKeyQueryRule')])
        table.add_row(['cname', cdn.get('cname')])
        table.add_row(['Origin server address', cdn.get('originHost')])

    env.fout(table)
Example #9
0
def cli(env, sortby):
    """List all CDN accounts."""

    manager = SoftLayer.CDNManager(env.client)
    accounts = manager.list_cdn()

    table = formatting.Table(
        ['unique_id', 'domain', 'origin', 'vendor', 'cname', 'status'])
    for account in accounts:
        table.add_row([
            account['uniqueId'], account['domain'], account['originHost'],
            account['vendorName'], account['cname'], account['status']
        ])

    table.sortby = sortby
    env.fout(table)
Example #10
0
def cli(env, account_id, content_url):
    """Purge cached files from all edge nodes.

    Examples:
         slcli cdn purge 97794 http://example.com/cdn/file.txt
         slcli cdn purge 97794 http://example.com/cdn/file.txt https://dal01.example.softlayer.net/image.png
    """

    manager = SoftLayer.CDNManager(env.client)
    content_list = manager.purge_content(account_id, content_url)

    table = formatting.Table(['url', 'status'])

    for content in content_list:
        table.add_row([content['url'], content['statusCode']])

    env.fout(table)
Example #11
0
def cli(env, sortby):
    """List all CDN accounts."""

    manager = SoftLayer.CDNManager(env.client)
    accounts = manager.list_accounts()

    table = formatting.Table(
        ['id', 'account_name', 'type', 'created', 'notes'])
    for account in accounts:
        table.add_row([
            account['id'], account['cdnAccountName'],
            account['cdnSolutionName'], account['createDate'],
            account.get('cdnAccountNote', formatting.blank())
        ])

    table.sortby = sortby
    env.fout(table)
Example #12
0
    def execute(self, args):
        manager = SoftLayer.CDNManager(self.client)
        account = manager.get_account(args.get('<account>'))

        table = formatting.KeyValueTable(['Name', 'Value'])
        table.align['Name'] = 'r'
        table.align['Value'] = 'l'

        table.add_row(['id', account['id']])
        table.add_row(['account_name', account['cdnAccountName']])
        table.add_row(['type', account['cdnSolutionName']])
        table.add_row(['status', account['status']['name']])
        table.add_row(['created', account['createDate']])
        table.add_row(
            ['notes',
             account.get('cdnAccountNote', formatting.blank())])

        return table
Example #13
0
def cli(env, account_id):
    """Detail a CDN Account."""

    manager = SoftLayer.CDNManager(env.client)
    account = manager.get_account(account_id)

    table = formatting.KeyValueTable(['Name', 'Value'])
    table.align['Name'] = 'r'
    table.align['Value'] = 'l'

    table.add_row(['id', account['id']])
    table.add_row(['account_name', account['cdnAccountName']])
    table.add_row(['type', account['cdnSolutionName']])
    table.add_row(['status', account['status']['name']])
    table.add_row(['created', account['createDate']])
    table.add_row(['notes', account.get('cdnAccountNote', formatting.blank())])

    return table
Example #14
0
def cli(env, unique_id, path):
    """Creates a purge record and also initiates the purge call.

        Example:
             slcli cdn purge 9779455 /article/file.txt

        For more information see the following documentation: \n
        https://cloud.ibm.com/docs/infrastructure/CDN?topic=CDN-manage-your-cdn#purging-cached-content
    """

    manager = SoftLayer.CDNManager(env.client)
    result = manager.purge_content(unique_id, path)

    table = formatting.Table(['Date', 'Path', 'Saved', 'Status'])

    for data in result:
        table.add_row(
            [data['date'], data['path'], data['saved'], data['status']])

    env.fout(table)
def cli(env, account_id, origin_id):
    """Remove an origin pull mapping."""

    manager = SoftLayer.CDNManager(env.client)
    manager.remove_origin(account_id, origin_id)
def cli(env, account_id, content_url, type, cname):
    """Create an origin pull mapping."""

    manager = SoftLayer.CDNManager(env.client)
    manager.add_origin(account_id, type, content_url, cname)
Example #17
0
    def execute(self, args):
        manager = SoftLayer.CDNManager(self.client)
        media_type = args.get('--type') or 'http'

        manager.add_origin(args.get('<account>'), media_type,
                           args.get('<url>'), args.get('--cname', None))
Example #18
0
 def execute(self, args):
     manager = SoftLayer.CDNManager(self.client)
     manager.remove_origin(args.get('<account>'), args.get('<origin_id>'))
Example #19
0
def cli(env, account_id, content_url):
    """Cache one or more files on all edge nodes."""

    manager = SoftLayer.CDNManager(env.client)
    manager.load_content(account_id, content_url)
Example #20
0
 def execute(self, args):
     manager = SoftLayer.CDNManager(self.client)
     manager.load_content(args.get('<account>'), args.get('<content_url>'))
Example #21
0
def cli(env, account_id, content_url):
    """Purge cached files from all edge nodes."""

    manager = SoftLayer.CDNManager(env.client)
    manager.purge_content(account_id, content_url)