Skip to content

Commit 41c4703

Browse files
committed
Merge branch 'master' into issue1916
2 parents b0aaf22 + 298cb14 commit 41c4703

27 files changed

+452
-10
lines changed

SoftLayer/CLI/account/orders.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,34 @@
1010
from SoftLayer import utils
1111

1212

13+
def upgrade_table(upgrades):
14+
"""Formats a table for upgrade orders"""
15+
table = formatting.Table(['Id', 'Maintance window', 'Status', 'Created Date',
16+
'Case'], title="Upgrade orders")
17+
table.align['Subject'] = 'l'
18+
table.align['Impacted Resources'] = 'l'
19+
for upgrade in upgrades:
20+
table.add_row([upgrade.get('id'),
21+
upgrade.get('maintenanceStartTimeUtc'),
22+
upgrade.get('statusId'),
23+
upgrade.get('createDate'),
24+
upgrade.get('ticketId') or '--'])
25+
return table
26+
27+
1328
@click.command(cls=SLCommand)
1429
@click.option('--limit', '-l',
1530
help='How many results to get in one api call',
16-
default=50,
31+
default=100,
1732
show_default=True)
33+
@click.option('--upgrades', is_flag=True, default=False,
34+
help="Show upgrades orders.")
1835
@environment.pass_env
19-
def cli(env, limit):
36+
def cli(env, limit, upgrades):
2037
"""Lists account orders. Use `slcli order lookup <ID>` to find more details about a specific order."""
2138
manager = AccountManager(env.client)
2239
orders = manager.get_account_all_billing_orders(limit)
40+
upgrade = manager.get_account_upgrade_orders(limit)
2341

2442
order_table = formatting.Table(['Id', 'State', 'User', 'Date', 'Amount', 'Item'],
2543
title="orders")
@@ -34,3 +52,5 @@ def cli(env, limit):
3452
order_table.add_row([order['id'], order['status'], order['userRecord']['username'], create_date,
3553
order['orderTotalAmount'], utils.trim_to(' '.join(map(str, items)), 50)])
3654
env.fout(order_table)
55+
if upgrades:
56+
env.fout(upgrade_table(upgrade))

SoftLayer/CLI/block/detail.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ def cli(env, volume_id):
2323
table.align['Name'] = 'r'
2424
table.align['Value'] = 'l'
2525

26+
capacity = '0'
27+
if block_volume['capacityGb'] != '':
28+
capacity = "%iGB" % block_volume['capacityGb']
2629
storage_type = block_volume['storageType']['keyName'].split('_').pop(0)
2730
table.add_row(['ID', block_volume['id']])
2831
table.add_row(['Username', block_volume['username']])
2932
table.add_row(['Type', storage_type])
30-
table.add_row(['Capacity (GB)', "%iGB" % block_volume['capacityGb']])
33+
table.add_row(['Capacity (GB)', capacity])
3134
table.add_row(['LUN Id', "%s" % block_volume['lunId']])
3235

3336
if block_volume.get('provisionedIops'):

SoftLayer/CLI/cdn/create.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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)

SoftLayer/CLI/cdn/delete.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Delete 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+
9+
10+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
11+
@click.argument('unique_id')
12+
@environment.pass_env
13+
def cli(env, unique_id):
14+
"""Delete a CDN domain mapping."""
15+
16+
manager = SoftLayer.CDNManager(env.client)
17+
18+
cdn = manager.delete_cdn(unique_id)
19+
20+
if cdn:
21+
env.fout("Cdn with uniqueId: {} was deleted.".format(unique_id))

SoftLayer/CLI/file/detail.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
from SoftLayer import utils
1010

1111

12+
def get_capacity(file_volume):
13+
"""Get the capacity Gb with validate the data"""
14+
capacity = '0'
15+
if file_volume['capacityGb'] != '':
16+
capacity = "%iGB" % file_volume['capacityGb']
17+
return capacity
18+
19+
1220
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1321
@click.argument('volume_id')
1422
@environment.pass_env
@@ -27,7 +35,7 @@ def cli(env, volume_id):
2735
table.add_row(['ID', file_volume['id']])
2836
table.add_row(['Username', file_volume['username']])
2937
table.add_row(['Type', storage_type])
30-
table.add_row(['Capacity (GB)', "%iGB" % file_volume['capacityGb']])
38+
table.add_row(['Capacity (GB)', get_capacity(file_volume)])
3139

3240
used_space = int(file_volume['bytesUsed']) \
3341
if file_volume['bytesUsed'] else 0

