Skip to content

Commit ac15931

Browse files
#1026 pylint fixes
1 parent 4815cdb commit ac15931

21 files changed

+275
-377
lines changed
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
11
"""Manages Reserved Capacity."""
22
# :license: MIT, see LICENSE for more details.
3+
34
import importlib
4-
import click
5-
import types
6-
import SoftLayer
75
import os
8-
from SoftLayer.CLI import environment
9-
from SoftLayer.CLI import formatting
106

11-
from pprint import pprint as pp
7+
import click
8+
129
CONTEXT = {'help_option_names': ['-h', '--help'],
1310
'max_content_width': 999}
14-
class capacityCommands(click.MultiCommand):
11+
12+
13+
class CapacityCommands(click.MultiCommand):
1514
"""Loads module for capacity related commands."""
1615

17-
def __init__(self, *path, **attrs):
16+
def __init__(self, **attrs):
1817
click.MultiCommand.__init__(self, **attrs)
1918
self.path = os.path.dirname(__file__)
2019

2120
def list_commands(self, ctx):
2221
"""List all sub-commands."""
23-
rv = []
22+
commands = []
2423
for filename in os.listdir(self.path):
2524
if filename == '__init__.py':
2625
continue
2726
if filename.endswith('.py'):
28-
rv.append(filename[:-3])
29-
rv.sort()
30-
return rv
27+
commands.append(filename[:-3])
28+
commands.sort()
29+
return commands
3130

32-
def get_command(self, ctx, name):
31+
def get_command(self, ctx, cmd_name):
3332
"""Get command for click."""
34-
path = "%s.%s" % (__name__, name)
33+
path = "%s.%s" % (__name__, cmd_name)
3534
module = importlib.import_module(path)
3635
return getattr(module, 'cli')
3736

38-
@click.group(cls=capacityCommands,
39-
context_settings=CONTEXT)
40-
@environment.pass_env
41-
def cli(env):
42-
"""Manages Reserved Capacity"""
37+
38+
# Required to get the sub-sub-sub command to work.
39+
@click.group(cls=CapacityCommands, context_settings=CONTEXT)
40+
def cli():
41+
"""Base command for all capacity related concerns"""
4342
pass

SoftLayer/CLI/virt/capacity/create.py

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
"""Create a Reserved Capacity instance.
2-
3-
4-
"""
5-
# :license: MIT, see LICENSE for more details.
1+
"""Create a Reserved Capacity instance."""
62

73
import click
84

9-
import SoftLayer
5+
106
from SoftLayer.CLI import environment
117
from SoftLayer.CLI import formatting
128
from SoftLayer.managers.vs_capacity import CapacityManager as CapacityManager
139

1410

15-
from pprint import pprint as pp
16-
1711
@click.command(epilog=click.style("""WARNING: Reserved Capacity is on a yearly contract"""
1812
""" and not cancelable until the contract is expired.""", fg='red'))
1913
@click.option('--name', '-n', required=True, prompt=True,
@@ -30,7 +24,10 @@
3024
help="Do not actually create the virtual server")
3125
@environment.pass_env
3226
def cli(env, name, datacenter, backend_router_id, capacity, quantity, test=False):
33-
"""Create a Reserved Capacity instance. *WARNING*: Reserved Capacity is on a yearly contract and not cancelable until the contract is expired."""
27+
"""Create a Reserved Capacity instance.
28+
29+
*WARNING*: Reserved Capacity is on a yearly contract and not cancelable until the contract is expired.
30+
"""
3431
manager = CapacityManager(env.client)
3532

