Skip to content

Commit 0ad78be

Browse files
committed
Addresses some code smells from landscale.io
1 parent 5d5cc93 commit 0ad78be

28 files changed

Lines changed: 215 additions & 237 deletions

SoftLayer/CLI/core.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@
5151
from SoftLayer import Client, TimedClient, SoftLayerError, SoftLayerAPIError
5252
from SoftLayer.consts import VERSION
5353
from helpers import CLIAbort, ArgumentError, format_output, KeyValueTable
54-
from environment import (
55-
Environment, CLIRunnableType, InvalidCommand, InvalidModule)
54+
from environment import Environment, InvalidCommand, InvalidModule
5655

5756

5857
DEBUG_LOGGING_MAP = {
@@ -154,7 +153,6 @@ def main(args=sys.argv[1:], env=Environment()):
154153
Entry point for the command-line client.
155154
"""
156155
# Parse Top-Level Arguments
157-
CLIRunnableType.env = env
158156
exit_status = 0
159157
resolver = CommandParser(env)
160158
try:
@@ -174,7 +172,7 @@ def main(args=sys.argv[1:], env=Environment()):
174172
client = Client(config_file=command_args.get('--config'))
175173

176174
# Do the thing
177-
data = command.execute(client, command_args)
175+
data = command.execute(client, command_args, env)
178176
if data:
179177
format = command_args.get('--format', 'table')
180178
if format not in VALID_FORMATS:

SoftLayer/CLI/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,5 @@ def add_additional_args(parser):
115115
pass
116116

117117
@staticmethod
118-
def execute(client, args):
118+
def execute(*args):
119119
pass

SoftLayer/CLI/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ def __init__(self, msg, *args):
2222

2323
class ArgumentError(CLIAbort):
2424
def __init__(self, msg, *args):
25-
super(CLIAbort, self).__init__(code=2, *args)
25+
super(ArgumentError, self).__init__(msg, *args)
2626
self.message = "Argument Error: %s" % msg

SoftLayer/CLI/modules/bmc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class BMCCreateOptions(CLIRunnable):
4444
options = ['datacenter', 'cpu', 'memory', 'os', 'disk', 'nic']
4545

4646
@classmethod
47-
def execute(cls, client, args):
47+
def execute(cls, client, args, env):
4848
t = KeyValueTable(['Name', 'Value'])
4949
t.align['Name'] = 'r'
5050
t.align['Value'] = 'l'
@@ -305,7 +305,7 @@ class CreateBMCInstance(CLIRunnable):
305305
required_params = ['--hostname', '--domain', '--cpu', '--memory', '--os']
306306

307307
@classmethod
308-
def execute(cls, client, args):
308+
def execute(cls, client, args, env):
309309
update_with_template_args(args)
310310
mgr = HardwareManager(client)
311311

@@ -520,7 +520,7 @@ class CancelInstance(CLIRunnable):
520520
options = ['confirm']
521521

522522
@staticmethod
523-
def execute(client, args):
523+
def execute(client, args, env):
524524
hw = HardwareManager(client)
525525
hw_id = resolve_id(
526526
hw.resolve_ids, args.get('<identifier>'), 'hardware')

SoftLayer/CLI/modules/cci.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ListCCIs(CLIRunnable):
7575
action = 'list'
7676

7777
@staticmethod
78-
def execute(client, args):
78+
def execute(client, args, env):
7979
cci = CCIManager(client)
8080

8181
tags = None
@@ -129,7 +129,7 @@ class CCIDetails(CLIRunnable):
129129
action = 'detail'
130130

131131
@staticmethod
132-
def execute(client, args):
132+
def execute(client, args, env):
133133
cci = CCIManager(client)
134134
t = KeyValueTable(['Name', 'Value'])
135135
t.align['Name'] = 'r'
@@ -226,7 +226,7 @@ class CreateOptionsCCI(CLIRunnable):
226226
options = ['datacenter', 'cpu', 'nic', 'disk', 'os', 'memory']
227227

228228
@classmethod
229-
def execute(cls, client, args):
229+
def execute(cls, client, args, env):
230230
cci = CCIManager(client)
231231
result = cci.get_create_options()
232232

@@ -385,7 +385,7 @@ class CreateCCI(CLIRunnable):
385385
required_params = ['--hostname', '--domain', '--cpu', '--memory']
386386

387387
@classmethod
388-
def execute(cls, client, args):
388+
def execute(cls, client, args, env):
389389
update_with_template_args(args)
390390
cci = CCIManager(client)
391391
cls._update_with_like_args(cci, args)
@@ -643,7 +643,7 @@ class ReadyCCI(CLIRunnable):
643643
action = 'ready'
644644

645645
@staticmethod
646-
def execute(client, args):
646+
def execute(client, args, env):
647647
cci = CCIManager(client)
648648

649649
cci_id = resolve_id(cci.resolve_ids, args.get('<identifier>'), 'CCI')
@@ -672,7 +672,7 @@ class ReloadCCI(CLIRunnable):
672672
options = ['confirm']
673673

674674
@staticmethod
675-
def execute(client, args):
675+
def execute(client, args, env):
676676
cci = CCIManager(client)
677677
cci_id = resolve_id(cci.resolve_ids, args.get('<identifier>'), 'CCI')
678678
keys = []
@@ -698,7 +698,7 @@ class CancelCCI(CLIRunnable):
698698
options = ['confirm']
699699

700700
@staticmethod
701-
def execute(client, args):
701+
def execute(client, args, env):
702702
cci = CCIManager(client)
703703
cci_id = resolve_id(cci.resolve_ids, args.get('<identifier>'), 'CCI')
704704
if args['--really'] or no_going_back(cci_id):
@@ -720,7 +720,7 @@ class CCIPowerOff(CLIRunnable):
720720
options = ['confirm']
721721

722722
@classmethod
723-
def execute(cls, client, args):
723+
def execute(cls, client, args, env):
724724
vg = client['Virtual_Guest']
725725
cci = CCIManager(client)
726726
cci_id = resolve_id(cci.resolve_ids, args.get('<identifier>'), 'CCI')
@@ -748,7 +748,7 @@ class CCIReboot(CLIRunnable):
748748
options = ['confirm']
749749

750750
@classmethod
751-
def execute(cls, client, args):
751+
def execute(cls, client, args, env):
752752
vg = client['Virtual_Guest']
753753
cci = CCIManager(client)
754754
cci_id = resolve_id(cci.resolve_ids, args.get('<identifier>'), 'CCI')
@@ -773,7 +773,7 @@ class CCIPowerOn(CLIRunnable):
773773
action = 'power-on'
774774

775775
@classmethod
776-
def execute(cls, client, args):
776+
def execute(cls, client, args, env):
777777
vg = client['Virtual_Guest']
778778
cci = CCIManager(client)
779779
cci_id = resolve_id(cci.resolve_ids, args.get('<identifier>'), 'CCI')
@@ -790,7 +790,7 @@ class CCIPause(CLIRunnable):
790790
options = ['confirm']
791791

792792
@classmethod
793-
def execute(cls, client, args):
793+
def execute(cls, client, args, env):
794794
vg = client['Virtual_Guest']
795795
cci = CCIManager(client)
796796
cci_id = resolve_id(cci.resolve_ids, args.get('<identifier>'), 'CCI')
@@ -811,7 +811,7 @@ class CCIResume(CLIRunnable):
811811
action = 'resume'
812812

813813
@classmethod
814-
def execute(cls, client, args):
814+
def execute(cls, client, args, env):
815815
vg = client['Virtual_Guest']
816816
cci = CCIManager(client)
817817
cci_id = resolve_id(cci.resolve_ids, args.get('<identifier>'), 'CCI')
@@ -831,7 +831,7 @@ class NicEditCCI(CLIRunnable):
831831
action = 'nic-edit'
832832

833833
@classmethod
834-
def execute(cls, client, args):
834+
def execute(cls, client, args, env):
835835
public = args['public']
836836

837837
cci = CCIManager(client)
@@ -858,7 +858,7 @@ class CCIDNS(CLIRunnable):
858858
options = ['confirm']
859859

860860
@classmethod
861-
def execute(cls, client, args):
861+
def execute(cls, client, args, env):
862862
args['--ttl'] = args['--ttl'] or DNSManager.DEFAULT_TTL
863863
if args['sync']:
864864
return cls.dns_sync(client, args)
@@ -961,7 +961,7 @@ class EditCCI(CLIRunnable):
961961
action = 'edit'
962962

963963
@staticmethod
964-
def execute(client, args):
964+
def execute(client, args, env):
965965
data = {}
966966

967967
if args['--userdata'] and args['--userfile']:

SoftLayer/CLI/modules/config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,30 +86,30 @@ class Setup(CLIRunnable):
8686
"""
8787
action = 'setup'
8888

89-
@classmethod
90-
def execute(cls, client, args):
89+
@staticmethod
90+
def execute(client, args, env):
9191
settings = get_settings_from_client(client)
9292

9393
# User Input
9494
# Ask for username
9595
while True:
96-
username = cls.env.input(
96+
username = env.input(
9797
'Username [%s]: ' % settings['username']) \
9898
or settings['username']
9999
if username:
100100
break
101101

102102
# Ask for 'secret' which can be api_key or their password
103103
while True:
104-
secret = cls.env.getpass(
104+
secret = env.getpass(
105105
'API Key or Password [%s]: ' % settings['api_key']) \
106106
or settings['api_key']
107107
if secret:
108108
break
109109

110110
# Ask for which endpoint they want to use
111111
while True:
112-
endpoint_type = cls.env.input('Endpoint (public|private|custom): ')
112+
endpoint_type = env.input('Endpoint (public|private|custom): ')
113113
endpoint_type = endpoint_type.lower()
114114
if not endpoint_type:
115115
endpoint_url = API_PUBLIC_ENDPOINT
@@ -121,7 +121,7 @@ def execute(cls, client, args):
121121
endpoint_url = API_PRIVATE_ENDPOINT
122122
break
123123
elif endpoint_type == 'custom':
124-
endpoint_url = cls.env.input(
124+
endpoint_url = env.input(
125125
'Endpoint URL [%s]: ' % settings['endpoint_url']
126126
) or settings['endpoint_url']
127127
break
@@ -137,7 +137,7 @@ def execute(cls, client, args):
137137
path = args.get('--config')
138138
config_path = os.path.expanduser(path)
139139

140-
cls.env.out(format_output(config_table(settings)))
140+
env.out(format_output(config_table(settings)))
141141

142142
if not confirm('Are you sure you want to write settings to "%s"?'
143143
% config_path, default=True):
@@ -174,7 +174,7 @@ class Show(CLIRunnable):
174174
"""
175175
action = 'show'
176176

177-
@classmethod
178-
def execute(cls, client, args):
177+
@staticmethod
178+
def execute(client, args, env):
179179
settings = get_settings_from_client(client)
180180
return config_table(settings)

SoftLayer/CLI/modules/dns.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DumpZone(CLIRunnable):
3434
action = "print"
3535

3636
@staticmethod
37-
def execute(client, args):
37+
def execute(client, args, env):
3838
manager = DNSManager(client)
3939
zone_id = resolve_id(manager.resolve_ids, args['<zone>'], name='zone')
4040
try:
@@ -55,7 +55,7 @@ class CreateZone(CLIRunnable):
5555
action = 'create'
5656

5757
@staticmethod
58-
def execute(client, args):
58+
def execute(client, args, env):
5959
manager = DNSManager(client)
6060
manager.create_zone(args['<zone>'])
6161

@@ -73,7 +73,7 @@ class DeleteZone(CLIRunnable):
7373
options = ['confirm']
7474

7575
@staticmethod
76-
def execute(client, args):
76+
def execute(client, args, env):
7777
manager = DNSManager(client)
7878
zone_id = resolve_id(manager.resolve_ids, args['<zone>'], name='zone')
7979

@@ -98,7 +98,7 @@ class ListZones(CLIRunnable):
9898
action = 'list'
9999

100100
@classmethod
101-
def execute(cls, client, args):
101+
def execute(cls, client, args, env):
102102
if args['<zone>']:
103103
return cls.list_zone(client, args['<zone>'], args)
104104

@@ -184,7 +184,7 @@ class AddRecord(CLIRunnable):
184184
action = 'add'
185185

186186
@staticmethod
187-
def execute(client, args):
187+
def execute(client, args, env):
188188
manager = DNSManager(client)
189189

190190
zone_id = resolve_id(manager.resolve_ids, args['<zone>'], name='zone')
@@ -217,7 +217,7 @@ class EditRecord(CLIRunnable):
217217
action = 'edit'
218218

219219
@staticmethod
220-
def execute(client, args):
220+
def execute(client, args, env):
221221
manager = DNSManager(client)
222222
zone_id = resolve_id(manager.resolve_ids, args['<zone>'], name='zone')
223223

@@ -253,7 +253,7 @@ class RecordRemove(CLIRunnable):
253253
options = ['confirm']
254254

255255
@staticmethod
256-
def execute(client, args):
256+
def execute(client, args, env):
257257
manager = DNSManager(client)
258258
zone_id = resolve_id(manager.resolve_ids, args['<zone>'], name='zone')
259259

SoftLayer/CLI/modules/firewall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FWList(CLIRunnable):
2323
action = 'list'
2424

2525
@staticmethod
26-
def execute(client, args):
26+
def execute(client, args, env):
2727
f = FirewallManager(client)
2828
fwvlans = f.get_firewalls()
2929
t = Table(['vlan', 'type', 'features'])

SoftLayer/CLI/modules/globalip.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class GlobalIpAssign(CLIRunnable):
3232
action = 'assign'
3333

3434
@staticmethod
35-
def execute(client, args):
35+
def execute(client, args, env):
3636
mgr = NetworkManager(client)
3737

3838
id = mgr.resolve_global_ip_ids(args.get('<identifier>'))
@@ -53,7 +53,7 @@ class GlobalIpCancel(CLIRunnable):
5353
options = ['confirm']
5454

5555
@staticmethod
56-
def execute(client, args):
56+
def execute(client, args, env):
5757
mgr = NetworkManager(client)
5858
id = mgr.resolve_global_ip_ids(args.get('<identifier>'))
5959

@@ -78,7 +78,7 @@ class GlobalIpCreate(CLIRunnable):
7878
options = ['confirm']
7979

8080
@staticmethod
81-
def execute(client, args):
81+
def execute(client, args, env):
8282
mgr = NetworkManager(client)
8383

8484
version = 4
@@ -127,7 +127,7 @@ class GlobalIpList(CLIRunnable):
127127
action = 'list'
128128

129129
@staticmethod
130-
def execute(client, args):
130+
def execute(client, args, env):
131131
mgr = NetworkManager(client)
132132

133133
t = Table([
@@ -175,7 +175,7 @@ class GlobalIpUnassign(CLIRunnable):
175175
action = 'unassign'
176176

177177
@staticmethod
178-
def execute(client, args):
178+
def execute(client, args, env):
179179
mgr = NetworkManager(client)
180180

181181
id = mgr.resolve_global_ip_ids(args.get('<identifier>'))

SoftLayer/CLI/modules/help.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class Show(CLIRunnable):
1717
__doc__ = __doc__
1818
action = None
1919

20-
@classmethod
21-
def execute(cls, client, args):
22-
parser = CommandParser(cls.env)
23-
cls.env.load_module(args['<module>'])
20+
@staticmethod
21+
def execute(client, args, env):
22+
parser = CommandParser(env)
23+
env.load_module(args['<module>'])
2424
if args['<command>']:
2525
return parser.get_command_help(args['<module>'], args['<command>'])
2626
elif args['<module>']:

0 commit comments

Comments
 (0)