Skip to content

Commit 6f24220

Browse files
author
caberos
committed
Merge branch 'master' of https://github.com/softlayer/softlayer-python into issue1295
2 parents d0ebf61 + 2ab11f4 commit 6f24220

File tree

17 files changed

+552
-511
lines changed

17 files changed

+552
-511
lines changed

SoftLayer/CLI/formatting.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,13 @@ def prettytable(self):
301301
else:
302302
msg = "Column (%s) doesn't exist to sort by" % self.sortby
303303
raise exceptions.CLIAbort(msg)
304-
for a_col, alignment in self.align.items():
305-
table.align[a_col] = alignment
304+
305+
if isinstance(self.align, str):
306+
table.align = self.align
307+
else:
308+
# Required because PrettyTable has a strict setter function for alignment
309+
for a_col, alignment in self.align.items():
310+
table.align[a_col] = alignment
306311

307312
if self.title:
308313
table.title = self.title

SoftLayer/CLI/hardware/create.py

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,27 @@
1212

1313

1414
@click.command(epilog="See 'slcli server create-options' for valid options.")
15-
@click.option('--hostname', '-H',
16-
help="Host portion of the FQDN",
17-
required=True,
18-
prompt=True)
19-
@click.option('--domain', '-D',
20-
help="Domain portion of the FQDN",
21-
required=True,
22-
prompt=True)
23-
@click.option('--size', '-s',
24-
help="Hardware size",
25-
required=True,
26-
prompt=True)
27-
@click.option('--os', '-o', help="OS install code",
28-
required=True,
29-
prompt=True)
30-
@click.option('--datacenter', '-d', help="Datacenter shortname",
31-
required=True,
32-
prompt=True)
33-
@click.option('--port-speed',
34-
type=click.INT,
35-
help="Port speeds",
36-
required=True,
37-
prompt=True)
38-
@click.option('--billing',
39-
type=click.Choice(['hourly', 'monthly']),
40-
default='hourly',
41-
show_default=True,
15+
@click.option('--hostname', '-H', required=True, prompt=True, help="Host portion of the FQDN")
16+
@click.option('--domain', '-D', required=True, prompt=True, help="Domain portion of the FQDN")
17+
@click.option('--size', '-s', required=True, prompt=True, help="Hardware size")
18+
@click.option('--os', '-o', required=True, prompt=True, help="OS Key value")
19+
@click.option('--datacenter', '-d', required=True, prompt=True, help="Datacenter shortname")
20+
@click.option('--port-speed', type=click.INT, help="Port speeds. DEPRECATED, use --network")
21+
@click.option('--no-public', is_flag=True, help="Private network only. DEPRECATED, use --network.")
22+
@click.option('--network', help="Network Option Key. Use instead of port-speed option")
23+
@click.option('--billing', default='hourly', show_default=True, type=click.Choice(['hourly', 'monthly']),
4224
help="Billing rate")
43-
@click.option('--postinstall', '-i', help="Post-install script to download")
44-
@helpers.multi_option('--key', '-k',
45-
help="SSH keys to add to the root user")
46-
@click.option('--no-public',
47-
is_flag=True,
48-
help="Private network only")
49-
@helpers.multi_option('--extra', '-e', help="Extra options")
50-
@click.option('--test',
51-
is_flag=True,
52-
help="Do not actually create the server")
53-
@click.option('--template', '-t',
54-
is_eager=True,
25+
@click.option('--postinstall', '-i', help="Post-install script. Should be a HTTPS URL.")
26+
@click.option('--test', is_flag=True, help="Do not actually create the server")
27+
@click.option('--template', '-t', is_eager=True, type=click.Path(exists=True, readable=True, resolve_path=True),
5528
callback=template.TemplateCallback(list_args=['key']),
56-
help="A template file that defaults the command-line options",
57-
type=click.Path(exists=True, readable=True, resolve_path=True))
58-
@click.option('--export',
59-
type=click.Path(writable=True, resolve_path=True),
29+
help="A template file that defaults the command-line options")
30+
@click.option('--export', type=click.Path(writable=True, resolve_path=True),
6031
help="Exports options to a template file")
61-
@click.option('--wait',
62-
type=click.INT,
63-
help="Wait until the server is finished provisioning for up to "
64-
"X seconds before returning")
32+
@click.option('--wait', type=click.INT,
33+
help="Wait until the server is finished provisioning for up to X seconds before returning")
34+
@helpers.multi_option('--key', '-k', help="SSH keys to add to the root user")
35+
@helpers.multi_option('--extra', '-e', help="Extra option Key Names")
6536
@environment.pass_env
6637
def cli(env, **args):
6738
"""Order/create a dedicated server."""
@@ -86,6 +57,7 @@ def cli(env, **args):
8657
'port_speed': args.get('port_speed'),
8758
'no_public': args.get('no_public') or False,
8859
'extras': args.get('extra'),
60+
'network': args.get('network')
8961
}
9062

9163
# Do not create hardware server with --test or --export
@@ -116,15 +88,13 @@ def cli(env, **args):
11688

11789
if args['export']:
11890
export_file = args.pop('export')
119-
template.export_to_template(export_file, args,
120-
exclude=['wait', 'test'])
91+
template.export_to_template(export_file, args, exclude=['wait', 'test'])
12192
env.fout('Successfully exported options to a template file.')
12293
return
12394

12495
if do_create:
12596
if not (env.skip_confirmations or formatting.confirm(
126-
"This action will incur charges on your account. "
127-
"Continue?")):
97+
"This action will incur charges on your account. Continue?")):
12898
raise exceptions.CLIAbort('Aborting dedicated server order.')
12999