3633
result = manager.create(
@@ -58,22 +55,3 @@ def cli(env, name, datacenter, backend_router_id, capacity, quantity, test=False
5855
table.add_row([item['categoryCode'], item['description']])
5956
table.add_row(['Total', result['orderDetails']['postTaxRecurring']])
6057
env.fout(table)
61-
62-
63-
"""
64-
Calling: SoftLayer_Product_Order::placeOrder(
65-
id=None,
66-
mask='',
67-
filter='None',
68-
args=(
69-
{'orderContainers': [
70-
{'backendRouterId': 1079095,
71-
'name': 'cgallo-test-capacity',
72-
'quantity': 1,
73-
'packageId': 1059,
74-
'location': 1854895,
75-
'useHourlyPricing': True,
76-
'complexType': 'SoftLayer_Container_Product_Order_Virtual_ReservedCapacity',
77-
'prices': [{'id': 217633}]}]},), limit=None, offset=None))
78-
Resetting dropped connection: r237377.application.qadal0501.softlayer.local
79-
"""

SoftLayer/CLI/virt/capacity/create-guest.py renamed to SoftLayer/CLI/virt/capacity/create_guest.py

Lines changed: 6 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -3,100 +3,17 @@
33

44
import click
55

6-
import SoftLayer
76
from SoftLayer.CLI import environment
87
from SoftLayer.CLI import formatting
98
from SoftLayer.CLI import helpers
9+
from SoftLayer.CLI.virt.create import _parse_create_args as _parse_create_args
1010
from SoftLayer.CLI.virt.create import _update_with_like_args as _update_with_like_args
1111
from SoftLayer.managers.vs_capacity import CapacityManager as CapacityManager
1212

1313

14-
from pprint import pprint as pp
15-
16-
17-
18-
def _parse_create_args(client, args):
19-
"""Parses CLI arguments into a single data structure to be used by vs_capacity::create_guest.
20-
21-
:param dict args: CLI arguments
22-
"""
23-
data = {
24-
"hourly": True,
25-
"domain": args['domain'],
26-
"hostname": args['hostname'],
27-
"private": args['private'],
28-
"disks": args['disk'],
29-
"boot_mode": args.get('boot_mode', None),
30-
"local_disk": None
31-
}
32-
if args.get('os'):
33-
data['os_code'] = args['os']
34-
35-
if args.get('image'):
36-
if args.get('image').isdigit():
37-
image_mgr = SoftLayer.ImageManager(client)
38-
image_details = image_mgr.get_image(args.get('image'),
39-
mask="id,globalIdentifier")
40-
data['image_id'] = image_details['globalIdentifier']
41-
else:
42-
data['image_id'] = args['image']
43-
44-
if args.get('network'):
45-
data['nic_speed'] = args.get('network')
46-
47-
if args.get('userdata'):
48-
data['userdata'] = args['userdata']
49-
elif args.get('userfile'):
50-
with open(args['userfile'], 'r') as userfile:
51-
data['userdata'] = userfile.read()
52-
53-
if args.get('postinstall'):
54-
data['post_uri'] = args.get('postinstall')
55-
56-
# Get the SSH keys
57-
if args.get('key'):
58-
keys = []
59-
for key in args.get('key'):
60-
resolver = SoftLayer.SshKeyManager(client).resolve_ids
61-
key_id = helpers.resolve_id(resolver, key, 'SshKey')
62-
keys.append(key_id)
63-
data['ssh_keys'] = keys
64-
65-
if args.get('vlan_public'):
66-
data['public_vlan'] = args['vlan_public']
67-
68-
if args.get('vlan_private'):
69-
data['private_vlan'] = args['vlan_private']
70-
71-
data['public_subnet'] = args.get('subnet_public', None)
72-
73-
data['private_subnet'] = args.get('subnet_private', None)
74-
75-
if args.get('public_security_group'):
76-
pub_groups = args.get('public_security_group')
77-
data['public_security_groups'] = [group for group in pub_groups]
78-
79-
if args.get('private_security_group'):
80-
priv_groups = args.get('private_security_group')
81-
data['private_security_groups'] = [group for group in priv_groups]
82-
83-
if args.get('tag'):
84-
data['tags'] = ','.join(args['tag'])
85-
86-
if args.get('host_id'):
87-
data['host_id'] = args['host_id']
88-
89-
if args.get('ipv6'):
90-
data['ipv6'] = True
91-
92-
data['primary_disk'] = args.get('primary_disk')
93-
94-
return data
95-
96-
9714
@click.command()
9815
@click.option('--capacity-id', type=click.INT, help="Reserve capacity Id to provision this guest into.")
99-
@click.option('--primary-disk', type=click.Choice(['25','100']), default='25', help="Size of the main drive." )
16+
@click.option('--primary-disk', type=click.Choice(['25', '100']), default='25', help="Size of the main drive.")
10017
@click.option('--hostname', '-H', required=True, prompt=True, help="Host portion of the FQDN.")
10118
@click.option('--domain', '-D', required=True, prompt=True, help="Domain portion of the FQDN.")
10219
@click.option('--os', '-o', help="OS install code. Tip: you can specify <OS>_LATEST.")
@@ -113,12 +30,15 @@ def _parse_create_args(client, args):
11330
@helpers.multi_option('--tag', '-g', help="Tags to add to the instance.")
11431
@click.option('--userdata', '-u', help="User defined metadata string.")
11532
@click.option('--ipv6', is_flag=True, help="Adds an IPv6 address to this guest")
116-
@click.option('--test', is_flag=True,
33+
@click.option('--test', is_flag=True,
11734
help="Test order, will return the order container, but not actually order a server.")
11835
@environment.pass_env
11936
def cli(env, **args):
12037
"""Allows for creating a virtual guest in a reserved capacity."""
12138
create_args = _parse_create_args(env.client, args)
39+
if args.get('ipv6'):
40+
create_args['ipv6'] = True
41+
create_args['primary_disk'] = args.get('primary_disk')
12242
manager = CapacityManager(env.client)
12343
capacity_id = args.get('capacity_id')
12444
test = args.get('test')
@@ -141,4 +61,3 @@ def _build_receipt(result, test=False):
14161
for item in prices:
14262
table.add_row([item['id'], item['item']['description']])
14363
return table
144-

SoftLayer/CLI/virt/capacity/create-options.py renamed to SoftLayer/CLI/virt/capacity/create_options.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33

44
import click
55

6-
import SoftLayer
76
from SoftLayer.CLI import environment
87
from SoftLayer.CLI import formatting
98
from SoftLayer.managers.vs_capacity import CapacityManager as CapacityManager
109

1110

12-
from pprint import pprint as pp
13-
1411
@click.command()
1512
@environment.pass_env
1613
def cli(env):
@@ -38,8 +35,9 @@ def cli(env):
3835

3936

4037
def get_price(item):
38+
"""Finds the price with the default locationGroupId"""
4139
the_price = "No Default Pricing"
42-
for price in item.get('prices',[]):
40+
for price in item.get('prices', []):
4341
if price.get('locationGroupId') == '':
44-
the_price = "%0.4f" % float(price['hourlyRecurringFee'])
42+
the_price = "%0.4f" % float(price['hourlyRecurringFee'])
4543
return the_price

SoftLayer/CLI/virt/capacity/detail.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
"""Shows the details of a reserved capacity group"""
2-
# :license: MIT, see LICENSE for more details.
32

43
import click
54

6-
import SoftLayer
75
from SoftLayer.CLI import columns as column_helper
86
from SoftLayer.CLI import environment
97
from SoftLayer.CLI import formatting
@@ -25,6 +23,7 @@
2523
'backend_ip'
2624
]
2725

26+
2827
@click.command(epilog="Once provisioned, virtual guests can be managed with the slcli vs commands")
2928
@click.argument('identifier')
3029
@click.option('--columns',
@@ -38,31 +37,20 @@ def cli(env, identifier, columns):
3837
"""Reserved Capacity Group details. Will show which guests are assigned to a reservation."""
3938

4039
manager = CapacityManager(env.client)
41-
mask = """mask[instances[id,createDate,guestId,billingItem[id, recurringFee, category[name]],
40+
mask = """mask[instances[id,createDate,guestId,billingItem[id, recurringFee, category[name]],
4241
guest[modifyDate,id, primaryBackendIpAddress, primaryIpAddress,domain, hostname]]]"""
4342
result = manager.get_object(identifier, mask)
4443
try:
4544
flavor = result['instances'][0]['billingItem']['description']
4645
except KeyError:
4746
flavor = "Pending Approval..."
4847

49-
table = formatting.Table(columns.columns,
50-
title = "%s - %s" % (result.get('name'), flavor)
51-
)
48+
table = formatting.Table(columns.columns, title="%s - %s" % (result.get('name'), flavor))
5249
# RCI = Reserved Capacity Instance
5350
for rci in result['instances']:
5451
guest = rci.get('guest', None)
55-
guest_string = "---"
56-
createDate = rci['createDate']
5752
if guest is not None:
58-
guest_string = "%s (%s)" % (
59-
guest.get('fullyQualifiedDomainName', 'No FQDN'),
60-
guest.get('primaryIpAddress', 'No Public Ip')
61-
)
62-
createDate = guest['modifyDate']
6353
table.add_row([value or formatting.blank() for value in columns.row(guest)])
6454
else:
6555
table.add_row(['-' for value in columns.columns])
6656
env.fout(table)
67-
68-
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
"""List Reserved Capacity"""
2-
# :license: MIT, see LICENSE for more details.
32

43
import click
54

6-
import SoftLayer
75
from SoftLayer.CLI import environment
86
from SoftLayer.CLI import formatting
97
from SoftLayer.managers.vs_capacity import CapacityManager as CapacityManager
@@ -16,19 +14,19 @@ def cli(env):
1614
manager = CapacityManager(env.client)
1715
result = manager.list()
1816
table = formatting.Table(
19-
["ID", "Name", "Capacity", "Flavor", "Location", "Created"],
17+
["ID", "Name", "Capacity", "Flavor", "Location", "Created"],
2018
title="Reserved Capacity"
2119
)
22-
for rc in result:
23-
occupied_string = "#" * int(rc.get('occupiedInstanceCount',0))
24-
available_string = "-" * int(rc.get('availableInstanceCount',0))
20+
for r_c in result:
21+
occupied_string = "#" * int(r_c.get('occupiedInstanceCount', 0))
22+
available_string = "-" * int(r_c.get('availableInstanceCount', 0))
2523

2624
try:
27-
flavor = rc['instances'][0]['billingItem']['description']
28-
cost = float(rc['instances'][0]['billingItem']['hourlyRecurringFee'])
25+
flavor = r_c['instances'][0]['billingItem']['description']
26+
# cost = float(r_c['instances'][0]['billingItem']['hourlyRecurringFee'])
2927
except KeyError:
3028
flavor = "Unknown Billing Item"
31-
location = rc['backendRouter']['hostname']
29+
location = r_c['backendRouter']['hostname']
3230
capacity = "%s%s" % (occupied_string, available_string)
33-
table.add_row([rc['id'], rc['name'], capacity, flavor, location, rc['createDate']])
31+
table.add_row([r_c['id'], r_c['name'], capacity, flavor, location, r_c['createDate']])
3432
env.fout(table)

SoftLayer/CLI/virt/create.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ def _parse_create_args(client, args):
7272
:param dict args: CLI arguments
7373
"""
7474
data = {
75-
"hourly": args['billing'] == 'hourly',
75+
"hourly": args.get('billing', 'hourly') == 'hourly',
7676
"domain": args['domain'],
7777
"hostname": args['hostname'],
78-
"private": args['private'],
79-
"dedicated": args['dedicated'],
78+
"private": args.get('private', None),
79+
"dedicated": args.get('dedicated', None),
8080
"disks": args['disk'],
8181
"cpus": args.get('cpu', None),
8282
"memory": args.get('memory', None),
@@ -89,7 +89,7 @@ def _parse_create_args(client, args):
8989
if not args.get('san') and args.get('flavor'):
9090
data['local_disk'] = None
9191
else:
92-
data['local_disk'] = not args['san']
92+
data['local_disk'] = not args.get('san')
9393

9494
if args.get('os'):
9595
data['os_code'] = args['os']

0 commit comments

Comments
 (0)