SoftLayer/CLI/firewall/detail.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1414
@click.argument('identifier')
15-
@click.option('--credentials', type=click.BOOL,
15+
@click.option('--password', is_flag=True,
1616
help="Display FortiGate username and FortiGate password to multi vlans.")
1717
@environment.pass_env
18-
def cli(env, identifier, credentials):
18+
def cli(env, identifier, password):
1919
"""Detail firewall.
2020
2121
EXAMPLES:
@@ -63,7 +63,7 @@ def cli(env, identifier, credentials):
6363
table.add_row(['private vlan', utils.lookup(_firewall, 'networkGateway', 'privateVlan', 'vlanNumber')])
6464
table.add_row(['type', _firewall.get('firewallType')])
6565

66-
if credentials:
66+
if password:
6767
table.add_row(['fortiGate username', utils.lookup(_firewall, 'managementCredentials', 'username')])
6868
table.add_row(['fortiGate password', utils.lookup(_firewall, 'managementCredentials', 'password')])
6969

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Cancel an existing object-storage account."""
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.argument('storage-id')
14+
@click.option('--reason', help="An optional reason for cancellation")
15+
@click.option('--immediate',
16+
is_flag=True,
17+
help="Cancels the object storage immediately instead "
18+
"of on the billing anniversary")
19+
@environment.pass_env
20+
def cli(env, storage_id, reason, immediate):
21+
"""Cancel an existing object storage."""
22+
23+
block_storage_manager = SoftLayer.BlockStorageManager(env.client)
24+
25+
if not (env.skip_confirmations or formatting.no_going_back(storage_id)):
26+
raise exceptions.CLIAbort('Aborted')
27+
28+
cancelled = block_storage_manager.cancel_block_volume(storage_id,
29+
reason, immediate)
30+
31+
if cancelled:
32+
if immediate:
33+
click.echo('Object storage with id %s has been marked'
34+
' for immediate cancellation' % storage_id)
35+
else:
36+
click.echo('Object storage with id %s has been marked'
37+
' for cancellation' % storage_id)
38+
else:
39+
click.echo('Unable to cancel object storage %s' % storage_id)

SoftLayer/CLI/routes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
('cdn:origin-list', 'SoftLayer.CLI.cdn.origin_list:cli'),
8282
('cdn:origin-remove', 'SoftLayer.CLI.cdn.origin_remove:cli'),
8383
('cdn:purge', 'SoftLayer.CLI.cdn.purge:cli'),
84+
('cdn:delete', 'SoftLayer.CLI.cdn.delete:cli'),
85+
('cdn:create', 'SoftLayer.CLI.cdn.create:cli'),
8486

8587
('config', 'SoftLayer.CLI.config'),
8688
('config:setup', 'SoftLayer.CLI.config.setup:cli'),
@@ -261,6 +263,7 @@
261263
('object-storage:accounts', 'SoftLayer.CLI.object_storage.list_accounts:cli'),
262264
('object-storage:endpoints', 'SoftLayer.CLI.object_storage.list_endpoints:cli'),
263265
('object-storage:credential', 'SoftLayer.CLI.object_storage.credential:cli'),
266+
('object-storage:cancel', 'SoftLayer.CLI.object_storage.cancel:cli'),
264267

265268
('order', 'SoftLayer.CLI.order'),
266269
('order:category-list', 'SoftLayer.CLI.order.category_list:cli'),
@@ -385,6 +388,7 @@
385388
('user:vpn-subnet', 'SoftLayer.CLI.user.vpn_subnet:cli'),
386389
('user:remove-access', 'SoftLayer.CLI.user.remove_access:cli'),
387390
('user:grant-access', 'SoftLayer.CLI.user.grant_access:cli'),
391+
('user:vpn-password', 'SoftLayer.CLI.user.vpn_password:cli'),
388392

389393
('vlan', 'SoftLayer.CLI.vlan'),
390394
('vlan:create', 'SoftLayer.CLI.vlan.create:cli'),

SoftLayer/CLI/user/detail.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,14 @@ def basic_info(user, keys):
6565

6666
table.add_row(['Id', user.get('id', '-')])
6767
table.add_row(['Username', user.get('username', '-')])
68-
if keys:
69-
for key in user.get('apiAuthenticationKeys'):
68+
keys_array = user.get('apiAuthenticationKeys')
69+
if keys and len(keys_array) != 0:
70+
for key in keys_array:
7071
table.add_row(['APIKEY', key.get('authenticationKey')])
72+
elif keys_array is not None and len(keys_array) != 0:
73+
table.add_row(['APIKEY', 'Yes'])
74+
else:
75+
table.add_row(['APIKEY', 'No'])
7176
table.add_row(['Name', "%s %s" % (user.get('firstName', '-'), user.get('lastName', '-'))])
7277
table.add_row(['Email', user.get('email')])
7378
table.add_row(['OpenID', user.get('openIdConnectUserName')])

SoftLayer/CLI/user/vpn_password.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Set the user VPN password."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
7+
from SoftLayer.CLI.command import SLCommand as SLCommand
8+
from SoftLayer.CLI import environment
9+
from SoftLayer.CLI import helpers
10+
11+
12+
@click.command(cls=SLCommand, )
13+
@click.argument('identifier')
14+
@click.option('--password', required=True, help="Your new VPN password")
15+
@environment.pass_env
16+
def cli(env, identifier, password):
17+
"""Set the user VPN password.
18+
19+
Example: slcli user vpn-password 123456 --password=Mypassword1.
20+
"""
21+
22+
mgr = SoftLayer.UserManager(env.client)
23+
user_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'username')
24+
result = mgr.update_vpn_password(user_id, password)
25+
if result:
26+
click.secho("Successfully updated user VPN password.", fg='green')

0 commit comments

Comments
 (0)