130100
result = mgr.place_order(**order)

SoftLayer/CLI/hardware/create_options.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,42 @@ def cli(env):
1919
tables = []
2020

2121
# Datacenters
22-
dc_table = formatting.Table(['datacenter', 'value'])
23-
dc_table.sortby = 'value'
22+
dc_table = formatting.Table(['Datacenter', 'Value'], title="Datacenters")
23+
dc_table.sortby = 'Value'
24+
dc_table.align = 'l'
2425
for location in options['locations']:
2526
dc_table.add_row([location['name'], location['key']])
2627
tables.append(dc_table)
2728

2829
# Presets
29-
preset_table = formatting.Table(['size', 'value'])
30-
preset_table.sortby = 'value'
30+
preset_table = formatting.Table(['Size', 'Value'], title="Sizes")
31+
preset_table.sortby = 'Value'
32+
preset_table.align = 'l'
3133
for size in options['sizes']:
3234
preset_table.add_row([size['name'], size['key']])
3335
tables.append(preset_table)
3436

3537
# Operating systems
36-
os_table = formatting.Table(['operating_system', 'value', 'operatingSystemReferenceCode '])
37-
os_table.sortby = 'value'
38+
os_table = formatting.Table(['OS', 'Key', 'Reference Code'], title="Operating Systems")
39+
os_table.sortby = 'Key'
40+
os_table.align = 'l'
3841
for operating_system in options['operating_systems']:
3942
os_table.add_row([operating_system['name'], operating_system['key'], operating_system['referenceCode']])
4043
tables.append(os_table)
4144

4245
# Port speed
43-
port_speed_table = formatting.Table(['port_speed', 'value'])
44-
port_speed_table.sortby = 'value'
46+
port_speed_table = formatting.Table(['Network', 'Speed', 'Key'], title="Network Options")
47+
port_speed_table.sortby = 'Speed'
48+
port_speed_table.align = 'l'
49+
4550
for speed in options['port_speeds']:
46-
port_speed_table.add_row([speed['name'], speed['key']])
51+
port_speed_table.add_row([speed['name'], speed['speed'], speed['key']])
4752
tables.append(port_speed_table)
4853

4954
# Extras
50-
extras_table = formatting.Table(['extras', 'value'])
51-
extras_table.sortby = 'value'
55+
extras_table = formatting.Table(['Extra Option', 'Value'], title="Extras")
56+
extras_table.sortby = 'Value'
57+
extras_table.align = 'l'
5258
for extra in options['extras']:
5359
extras_table.add_row([extra['name'], extra['key']])
5460
tables.append(extras_table)

SoftLayer/CLI/routes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@
316316
('user:detail', 'SoftLayer.CLI.user.detail:cli'),
317317
('user:permissions', 'SoftLayer.CLI.user.permissions:cli'),
318318
('user:edit-permissions', 'SoftLayer.CLI.user.edit_permissions:cli'),
319+
('user:notifications', 'SoftLayer.CLI.user.notifications:cli'),
320+
('user:edit-notifications', 'SoftLayer.CLI.user.edit_notifications:cli'),
319321
('user:edit-details', 'SoftLayer.CLI.user.edit_details:cli'),
320322
('user:create', 'SoftLayer.CLI.user.create:cli'),
321323
('user:delete', 'SoftLayer.CLI.user.delete:cli'),
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Enable or Disable specific noticication for the current user"""
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()
11+
@click.option('--enable/--disable', default=True,
12+
help="Enable (DEFAULT) or Disable selected notification")
13+
@click.argument('notification', nargs=-1, required=True)
14+
@environment.pass_env
15+
def cli(env, enable, notification):
16+
"""Enable or Disable specific notifications for the active user.
17+
18+
Notification names should be enclosed in quotation marks.
19+
Example::
20+
21+
slcli user edit-notifications --enable 'Order Approved' 'Reload Complete'
22+
23+
"""
24+
25+
mgr = SoftLayer.UserManager(env.client)
26+
27+
if enable:
28+
result = mgr.enable_notifications(notification)
29+
else:
30+
result = mgr.disable_notifications(notification)
31+
32+
if result:
33+
click.secho("Notifications updated successfully: %s" % ", ".join(notification), fg='green')
34+
else:
35+
click.secho("Failed to update notifications: %s" % ", ".join(notification), fg='red')
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""List user notifications"""
2+
import click
3+
4+
import SoftLayer
5+
from SoftLayer.CLI import environment
6+
from SoftLayer.CLI import formatting
7+
8+
9+
@click.command()
10+
@environment.pass_env
11+
def cli(env):
12+
"""My Notifications."""
13+
14+
mgr = SoftLayer.UserManager(env.client)
15+
16+
all_notifications = mgr.get_all_notifications()
17+
18+
env.fout(notification_table(all_notifications))
19+
20+
21+
def notification_table(all_notifications):
22+
"""Creates a table of available notifications"""
23+
24+
table = formatting.Table(['Id', 'Name', 'Description', 'Enabled'])
25+
table.align['Id'] = 'l'
26+
table.align['Name'] = 'l'
27+
table.align['Description'] = 'l'
28+
table.align['Enabled'] = 'l'
29+
for notification in all_notifications:
30+
table.add_row([notification['id'],
31+
notification['name'],
32+
notification['description'],
33+
notification['enabled']])
34+
return table

SoftLayer/CLI/virt/detail.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from SoftLayer.CLI import environment
1010
from SoftLayer.CLI import formatting
1111
from SoftLayer.CLI import helpers
12+
from SoftLayer.CLI.virt.storage import get_local_type
1213
from SoftLayer import utils
1314

1415
LOGGER = logging.getLogger(__name__)
@@ -200,15 +201,3 @@ def _get_security_table(result):
200201
return secgroup_table
201202
else:
202203
return None
203-
204-
205-
def get_local_type(disks):
206-
"""Returns the virtual server local disk type.
207-
208-
:param disks: virtual serve local disks.
209-
"""
210-
disk_type = 'System'
211-
if 'SWAP' in disks['diskImage']['description']:
212-
disk_type = 'Swap'
213-
214-
return disk_type

SoftLayer/CLI/virt/storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def get_local_type(disks):
6767
:param disks: virtual serve local disks.
6868
"""
6969
disk_type = 'System'
70-
if 'SWAP' in disks['diskImage']['description']:
70+
if 'SWAP' in disks.get('diskImage', {}).get('description', []):
7171
disk_type = 'Swap'
7272

7373
return disk_type
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
getAllObjects = [
2+
{'description': 'Email about your order.',
3+
'enabled': True,
4+
'id': 1,
5+
'name': 'Order Being Reviewed'
6+
},
7+
{'description': 'Maintenances that will or are likely to cause service '
8+
'outages and disruptions',
9+
'enabled': True,
10+
'id': 8,
11+
'name': 'High Impact'
12+
},
13+
{'description': 'Testing description.',
14+
'enabled': True,
15+
'id': 111,
16+
'name': 'Test notification'
17+
}
18+
]
19+
20+
enable = True
21+
22+
disable = True

0 commit comments

Comments
 (0)