From 930171a6edeea9548dca32e194b5357b2890cbab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Ole=C5=9B?= Date: Wed, 16 Oct 2013 10:44:14 +0200 Subject: [PATCH 01/47] CLI: --network arg in `sl bmc create` is always string It is possible to pass --network 1000 or --network 1000_DUAL. If 1000 is treated as int it will return error 'Invalid NIC speed specified' --- SoftLayer/CLI/modules/bmc.py | 2 +- SoftLayer/tests/CLI/modules/bmc_tests.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/SoftLayer/CLI/modules/bmc.py b/SoftLayer/CLI/modules/bmc.py index 5aeac8629..a9ee1d22b 100644 --- a/SoftLayer/CLI/modules/bmc.py +++ b/SoftLayer/CLI/modules/bmc.py @@ -257,7 +257,7 @@ def _generate_windows_code(description): dual.append((str(int(item['capacity'])) + '_DUAL', item['price_id'])) else: - single.append((int(item['capacity']), item['price_id'])) + single.append((str(int(item['capacity'])), item['price_id'])) return [('single nic', single), ('dual nic', dual)] diff --git a/SoftLayer/tests/CLI/modules/bmc_tests.py b/SoftLayer/tests/CLI/modules/bmc_tests.py index 1e4d6d21a..fdae9f14f 100644 --- a/SoftLayer/tests/CLI/modules/bmc_tests.py +++ b/SoftLayer/tests/CLI/modules/bmc_tests.py @@ -33,7 +33,6 @@ def test_BMCCreateOptions(self): } client = self._setup_package_mocks(self.client) - output = bmc.BMCCreateOptions.execute(client, args) expected = { @@ -46,7 +45,7 @@ def test_BMCCreateOptions(self): 'WIN_2008-STD-R2_64', 'WIN_2008-STD_64', 'WIN_2012-DC-HYPERV_64'], 'disks': [250, 500], - 'single nic': [100, 1000], + 'single nic': ['100', '1000'], 'memory/cpu': [ {'cpu': ['2'], 'memory': '2'}, {'cpu': ['4'], 'memory': '4'} @@ -90,7 +89,7 @@ def test_CreateBMCInstance(self): '--domain': 'example.com', '--datacenter': 'TEST00', '--cpu': '2', - '--network': 100, + '--network': '100', '--disk': [250, 250], '--os': 'UBUNTU_12_64_MINIMAL', '--memory': '2', From b93a9018c9ee8304065114b023ffb878959d885c Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Fri, 25 Oct 2013 11:50:39 -0500 Subject: [PATCH 02/47] Fixes Bugs with the CLI Messaging module * Adds messaging service to the main help so it can be discovered * Fixes an issue that occurred if the user didn't have permission to manage message queue accounts. * Changes SoftLayer.exceptions.Unauthenticated to be a SoftLayerError instead of StandardError --- SoftLayer/CLI/core.py | 15 ++++++++------- SoftLayer/CLI/modules/messaging.py | 3 +++ SoftLayer/exceptions.py | 2 +- SoftLayer/managers/messaging.py | 3 ++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/SoftLayer/CLI/core.py b/SoftLayer/CLI/core.py index 1ab546509..00ff7cb5f 100644 --- a/SoftLayer/CLI/core.py +++ b/SoftLayer/CLI/core.py @@ -17,13 +17,14 @@ sshkey Manage SSH keys on your account Networking: - dns Domain Name System - firewall Firewall rule and security management - globalip Global IP address management - rwhois RWhoIs operations - ssl Manages SSL - subnet Subnet ordering and management - vlan Manage VLANs on your account + dns Domain Name System + firewall Firewall rule and security management + globalip Global IP address management + messaging Message Queue Service + rwhois RWhoIs operations + ssl Manages SSL + subnet Subnet ordering and management + vlan Manage VLANs on your account Storage: iscsi View iSCSI details diff --git a/SoftLayer/CLI/modules/messaging.py b/SoftLayer/CLI/modules/messaging.py index b50fa1f31..63ebc288f 100644 --- a/SoftLayer/CLI/modules/messaging.py +++ b/SoftLayer/CLI/modules/messaging.py @@ -59,6 +59,9 @@ def execute(client, args): 'id', 'name', 'status' ]) for account in accounts: + if not account['nodes']: + continue + t.add_row([ account['nodes'][0]['accountName'], account['name'], diff --git a/SoftLayer/exceptions.py b/SoftLayer/exceptions.py index 8657da301..3e04df955 100644 --- a/SoftLayer/exceptions.py +++ b/SoftLayer/exceptions.py @@ -12,7 +12,7 @@ class SoftLayerError(StandardError): " The base SoftLayer error. " -class Unauthenticated(StandardError): +class Unauthenticated(SoftLayerError): " Unauthenticated " diff --git a/SoftLayer/managers/messaging.py b/SoftLayer/managers/messaging.py index 0af52519e..de71801a2 100644 --- a/SoftLayer/managers/messaging.py +++ b/SoftLayer/managers/messaging.py @@ -44,7 +44,8 @@ def auth(self): if resp.ok: self.auth_token = resp.headers['X-Auth-Token'] else: - raise Unauthenticated("Error while authenticating", resp) + raise Unauthenticated("Error while authenticating: %s" + % resp.status_code) def handle_error(self, r, **kwargs): """ Handle errors """ From f0eb7e82d0e1a2514906cf59c9ccdb8a8300b8f5 Mon Sep 17 00:00:00 2001 From: Nathan Beittenmiller Date: Tue, 29 Oct 2013 12:58:55 -0500 Subject: [PATCH 03/47] Fixes dictionary lookup bug. Closes #211 --- SoftLayer/CLI/modules/subnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/CLI/modules/subnet.py b/SoftLayer/CLI/modules/subnet.py index ee68219ff..06c3ab318 100644 --- a/SoftLayer/CLI/modules/subnet.py +++ b/SoftLayer/CLI/modules/subnet.py @@ -93,7 +93,7 @@ def execute(client, args): t.align['cost'] = 'r' total = 0.0 - for price in result['orderDetails']['prices']: + for price in result['prices']: total += float(price.get('recurringFee', 0.0)) rate = "%.2f" % float(price['recurringFee']) From 9f1f831985e4869c1046a6a98b228a6ea65ee6d2 Mon Sep 17 00:00:00 2001 From: Nathan Beittenmiller Date: Mon, 4 Nov 2013 15:40:58 -0600 Subject: [PATCH 04/47] Fix to prevent double counting results in the summary_by_datacenter() function due to multiple network interfaces. --- SoftLayer/managers/network.py | 26 ++++++++++++++++++----- SoftLayer/tests/managers/network_tests.py | 12 +++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index d8c3d2772..fdf437a2b 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -312,6 +312,11 @@ def summary_by_datacenter(self): """ datacenters = {} + datacenters = {} + unique_vms = [] + unique_servers = [] + unique_network = [] + for vlan in self._get_vlans(): dc = vlan['primaryRouter']['datacenter'] name = dc['name'] @@ -326,14 +331,25 @@ def summary_by_datacenter(self): } datacenters[name]['vlanCount'] += 1 - datacenters[name]['hardwareCount'] += len(vlan['hardware']) - datacenters[name]['networkingCount'] += \ - len(vlan['networkComponents']) + + for hw in vlan['hardware']: + if hw['id'] not in unique_servers: + datacenters[name]['hardwareCount'] += 1 + unique_servers.append(hw['id']) + + for net in vlan['networkComponents']: + if net['id'] not in unique_network: + datacenters[name]['networkingCount'] += 1 + unique_network.append(net['id']) + + for vm in vlan['virtualGuests']: + if vm['id'] not in unique_vms: + datacenters[name]['virtualGuestCount'] += 1 + unique_vms.append(vm['id']) + datacenters[name]['primaryIpCount'] += \ vlan['totalPrimaryIpAddressCount'] datacenters[name]['subnetCount'] += len(vlan['subnets']) - datacenters[name]['virtualGuestCount'] += \ - len(vlan['virtualGuests']) return datacenters diff --git a/SoftLayer/tests/managers/network_tests.py b/SoftLayer/tests/managers/network_tests.py index c83f20db8..43d2814d6 100644 --- a/SoftLayer/tests/managers/network_tests.py +++ b/SoftLayer/tests/managers/network_tests.py @@ -331,23 +331,23 @@ def test_summary_by_datacenter(self): service.getNetworkVlans.return_value = [ { 'name': 'dal00', - 'hardware': [], - 'networkComponents': [], + 'hardware': [{'id': 1}], + 'networkComponents': [{'id': 2}], 'primaryRouter': { 'datacenter': {'name': 'dal00'} }, 'totalPrimaryIpAddressCount': 3, 'subnets': [], - 'virtualGuests': [] + 'virtualGuests': [{'id': 3}] } ] expected = {'dal00': { - 'hardwareCount': 0, - 'networkingCount': 0, + 'hardwareCount': 1, + 'networkingCount': 1, 'primaryIpCount': 3, 'subnetCount': 0, - 'virtualGuestCount': 0, + 'virtualGuestCount': 1, 'vlanCount': 1 }} From f256bb3667d834841c82bf94d7a93046ce63e2f9 Mon Sep 17 00:00:00 2001 From: Nathan Beittenmiller Date: Mon, 4 Nov 2013 16:19:36 -0600 Subject: [PATCH 05/47] Fixing copy/paste error --- SoftLayer/managers/network.py | 1 - 1 file changed, 1 deletion(-) diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index fdf437a2b..76322f064 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -312,7 +312,6 @@ def summary_by_datacenter(self): """ datacenters = {} - datacenters = {} unique_vms = [] unique_servers = [] unique_network = [] From 0ad78be0b949d6274d6039716c8f5f64d6f8eb73 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Tue, 5 Nov 2013 15:00:28 -0600 Subject: [PATCH 06/47] Addresses some code smells from landscale.io --- SoftLayer/CLI/core.py | 6 +- SoftLayer/CLI/environment.py | 2 +- SoftLayer/CLI/exceptions.py | 2 +- SoftLayer/CLI/modules/bmc.py | 6 +- SoftLayer/CLI/modules/cci.py | 30 ++++---- SoftLayer/CLI/modules/config.py | 18 ++--- SoftLayer/CLI/modules/dns.py | 14 ++-- SoftLayer/CLI/modules/firewall.py | 2 +- SoftLayer/CLI/modules/globalip.py | 10 +-- SoftLayer/CLI/modules/help.py | 8 +- SoftLayer/CLI/modules/image.py | 2 +- SoftLayer/CLI/modules/iscsi.py | 2 +- SoftLayer/CLI/modules/messaging.py | 34 ++++----- SoftLayer/CLI/modules/metadata.py | 26 +++---- SoftLayer/CLI/modules/nas.py | 2 +- SoftLayer/CLI/modules/rwhois.py | 4 +- SoftLayer/CLI/modules/server.py | 36 ++++----- SoftLayer/CLI/modules/sshkey.py | 10 +-- SoftLayer/CLI/modules/ssl.py | 10 +-- SoftLayer/CLI/modules/subnet.py | 10 +-- SoftLayer/CLI/modules/summary.py | 2 +- SoftLayer/CLI/modules/vlan.py | 4 +- SoftLayer/tests/CLI/core_tests.py | 11 ++- SoftLayer/tests/CLI/modules/bmc_tests.py | 45 ++++++----- SoftLayer/tests/CLI/modules/server_tests.py | 85 ++++++++++++--------- docs/dev/cli.rst | 14 ++-- docs/dev/example_module.rst | 6 +- example.py | 51 ------------- 28 files changed, 215 insertions(+), 237 deletions(-) delete mode 100644 example.py diff --git a/SoftLayer/CLI/core.py b/SoftLayer/CLI/core.py index 00ff7cb5f..793982983 100644 --- a/SoftLayer/CLI/core.py +++ b/SoftLayer/CLI/core.py @@ -51,8 +51,7 @@ from SoftLayer import Client, TimedClient, SoftLayerError, SoftLayerAPIError from SoftLayer.consts import VERSION from helpers import CLIAbort, ArgumentError, format_output, KeyValueTable -from environment import ( - Environment, CLIRunnableType, InvalidCommand, InvalidModule) +from environment import Environment, InvalidCommand, InvalidModule DEBUG_LOGGING_MAP = { @@ -154,7 +153,6 @@ def main(args=sys.argv[1:], env=Environment()): Entry point for the command-line client. """ # Parse Top-Level Arguments - CLIRunnableType.env = env exit_status = 0 resolver = CommandParser(env) try: @@ -174,7 +172,7 @@ def main(args=sys.argv[1:], env=Environment()): client = Client(config_file=command_args.get('--config')) # Do the thing - data = command.execute(client, command_args) + data = command.execute(client, command_args, env) if data: format = command_args.get('--format', 'table') if format not in VALID_FORMATS: diff --git a/SoftLayer/CLI/environment.py b/SoftLayer/CLI/environment.py index 3da51f654..d6e4d93f8 100644 --- a/SoftLayer/CLI/environment.py +++ b/SoftLayer/CLI/environment.py @@ -115,5 +115,5 @@ def add_additional_args(parser): pass @staticmethod - def execute(client, args): + def execute(*args): pass diff --git a/SoftLayer/CLI/exceptions.py b/SoftLayer/CLI/exceptions.py index 510f9859c..104ae90f3 100644 --- a/SoftLayer/CLI/exceptions.py +++ b/SoftLayer/CLI/exceptions.py @@ -22,5 +22,5 @@ def __init__(self, msg, *args): class ArgumentError(CLIAbort): def __init__(self, msg, *args): - super(CLIAbort, self).__init__(code=2, *args) + super(ArgumentError, self).__init__(msg, *args) self.message = "Argument Error: %s" % msg diff --git a/SoftLayer/CLI/modules/bmc.py b/SoftLayer/CLI/modules/bmc.py index a9ee1d22b..78b4b8aca 100644 --- a/SoftLayer/CLI/modules/bmc.py +++ b/SoftLayer/CLI/modules/bmc.py @@ -44,7 +44,7 @@ class BMCCreateOptions(CLIRunnable): options = ['datacenter', 'cpu', 'memory', 'os', 'disk', 'nic'] @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): t = KeyValueTable(['Name', 'Value']) t.align['Name'] = 'r' t.align['Value'] = 'l' @@ -305,7 +305,7 @@ class CreateBMCInstance(CLIRunnable): required_params = ['--hostname', '--domain', '--cpu', '--memory', '--os'] @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): update_with_template_args(args) mgr = HardwareManager(client) @@ -520,7 +520,7 @@ class CancelInstance(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): hw = HardwareManager(client) hw_id = resolve_id( hw.resolve_ids, args.get(''), 'hardware') diff --git a/SoftLayer/CLI/modules/cci.py b/SoftLayer/CLI/modules/cci.py index 3af2c684e..07284fb09 100755 --- a/SoftLayer/CLI/modules/cci.py +++ b/SoftLayer/CLI/modules/cci.py @@ -75,7 +75,7 @@ class ListCCIs(CLIRunnable): action = 'list' @staticmethod - def execute(client, args): + def execute(client, args, env): cci = CCIManager(client) tags = None @@ -129,7 +129,7 @@ class CCIDetails(CLIRunnable): action = 'detail' @staticmethod - def execute(client, args): + def execute(client, args, env): cci = CCIManager(client) t = KeyValueTable(['Name', 'Value']) t.align['Name'] = 'r' @@ -226,7 +226,7 @@ class CreateOptionsCCI(CLIRunnable): options = ['datacenter', 'cpu', 'nic', 'disk', 'os', 'memory'] @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): cci = CCIManager(client) result = cci.get_create_options() @@ -385,7 +385,7 @@ class CreateCCI(CLIRunnable): required_params = ['--hostname', '--domain', '--cpu', '--memory'] @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): update_with_template_args(args) cci = CCIManager(client) cls._update_with_like_args(cci, args) @@ -643,7 +643,7 @@ class ReadyCCI(CLIRunnable): action = 'ready' @staticmethod - def execute(client, args): + def execute(client, args, env): cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') @@ -672,7 +672,7 @@ class ReloadCCI(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') keys = [] @@ -698,7 +698,7 @@ class CancelCCI(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') if args['--really'] or no_going_back(cci_id): @@ -720,7 +720,7 @@ class CCIPowerOff(CLIRunnable): options = ['confirm'] @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): vg = client['Virtual_Guest'] cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') @@ -748,7 +748,7 @@ class CCIReboot(CLIRunnable): options = ['confirm'] @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): vg = client['Virtual_Guest'] cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') @@ -773,7 +773,7 @@ class CCIPowerOn(CLIRunnable): action = 'power-on' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): vg = client['Virtual_Guest'] cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') @@ -790,7 +790,7 @@ class CCIPause(CLIRunnable): options = ['confirm'] @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): vg = client['Virtual_Guest'] cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') @@ -811,7 +811,7 @@ class CCIResume(CLIRunnable): action = 'resume' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): vg = client['Virtual_Guest'] cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') @@ -831,7 +831,7 @@ class NicEditCCI(CLIRunnable): action = 'nic-edit' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): public = args['public'] cci = CCIManager(client) @@ -858,7 +858,7 @@ class CCIDNS(CLIRunnable): options = ['confirm'] @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): args['--ttl'] = args['--ttl'] or DNSManager.DEFAULT_TTL if args['sync']: return cls.dns_sync(client, args) @@ -961,7 +961,7 @@ class EditCCI(CLIRunnable): action = 'edit' @staticmethod - def execute(client, args): + def execute(client, args, env): data = {} if args['--userdata'] and args['--userfile']: diff --git a/SoftLayer/CLI/modules/config.py b/SoftLayer/CLI/modules/config.py index e5ade3cd3..7d3210cf8 100644 --- a/SoftLayer/CLI/modules/config.py +++ b/SoftLayer/CLI/modules/config.py @@ -86,14 +86,14 @@ class Setup(CLIRunnable): """ action = 'setup' - @classmethod - def execute(cls, client, args): + @staticmethod + def execute(client, args, env): settings = get_settings_from_client(client) # User Input # Ask for username while True: - username = cls.env.input( + username = env.input( 'Username [%s]: ' % settings['username']) \ or settings['username'] if username: @@ -101,7 +101,7 @@ def execute(cls, client, args): # Ask for 'secret' which can be api_key or their password while True: - secret = cls.env.getpass( + secret = env.getpass( 'API Key or Password [%s]: ' % settings['api_key']) \ or settings['api_key'] if secret: @@ -109,7 +109,7 @@ def execute(cls, client, args): # Ask for which endpoint they want to use while True: - endpoint_type = cls.env.input('Endpoint (public|private|custom): ') + endpoint_type = env.input('Endpoint (public|private|custom): ') endpoint_type = endpoint_type.lower() if not endpoint_type: endpoint_url = API_PUBLIC_ENDPOINT @@ -121,7 +121,7 @@ def execute(cls, client, args): endpoint_url = API_PRIVATE_ENDPOINT break elif endpoint_type == 'custom': - endpoint_url = cls.env.input( + endpoint_url = env.input( 'Endpoint URL [%s]: ' % settings['endpoint_url'] ) or settings['endpoint_url'] break @@ -137,7 +137,7 @@ def execute(cls, client, args): path = args.get('--config') config_path = os.path.expanduser(path) - cls.env.out(format_output(config_table(settings))) + env.out(format_output(config_table(settings))) if not confirm('Are you sure you want to write settings to "%s"?' % config_path, default=True): @@ -174,7 +174,7 @@ class Show(CLIRunnable): """ action = 'show' - @classmethod - def execute(cls, client, args): + @staticmethod + def execute(client, args, env): settings = get_settings_from_client(client) return config_table(settings) diff --git a/SoftLayer/CLI/modules/dns.py b/SoftLayer/CLI/modules/dns.py index d8a2e852d..0a646911a 100755 --- a/SoftLayer/CLI/modules/dns.py +++ b/SoftLayer/CLI/modules/dns.py @@ -34,7 +34,7 @@ class DumpZone(CLIRunnable): action = "print" @staticmethod - def execute(client, args): + def execute(client, args, env): manager = DNSManager(client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') try: @@ -55,7 +55,7 @@ class CreateZone(CLIRunnable): action = 'create' @staticmethod - def execute(client, args): + def execute(client, args, env): manager = DNSManager(client) manager.create_zone(args['']) @@ -73,7 +73,7 @@ class DeleteZone(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): manager = DNSManager(client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') @@ -98,7 +98,7 @@ class ListZones(CLIRunnable): action = 'list' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): if args['']: return cls.list_zone(client, args[''], args) @@ -184,7 +184,7 @@ class AddRecord(CLIRunnable): action = 'add' @staticmethod - def execute(client, args): + def execute(client, args, env): manager = DNSManager(client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') @@ -217,7 +217,7 @@ class EditRecord(CLIRunnable): action = 'edit' @staticmethod - def execute(client, args): + def execute(client, args, env): manager = DNSManager(client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') @@ -253,7 +253,7 @@ class RecordRemove(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): manager = DNSManager(client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') diff --git a/SoftLayer/CLI/modules/firewall.py b/SoftLayer/CLI/modules/firewall.py index 0ab7b16a3..85ec98daa 100755 --- a/SoftLayer/CLI/modules/firewall.py +++ b/SoftLayer/CLI/modules/firewall.py @@ -23,7 +23,7 @@ class FWList(CLIRunnable): action = 'list' @staticmethod - def execute(client, args): + def execute(client, args, env): f = FirewallManager(client) fwvlans = f.get_firewalls() t = Table(['vlan', 'type', 'features']) diff --git a/SoftLayer/CLI/modules/globalip.py b/SoftLayer/CLI/modules/globalip.py index 7eae77dc0..7725fc1c8 100644 --- a/SoftLayer/CLI/modules/globalip.py +++ b/SoftLayer/CLI/modules/globalip.py @@ -32,7 +32,7 @@ class GlobalIpAssign(CLIRunnable): action = 'assign' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) id = mgr.resolve_global_ip_ids(args.get('')) @@ -53,7 +53,7 @@ class GlobalIpCancel(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) id = mgr.resolve_global_ip_ids(args.get('')) @@ -78,7 +78,7 @@ class GlobalIpCreate(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) version = 4 @@ -127,7 +127,7 @@ class GlobalIpList(CLIRunnable): action = 'list' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) t = Table([ @@ -175,7 +175,7 @@ class GlobalIpUnassign(CLIRunnable): action = 'unassign' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) id = mgr.resolve_global_ip_ids(args.get('')) diff --git a/SoftLayer/CLI/modules/help.py b/SoftLayer/CLI/modules/help.py index 11137a4a1..f8c8f09c2 100644 --- a/SoftLayer/CLI/modules/help.py +++ b/SoftLayer/CLI/modules/help.py @@ -17,10 +17,10 @@ class Show(CLIRunnable): __doc__ = __doc__ action = None - @classmethod - def execute(cls, client, args): - parser = CommandParser(cls.env) - cls.env.load_module(args['']) + @staticmethod + def execute(client, args, env): + parser = CommandParser(env) + env.load_module(args['']) if args['']: return parser.get_command_help(args[''], args['']) elif args['']: diff --git a/SoftLayer/CLI/modules/image.py b/SoftLayer/CLI/modules/image.py index dae619a1e..47cf3dd5c 100644 --- a/SoftLayer/CLI/modules/image.py +++ b/SoftLayer/CLI/modules/image.py @@ -26,7 +26,7 @@ class ListImages(CLIRunnable): action = 'list' @staticmethod - def execute(client, args): + def execute(client, args, env): account = client['Account'] neither = not any([args['--private'], args['--public']]) diff --git a/SoftLayer/CLI/modules/iscsi.py b/SoftLayer/CLI/modules/iscsi.py index 216adbd60..306c3de67 100644 --- a/SoftLayer/CLI/modules/iscsi.py +++ b/SoftLayer/CLI/modules/iscsi.py @@ -22,7 +22,7 @@ class ListISCSI(CLIRunnable): action = 'list' @staticmethod - def execute(client, args): + def execute(client, args, env): account = client['Account'] iscsi = account.getIscsiNetworkStorage( diff --git a/SoftLayer/CLI/modules/messaging.py b/SoftLayer/CLI/modules/messaging.py index 63ebc288f..04f8b292e 100644 --- a/SoftLayer/CLI/modules/messaging.py +++ b/SoftLayer/CLI/modules/messaging.py @@ -51,7 +51,7 @@ class ListAccounts(CLIRunnable): action = 'accounts-list' @staticmethod - def execute(client, args): + def execute(client, args, env): manager = MessagingManager(client) accounts = manager.list_accounts() @@ -81,7 +81,7 @@ class ListEndpoints(CLIRunnable): action = 'endpoints-list' @staticmethod - def execute(client, args): + def execute(client, args, env): manager = MessagingManager(client) regions = manager.get_endpoints() @@ -108,7 +108,7 @@ class Ping(CLIRunnable): action = 'ping' @staticmethod - def execute(client, args): + def execute(client, args, env): manager = MessagingManager(client) ok = manager.ping( datacenter=args['--datacenter'], network=args['--network']) @@ -177,7 +177,7 @@ class QueueList(CLIRunnable): action = 'queue-list' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) @@ -205,7 +205,7 @@ class QueueDetail(CLIRunnable): action = 'queue-detail' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) queue = mq_client.get_queue(args['']) @@ -228,7 +228,7 @@ class QueueCreate(CLIRunnable): action = 'queue-add' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) tags = None @@ -260,7 +260,7 @@ class QueueModify(CLIRunnable): action = 'queue-edit' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) tags = None @@ -290,7 +290,7 @@ class QueueDelete(CLIRunnable): action = 'queue-remove' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) @@ -315,7 +315,7 @@ class QueuePush(CLIRunnable): action = 'queue-push' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) body = '' @@ -341,7 +341,7 @@ class QueuePop(CLIRunnable): action = 'queue-pop' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) @@ -370,7 +370,7 @@ class TopicList(CLIRunnable): action = 'topic-list' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) topics = mq_client.get_topics()['items'] @@ -391,7 +391,7 @@ class TopicDetail(CLIRunnable): action = 'topic-detail' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) topic = mq_client.get_topic(args['']) @@ -412,7 +412,7 @@ class TopicCreate(CLIRunnable): action = 'topic-add' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) tags = None @@ -442,7 +442,7 @@ class TopicDelete(CLIRunnable): action = 'topic-remove' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) mq_client.delete_topic(args[''], args.get('--force')) @@ -465,7 +465,7 @@ class TopicSubscribe(CLIRunnable): action = 'topic-subscribe' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) if args['--type'] == 'queue': @@ -499,7 +499,7 @@ class TopicUnsubscribe(CLIRunnable): action = 'topic-unsubscribe' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) @@ -519,7 +519,7 @@ class TopicPush(CLIRunnable): action = 'topic-push' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) diff --git a/SoftLayer/CLI/modules/metadata.py b/SoftLayer/CLI/modules/metadata.py index f6b5727dd..26cbbef19 100644 --- a/SoftLayer/CLI/modules/metadata.py +++ b/SoftLayer/CLI/modules/metadata.py @@ -36,7 +36,7 @@ class BackendMacAddresses(CLIRunnable): action = 'backend_mac' @staticmethod - def execute(client, args): + def execute(client, args, env): return listing(MetadataManager().get('backend_mac'), separator=',') @@ -49,7 +49,7 @@ class Datacenter(CLIRunnable): action = 'datacenter' @staticmethod - def execute(client, args): + def execute(client, args, env): return MetadataManager().get('datacenter') @@ -62,7 +62,7 @@ class DatacenterId(CLIRunnable): action = 'datacenter_id' @staticmethod - def execute(client, args): + def execute(client, args, env): return MetadataManager().get('datacenter_id') @@ -75,7 +75,7 @@ class FrontendMacAddresses(CLIRunnable): action = 'frontend_mac' @staticmethod - def execute(client, args): + def execute(client, args, env): return listing(MetadataManager().get('frontend_mac'), separator=',') @@ -88,7 +88,7 @@ class FullyQualifiedDomainName(CLIRunnable): action = 'fqdn' @staticmethod - def execute(client, args): + def execute(client, args, env): return MetadataManager().get('fqdn') @@ -101,7 +101,7 @@ class Hostname(CLIRunnable): action = 'hostname' @staticmethod - def execute(client, args): + def execute(client, args, env): return MetadataManager().get('hostname') @@ -114,7 +114,7 @@ class Id(CLIRunnable): action = 'id' @staticmethod - def execute(client, args): + def execute(client, args, env): return MetadataManager().get('id') @@ -127,7 +127,7 @@ class PrimaryBackendIpAddress(CLIRunnable): action = 'backend_ip' @staticmethod - def execute(client, args): + def execute(client, args, env): return MetadataManager().get('primary_backend_ip') @@ -140,7 +140,7 @@ class PrimaryIpAddress(CLIRunnable): action = 'ip' @staticmethod - def execute(client, args): + def execute(client, args, env): return MetadataManager().get('primary_ip') @@ -153,7 +153,7 @@ class ProvisionState(CLIRunnable): action = 'provision_state' @staticmethod - def execute(client, args): + def execute(client, args, env): return MetadataManager().get('provision_state') @@ -166,7 +166,7 @@ class Tags(CLIRunnable): action = 'tags' @staticmethod - def execute(client, args): + def execute(client, args, env): return listing(MetadataManager().get('tags'), separator=',') @@ -179,7 +179,7 @@ class UserMetadata(CLIRunnable): action = 'user_data' @staticmethod - def execute(client, args): + def execute(client, args, env): userdata = MetadataManager().get('user_data') if userdata: return userdata @@ -197,7 +197,7 @@ class Network(CLIRunnable): action = 'network' @staticmethod - def execute(client, args): + def execute(client, args, env): meta = MetadataManager() if args['']: t = KeyValueTable(['Name', 'Value']) diff --git a/SoftLayer/CLI/modules/nas.py b/SoftLayer/CLI/modules/nas.py index 0bdf06dc8..c4bb1e301 100644 --- a/SoftLayer/CLI/modules/nas.py +++ b/SoftLayer/CLI/modules/nas.py @@ -24,7 +24,7 @@ class ListNAS(CLIRunnable): action = 'list' @staticmethod - def execute(client, args): + def execute(client, args, env): account = client['Account'] nas = account.getNasNetworkStorage( diff --git a/SoftLayer/CLI/modules/rwhois.py b/SoftLayer/CLI/modules/rwhois.py index 0cf43ea86..975524d02 100644 --- a/SoftLayer/CLI/modules/rwhois.py +++ b/SoftLayer/CLI/modules/rwhois.py @@ -40,7 +40,7 @@ class RWhoisEdit(CLIRunnable): action = 'edit' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) update = { @@ -76,7 +76,7 @@ class RWhoisShow(CLIRunnable): action = 'show' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) result = mgr.get_rwhois() diff --git a/SoftLayer/CLI/modules/server.py b/SoftLayer/CLI/modules/server.py index 116fc7fe2..a5168f6d9 100644 --- a/SoftLayer/CLI/modules/server.py +++ b/SoftLayer/CLI/modules/server.py @@ -64,7 +64,7 @@ class ListServers(CLIRunnable): action = 'list' @staticmethod - def execute(client, args): + def execute(client, args, env): manager = HardwareManager(client) tags = None @@ -121,7 +121,7 @@ class ServerDetails(CLIRunnable): action = 'detail' @staticmethod - def execute(client, args): + def execute(client, args, env): hardware = HardwareManager(client) t = KeyValueTable(['Name', 'Value']) @@ -206,7 +206,7 @@ class ServerReload(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): hardware = HardwareManager(client) hardware_id = resolve_id( hardware.resolve_ids, args.get(''), 'hardware') @@ -237,8 +237,8 @@ class CancelServer(CLIRunnable): action = 'cancel' options = ['confirm'] - @classmethod - def execute(cls, client, args): + @staticmethod + def execute(client, args, env): hw = HardwareManager(client) hw_id = resolve_id( hw.resolve_ids, args.get(''), 'hardware') @@ -246,7 +246,7 @@ def execute(cls, client, args): comment = args.get('--comment') if not comment and not args['--really']: - comment = cls.env.input("(Optional) Add a cancellation comment:") + comment = env.input("(Optional) Add a cancellation comment:") reason = args.get('--reason') @@ -266,7 +266,7 @@ class ServerCancelReasons(CLIRunnable): action = 'cancel-reasons' @staticmethod - def execute(client, args): + def execute(client, args, env): t = Table(['Code', 'Reason']) t.align['Code'] = 'r' t.align['Reason'] = 'l' @@ -289,8 +289,8 @@ class ServerPowerOff(CLIRunnable): action = 'power-off' options = ['confirm'] - @classmethod - def execute(cls, client, args): + @staticmethod + def execute(client, args, env): hw = client['Hardware_Server'] mgr = HardwareManager(client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), @@ -315,8 +315,8 @@ class ServerReboot(CLIRunnable): action = 'reboot' options = ['confirm'] - @classmethod - def execute(cls, client, args): + @staticmethod + def execute(client, args, env): hw = client['Hardware_Server'] mgr = HardwareManager(client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), @@ -342,7 +342,7 @@ class ServerPowerOn(CLIRunnable): action = 'power-on' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): hw = client['Hardware_Server'] mgr = HardwareManager(client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), @@ -360,7 +360,7 @@ class ServerPowerCycle(CLIRunnable): options = ['confirm'] @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): hw = client['Hardware_Server'] mgr = HardwareManager(client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), @@ -387,7 +387,7 @@ class NicEditServer(CLIRunnable): action = 'nic-edit' @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): public = args['public'] mgr = HardwareManager(client) @@ -406,7 +406,7 @@ class ListChassisServer(CLIRunnable): action = 'list-chassis' @staticmethod - def execute(client, args): + def execute(client, args, env): t = Table(['Code', 'Chassis']) t.align['Code'] = 'r' t.align['Chassis'] = 'l' @@ -443,7 +443,7 @@ class ServerCreateOptions(CLIRunnable): 'controller'] @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): mgr = HardwareManager(client) t = KeyValueTable(['Name', 'Value']) @@ -732,7 +732,7 @@ class CreateServer(CLIRunnable): '--memory', '--os'] @classmethod - def execute(cls, client, args): + def execute(cls, client, args, env): update_with_template_args(args) mgr = HardwareManager(client) @@ -933,7 +933,7 @@ class EditServer(CLIRunnable): action = 'edit' @staticmethod - def execute(client, args): + def execute(client, args, env): data = {} if args['--userdata'] and args['--userfile']: diff --git a/SoftLayer/CLI/modules/sshkey.py b/SoftLayer/CLI/modules/sshkey.py index bd392c35b..1f8b36ccd 100644 --- a/SoftLayer/CLI/modules/sshkey.py +++ b/SoftLayer/CLI/modules/sshkey.py @@ -42,7 +42,7 @@ class AddSshKey(CLIRunnable): action = 'add' @staticmethod - def execute(client, args): + def execute(client, args, env): if args.get('--key'): key = args['--key'] else: @@ -72,7 +72,7 @@ class RemoveSshKey(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = SshKeyManager(client) key_id = resolve_id(mgr.resolve_ids, @@ -95,7 +95,7 @@ class EditSshKey(CLIRunnable): action = 'edit' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = SshKeyManager(client) key_id = resolve_id(mgr.resolve_ids, @@ -124,7 +124,7 @@ class ListSshKey(CLIRunnable): action = 'list' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = SshKeyManager(client) keys = mgr.list_keys() @@ -150,7 +150,7 @@ class PrintSshKey(CLIRunnable): action = 'print' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = SshKeyManager(client) key_id = resolve_id(mgr.resolve_ids, diff --git a/SoftLayer/CLI/modules/ssl.py b/SoftLayer/CLI/modules/ssl.py index 34c45866f..8f2765f74 100755 --- a/SoftLayer/CLI/modules/ssl.py +++ b/SoftLayer/CLI/modules/ssl.py @@ -34,7 +34,7 @@ class ListCerts(CLIRunnable): action = 'list' @staticmethod - def execute(client, args): + def execute(client, args, env): manager = SSLManager(client) certificates = manager.list_certs(args['--status']) @@ -67,7 +67,7 @@ class AddCertificate(CLIRunnable): action = 'add' @staticmethod - def execute(client, args): + def execute(client, args, env): template = { 'intermediateCertificate': '', 'certificateSigningRequest': '', @@ -107,7 +107,7 @@ class EditCertificate(CLIRunnable): action = 'edit' @staticmethod - def execute(client, args): + def execute(client, args, env): template = {'id': args['']} if args['--crt']: template['certificate'] = open(args['--crt']).read() @@ -134,7 +134,7 @@ class RemoveCertificate(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): manager = SSLManager(client) if args['--really'] or no_going_back('yes'): manager.remove_certificate(args['']) @@ -150,7 +150,7 @@ class DownloadCertificate(CLIRunnable): action = 'download' @staticmethod - def execute(client, args): + def execute(client, args, env): def write_cert(filename, content): try: fo = open(filename, 'w') diff --git a/SoftLayer/CLI/modules/subnet.py b/SoftLayer/CLI/modules/subnet.py index 06c3ab318..2d234fccf 100644 --- a/SoftLayer/CLI/modules/subnet.py +++ b/SoftLayer/CLI/modules/subnet.py @@ -30,7 +30,7 @@ class SubnetCancel(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) subnet_id = mgr.resolve_subnet_ids(args.get('')) @@ -67,7 +67,7 @@ class SubnetCreate(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) _type = 'private' @@ -123,7 +123,7 @@ class SubnetDetail(CLIRunnable): action = 'detail' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) subnet_id = mgr.resolve_subnet_ids(args.get('')) @@ -190,7 +190,7 @@ class SubnetList(CLIRunnable): action = 'list' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) t = Table([ @@ -238,7 +238,7 @@ class SubnetLookup(CLIRunnable): action = 'lookup' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) ip = mgr.ip_lookup(args['']) diff --git a/SoftLayer/CLI/modules/summary.py b/SoftLayer/CLI/modules/summary.py index 6df27b7c6..b530d1cfc 100644 --- a/SoftLayer/CLI/modules/summary.py +++ b/SoftLayer/CLI/modules/summary.py @@ -23,7 +23,7 @@ class Summary(CLIRunnable): action = None @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) datacenters = mgr.summary_by_datacenter() diff --git a/SoftLayer/CLI/modules/vlan.py b/SoftLayer/CLI/modules/vlan.py index 0578a8ab3..41670fe2c 100644 --- a/SoftLayer/CLI/modules/vlan.py +++ b/SoftLayer/CLI/modules/vlan.py @@ -27,7 +27,7 @@ class VlanDetail(CLIRunnable): action = 'detail' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) vlan = mgr.get_vlan(args.get('')) @@ -105,7 +105,7 @@ class VlanList(CLIRunnable): action = 'list' @staticmethod - def execute(client, args): + def execute(client, args, env): mgr = NetworkManager(client) t = Table([ diff --git a/SoftLayer/tests/CLI/core_tests.py b/SoftLayer/tests/CLI/core_tests.py index 93995ab02..93d34a149 100644 --- a/SoftLayer/tests/CLI/core_tests.py +++ b/SoftLayer/tests/CLI/core_tests.py @@ -38,7 +38,7 @@ class submodule_fixture(object): options = [] @staticmethod - def execute(client, args): + def execute(client, args, env): return "test" @@ -113,6 +113,15 @@ def test_module_with_no_command(self): command, command_args = resolver.parse(['cci', 'list']) self.assertEqual(submodule_fixture, command) + def test_main(self): + self.env.plugins = { + 'cci': {'list': submodule_fixture} + } + self.assertRaises( + SystemExit, cli.core.main, + args=['cci', 'list'], + env=self.env) + def test_help(self): self.env.get_module_name.return_value = 'help' self.assertRaises( diff --git a/SoftLayer/tests/CLI/modules/bmc_tests.py b/SoftLayer/tests/CLI/modules/bmc_tests.py index fdae9f14f..1ae25cb12 100644 --- a/SoftLayer/tests/CLI/modules/bmc_tests.py +++ b/SoftLayer/tests/CLI/modules/bmc_tests.py @@ -33,7 +33,7 @@ def test_BMCCreateOptions(self): } client = self._setup_package_mocks(self.client) - output = bmc.BMCCreateOptions.execute(client, args) + output = bmc.BMCCreateOptions.execute(client, args, MagicMock()) expected = { 'datacenter': ['RANDOM_LOCATION'], @@ -72,7 +72,7 @@ def test_BMCCreateOptions_with_cpu_only(self): client = self._setup_package_mocks(self.client) - output = bmc.BMCCreateOptions.execute(client, args) + output = bmc.BMCCreateOptions.execute(client, args, MagicMock()) expected = { 'memory/cpu': [ @@ -124,7 +124,7 @@ def test_CreateBMCInstance(self): } ] } - output = bmc.CreateBMCInstance.execute(client, args) + output = bmc.CreateBMCInstance.execute(client, args, MagicMock()) expected = """:...................:......: : Item : cost : @@ -140,7 +140,7 @@ def test_CreateBMCInstance(self): args['--hourly'] = False args['--monthly'] = True - output = bmc.CreateBMCInstance.execute(client, args) + output = bmc.CreateBMCInstance.execute(client, args, MagicMock()) expected = """:....................:.......: : Item : cost : @@ -156,7 +156,7 @@ def test_CreateBMCInstance(self): # Make sure we can order without specifying the disk as well args['--disk'] = [] - output = bmc.CreateBMCInstance.execute(client, args) + output = bmc.CreateBMCInstance.execute(client, args, MagicMock()) self.assertEqual(expected, format_output(output, 'table')) @@ -165,14 +165,14 @@ def test_CreateBMCInstance(self): args['--disk'] = '1000_DRIVE,1000_DRIVE' args['--key'] = '123,456' - output = bmc.CreateBMCInstance.execute(client, args) + output = bmc.CreateBMCInstance.execute(client, args, MagicMock()) self.assertEqual(expected, format_output(output, 'table')) # Test explicitly setting a RAID configuration args['--controller'] = 'RAID0' - output = bmc.CreateBMCInstance.execute(client, args) + output = bmc.CreateBMCInstance.execute(client, args, MagicMock()) self.assertEqual(expected, format_output(output, 'table')) @@ -186,7 +186,8 @@ def test_CreateBMCInstance(self): args['--test'] = False args['--really'] = True - output = bmc.CreateBMCInstance.execute(self.client, args) + output = bmc.CreateBMCInstance.execute( + self.client, args, MagicMock()) expected = {'id': 98765, 'created': '2013-08-02 15:23:47'} self.assertEqual(expected, format_output(output, 'python')) @@ -198,7 +199,8 @@ def test_CreateBMCInstance(self): args['--really'] = False self.assertRaises(CLIAbort, - bmc.CreateBMCInstance.execute, self.client, args) + bmc.CreateBMCInstance.execute, + self.client, args, MagicMock()) def test_CreateBMCInstance_failures(self): client = self._setup_package_mocks(self.client) @@ -222,44 +224,51 @@ def test_CreateBMCInstance_failures(self): # Verify that ArgumentError is properly raised on error self.assertRaises(ArgumentError, - bmc.CreateBMCInstance.execute, client, args) + bmc.CreateBMCInstance.execute, + client, args, MagicMock()) # Sending strange values for hourly and monthly args['--hostname'] = 'bmc-test' self.assertRaises(ArgumentError, - bmc.CreateBMCInstance.execute, client, args) + bmc.CreateBMCInstance.execute, + client, args, MagicMock()) # Send both hourly and monthly args['--hourly'] = True args['--monthly'] = True self.assertRaises(ArgumentError, - bmc.CreateBMCInstance.execute, client, args) + bmc.CreateBMCInstance.execute, + client, args, MagicMock()) # Send neither hourly nor monthly args['--hourly'] = False args['--monthly'] = False self.assertRaises(ArgumentError, - bmc.CreateBMCInstance.execute, client, args) + bmc.CreateBMCInstance.execute, + client, args, MagicMock()) # This is missing a server_core combo args['--monthly'] = True args['--cpu'] = 100 self.assertRaises(CLIAbort, - bmc.CreateBMCInstance.execute, client, args) + bmc.CreateBMCInstance.execute, + client, args, MagicMock()) # This section is missing an OS code args['--cpu'] = '2' args['--os'] = 'nope' self.assertRaises(CLIAbort, - bmc.CreateBMCInstance.execute, client, args) + bmc.CreateBMCInstance.execute, + client, args, MagicMock()) # This section is missing a NIC speed args['--os'] = 'UBUNTU_12_64_MINIMAL' args['--network'] = 'nope' self.assertRaises(CLIAbort, - bmc.CreateBMCInstance.execute, client, args) + bmc.CreateBMCInstance.execute, + client, args, MagicMock()) @patch('SoftLayer.CLI.modules.bmc.CLIAbort') @patch('SoftLayer.CLI.modules.bmc.no_going_back') @@ -273,14 +282,14 @@ def test_CancelInstance( # Check the positive case args = {'--really': True, '--immediate': False} - bmc.CancelInstance.execute(self.client, args) + bmc.CancelInstance.execute(self.client, args, MagicMock()) cancel_mock.assert_called_with(hw_id, False) # Now check to make sure we properly call CLIAbort in the negative case args['--really'] = False - bmc.CancelInstance.execute(self.client, args) + bmc.CancelInstance.execute(self.client, args, MagicMock()) abort_mock.assert_called() def test_get_default_value_returns_none_for_unknown_category(self): diff --git a/SoftLayer/tests/CLI/modules/server_tests.py b/SoftLayer/tests/CLI/modules/server_tests.py index 57cd00f8f..bbb095f8e 100644 --- a/SoftLayer/tests/CLI/modules/server_tests.py +++ b/SoftLayer/tests/CLI/modules/server_tests.py @@ -28,7 +28,8 @@ def setUp(self): self.client = MagicMock() def test_ServerCancelReasons(self): - output = server.ServerCancelReasons.execute(self.client, {}) + output = server.ServerCancelReasons.execute( + self.client, {}, MagicMock()) expected = [ {'Code': 'datacenter', @@ -69,7 +70,7 @@ def test_ServerCreateOptions(self): client = self._setup_package_mocks(self.client) - output = server.ServerCreateOptions.execute(client, args) + output = server.ServerCreateOptions.execute(client, args, MagicMock()) expected = { 'datacenter': ['RANDOM_LOCATION'], @@ -109,7 +110,7 @@ def test_ServerCreateOptions_with_cpu_only(self): client = self._setup_package_mocks(self.client) - output = server.ServerCreateOptions.execute(client, args) + output = server.ServerCreateOptions.execute(client, args, MagicMock()) expected = { 'cpu': [ @@ -133,7 +134,7 @@ def test_ServerDetails(self): service.getReverseDomainRecords = dns_mock args = {'': hw_id, '--passwords': True, '--price': True} - output = server.ServerDetails.execute(client, args) + output = server.ServerDetails.execute(client, args, MagicMock()) expected = { 'status': 'ACTIVE', @@ -161,7 +162,7 @@ def test_ListServers(self): self.client['Account'].getHardware = account_mock.getHardware_Mock() output = server.ListServers.execute( - self.client, {'--tags': 'openstack'}) + self.client, {'--tags': 'openstack'}, MagicMock()) expected = [ { @@ -200,14 +201,14 @@ def test_ServerReload( # Check the positive case args = {'--really': True, '--postinstall': None, '--key': [12345]} - server.ServerReload.execute(self.client, args) + server.ServerReload.execute(self.client, args, MagicMock()) reload_mock.assert_called_with(hw_id, args['--postinstall'], [12345]) # Now check to make sure we properly call CLIAbort in the negative case args['--really'] = False - server.ServerReload.execute(self.client, args) + server.ServerReload.execute(self.client, args, MagicMock()) abort_mock.assert_called() @patch('SoftLayer.CLI.modules.server.CLIAbort') @@ -222,7 +223,7 @@ def test_CancelServer( # Check the positive case args = {'--really': True, '--reason': 'Test'} - server.CancelServer.execute(self.client, args) + server.CancelServer.execute(self.client, args, MagicMock()) cancel_mock.assert_called_with(hw_id, args['--reason'], None) @@ -235,7 +236,7 @@ def test_CancelServer( args['--really'] = False - server.CancelServer.execute(self.client, args) + server.CancelServer.execute(self.client, args, MagicMock()) abort_mock.assert_called() env_mock.assert_called() @@ -246,7 +247,7 @@ def test_ServerPowerOff(self, confirm_mock): # Check the positive case args = {'--really': True, '': '12345'} - server.ServerPowerOff.execute(self.client, args) + server.ServerPowerOff.execute(self.client, args, MagicMock()) self.client['Hardware_Server'].powerOff.assert_called_with(id=hw_id) @@ -254,7 +255,8 @@ def test_ServerPowerOff(self, confirm_mock): confirm_mock.return_value = False args['--really'] = False self.assertRaises(CLIAbort, - server.ServerPowerOff.execute, self.client, args) + server.ServerPowerOff.execute, + self.client, args, MagicMock()) @patch('SoftLayer.CLI.modules.server.confirm') def test_ServerReboot(self, confirm_mock): @@ -268,25 +270,26 @@ def test_ServerReboot(self, confirm_mock): '--soft': False, } - server.ServerReboot.execute(self.client, args) + server.ServerReboot.execute(self.client, args, MagicMock()) self.client['Hardware_Server'].rebootDefault.assert_called_with( id=hw_id) args['--soft'] = True args['--hard'] = False - server.ServerReboot.execute(self.client, args) + server.ServerReboot.execute(self.client, args, MagicMock()) self.client['Hardware_Server'].rebootSoft.assert_called_with(id=hw_id) args['--soft'] = False args['--hard'] = True - server.ServerReboot.execute(self.client, args) + server.ServerReboot.execute(self.client, args, MagicMock()) self.client['Hardware_Server'].rebootHard.assert_called_with(id=hw_id) # Now check to make sure we properly call CLIAbort in the negative case confirm_mock.return_value = False args['--really'] = False self.assertRaises(CLIAbort, - server.ServerReboot.execute, self.client, args) + server.ServerReboot.execute, + self.client, args, MagicMock()) def test_ServerPowerOn(self): hw_id = 12345 @@ -296,7 +299,7 @@ def test_ServerPowerOn(self): '': '12345', } - server.ServerPowerOn.execute(self.client, args) + server.ServerPowerOn.execute(self.client, args, MagicMock()) self.client['Hardware_Server'].powerOn.assert_called_with(id=hw_id) @patch('SoftLayer.CLI.modules.server.confirm') @@ -309,14 +312,15 @@ def test_ServerPowerCycle(self, confirm_mock): '--really': True, } - server.ServerPowerCycle.execute(self.client, args) + server.ServerPowerCycle.execute(self.client, args, MagicMock()) self.client['Hardware_Server'].powerCycle.assert_called_with(id=hw_id) # Now check to make sure we properly call CLIAbort in the negative case confirm_mock.return_value = False args['--really'] = False self.assertRaises(CLIAbort, - server.ServerPowerCycle.execute, self.client, args) + server.ServerPowerCycle.execute, + self.client, args, MagicMock()) @patch('SoftLayer.HardwareManager.change_port_speed') @patch('SoftLayer.CLI.modules.server.resolve_id') @@ -335,11 +339,12 @@ def test_NicEditServer(self, resolve_mock, port_mock): port_mock.side_effect = [True, False] # First call simulates a success - server.NicEditServer.execute(self.client, args) + server.NicEditServer.execute(self.client, args, MagicMock()) port_mock.assert_called_with(hw_id, False, 100) # Second call simulates an error - self.assertFalse(server.NicEditServer.execute(self.client, args)) + self.assertFalse( + server.NicEditServer.execute(self.client, args, MagicMock())) @patch('SoftLayer.HardwareManager.get_available_dedicated_server_packages') def test_ListChassisServer(self, packages): @@ -349,7 +354,7 @@ def test_ListChassisServer(self, packages): ] packages.return_value = test_data - output = server.ListChassisServer.execute(self.client, {}) + output = server.ListChassisServer.execute(self.client, {}, MagicMock()) expected = [ {'Chassis': 'Chassis 1', 'Code': 1}, @@ -396,7 +401,7 @@ def test_CreateServer(self): } ] } - output = server.CreateServer.execute(client, args) + output = server.CreateServer.execute(client, args, MagicMock()) expected = [ [ @@ -412,7 +417,7 @@ def test_CreateServer(self): # Make sure we can order without specifying the disk as well args['--disk'] = [] - output = server.CreateServer.execute(client, args) + output = server.CreateServer.execute(client, args, MagicMock()) self.assertEqual(expected, format_output(output, 'python')) @@ -421,14 +426,14 @@ def test_CreateServer(self): args['--disk'] = '1000_DRIVE,1000_DRIVE' args['--key'] = '123,456' - output = server.CreateServer.execute(client, args) + output = server.CreateServer.execute(client, args, MagicMock()) self.assertEqual(expected, format_output(output, 'python')) # Test explicitly setting a RAID configuration args['--controller'] = 'RAID0' - output = server.CreateServer.execute(client, args) + output = server.CreateServer.execute(client, args, MagicMock()) self.assertEqual(expected, format_output(output, 'python')) @@ -442,7 +447,8 @@ def test_CreateServer(self): args['--test'] = False args['--really'] = True - output = server.CreateServer.execute(self.client, args) + output = server.CreateServer.execute( + self.client, args, MagicMock()) expected = {'id': 98765, 'created': '2013-08-02 15:23:47'} self.assertEqual(expected, format_output(output, 'python')) @@ -454,7 +460,8 @@ def test_CreateServer(self): args['--really'] = False self.assertRaises(CLIAbort, - server.CreateServer.execute, self.client, args) + server.CreateServer.execute, + self.client, args, MagicMock()) def test_CreateServer_failures(self): client = self._setup_package_mocks(self.client) @@ -476,7 +483,8 @@ def test_CreateServer_failures(self): # Verify that ArgumentError is properly raised on error self.assertRaises(ArgumentError, - server.CreateServer.execute, client, args) + server.CreateServer.execute, + client, args, MagicMock()) # This contains an invalid network argument args['--chassis'] = 999 @@ -484,7 +492,8 @@ def test_CreateServer_failures(self): # Verify that CLIAbort is properly raised on error self.assertRaises(CLIAbort, - server.CreateServer.execute, client, args) + server.CreateServer.execute, + client, args, MagicMock()) # This contains an invalid operating system argument args['--network'] = '100' @@ -492,7 +501,8 @@ def test_CreateServer_failures(self): # Verify that CLIAbort is properly raised on error self.assertRaises(CLIAbort, - server.CreateServer.execute, client, args) + server.CreateServer.execute, + client, args, MagicMock()) @patch('SoftLayer.CLI.modules.server.export_to_template') def test_CreateServer_with_export(self, export_to_template): @@ -518,7 +528,7 @@ def test_CreateServer_with_export(self, export_to_template): expected = args.copy() del(expected['--export']) - server.CreateServer.execute(client, args) + server.CreateServer.execute(client, args, MagicMock()) export_to_template.assert_called_with('test_file.txt', expected, exclude=['--wait', '--test']) @@ -534,7 +544,8 @@ def test_EditServer(self): } self.assertRaises(ArgumentError, - server.EditServer.execute, self.client, args) + server.EditServer.execute, + self.client, args, MagicMock()) # Simulate a missing file error args['--userdata'] = None @@ -543,7 +554,8 @@ def test_EditServer(self): exists.return_value = False self.assertRaises(ArgumentError, - server.EditServer.execute, self.client, args) + server.EditServer.execute, + self.client, args, MagicMock()) # Test a successful edit with user data args['--userdata'] = 'My data' @@ -558,7 +570,7 @@ def test_EditServer(self): with patch('SoftLayer.HardwareManager.edit') as edit_mock: edit_mock.return_value = True - server.EditServer.execute(self.client, args) + server.EditServer.execute(self.client, args, MagicMock()) edit_mock.assert_called_with(1000, **expected) @@ -566,7 +578,8 @@ def test_EditServer(self): edit_mock.return_value = False self.assertRaises(CLIAbort, - server.EditServer.execute, self.client, args) + server.EditServer.execute, + self.client, args, MagicMock()) # Test a successful edit with a user file args['--userdata'] = None @@ -589,7 +602,7 @@ def test_EditServer(self): edit_mock.return_value = True expected['userdata'] = 'some data' - server.EditServer.execute(self.client, args) + server.EditServer.execute(self.client, args, MagicMock()) edit_mock.assert_called_with(1000, **expected) diff --git a/docs/dev/cli.rst b/docs/dev/cli.rst index 27b7fd84a..6795042c3 100644 --- a/docs/dev/cli.rst +++ b/docs/dev/cli.rst @@ -55,17 +55,17 @@ Actions are implemented using classes in the module that subclass `SoftLayer.CLI pass @staticmethod - def execute(client, args): + def execute(client, args, env): pass The required interfaces are: * The docblock (__doc__) for docopt * action class attribute -* def execute(client, args) +* def execute(client, args, env) - Don't forget the @staticmethod annotation! - - you can also use @classmethod and use execute(cls, client, args) if you plan on dispatching instead of executing a simple task. + - you can also use @classmethod and use execute(cls, client, args, env) if you plan on dispatching instead of executing a simple task. A minimal implementation for `sl example print` would look like this: :: @@ -80,7 +80,7 @@ A minimal implementation for `sl example print` would look like this: action = 'print' @staticmethod - def execute(client, args): + def execute(client, args, env): print "EXAMPLE!" @@ -115,7 +115,7 @@ The `execute()` method is expected to return either `None` or an instance of `So action = 'pretty' @staticmethod - def execute(client, args): + def execute(client, args, env): # create a table with two columns: col1, col2 t = Table(['col1', 'col2']) @@ -169,7 +169,7 @@ Refer to docopt for more complete documentation action = 'parse' @staticmethod - def execute(client, args): + def execute(client, args, env): if args.get('--test'): print "Just testing, move along..." else: @@ -213,7 +213,7 @@ All confirmations should be easily bypassed by checking for `args['--really']`. options = ['confirm'] # confirm adds the '-y|--really' options and help @staticmethod - def execute(client, args): + def execute(client, args, env): pass There are two primary confirmation prompts that both leverage `SoftLayer.CLI.valid_response`: diff --git a/docs/dev/example_module.rst b/docs/dev/example_module.rst index 9b3209da4..5728f7a0b 100644 --- a/docs/dev/example_module.rst +++ b/docs/dev/example_module.rst @@ -32,7 +32,7 @@ Example CLI Module action = 'print' @staticmethod - def execute(client, args): + def execute(client, args, env): print "EXAMPLE!" @@ -46,7 +46,7 @@ Example CLI Module action = 'pretty' @staticmethod - def execute(client, args): + def execute(client, args, env): # create a table with two columns: col1, col2 t = Table(['col1', 'col2']) @@ -78,7 +78,7 @@ Example CLI Module options = ['confirm'] @staticmethod - def execute(client, args): + def execute(client, args, env): if args.get('--test'): print "Just testing, move along..." else: diff --git a/example.py b/example.py deleted file mode 100644 index 880ad1fa6..000000000 --- a/example.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" - example - ~~~~~~~ - This is an example of using the SoftLayer API Python Client. - - For more examples and documentation, refer to: - https://softlayer-api-python-client.readthedocs.org - - :copyright: (c) 2013, SoftLayer Technologies, Inc. All rights reserved. - :license: MIT, see LICENSE for more details. -""" -# The SoftLayer API client package is here: -import SoftLayer -import pprint - -# Usage: -# SoftLayer.Client(username=[Username], api_key=[API key]) -# -# Username: Your SoftLayer API username. -# API key: Your SoftLayer API key, -username = 'SET ME' -api_key = 'SET ME' - -client = SoftLayer.Client(username=username, api_key=api_key) - -# Once your client object is created you can call API methods for that service -# directly against your client object. Each call may throw an raise a -# SoftLayerError exception. -# -# This example calls the getObject() method in the SoftLayer_Account API -# service. -# It retrieves basic account information, and is a great way to test your API -# account and connectivity. -pprint.pprint(client['Account'].getObject()) - -# For a more complex example we’ll retrieve a support ticket with id 123456 -# along with the ticket’s updates, the user it’s assigned to, the servers -# attached to it, and the datacenter those servers are in. We’ll retrieve our -# extra information using a nested object mask. After we have the ticket we’ll -# update it with the text ‘Hello!’. - -# Retrieve the ticket record. -ticket = client['Ticket'].getObject( - id=123456, mask='updates,assignedUser,attachedHardware.datacenter') -pprint.pprint(ticket) - -# Now update the ticket. -update = client['Ticket'].addUpdate(id=123456, {'entry': 'Hello!'}) -pprint.pprint(update) From b30dd3ed0c94a29f998306ff08e9726ae28cfdc6 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Tue, 5 Nov 2013 15:07:35 -0600 Subject: [PATCH 07/47] Removes duplicate import. Fixes invalid reference to default TTL. --- SoftLayer/CLI/modules/cci.py | 5 ++--- SoftLayer/managers/dns.py | 3 --- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/SoftLayer/CLI/modules/cci.py b/SoftLayer/CLI/modules/cci.py index 07284fb09..2e8161de8 100755 --- a/SoftLayer/CLI/modules/cci.py +++ b/SoftLayer/CLI/modules/cci.py @@ -30,7 +30,7 @@ from os import linesep import os.path -from SoftLayer import CCIManager, SshKeyManager, DNSManager +from SoftLayer import CCIManager, SshKeyManager, DNSManager, DNSZoneNotFound from SoftLayer.utils import lookup from SoftLayer.CLI import ( CLIRunnable, Table, no_going_back, confirm, mb_to_gb, listing, @@ -859,13 +859,12 @@ class CCIDNS(CLIRunnable): @classmethod def execute(cls, client, args, env): - args['--ttl'] = args['--ttl'] or DNSManager.DEFAULT_TTL + args['--ttl'] = args['--ttl'] or 7200 if args['sync']: return cls.dns_sync(client, args) @staticmethod def dns_sync(client, args): - from SoftLayer import DNSManager, DNSZoneNotFound dns = DNSManager(client) cci = CCIManager(client) diff --git a/SoftLayer/managers/dns.py b/SoftLayer/managers/dns.py index 4fc6c61c7..2b104e6c9 100644 --- a/SoftLayer/managers/dns.py +++ b/SoftLayer/managers/dns.py @@ -12,9 +12,6 @@ from SoftLayer.utils import NestedDict, query_filter, IdentifierMixin -DEFAULT_TTL = 7200 - - class DNSManager(IdentifierMixin, object): """ DNSManager initialization. From 81cc4cba14e559dac47b691c9e661a741da375ac Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Tue, 5 Nov 2013 15:21:11 -0600 Subject: [PATCH 08/47] Removes lingering refactor comment --- SoftLayer/CLI/modules/metadata.py | 1 - 1 file changed, 1 deletion(-) diff --git a/SoftLayer/CLI/modules/metadata.py b/SoftLayer/CLI/modules/metadata.py index 26cbbef19..934ad3a38 100644 --- a/SoftLayer/CLI/modules/metadata.py +++ b/SoftLayer/CLI/modules/metadata.py @@ -193,7 +193,6 @@ class Network(CLIRunnable): Get details about the public or private network """ - """ details about either the public or private network """ action = 'network' @staticmethod From f66260c869e3d1a97d3e42ad1cf63151ae812158 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Tue, 5 Nov 2013 15:26:28 -0600 Subject: [PATCH 09/47] Reverts some of the changes since they backfired on me --- SoftLayer/CLI/core.py | 6 +- SoftLayer/CLI/environment.py | 2 +- SoftLayer/CLI/exceptions.py | 2 +- SoftLayer/CLI/modules/bmc.py | 6 +- SoftLayer/CLI/modules/cci.py | 28 +++---- SoftLayer/CLI/modules/config.py | 18 ++--- SoftLayer/CLI/modules/dns.py | 14 ++-- SoftLayer/CLI/modules/firewall.py | 2 +- SoftLayer/CLI/modules/globalip.py | 10 +-- SoftLayer/CLI/modules/help.py | 8 +- SoftLayer/CLI/modules/image.py | 2 +- SoftLayer/CLI/modules/iscsi.py | 2 +- SoftLayer/CLI/modules/messaging.py | 34 ++++----- SoftLayer/CLI/modules/metadata.py | 26 +++---- SoftLayer/CLI/modules/nas.py | 2 +- SoftLayer/CLI/modules/rwhois.py | 4 +- SoftLayer/CLI/modules/server.py | 36 ++++----- SoftLayer/CLI/modules/sshkey.py | 10 +-- SoftLayer/CLI/modules/ssl.py | 10 +-- SoftLayer/CLI/modules/subnet.py | 10 +-- SoftLayer/CLI/modules/summary.py | 2 +- SoftLayer/CLI/modules/vlan.py | 4 +- SoftLayer/tests/CLI/core_tests.py | 11 +-- SoftLayer/tests/CLI/modules/bmc_tests.py | 45 +++++------ SoftLayer/tests/CLI/modules/server_tests.py | 85 +++++++++------------ docs/dev/cli.rst | 14 ++-- docs/dev/example_module.rst | 6 +- example.py | 51 +++++++++++++ 28 files changed, 236 insertions(+), 214 deletions(-) create mode 100644 example.py diff --git a/SoftLayer/CLI/core.py b/SoftLayer/CLI/core.py index 793982983..00ff7cb5f 100644 --- a/SoftLayer/CLI/core.py +++ b/SoftLayer/CLI/core.py @@ -51,7 +51,8 @@ from SoftLayer import Client, TimedClient, SoftLayerError, SoftLayerAPIError from SoftLayer.consts import VERSION from helpers import CLIAbort, ArgumentError, format_output, KeyValueTable -from environment import Environment, InvalidCommand, InvalidModule +from environment import ( + Environment, CLIRunnableType, InvalidCommand, InvalidModule) DEBUG_LOGGING_MAP = { @@ -153,6 +154,7 @@ def main(args=sys.argv[1:], env=Environment()): Entry point for the command-line client. """ # Parse Top-Level Arguments + CLIRunnableType.env = env exit_status = 0 resolver = CommandParser(env) try: @@ -172,7 +174,7 @@ def main(args=sys.argv[1:], env=Environment()): client = Client(config_file=command_args.get('--config')) # Do the thing - data = command.execute(client, command_args, env) + data = command.execute(client, command_args) if data: format = command_args.get('--format', 'table') if format not in VALID_FORMATS: diff --git a/SoftLayer/CLI/environment.py b/SoftLayer/CLI/environment.py index d6e4d93f8..3da51f654 100644 --- a/SoftLayer/CLI/environment.py +++ b/SoftLayer/CLI/environment.py @@ -115,5 +115,5 @@ def add_additional_args(parser): pass @staticmethod - def execute(*args): + def execute(client, args): pass diff --git a/SoftLayer/CLI/exceptions.py b/SoftLayer/CLI/exceptions.py index 104ae90f3..510f9859c 100644 --- a/SoftLayer/CLI/exceptions.py +++ b/SoftLayer/CLI/exceptions.py @@ -22,5 +22,5 @@ def __init__(self, msg, *args): class ArgumentError(CLIAbort): def __init__(self, msg, *args): - super(ArgumentError, self).__init__(msg, *args) + super(CLIAbort, self).__init__(code=2, *args) self.message = "Argument Error: %s" % msg diff --git a/SoftLayer/CLI/modules/bmc.py b/SoftLayer/CLI/modules/bmc.py index 78b4b8aca..a9ee1d22b 100644 --- a/SoftLayer/CLI/modules/bmc.py +++ b/SoftLayer/CLI/modules/bmc.py @@ -44,7 +44,7 @@ class BMCCreateOptions(CLIRunnable): options = ['datacenter', 'cpu', 'memory', 'os', 'disk', 'nic'] @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): t = KeyValueTable(['Name', 'Value']) t.align['Name'] = 'r' t.align['Value'] = 'l' @@ -305,7 +305,7 @@ class CreateBMCInstance(CLIRunnable): required_params = ['--hostname', '--domain', '--cpu', '--memory', '--os'] @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): update_with_template_args(args) mgr = HardwareManager(client) @@ -520,7 +520,7 @@ class CancelInstance(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): hw = HardwareManager(client) hw_id = resolve_id( hw.resolve_ids, args.get(''), 'hardware') diff --git a/SoftLayer/CLI/modules/cci.py b/SoftLayer/CLI/modules/cci.py index 2e8161de8..faee70508 100755 --- a/SoftLayer/CLI/modules/cci.py +++ b/SoftLayer/CLI/modules/cci.py @@ -75,7 +75,7 @@ class ListCCIs(CLIRunnable): action = 'list' @staticmethod - def execute(client, args, env): + def execute(client, args): cci = CCIManager(client) tags = None @@ -129,7 +129,7 @@ class CCIDetails(CLIRunnable): action = 'detail' @staticmethod - def execute(client, args, env): + def execute(client, args): cci = CCIManager(client) t = KeyValueTable(['Name', 'Value']) t.align['Name'] = 'r' @@ -226,7 +226,7 @@ class CreateOptionsCCI(CLIRunnable): options = ['datacenter', 'cpu', 'nic', 'disk', 'os', 'memory'] @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): cci = CCIManager(client) result = cci.get_create_options() @@ -385,7 +385,7 @@ class CreateCCI(CLIRunnable): required_params = ['--hostname', '--domain', '--cpu', '--memory'] @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): update_with_template_args(args) cci = CCIManager(client) cls._update_with_like_args(cci, args) @@ -643,7 +643,7 @@ class ReadyCCI(CLIRunnable): action = 'ready' @staticmethod - def execute(client, args, env): + def execute(client, args): cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') @@ -672,7 +672,7 @@ class ReloadCCI(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') keys = [] @@ -698,7 +698,7 @@ class CancelCCI(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') if args['--really'] or no_going_back(cci_id): @@ -720,7 +720,7 @@ class CCIPowerOff(CLIRunnable): options = ['confirm'] @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): vg = client['Virtual_Guest'] cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') @@ -748,7 +748,7 @@ class CCIReboot(CLIRunnable): options = ['confirm'] @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): vg = client['Virtual_Guest'] cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') @@ -773,7 +773,7 @@ class CCIPowerOn(CLIRunnable): action = 'power-on' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): vg = client['Virtual_Guest'] cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') @@ -790,7 +790,7 @@ class CCIPause(CLIRunnable): options = ['confirm'] @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): vg = client['Virtual_Guest'] cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') @@ -811,7 +811,7 @@ class CCIResume(CLIRunnable): action = 'resume' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): vg = client['Virtual_Guest'] cci = CCIManager(client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') @@ -831,7 +831,7 @@ class NicEditCCI(CLIRunnable): action = 'nic-edit' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): public = args['public'] cci = CCIManager(client) @@ -960,7 +960,7 @@ class EditCCI(CLIRunnable): action = 'edit' @staticmethod - def execute(client, args, env): + def execute(client, args): data = {} if args['--userdata'] and args['--userfile']: diff --git a/SoftLayer/CLI/modules/config.py b/SoftLayer/CLI/modules/config.py index 7d3210cf8..e5ade3cd3 100644 --- a/SoftLayer/CLI/modules/config.py +++ b/SoftLayer/CLI/modules/config.py @@ -86,14 +86,14 @@ class Setup(CLIRunnable): """ action = 'setup' - @staticmethod - def execute(client, args, env): + @classmethod + def execute(cls, client, args): settings = get_settings_from_client(client) # User Input # Ask for username while True: - username = env.input( + username = cls.env.input( 'Username [%s]: ' % settings['username']) \ or settings['username'] if username: @@ -101,7 +101,7 @@ def execute(client, args, env): # Ask for 'secret' which can be api_key or their password while True: - secret = env.getpass( + secret = cls.env.getpass( 'API Key or Password [%s]: ' % settings['api_key']) \ or settings['api_key'] if secret: @@ -109,7 +109,7 @@ def execute(client, args, env): # Ask for which endpoint they want to use while True: - endpoint_type = env.input('Endpoint (public|private|custom): ') + endpoint_type = cls.env.input('Endpoint (public|private|custom): ') endpoint_type = endpoint_type.lower() if not endpoint_type: endpoint_url = API_PUBLIC_ENDPOINT @@ -121,7 +121,7 @@ def execute(client, args, env): endpoint_url = API_PRIVATE_ENDPOINT break elif endpoint_type == 'custom': - endpoint_url = env.input( + endpoint_url = cls.env.input( 'Endpoint URL [%s]: ' % settings['endpoint_url'] ) or settings['endpoint_url'] break @@ -137,7 +137,7 @@ def execute(client, args, env): path = args.get('--config') config_path = os.path.expanduser(path) - env.out(format_output(config_table(settings))) + cls.env.out(format_output(config_table(settings))) if not confirm('Are you sure you want to write settings to "%s"?' % config_path, default=True): @@ -174,7 +174,7 @@ class Show(CLIRunnable): """ action = 'show' - @staticmethod - def execute(client, args, env): + @classmethod + def execute(cls, client, args): settings = get_settings_from_client(client) return config_table(settings) diff --git a/SoftLayer/CLI/modules/dns.py b/SoftLayer/CLI/modules/dns.py index 0a646911a..d8a2e852d 100755 --- a/SoftLayer/CLI/modules/dns.py +++ b/SoftLayer/CLI/modules/dns.py @@ -34,7 +34,7 @@ class DumpZone(CLIRunnable): action = "print" @staticmethod - def execute(client, args, env): + def execute(client, args): manager = DNSManager(client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') try: @@ -55,7 +55,7 @@ class CreateZone(CLIRunnable): action = 'create' @staticmethod - def execute(client, args, env): + def execute(client, args): manager = DNSManager(client) manager.create_zone(args['']) @@ -73,7 +73,7 @@ class DeleteZone(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): manager = DNSManager(client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') @@ -98,7 +98,7 @@ class ListZones(CLIRunnable): action = 'list' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): if args['']: return cls.list_zone(client, args[''], args) @@ -184,7 +184,7 @@ class AddRecord(CLIRunnable): action = 'add' @staticmethod - def execute(client, args, env): + def execute(client, args): manager = DNSManager(client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') @@ -217,7 +217,7 @@ class EditRecord(CLIRunnable): action = 'edit' @staticmethod - def execute(client, args, env): + def execute(client, args): manager = DNSManager(client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') @@ -253,7 +253,7 @@ class RecordRemove(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): manager = DNSManager(client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') diff --git a/SoftLayer/CLI/modules/firewall.py b/SoftLayer/CLI/modules/firewall.py index 85ec98daa..0ab7b16a3 100755 --- a/SoftLayer/CLI/modules/firewall.py +++ b/SoftLayer/CLI/modules/firewall.py @@ -23,7 +23,7 @@ class FWList(CLIRunnable): action = 'list' @staticmethod - def execute(client, args, env): + def execute(client, args): f = FirewallManager(client) fwvlans = f.get_firewalls() t = Table(['vlan', 'type', 'features']) diff --git a/SoftLayer/CLI/modules/globalip.py b/SoftLayer/CLI/modules/globalip.py index 7725fc1c8..7eae77dc0 100644 --- a/SoftLayer/CLI/modules/globalip.py +++ b/SoftLayer/CLI/modules/globalip.py @@ -32,7 +32,7 @@ class GlobalIpAssign(CLIRunnable): action = 'assign' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) id = mgr.resolve_global_ip_ids(args.get('')) @@ -53,7 +53,7 @@ class GlobalIpCancel(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) id = mgr.resolve_global_ip_ids(args.get('')) @@ -78,7 +78,7 @@ class GlobalIpCreate(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) version = 4 @@ -127,7 +127,7 @@ class GlobalIpList(CLIRunnable): action = 'list' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) t = Table([ @@ -175,7 +175,7 @@ class GlobalIpUnassign(CLIRunnable): action = 'unassign' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) id = mgr.resolve_global_ip_ids(args.get('')) diff --git a/SoftLayer/CLI/modules/help.py b/SoftLayer/CLI/modules/help.py index f8c8f09c2..11137a4a1 100644 --- a/SoftLayer/CLI/modules/help.py +++ b/SoftLayer/CLI/modules/help.py @@ -17,10 +17,10 @@ class Show(CLIRunnable): __doc__ = __doc__ action = None - @staticmethod - def execute(client, args, env): - parser = CommandParser(env) - env.load_module(args['']) + @classmethod + def execute(cls, client, args): + parser = CommandParser(cls.env) + cls.env.load_module(args['']) if args['']: return parser.get_command_help(args[''], args['']) elif args['']: diff --git a/SoftLayer/CLI/modules/image.py b/SoftLayer/CLI/modules/image.py index 47cf3dd5c..dae619a1e 100644 --- a/SoftLayer/CLI/modules/image.py +++ b/SoftLayer/CLI/modules/image.py @@ -26,7 +26,7 @@ class ListImages(CLIRunnable): action = 'list' @staticmethod - def execute(client, args, env): + def execute(client, args): account = client['Account'] neither = not any([args['--private'], args['--public']]) diff --git a/SoftLayer/CLI/modules/iscsi.py b/SoftLayer/CLI/modules/iscsi.py index 306c3de67..216adbd60 100644 --- a/SoftLayer/CLI/modules/iscsi.py +++ b/SoftLayer/CLI/modules/iscsi.py @@ -22,7 +22,7 @@ class ListISCSI(CLIRunnable): action = 'list' @staticmethod - def execute(client, args, env): + def execute(client, args): account = client['Account'] iscsi = account.getIscsiNetworkStorage( diff --git a/SoftLayer/CLI/modules/messaging.py b/SoftLayer/CLI/modules/messaging.py index 04f8b292e..63ebc288f 100644 --- a/SoftLayer/CLI/modules/messaging.py +++ b/SoftLayer/CLI/modules/messaging.py @@ -51,7 +51,7 @@ class ListAccounts(CLIRunnable): action = 'accounts-list' @staticmethod - def execute(client, args, env): + def execute(client, args): manager = MessagingManager(client) accounts = manager.list_accounts() @@ -81,7 +81,7 @@ class ListEndpoints(CLIRunnable): action = 'endpoints-list' @staticmethod - def execute(client, args, env): + def execute(client, args): manager = MessagingManager(client) regions = manager.get_endpoints() @@ -108,7 +108,7 @@ class Ping(CLIRunnable): action = 'ping' @staticmethod - def execute(client, args, env): + def execute(client, args): manager = MessagingManager(client) ok = manager.ping( datacenter=args['--datacenter'], network=args['--network']) @@ -177,7 +177,7 @@ class QueueList(CLIRunnable): action = 'queue-list' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) @@ -205,7 +205,7 @@ class QueueDetail(CLIRunnable): action = 'queue-detail' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) queue = mq_client.get_queue(args['']) @@ -228,7 +228,7 @@ class QueueCreate(CLIRunnable): action = 'queue-add' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) tags = None @@ -260,7 +260,7 @@ class QueueModify(CLIRunnable): action = 'queue-edit' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) tags = None @@ -290,7 +290,7 @@ class QueueDelete(CLIRunnable): action = 'queue-remove' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) @@ -315,7 +315,7 @@ class QueuePush(CLIRunnable): action = 'queue-push' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) body = '' @@ -341,7 +341,7 @@ class QueuePop(CLIRunnable): action = 'queue-pop' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) @@ -370,7 +370,7 @@ class TopicList(CLIRunnable): action = 'topic-list' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) topics = mq_client.get_topics()['items'] @@ -391,7 +391,7 @@ class TopicDetail(CLIRunnable): action = 'topic-detail' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) topic = mq_client.get_topic(args['']) @@ -412,7 +412,7 @@ class TopicCreate(CLIRunnable): action = 'topic-add' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) tags = None @@ -442,7 +442,7 @@ class TopicDelete(CLIRunnable): action = 'topic-remove' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) mq_client.delete_topic(args[''], args.get('--force')) @@ -465,7 +465,7 @@ class TopicSubscribe(CLIRunnable): action = 'topic-subscribe' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) if args['--type'] == 'queue': @@ -499,7 +499,7 @@ class TopicUnsubscribe(CLIRunnable): action = 'topic-unsubscribe' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) @@ -519,7 +519,7 @@ class TopicPush(CLIRunnable): action = 'topic-push' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): manager = MessagingManager(client) mq_client = manager.get_connection(args['']) diff --git a/SoftLayer/CLI/modules/metadata.py b/SoftLayer/CLI/modules/metadata.py index 934ad3a38..d3553ca07 100644 --- a/SoftLayer/CLI/modules/metadata.py +++ b/SoftLayer/CLI/modules/metadata.py @@ -36,7 +36,7 @@ class BackendMacAddresses(CLIRunnable): action = 'backend_mac' @staticmethod - def execute(client, args, env): + def execute(client, args): return listing(MetadataManager().get('backend_mac'), separator=',') @@ -49,7 +49,7 @@ class Datacenter(CLIRunnable): action = 'datacenter' @staticmethod - def execute(client, args, env): + def execute(client, args): return MetadataManager().get('datacenter') @@ -62,7 +62,7 @@ class DatacenterId(CLIRunnable): action = 'datacenter_id' @staticmethod - def execute(client, args, env): + def execute(client, args): return MetadataManager().get('datacenter_id') @@ -75,7 +75,7 @@ class FrontendMacAddresses(CLIRunnable): action = 'frontend_mac' @staticmethod - def execute(client, args, env): + def execute(client, args): return listing(MetadataManager().get('frontend_mac'), separator=',') @@ -88,7 +88,7 @@ class FullyQualifiedDomainName(CLIRunnable): action = 'fqdn' @staticmethod - def execute(client, args, env): + def execute(client, args): return MetadataManager().get('fqdn') @@ -101,7 +101,7 @@ class Hostname(CLIRunnable): action = 'hostname' @staticmethod - def execute(client, args, env): + def execute(client, args): return MetadataManager().get('hostname') @@ -114,7 +114,7 @@ class Id(CLIRunnable): action = 'id' @staticmethod - def execute(client, args, env): + def execute(client, args): return MetadataManager().get('id') @@ -127,7 +127,7 @@ class PrimaryBackendIpAddress(CLIRunnable): action = 'backend_ip' @staticmethod - def execute(client, args, env): + def execute(client, args): return MetadataManager().get('primary_backend_ip') @@ -140,7 +140,7 @@ class PrimaryIpAddress(CLIRunnable): action = 'ip' @staticmethod - def execute(client, args, env): + def execute(client, args): return MetadataManager().get('primary_ip') @@ -153,7 +153,7 @@ class ProvisionState(CLIRunnable): action = 'provision_state' @staticmethod - def execute(client, args, env): + def execute(client, args): return MetadataManager().get('provision_state') @@ -166,7 +166,7 @@ class Tags(CLIRunnable): action = 'tags' @staticmethod - def execute(client, args, env): + def execute(client, args): return listing(MetadataManager().get('tags'), separator=',') @@ -179,7 +179,7 @@ class UserMetadata(CLIRunnable): action = 'user_data' @staticmethod - def execute(client, args, env): + def execute(client, args): userdata = MetadataManager().get('user_data') if userdata: return userdata @@ -196,7 +196,7 @@ class Network(CLIRunnable): action = 'network' @staticmethod - def execute(client, args, env): + def execute(client, args): meta = MetadataManager() if args['']: t = KeyValueTable(['Name', 'Value']) diff --git a/SoftLayer/CLI/modules/nas.py b/SoftLayer/CLI/modules/nas.py index c4bb1e301..0bdf06dc8 100644 --- a/SoftLayer/CLI/modules/nas.py +++ b/SoftLayer/CLI/modules/nas.py @@ -24,7 +24,7 @@ class ListNAS(CLIRunnable): action = 'list' @staticmethod - def execute(client, args, env): + def execute(client, args): account = client['Account'] nas = account.getNasNetworkStorage( diff --git a/SoftLayer/CLI/modules/rwhois.py b/SoftLayer/CLI/modules/rwhois.py index 975524d02..0cf43ea86 100644 --- a/SoftLayer/CLI/modules/rwhois.py +++ b/SoftLayer/CLI/modules/rwhois.py @@ -40,7 +40,7 @@ class RWhoisEdit(CLIRunnable): action = 'edit' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) update = { @@ -76,7 +76,7 @@ class RWhoisShow(CLIRunnable): action = 'show' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) result = mgr.get_rwhois() diff --git a/SoftLayer/CLI/modules/server.py b/SoftLayer/CLI/modules/server.py index a5168f6d9..116fc7fe2 100644 --- a/SoftLayer/CLI/modules/server.py +++ b/SoftLayer/CLI/modules/server.py @@ -64,7 +64,7 @@ class ListServers(CLIRunnable): action = 'list' @staticmethod - def execute(client, args, env): + def execute(client, args): manager = HardwareManager(client) tags = None @@ -121,7 +121,7 @@ class ServerDetails(CLIRunnable): action = 'detail' @staticmethod - def execute(client, args, env): + def execute(client, args): hardware = HardwareManager(client) t = KeyValueTable(['Name', 'Value']) @@ -206,7 +206,7 @@ class ServerReload(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): hardware = HardwareManager(client) hardware_id = resolve_id( hardware.resolve_ids, args.get(''), 'hardware') @@ -237,8 +237,8 @@ class CancelServer(CLIRunnable): action = 'cancel' options = ['confirm'] - @staticmethod - def execute(client, args, env): + @classmethod + def execute(cls, client, args): hw = HardwareManager(client) hw_id = resolve_id( hw.resolve_ids, args.get(''), 'hardware') @@ -246,7 +246,7 @@ def execute(client, args, env): comment = args.get('--comment') if not comment and not args['--really']: - comment = env.input("(Optional) Add a cancellation comment:") + comment = cls.env.input("(Optional) Add a cancellation comment:") reason = args.get('--reason') @@ -266,7 +266,7 @@ class ServerCancelReasons(CLIRunnable): action = 'cancel-reasons' @staticmethod - def execute(client, args, env): + def execute(client, args): t = Table(['Code', 'Reason']) t.align['Code'] = 'r' t.align['Reason'] = 'l' @@ -289,8 +289,8 @@ class ServerPowerOff(CLIRunnable): action = 'power-off' options = ['confirm'] - @staticmethod - def execute(client, args, env): + @classmethod + def execute(cls, client, args): hw = client['Hardware_Server'] mgr = HardwareManager(client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), @@ -315,8 +315,8 @@ class ServerReboot(CLIRunnable): action = 'reboot' options = ['confirm'] - @staticmethod - def execute(client, args, env): + @classmethod + def execute(cls, client, args): hw = client['Hardware_Server'] mgr = HardwareManager(client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), @@ -342,7 +342,7 @@ class ServerPowerOn(CLIRunnable): action = 'power-on' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): hw = client['Hardware_Server'] mgr = HardwareManager(client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), @@ -360,7 +360,7 @@ class ServerPowerCycle(CLIRunnable): options = ['confirm'] @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): hw = client['Hardware_Server'] mgr = HardwareManager(client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), @@ -387,7 +387,7 @@ class NicEditServer(CLIRunnable): action = 'nic-edit' @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): public = args['public'] mgr = HardwareManager(client) @@ -406,7 +406,7 @@ class ListChassisServer(CLIRunnable): action = 'list-chassis' @staticmethod - def execute(client, args, env): + def execute(client, args): t = Table(['Code', 'Chassis']) t.align['Code'] = 'r' t.align['Chassis'] = 'l' @@ -443,7 +443,7 @@ class ServerCreateOptions(CLIRunnable): 'controller'] @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): mgr = HardwareManager(client) t = KeyValueTable(['Name', 'Value']) @@ -732,7 +732,7 @@ class CreateServer(CLIRunnable): '--memory', '--os'] @classmethod - def execute(cls, client, args, env): + def execute(cls, client, args): update_with_template_args(args) mgr = HardwareManager(client) @@ -933,7 +933,7 @@ class EditServer(CLIRunnable): action = 'edit' @staticmethod - def execute(client, args, env): + def execute(client, args): data = {} if args['--userdata'] and args['--userfile']: diff --git a/SoftLayer/CLI/modules/sshkey.py b/SoftLayer/CLI/modules/sshkey.py index 1f8b36ccd..bd392c35b 100644 --- a/SoftLayer/CLI/modules/sshkey.py +++ b/SoftLayer/CLI/modules/sshkey.py @@ -42,7 +42,7 @@ class AddSshKey(CLIRunnable): action = 'add' @staticmethod - def execute(client, args, env): + def execute(client, args): if args.get('--key'): key = args['--key'] else: @@ -72,7 +72,7 @@ class RemoveSshKey(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = SshKeyManager(client) key_id = resolve_id(mgr.resolve_ids, @@ -95,7 +95,7 @@ class EditSshKey(CLIRunnable): action = 'edit' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = SshKeyManager(client) key_id = resolve_id(mgr.resolve_ids, @@ -124,7 +124,7 @@ class ListSshKey(CLIRunnable): action = 'list' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = SshKeyManager(client) keys = mgr.list_keys() @@ -150,7 +150,7 @@ class PrintSshKey(CLIRunnable): action = 'print' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = SshKeyManager(client) key_id = resolve_id(mgr.resolve_ids, diff --git a/SoftLayer/CLI/modules/ssl.py b/SoftLayer/CLI/modules/ssl.py index 8f2765f74..34c45866f 100755 --- a/SoftLayer/CLI/modules/ssl.py +++ b/SoftLayer/CLI/modules/ssl.py @@ -34,7 +34,7 @@ class ListCerts(CLIRunnable): action = 'list' @staticmethod - def execute(client, args, env): + def execute(client, args): manager = SSLManager(client) certificates = manager.list_certs(args['--status']) @@ -67,7 +67,7 @@ class AddCertificate(CLIRunnable): action = 'add' @staticmethod - def execute(client, args, env): + def execute(client, args): template = { 'intermediateCertificate': '', 'certificateSigningRequest': '', @@ -107,7 +107,7 @@ class EditCertificate(CLIRunnable): action = 'edit' @staticmethod - def execute(client, args, env): + def execute(client, args): template = {'id': args['']} if args['--crt']: template['certificate'] = open(args['--crt']).read() @@ -134,7 +134,7 @@ class RemoveCertificate(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): manager = SSLManager(client) if args['--really'] or no_going_back('yes'): manager.remove_certificate(args['']) @@ -150,7 +150,7 @@ class DownloadCertificate(CLIRunnable): action = 'download' @staticmethod - def execute(client, args, env): + def execute(client, args): def write_cert(filename, content): try: fo = open(filename, 'w') diff --git a/SoftLayer/CLI/modules/subnet.py b/SoftLayer/CLI/modules/subnet.py index 2d234fccf..06c3ab318 100644 --- a/SoftLayer/CLI/modules/subnet.py +++ b/SoftLayer/CLI/modules/subnet.py @@ -30,7 +30,7 @@ class SubnetCancel(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) subnet_id = mgr.resolve_subnet_ids(args.get('')) @@ -67,7 +67,7 @@ class SubnetCreate(CLIRunnable): options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) _type = 'private' @@ -123,7 +123,7 @@ class SubnetDetail(CLIRunnable): action = 'detail' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) subnet_id = mgr.resolve_subnet_ids(args.get('')) @@ -190,7 +190,7 @@ class SubnetList(CLIRunnable): action = 'list' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) t = Table([ @@ -238,7 +238,7 @@ class SubnetLookup(CLIRunnable): action = 'lookup' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) ip = mgr.ip_lookup(args['']) diff --git a/SoftLayer/CLI/modules/summary.py b/SoftLayer/CLI/modules/summary.py index b530d1cfc..6df27b7c6 100644 --- a/SoftLayer/CLI/modules/summary.py +++ b/SoftLayer/CLI/modules/summary.py @@ -23,7 +23,7 @@ class Summary(CLIRunnable): action = None @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) datacenters = mgr.summary_by_datacenter() diff --git a/SoftLayer/CLI/modules/vlan.py b/SoftLayer/CLI/modules/vlan.py index 41670fe2c..0578a8ab3 100644 --- a/SoftLayer/CLI/modules/vlan.py +++ b/SoftLayer/CLI/modules/vlan.py @@ -27,7 +27,7 @@ class VlanDetail(CLIRunnable): action = 'detail' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) vlan = mgr.get_vlan(args.get('')) @@ -105,7 +105,7 @@ class VlanList(CLIRunnable): action = 'list' @staticmethod - def execute(client, args, env): + def execute(client, args): mgr = NetworkManager(client) t = Table([ diff --git a/SoftLayer/tests/CLI/core_tests.py b/SoftLayer/tests/CLI/core_tests.py index 93d34a149..93995ab02 100644 --- a/SoftLayer/tests/CLI/core_tests.py +++ b/SoftLayer/tests/CLI/core_tests.py @@ -38,7 +38,7 @@ class submodule_fixture(object): options = [] @staticmethod - def execute(client, args, env): + def execute(client, args): return "test" @@ -113,15 +113,6 @@ def test_module_with_no_command(self): command, command_args = resolver.parse(['cci', 'list']) self.assertEqual(submodule_fixture, command) - def test_main(self): - self.env.plugins = { - 'cci': {'list': submodule_fixture} - } - self.assertRaises( - SystemExit, cli.core.main, - args=['cci', 'list'], - env=self.env) - def test_help(self): self.env.get_module_name.return_value = 'help' self.assertRaises( diff --git a/SoftLayer/tests/CLI/modules/bmc_tests.py b/SoftLayer/tests/CLI/modules/bmc_tests.py index 1ae25cb12..fdae9f14f 100644 --- a/SoftLayer/tests/CLI/modules/bmc_tests.py +++ b/SoftLayer/tests/CLI/modules/bmc_tests.py @@ -33,7 +33,7 @@ def test_BMCCreateOptions(self): } client = self._setup_package_mocks(self.client) - output = bmc.BMCCreateOptions.execute(client, args, MagicMock()) + output = bmc.BMCCreateOptions.execute(client, args) expected = { 'datacenter': ['RANDOM_LOCATION'], @@ -72,7 +72,7 @@ def test_BMCCreateOptions_with_cpu_only(self): client = self._setup_package_mocks(self.client) - output = bmc.BMCCreateOptions.execute(client, args, MagicMock()) + output = bmc.BMCCreateOptions.execute(client, args) expected = { 'memory/cpu': [ @@ -124,7 +124,7 @@ def test_CreateBMCInstance(self): } ] } - output = bmc.CreateBMCInstance.execute(client, args, MagicMock()) + output = bmc.CreateBMCInstance.execute(client, args) expected = """:...................:......: : Item : cost : @@ -140,7 +140,7 @@ def test_CreateBMCInstance(self): args['--hourly'] = False args['--monthly'] = True - output = bmc.CreateBMCInstance.execute(client, args, MagicMock()) + output = bmc.CreateBMCInstance.execute(client, args) expected = """:....................:.......: : Item : cost : @@ -156,7 +156,7 @@ def test_CreateBMCInstance(self): # Make sure we can order without specifying the disk as well args['--disk'] = [] - output = bmc.CreateBMCInstance.execute(client, args, MagicMock()) + output = bmc.CreateBMCInstance.execute(client, args) self.assertEqual(expected, format_output(output, 'table')) @@ -165,14 +165,14 @@ def test_CreateBMCInstance(self): args['--disk'] = '1000_DRIVE,1000_DRIVE' args['--key'] = '123,456' - output = bmc.CreateBMCInstance.execute(client, args, MagicMock()) + output = bmc.CreateBMCInstance.execute(client, args) self.assertEqual(expected, format_output(output, 'table')) # Test explicitly setting a RAID configuration args['--controller'] = 'RAID0' - output = bmc.CreateBMCInstance.execute(client, args, MagicMock()) + output = bmc.CreateBMCInstance.execute(client, args) self.assertEqual(expected, format_output(output, 'table')) @@ -186,8 +186,7 @@ def test_CreateBMCInstance(self): args['--test'] = False args['--really'] = True - output = bmc.CreateBMCInstance.execute( - self.client, args, MagicMock()) + output = bmc.CreateBMCInstance.execute(self.client, args) expected = {'id': 98765, 'created': '2013-08-02 15:23:47'} self.assertEqual(expected, format_output(output, 'python')) @@ -199,8 +198,7 @@ def test_CreateBMCInstance(self): args['--really'] = False self.assertRaises(CLIAbort, - bmc.CreateBMCInstance.execute, - self.client, args, MagicMock()) + bmc.CreateBMCInstance.execute, self.client, args) def test_CreateBMCInstance_failures(self): client = self._setup_package_mocks(self.client) @@ -224,51 +222,44 @@ def test_CreateBMCInstance_failures(self): # Verify that ArgumentError is properly raised on error self.assertRaises(ArgumentError, - bmc.CreateBMCInstance.execute, - client, args, MagicMock()) + bmc.CreateBMCInstance.execute, client, args) # Sending strange values for hourly and monthly args['--hostname'] = 'bmc-test' self.assertRaises(ArgumentError, - bmc.CreateBMCInstance.execute, - client, args, MagicMock()) + bmc.CreateBMCInstance.execute, client, args) # Send both hourly and monthly args['--hourly'] = True args['--monthly'] = True self.assertRaises(ArgumentError, - bmc.CreateBMCInstance.execute, - client, args, MagicMock()) + bmc.CreateBMCInstance.execute, client, args) # Send neither hourly nor monthly args['--hourly'] = False args['--monthly'] = False self.assertRaises(ArgumentError, - bmc.CreateBMCInstance.execute, - client, args, MagicMock()) + bmc.CreateBMCInstance.execute, client, args) # This is missing a server_core combo args['--monthly'] = True args['--cpu'] = 100 self.assertRaises(CLIAbort, - bmc.CreateBMCInstance.execute, - client, args, MagicMock()) + bmc.CreateBMCInstance.execute, client, args) # This section is missing an OS code args['--cpu'] = '2' args['--os'] = 'nope' self.assertRaises(CLIAbort, - bmc.CreateBMCInstance.execute, - client, args, MagicMock()) + bmc.CreateBMCInstance.execute, client, args) # This section is missing a NIC speed args['--os'] = 'UBUNTU_12_64_MINIMAL' args['--network'] = 'nope' self.assertRaises(CLIAbort, - bmc.CreateBMCInstance.execute, - client, args, MagicMock()) + bmc.CreateBMCInstance.execute, client, args) @patch('SoftLayer.CLI.modules.bmc.CLIAbort') @patch('SoftLayer.CLI.modules.bmc.no_going_back') @@ -282,14 +273,14 @@ def test_CancelInstance( # Check the positive case args = {'--really': True, '--immediate': False} - bmc.CancelInstance.execute(self.client, args, MagicMock()) + bmc.CancelInstance.execute(self.client, args) cancel_mock.assert_called_with(hw_id, False) # Now check to make sure we properly call CLIAbort in the negative case args['--really'] = False - bmc.CancelInstance.execute(self.client, args, MagicMock()) + bmc.CancelInstance.execute(self.client, args) abort_mock.assert_called() def test_get_default_value_returns_none_for_unknown_category(self): diff --git a/SoftLayer/tests/CLI/modules/server_tests.py b/SoftLayer/tests/CLI/modules/server_tests.py index bbb095f8e..57cd00f8f 100644 --- a/SoftLayer/tests/CLI/modules/server_tests.py +++ b/SoftLayer/tests/CLI/modules/server_tests.py @@ -28,8 +28,7 @@ def setUp(self): self.client = MagicMock() def test_ServerCancelReasons(self): - output = server.ServerCancelReasons.execute( - self.client, {}, MagicMock()) + output = server.ServerCancelReasons.execute(self.client, {}) expected = [ {'Code': 'datacenter', @@ -70,7 +69,7 @@ def test_ServerCreateOptions(self): client = self._setup_package_mocks(self.client) - output = server.ServerCreateOptions.execute(client, args, MagicMock()) + output = server.ServerCreateOptions.execute(client, args) expected = { 'datacenter': ['RANDOM_LOCATION'], @@ -110,7 +109,7 @@ def test_ServerCreateOptions_with_cpu_only(self): client = self._setup_package_mocks(self.client) - output = server.ServerCreateOptions.execute(client, args, MagicMock()) + output = server.ServerCreateOptions.execute(client, args) expected = { 'cpu': [ @@ -134,7 +133,7 @@ def test_ServerDetails(self): service.getReverseDomainRecords = dns_mock args = {'': hw_id, '--passwords': True, '--price': True} - output = server.ServerDetails.execute(client, args, MagicMock()) + output = server.ServerDetails.execute(client, args) expected = { 'status': 'ACTIVE', @@ -162,7 +161,7 @@ def test_ListServers(self): self.client['Account'].getHardware = account_mock.getHardware_Mock() output = server.ListServers.execute( - self.client, {'--tags': 'openstack'}, MagicMock()) + self.client, {'--tags': 'openstack'}) expected = [ { @@ -201,14 +200,14 @@ def test_ServerReload( # Check the positive case args = {'--really': True, '--postinstall': None, '--key': [12345]} - server.ServerReload.execute(self.client, args, MagicMock()) + server.ServerReload.execute(self.client, args) reload_mock.assert_called_with(hw_id, args['--postinstall'], [12345]) # Now check to make sure we properly call CLIAbort in the negative case args['--really'] = False - server.ServerReload.execute(self.client, args, MagicMock()) + server.ServerReload.execute(self.client, args) abort_mock.assert_called() @patch('SoftLayer.CLI.modules.server.CLIAbort') @@ -223,7 +222,7 @@ def test_CancelServer( # Check the positive case args = {'--really': True, '--reason': 'Test'} - server.CancelServer.execute(self.client, args, MagicMock()) + server.CancelServer.execute(self.client, args) cancel_mock.assert_called_with(hw_id, args['--reason'], None) @@ -236,7 +235,7 @@ def test_CancelServer( args['--really'] = False - server.CancelServer.execute(self.client, args, MagicMock()) + server.CancelServer.execute(self.client, args) abort_mock.assert_called() env_mock.assert_called() @@ -247,7 +246,7 @@ def test_ServerPowerOff(self, confirm_mock): # Check the positive case args = {'--really': True, '': '12345'} - server.ServerPowerOff.execute(self.client, args, MagicMock()) + server.ServerPowerOff.execute(self.client, args) self.client['Hardware_Server'].powerOff.assert_called_with(id=hw_id) @@ -255,8 +254,7 @@ def test_ServerPowerOff(self, confirm_mock): confirm_mock.return_value = False args['--really'] = False self.assertRaises(CLIAbort, - server.ServerPowerOff.execute, - self.client, args, MagicMock()) + server.ServerPowerOff.execute, self.client, args) @patch('SoftLayer.CLI.modules.server.confirm') def test_ServerReboot(self, confirm_mock): @@ -270,26 +268,25 @@ def test_ServerReboot(self, confirm_mock): '--soft': False, } - server.ServerReboot.execute(self.client, args, MagicMock()) + server.ServerReboot.execute(self.client, args) self.client['Hardware_Server'].rebootDefault.assert_called_with( id=hw_id) args['--soft'] = True args['--hard'] = False - server.ServerReboot.execute(self.client, args, MagicMock()) + server.ServerReboot.execute(self.client, args) self.client['Hardware_Server'].rebootSoft.assert_called_with(id=hw_id) args['--soft'] = False args['--hard'] = True - server.ServerReboot.execute(self.client, args, MagicMock()) + server.ServerReboot.execute(self.client, args) self.client['Hardware_Server'].rebootHard.assert_called_with(id=hw_id) # Now check to make sure we properly call CLIAbort in the negative case confirm_mock.return_value = False args['--really'] = False self.assertRaises(CLIAbort, - server.ServerReboot.execute, - self.client, args, MagicMock()) + server.ServerReboot.execute, self.client, args) def test_ServerPowerOn(self): hw_id = 12345 @@ -299,7 +296,7 @@ def test_ServerPowerOn(self): '': '12345', } - server.ServerPowerOn.execute(self.client, args, MagicMock()) + server.ServerPowerOn.execute(self.client, args) self.client['Hardware_Server'].powerOn.assert_called_with(id=hw_id) @patch('SoftLayer.CLI.modules.server.confirm') @@ -312,15 +309,14 @@ def test_ServerPowerCycle(self, confirm_mock): '--really': True, } - server.ServerPowerCycle.execute(self.client, args, MagicMock()) + server.ServerPowerCycle.execute(self.client, args) self.client['Hardware_Server'].powerCycle.assert_called_with(id=hw_id) # Now check to make sure we properly call CLIAbort in the negative case confirm_mock.return_value = False args['--really'] = False self.assertRaises(CLIAbort, - server.ServerPowerCycle.execute, - self.client, args, MagicMock()) + server.ServerPowerCycle.execute, self.client, args) @patch('SoftLayer.HardwareManager.change_port_speed') @patch('SoftLayer.CLI.modules.server.resolve_id') @@ -339,12 +335,11 @@ def test_NicEditServer(self, resolve_mock, port_mock): port_mock.side_effect = [True, False] # First call simulates a success - server.NicEditServer.execute(self.client, args, MagicMock()) + server.NicEditServer.execute(self.client, args) port_mock.assert_called_with(hw_id, False, 100) # Second call simulates an error - self.assertFalse( - server.NicEditServer.execute(self.client, args, MagicMock())) + self.assertFalse(server.NicEditServer.execute(self.client, args)) @patch('SoftLayer.HardwareManager.get_available_dedicated_server_packages') def test_ListChassisServer(self, packages): @@ -354,7 +349,7 @@ def test_ListChassisServer(self, packages): ] packages.return_value = test_data - output = server.ListChassisServer.execute(self.client, {}, MagicMock()) + output = server.ListChassisServer.execute(self.client, {}) expected = [ {'Chassis': 'Chassis 1', 'Code': 1}, @@ -401,7 +396,7 @@ def test_CreateServer(self): } ] } - output = server.CreateServer.execute(client, args, MagicMock()) + output = server.CreateServer.execute(client, args) expected = [ [ @@ -417,7 +412,7 @@ def test_CreateServer(self): # Make sure we can order without specifying the disk as well args['--disk'] = [] - output = server.CreateServer.execute(client, args, MagicMock()) + output = server.CreateServer.execute(client, args) self.assertEqual(expected, format_output(output, 'python')) @@ -426,14 +421,14 @@ def test_CreateServer(self): args['--disk'] = '1000_DRIVE,1000_DRIVE' args['--key'] = '123,456' - output = server.CreateServer.execute(client, args, MagicMock()) + output = server.CreateServer.execute(client, args) self.assertEqual(expected, format_output(output, 'python')) # Test explicitly setting a RAID configuration args['--controller'] = 'RAID0' - output = server.CreateServer.execute(client, args, MagicMock()) + output = server.CreateServer.execute(client, args) self.assertEqual(expected, format_output(output, 'python')) @@ -447,8 +442,7 @@ def test_CreateServer(self): args['--test'] = False args['--really'] = True - output = server.CreateServer.execute( - self.client, args, MagicMock()) + output = server.CreateServer.execute(self.client, args) expected = {'id': 98765, 'created': '2013-08-02 15:23:47'} self.assertEqual(expected, format_output(output, 'python')) @@ -460,8 +454,7 @@ def test_CreateServer(self): args['--really'] = False self.assertRaises(CLIAbort, - server.CreateServer.execute, - self.client, args, MagicMock()) + server.CreateServer.execute, self.client, args) def test_CreateServer_failures(self): client = self._setup_package_mocks(self.client) @@ -483,8 +476,7 @@ def test_CreateServer_failures(self): # Verify that ArgumentError is properly raised on error self.assertRaises(ArgumentError, - server.CreateServer.execute, - client, args, MagicMock()) + server.CreateServer.execute, client, args) # This contains an invalid network argument args['--chassis'] = 999 @@ -492,8 +484,7 @@ def test_CreateServer_failures(self): # Verify that CLIAbort is properly raised on error self.assertRaises(CLIAbort, - server.CreateServer.execute, - client, args, MagicMock()) + server.CreateServer.execute, client, args) # This contains an invalid operating system argument args['--network'] = '100' @@ -501,8 +492,7 @@ def test_CreateServer_failures(self): # Verify that CLIAbort is properly raised on error self.assertRaises(CLIAbort, - server.CreateServer.execute, - client, args, MagicMock()) + server.CreateServer.execute, client, args) @patch('SoftLayer.CLI.modules.server.export_to_template') def test_CreateServer_with_export(self, export_to_template): @@ -528,7 +518,7 @@ def test_CreateServer_with_export(self, export_to_template): expected = args.copy() del(expected['--export']) - server.CreateServer.execute(client, args, MagicMock()) + server.CreateServer.execute(client, args) export_to_template.assert_called_with('test_file.txt', expected, exclude=['--wait', '--test']) @@ -544,8 +534,7 @@ def test_EditServer(self): } self.assertRaises(ArgumentError, - server.EditServer.execute, - self.client, args, MagicMock()) + server.EditServer.execute, self.client, args) # Simulate a missing file error args['--userdata'] = None @@ -554,8 +543,7 @@ def test_EditServer(self): exists.return_value = False self.assertRaises(ArgumentError, - server.EditServer.execute, - self.client, args, MagicMock()) + server.EditServer.execute, self.client, args) # Test a successful edit with user data args['--userdata'] = 'My data' @@ -570,7 +558,7 @@ def test_EditServer(self): with patch('SoftLayer.HardwareManager.edit') as edit_mock: edit_mock.return_value = True - server.EditServer.execute(self.client, args, MagicMock()) + server.EditServer.execute(self.client, args) edit_mock.assert_called_with(1000, **expected) @@ -578,8 +566,7 @@ def test_EditServer(self): edit_mock.return_value = False self.assertRaises(CLIAbort, - server.EditServer.execute, - self.client, args, MagicMock()) + server.EditServer.execute, self.client, args) # Test a successful edit with a user file args['--userdata'] = None @@ -602,7 +589,7 @@ def test_EditServer(self): edit_mock.return_value = True expected['userdata'] = 'some data' - server.EditServer.execute(self.client, args, MagicMock()) + server.EditServer.execute(self.client, args) edit_mock.assert_called_with(1000, **expected) diff --git a/docs/dev/cli.rst b/docs/dev/cli.rst index 6795042c3..27b7fd84a 100644 --- a/docs/dev/cli.rst +++ b/docs/dev/cli.rst @@ -55,17 +55,17 @@ Actions are implemented using classes in the module that subclass `SoftLayer.CLI pass @staticmethod - def execute(client, args, env): + def execute(client, args): pass The required interfaces are: * The docblock (__doc__) for docopt * action class attribute -* def execute(client, args, env) +* def execute(client, args) - Don't forget the @staticmethod annotation! - - you can also use @classmethod and use execute(cls, client, args, env) if you plan on dispatching instead of executing a simple task. + - you can also use @classmethod and use execute(cls, client, args) if you plan on dispatching instead of executing a simple task. A minimal implementation for `sl example print` would look like this: :: @@ -80,7 +80,7 @@ A minimal implementation for `sl example print` would look like this: action = 'print' @staticmethod - def execute(client, args, env): + def execute(client, args): print "EXAMPLE!" @@ -115,7 +115,7 @@ The `execute()` method is expected to return either `None` or an instance of `So action = 'pretty' @staticmethod - def execute(client, args, env): + def execute(client, args): # create a table with two columns: col1, col2 t = Table(['col1', 'col2']) @@ -169,7 +169,7 @@ Refer to docopt for more complete documentation action = 'parse' @staticmethod - def execute(client, args, env): + def execute(client, args): if args.get('--test'): print "Just testing, move along..." else: @@ -213,7 +213,7 @@ All confirmations should be easily bypassed by checking for `args['--really']`. options = ['confirm'] # confirm adds the '-y|--really' options and help @staticmethod - def execute(client, args, env): + def execute(client, args): pass There are two primary confirmation prompts that both leverage `SoftLayer.CLI.valid_response`: diff --git a/docs/dev/example_module.rst b/docs/dev/example_module.rst index 5728f7a0b..9b3209da4 100644 --- a/docs/dev/example_module.rst +++ b/docs/dev/example_module.rst @@ -32,7 +32,7 @@ Example CLI Module action = 'print' @staticmethod - def execute(client, args, env): + def execute(client, args): print "EXAMPLE!" @@ -46,7 +46,7 @@ Example CLI Module action = 'pretty' @staticmethod - def execute(client, args, env): + def execute(client, args): # create a table with two columns: col1, col2 t = Table(['col1', 'col2']) @@ -78,7 +78,7 @@ Example CLI Module options = ['confirm'] @staticmethod - def execute(client, args, env): + def execute(client, args): if args.get('--test'): print "Just testing, move along..." else: diff --git a/example.py b/example.py new file mode 100644 index 000000000..880ad1fa6 --- /dev/null +++ b/example.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" + example + ~~~~~~~ + This is an example of using the SoftLayer API Python Client. + + For more examples and documentation, refer to: + https://softlayer-api-python-client.readthedocs.org + + :copyright: (c) 2013, SoftLayer Technologies, Inc. All rights reserved. + :license: MIT, see LICENSE for more details. +""" +# The SoftLayer API client package is here: +import SoftLayer +import pprint + +# Usage: +# SoftLayer.Client(username=[Username], api_key=[API key]) +# +# Username: Your SoftLayer API username. +# API key: Your SoftLayer API key, +username = 'SET ME' +api_key = 'SET ME' + +client = SoftLayer.Client(username=username, api_key=api_key) + +# Once your client object is created you can call API methods for that service +# directly against your client object. Each call may throw an raise a +# SoftLayerError exception. +# +# This example calls the getObject() method in the SoftLayer_Account API +# service. +# It retrieves basic account information, and is a great way to test your API +# account and connectivity. +pprint.pprint(client['Account'].getObject()) + +# For a more complex example we’ll retrieve a support ticket with id 123456 +# along with the ticket’s updates, the user it’s assigned to, the servers +# attached to it, and the datacenter those servers are in. We’ll retrieve our +# extra information using a nested object mask. After we have the ticket we’ll +# update it with the text ‘Hello!’. + +# Retrieve the ticket record. +ticket = client['Ticket'].getObject( + id=123456, mask='updates,assignedUser,attachedHardware.datacenter') +pprint.pprint(ticket) + +# Now update the ticket. +update = client['Ticket'].addUpdate(id=123456, {'entry': 'Hello!'}) +pprint.pprint(update) From fe8d94931d119463a68e6f6562402cc0e29726b5 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Tue, 5 Nov 2013 15:28:44 -0600 Subject: [PATCH 10/47] Fixes exception super() call. Deletes Example.py --- SoftLayer/CLI/exceptions.py | 2 +- example.py | 51 ------------------------------------- 2 files changed, 1 insertion(+), 52 deletions(-) delete mode 100644 example.py diff --git a/SoftLayer/CLI/exceptions.py b/SoftLayer/CLI/exceptions.py index 510f9859c..104ae90f3 100644 --- a/SoftLayer/CLI/exceptions.py +++ b/SoftLayer/CLI/exceptions.py @@ -22,5 +22,5 @@ def __init__(self, msg, *args): class ArgumentError(CLIAbort): def __init__(self, msg, *args): - super(CLIAbort, self).__init__(code=2, *args) + super(ArgumentError, self).__init__(msg, *args) self.message = "Argument Error: %s" % msg diff --git a/example.py b/example.py deleted file mode 100644 index 880ad1fa6..000000000 --- a/example.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" - example - ~~~~~~~ - This is an example of using the SoftLayer API Python Client. - - For more examples and documentation, refer to: - https://softlayer-api-python-client.readthedocs.org - - :copyright: (c) 2013, SoftLayer Technologies, Inc. All rights reserved. - :license: MIT, see LICENSE for more details. -""" -# The SoftLayer API client package is here: -import SoftLayer -import pprint - -# Usage: -# SoftLayer.Client(username=[Username], api_key=[API key]) -# -# Username: Your SoftLayer API username. -# API key: Your SoftLayer API key, -username = 'SET ME' -api_key = 'SET ME' - -client = SoftLayer.Client(username=username, api_key=api_key) - -# Once your client object is created you can call API methods for that service -# directly against your client object. Each call may throw an raise a -# SoftLayerError exception. -# -# This example calls the getObject() method in the SoftLayer_Account API -# service. -# It retrieves basic account information, and is a great way to test your API -# account and connectivity. -pprint.pprint(client['Account'].getObject()) - -# For a more complex example we’ll retrieve a support ticket with id 123456 -# along with the ticket’s updates, the user it’s assigned to, the servers -# attached to it, and the datacenter those servers are in. We’ll retrieve our -# extra information using a nested object mask. After we have the ticket we’ll -# update it with the text ‘Hello!’. - -# Retrieve the ticket record. -ticket = client['Ticket'].getObject( - id=123456, mask='updates,assignedUser,attachedHardware.datacenter') -pprint.pprint(ticket) - -# Now update the ticket. -update = client['Ticket'].addUpdate(id=123456, {'entry': 'Hello!'}) -pprint.pprint(update) From 9018eb214ada72da88e239392b35d5db076dc32f Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Tue, 5 Nov 2013 15:32:25 -0600 Subject: [PATCH 11/47] removes invalid reference to default TTL --- SoftLayer/CLI/modules/dns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/CLI/modules/dns.py b/SoftLayer/CLI/modules/dns.py index d8a2e852d..c0f899f6e 100755 --- a/SoftLayer/CLI/modules/dns.py +++ b/SoftLayer/CLI/modules/dns.py @@ -188,7 +188,7 @@ def execute(client, args): manager = DNSManager(client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') - args['--ttl'] = args['--ttl'] or DNSManager.DEFAULT_TTL + args['--ttl'] = args['--ttl'] or 7200 manager.create_record( zone_id, From e374bf0d2c8a3716d9859b7d70591c94cdc8c067 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Tue, 5 Nov 2013 16:15:03 -0600 Subject: [PATCH 12/47] Small Code Smell Fixes --- SoftLayer/transports.py | 4 ++-- SoftLayer/utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SoftLayer/transports.py b/SoftLayer/transports.py index 7d0854d19..a162b0b2e 100644 --- a/SoftLayer/transports.py +++ b/SoftLayer/transports.py @@ -36,7 +36,7 @@ def make_xml_rpc_api_call(uri, method, args=None, headers=None, payload = xmlrpclib.dumps(tuple(largs), methodname=method, allow_none=True) - log.info('POST %s' % (uri)) + log.info('POST %s', uri) log.debug(payload) response = requests.post(uri, data=payload, headers=http_headers, @@ -76,7 +76,7 @@ def make_rest_api_call(method, url, http_headers=None, timeout=None): :param dict http_headers: HTTP headers to use for the request :param int timeout: number of seconds to use as a timeout """ - log.info('%s %s' % (method, url)) + log.info('%s %s', method, url) try: resp = requests.request( method, url, headers=http_headers, timeout=timeout) diff --git a/SoftLayer/utils.py b/SoftLayer/utils.py index ac1e94a88..beacc0a95 100644 --- a/SoftLayer/utils.py +++ b/SoftLayer/utils.py @@ -77,7 +77,7 @@ def query_filter(query): return {'operation': query} -class IdentifierMixin: +class IdentifierMixin(object): """ This mixin provides an interface to provide multiple methods for converting an 'indentifier' to an id """ resolvers = [] From d48fa0583193356838826feea0933c61d1b7cef5 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Wed, 6 Nov 2013 15:03:50 -0600 Subject: [PATCH 13/47] CLI: Removes Metaclass Shinanigans for module loading --- SoftLayer/CLI/core.py | 4 +--- SoftLayer/CLI/environment.py | 27 +++++++++++------------- SoftLayer/tests/CLI/environment_tests.py | 8 +++++++ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/SoftLayer/CLI/core.py b/SoftLayer/CLI/core.py index 00ff7cb5f..186d5efa3 100644 --- a/SoftLayer/CLI/core.py +++ b/SoftLayer/CLI/core.py @@ -51,8 +51,7 @@ from SoftLayer import Client, TimedClient, SoftLayerError, SoftLayerAPIError from SoftLayer.consts import VERSION from helpers import CLIAbort, ArgumentError, format_output, KeyValueTable -from environment import ( - Environment, CLIRunnableType, InvalidCommand, InvalidModule) +from environment import Environment, InvalidCommand, InvalidModule DEBUG_LOGGING_MAP = { @@ -154,7 +153,6 @@ def main(args=sys.argv[1:], env=Environment()): Entry point for the command-line client. """ # Parse Top-Level Arguments - CLIRunnableType.env = env exit_status = 0 resolver = CommandParser(env) try: diff --git a/SoftLayer/CLI/environment.py b/SoftLayer/CLI/environment.py index 3da51f654..a35f461b1 100644 --- a/SoftLayer/CLI/environment.py +++ b/SoftLayer/CLI/environment.py @@ -6,11 +6,12 @@ :copyright: (c) 2013, SoftLayer Technologies, Inc. All rights reserved. :license: MIT, see LICENSE for more details. """ -import sys import getpass from importlib import import_module +import inspect import os import os.path +import sys from SoftLayer.CLI.modules import get_module_list from SoftLayer import SoftLayerError @@ -62,7 +63,12 @@ def get_module_name(self, module_name): def load_module(self, module_name): # pragma: no cover try: - return import_module('SoftLayer.CLI.modules.%s' % module_name) + module = import_module('SoftLayer.CLI.modules.%s' % module_name) + for name, obj in inspect.getmembers(module): + if inspect.isclass(obj) and issubclass(obj, CLIRunnable): + obj.env = self + self.add_plugin(obj) + return module except ImportError: raise InvalidModule(module_name) @@ -95,20 +101,11 @@ def exit(self, code=0): sys.exit(code) -class CLIRunnableType(type): - - env = Environment() - - def __init__(cls, name, bases, attrs): - super(CLIRunnableType, cls).__init__(name, bases, attrs) - if cls.env and name != 'CLIRunnable': - cls.env.add_plugin(cls) - - class CLIRunnable(object): - __metaclass__ = CLIRunnableType - options = [] - action = None + options = [] # set by subclass + action = None # set by subclass + + env = None # gets set later by Environment.load_module() @staticmethod def add_additional_args(parser): diff --git a/SoftLayer/tests/CLI/environment_tests.py b/SoftLayer/tests/CLI/environment_tests.py index 27a05ed33..9d50c26a4 100644 --- a/SoftLayer/tests/CLI/environment_tests.py +++ b/SoftLayer/tests/CLI/environment_tests.py @@ -28,6 +28,14 @@ def test_plugin_list(self): self.assertIn('cci', actions) self.assertIn('dns', actions) + def test_add_plugin(self): + m = MagicMock() + m.action = 'add_plugin_action_test' + self.env.add_plugin(m) + + self.assertEqual(self.env.plugins, + {'mock': {'add_plugin_action_test': m}}) + def test_out(self): self.env.stdout = MagicMock() self.env.out('TEXT OUTPUT') From c13d22137f592939adc79b72a822ed93de9796c2 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Wed, 6 Nov 2013 15:25:12 -0600 Subject: [PATCH 14/47] Fixes Code Smells Removes assignment of unused variables Removes static/class methods from CLIRunnables Avoids directly setting built-in copyright variable --- SoftLayer/CLI/core.py | 23 ++- SoftLayer/CLI/environment.py | 14 +- SoftLayer/CLI/modules/bmc.py | 75 ++++----- SoftLayer/CLI/modules/cci.py | 113 ++++++-------- SoftLayer/CLI/modules/config.py | 21 ++- SoftLayer/CLI/modules/dns.py | 49 +++--- SoftLayer/CLI/modules/firewall.py | 5 +- SoftLayer/CLI/modules/globalip.py | 43 +++--- SoftLayer/CLI/modules/help.py | 7 +- SoftLayer/CLI/modules/image.py | 9 +- SoftLayer/CLI/modules/iscsi.py | 5 +- SoftLayer/CLI/modules/messaging.py | 85 ++++------ SoftLayer/CLI/modules/metadata.py | 39 ++--- SoftLayer/CLI/modules/nas.py | 5 +- SoftLayer/CLI/modules/rwhois.py | 10 +- SoftLayer/CLI/modules/server.py | 162 +++++++++----------- SoftLayer/CLI/modules/sshkey.py | 25 ++- SoftLayer/CLI/modules/ssl.py | 25 ++- SoftLayer/CLI/modules/subnet.py | 27 ++-- SoftLayer/CLI/modules/summary.py | 5 +- SoftLayer/CLI/modules/vlan.py | 10 +- SoftLayer/config.py | 2 +- SoftLayer/managers/cci.py | 39 ++--- SoftLayer/managers/dns.py | 28 ++-- SoftLayer/managers/hardware.py | 37 +++-- SoftLayer/managers/messaging.py | 21 +-- SoftLayer/managers/metadata.py | 1 + SoftLayer/managers/network.py | 49 +++--- SoftLayer/managers/sshkey.py | 18 +-- SoftLayer/managers/ssl.py | 12 +- SoftLayer/tests/CLI/core_tests.py | 19 ++- SoftLayer/tests/CLI/helper_tests.py | 5 +- SoftLayer/tests/CLI/modules/bmc_tests.py | 64 ++++---- SoftLayer/tests/CLI/modules/server_tests.py | 107 +++++++------ SoftLayer/tests/managers/cci_tests.py | 4 +- SoftLayer/tests/managers/dns_tests.py | 4 +- SoftLayer/tests/managers/hardware_tests.py | 4 +- SoftLayer/tests/managers/network_tests.py | 10 +- SoftLayer/tests/managers/sshkey_tests.py | 2 +- docs/conf.py | 4 +- 40 files changed, 536 insertions(+), 651 deletions(-) diff --git a/SoftLayer/CLI/core.py b/SoftLayer/CLI/core.py index 186d5efa3..eb9ee50fe 100644 --- a/SoftLayer/CLI/core.py +++ b/SoftLayer/CLI/core.py @@ -120,8 +120,7 @@ def parse_module_args(self, module_name, args): version=VERSION, argv=[module_name] + args, options_first=True) - module = self.env.load_module(module_name) - return module, arguments + return arguments def parse_command_args(self, module_name, command_name, args): command = self.env.get_command(module_name, command_name) @@ -135,8 +134,7 @@ def parse(self, args): module_name = main_args[''] # handle `sl ...` - module, module_args = self.parse_module_args( - module_name, main_args['']) + module_args = self.parse_module_args(module_name, main_args['']) # get the command argument command_name = module_args.get('') @@ -172,24 +170,25 @@ def main(args=sys.argv[1:], env=Environment()): client = Client(config_file=command_args.get('--config')) # Do the thing - data = command.execute(client, command_args) + runnable = command(client=client, env=env) + data = runnable.execute(command_args) if data: - format = command_args.get('--format', 'table') - if format not in VALID_FORMATS: - raise ArgumentError('Invalid format "%s"' % format) - s = format_output(data, fmt=format) + out_format = command_args.get('--format', 'table') + if out_format not in VALID_FORMATS: + raise ArgumentError('Invalid format "%s"' % out_format) + s = format_output(data, fmt=out_format) if s: env.out(s) if command_args.get('--timings'): - format = command_args.get('--format', 'table') + out_format = command_args.get('--format', 'table') api_calls = client.get_last_calls() t = KeyValueTable(['call', 'time']) - for call, initiated, duration in api_calls: + for call, _, duration in api_calls: t.add_row([call, duration]) - env.err(format_output(t, fmt=format)) + env.err(format_output(t, fmt=out_format)) except InvalidCommand as e: env.err(resolver.get_module_help(e.module_name)) diff --git a/SoftLayer/CLI/environment.py b/SoftLayer/CLI/environment.py index a35f461b1..b16877ab4 100644 --- a/SoftLayer/CLI/environment.py +++ b/SoftLayer/CLI/environment.py @@ -64,9 +64,8 @@ def get_module_name(self, module_name): def load_module(self, module_name): # pragma: no cover try: module = import_module('SoftLayer.CLI.modules.%s' % module_name) - for name, obj in inspect.getmembers(module): + for _, obj in inspect.getmembers(module): if inspect.isclass(obj) and issubclass(obj, CLIRunnable): - obj.env = self self.add_plugin(obj) return module except ImportError: @@ -105,12 +104,9 @@ class CLIRunnable(object): options = [] # set by subclass action = None # set by subclass - env = None # gets set later by Environment.load_module() + def __init__(self, client=None, env=None): + self.client = client + self.env = env - @staticmethod - def add_additional_args(parser): - pass - - @staticmethod - def execute(client, args): + def execute(self, args): pass diff --git a/SoftLayer/CLI/modules/bmc.py b/SoftLayer/CLI/modules/bmc.py index a9ee1d22b..07f4e9e4a 100644 --- a/SoftLayer/CLI/modules/bmc.py +++ b/SoftLayer/CLI/modules/bmc.py @@ -43,19 +43,18 @@ class BMCCreateOptions(CLIRunnable): action = 'create-options' options = ['datacenter', 'cpu', 'memory', 'os', 'disk', 'nic'] - @classmethod - def execute(cls, client, args): + def execute(self, args): t = KeyValueTable(['Name', 'Value']) t.align['Name'] = 'r' t.align['Value'] = 'l' show_all = True - for opt_name in cls.options: + for opt_name in self.options: if args.get("--" + opt_name): show_all = False break - mgr = HardwareManager(client) + mgr = HardwareManager(self.client) bmi_options = mgr.get_bare_metal_create_options() @@ -63,12 +62,12 @@ def execute(cls, client, args): show_all = True if args['--datacenter'] or show_all: - results = cls.get_create_options(bmi_options, 'datacenter')[0] + results = self.get_create_options(bmi_options, 'datacenter')[0] t.add_row([results[0], listing(sorted(results[1]))]) if args['--cpu'] or args['--memory'] or show_all: - results = cls.get_create_options(bmi_options, 'cpu') + results = self.get_create_options(bmi_options, 'cpu') memory_cpu_table = Table(['memory', 'cpu']) for result in results: memory_cpu_table.add_row([ @@ -80,7 +79,7 @@ def execute(cls, client, args): t.add_row(['memory/cpu', memory_cpu_table]) if args['--os'] or show_all: - results = cls.get_create_options(bmi_options, 'os') + results = self.get_create_options(bmi_options, 'os') for result in results: t.add_row([ @@ -91,13 +90,13 @@ def execute(cls, client, args): )]) if args['--disk'] or show_all: - results = cls.get_create_options(bmi_options, 'disk')[0] + results = self.get_create_options(bmi_options, 'disk')[0] t.add_row([results[0], listing( [item[0] for item in sorted(results[1])])]) if args['--nic'] or show_all: - results = cls.get_create_options(bmi_options, 'nic') + results = self.get_create_options(bmi_options, 'nic') for result in results: t.add_row([result[0], listing( @@ -105,8 +104,7 @@ def execute(cls, client, args): return t - @classmethod - def get_create_options(cls, bmi_options, section, pretty=True): + def get_create_options(self, bmi_options, section, pretty=True): """ This method can be used to parse the bare metal instance creation options into different sections. This can be useful for data validation as well as printing the options on a help screen. @@ -257,7 +255,8 @@ def _generate_windows_code(description): dual.append((str(int(item['capacity'])) + '_DUAL', item['price_id'])) else: - single.append((str(int(item['capacity'])), item['price_id'])) + single.append((str(int(item['capacity'])), + item['price_id'])) return [('single nic', single), ('dual nic', dual)] @@ -304,10 +303,9 @@ class CreateBMCInstance(CLIRunnable): options = ['confirm'] required_params = ['--hostname', '--domain', '--cpu', '--memory', '--os'] - @classmethod - def execute(cls, client, args): + def execute(self, args): update_with_template_args(args) - mgr = HardwareManager(client) + mgr = HardwareManager(self.client) # Disks will be a comma-separated list. Let's make it a real list. if isinstance(args.get('--disk'), str): @@ -317,7 +315,7 @@ def execute(cls, client, args): if isinstance(args.get('--key'), str): args['--key'] = args.get('--key').split(',') - cls._validate_args(args) + self._validate_args(args) bmi_options = mgr.get_bare_metal_create_options() @@ -328,9 +326,9 @@ def execute(cls, client, args): } # Validate the CPU/Memory combination and get the price ID - server_core = cls._get_cpu_and_memory_price_ids(bmi_options, - args['--cpu'], - args['--memory']) + server_core = self._get_cpu_and_memory_price_ids(bmi_options, + args['--cpu'], + args['--memory']) if server_core: order['server'] = server_core @@ -340,8 +338,8 @@ def execute(cls, client, args): order['hourly'] = args['--hourly'] # Convert the OS code back into a price ID - os_price = cls._get_price_id_from_options(bmi_options, 'os', - args['--os']) + os_price = self._get_price_id_from_options(bmi_options, 'os', + args['--os']) if os_price: order['os'] = os_price @@ -353,22 +351,22 @@ def execute(cls, client, args): # Set the disk size disk_prices = [] for disk in args.get('--disk'): - disk_price = cls._get_price_id_from_options(bmi_options, 'disk', - disk) + disk_price = self._get_price_id_from_options(bmi_options, 'disk', + disk) if disk_price: disk_prices.append(disk_price) if not disk_prices: - disk_prices.append(cls._get_default_value(bmi_options, 'disk0')) + disk_prices.append(self._get_default_value(bmi_options, 'disk0')) order['disks'] = disk_prices # Set the port speed port_speed = args.get('--network') or 10 - nic_price = cls._get_price_id_from_options(bmi_options, 'nic', - port_speed) + nic_price = self._get_price_id_from_options(bmi_options, 'nic', + port_speed) if nic_price: order['port_speed'] = nic_price @@ -379,8 +377,8 @@ def execute(cls, client, args): if args.get('--key'): keys = [] for key in args.get('--key'): - key_id = resolve_id(SshKeyManager(client).resolve_ids, key, - 'SshKey') + key_id = resolve_id(SshKeyManager(self.client).resolve_ids, + key, 'SshKey') keys.append(key_id) order['ssh_keys'] = keys @@ -441,9 +439,8 @@ def execute(cls, client, args): return output - @classmethod - def _validate_args(cls, args): - invalid_args = [k for k in cls.required_params if args.get(k) is None] + def _validate_args(self, args): + invalid_args = [k for k in self.required_params if args.get(k) is None] if invalid_args: raise ArgumentError('Missing required options: %s' % ','.join(invalid_args)) @@ -460,8 +457,7 @@ def _validate_args(cls, args): if not any([args['--hourly'], args['--monthly']]): raise ArgumentError('One of [--hourly | --monthly] is required') - @classmethod - def _get_cpu_and_memory_price_ids(cls, bmi_options, cpu_value, + def _get_cpu_and_memory_price_ids(self, bmi_options, cpu_value, memory_value): bmi_obj = BMCCreateOptions() price_id = None @@ -477,8 +473,7 @@ def _get_cpu_and_memory_price_ids(cls, bmi_options, cpu_value, return price_id - @classmethod - def _get_default_value(cls, bmi_options, option): + def _get_default_value(self, bmi_options, option): if option not in bmi_options['categories']: return @@ -492,12 +487,11 @@ def _get_default_value(cls, bmi_options, option): ]): return item['price_id'] - @classmethod - def _get_price_id_from_options(cls, bmi_options, option, value): + def _get_price_id_from_options(self, bmi_options, option, value): bmi_obj = BMCCreateOptions() price_id = None - for k, v in bmi_obj.get_create_options(bmi_options, option, False): + for _, v in bmi_obj.get_create_options(bmi_options, option, False): for item_options in v: if item_options[0] == value: price_id = item_options[1] @@ -519,9 +513,8 @@ class CancelInstance(CLIRunnable): action = 'cancel' options = ['confirm'] - @staticmethod - def execute(client, args): - hw = HardwareManager(client) + def execute(self, args): + hw = HardwareManager(self.client) hw_id = resolve_id( hw.resolve_ids, args.get(''), 'hardware') diff --git a/SoftLayer/CLI/modules/cci.py b/SoftLayer/CLI/modules/cci.py index faee70508..46cf986c9 100755 --- a/SoftLayer/CLI/modules/cci.py +++ b/SoftLayer/CLI/modules/cci.py @@ -74,9 +74,8 @@ class ListCCIs(CLIRunnable): """ action = 'list' - @staticmethod - def execute(client, args): - cci = CCIManager(client) + def execute(self, args): + cci = CCIManager(self.client) tags = None if args.get('--tags'): @@ -128,9 +127,8 @@ class CCIDetails(CLIRunnable): """ action = 'detail' - @staticmethod - def execute(client, args): - cci = CCIManager(client) + def execute(self, args): + cci = CCIManager(self.client) t = KeyValueTable(['Name', 'Value']) t.align['Name'] = 'r' t.align['Value'] = 'l' @@ -197,7 +195,7 @@ def execute(client, args): t.add_row(['tags', listing(tag_row, separator=',')]) if not result['privateNetworkOnlyFlag']: - ptr_domains = client['Virtual_Guest'].\ + ptr_domains = self.client['Virtual_Guest'].\ getReverseDomainRecords(id=cci_id) for ptr_domain in ptr_domains: @@ -225,13 +223,12 @@ class CreateOptionsCCI(CLIRunnable): action = 'create-options' options = ['datacenter', 'cpu', 'nic', 'disk', 'os', 'memory'] - @classmethod - def execute(cls, client, args): - cci = CCIManager(client) + def execute(self, args): + cci = CCIManager(self.client) result = cci.get_create_options() show_all = True - for opt_name in cls.options: + for opt_name in self.options: if args.get("--" + opt_name): show_all = False break @@ -384,17 +381,16 @@ class CreateCCI(CLIRunnable): options = ['confirm'] required_params = ['--hostname', '--domain', '--cpu', '--memory'] - @classmethod - def execute(cls, client, args): + def execute(self, args): update_with_template_args(args) - cci = CCIManager(client) - cls._update_with_like_args(cci, args) + cci = CCIManager(self.client) + self._update_with_like_args(cci, args) # SSH keys may be a comma-separated list. Let's make it a real list. if isinstance(args.get('--key'), str): args['--key'] = args.get('--key').split(',') - cls._validate_args(args) + self._validate_args(args) # Do not create CCI with --test or --export do_create = not (args['--export'] or args['--test']) @@ -402,7 +398,7 @@ def execute(cls, client, args): t = Table(['Item', 'cost']) t.align['Item'] = 'r' t.align['cost'] = 'r' - data = cls._parse_create_args(client, args) + data = self._parse_create_args(self.client, args) output = [] if args.get('--test'): @@ -468,9 +464,8 @@ def execute(cls, client, args): return output - @classmethod - def _validate_args(cls, args): - invalid_args = [k for k in cls.required_params if args.get(k) is None] + def _validate_args(self, args): + invalid_args = [k for k in self.required_params if args.get(k) is None] if invalid_args: raise ArgumentError('Missing required options: %s' % ','.join(invalid_args)) @@ -504,8 +499,7 @@ def _validate_args(cls, args): 'File does not exist [-u | --userfile] = %s' % args['--userfile']) - @staticmethod - def _update_with_like_args(cci, args): + def _update_with_like_args(self, cci, args): """ Update arguments with options taken from a currently running CCI. :param CCIManager args: A CCIManager @@ -554,8 +548,7 @@ def _update_with_like_args(cci, args): if args.get(key) in [None, False]: args[key] = value - @staticmethod - def _parse_create_args(client, args): + def _parse_create_args(self, client, args): """ Converts CLI arguments to arguments that can be passed into CCIManager.create_instance. @@ -642,9 +635,8 @@ class ReadyCCI(CLIRunnable): """ action = 'ready' - @staticmethod - def execute(client, args): - cci = CCIManager(client) + def execute(self, args): + cci = CCIManager(self.client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') ready = cci.wait_for_transaction(cci_id, int(args.get('--wait') or 0)) @@ -671,15 +663,14 @@ class ReloadCCI(CLIRunnable): action = 'reload' options = ['confirm'] - @staticmethod - def execute(client, args): - cci = CCIManager(client) + def execute(self, args): + cci = CCIManager(self.client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') keys = [] if args.get('--key'): for key in args.get('--key'): - key_id = resolve_id(SshKeyManager(client).resolve_ids, key, - 'SshKey') + key_id = resolve_id(SshKeyManager(self.client).resolve_ids, + key, 'SshKey') keys.append(key_id) if args['--really'] or no_going_back(cci_id): cci.reload_instance(cci_id, args['--postinstall'], keys) @@ -697,9 +688,8 @@ class CancelCCI(CLIRunnable): action = 'cancel' options = ['confirm'] - @staticmethod - def execute(client, args): - cci = CCIManager(client) + def execute(self, args): + cci = CCIManager(self.client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') if args['--really'] or no_going_back(cci_id): cci.cancel_instance(cci_id) @@ -719,10 +709,9 @@ class CCIPowerOff(CLIRunnable): action = 'power-off' options = ['confirm'] - @classmethod - def execute(cls, client, args): - vg = client['Virtual_Guest'] - cci = CCIManager(client) + def execute(self, args): + vg = self.client['Virtual_Guest'] + cci = CCIManager(self.client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') if args['--really'] or confirm('This will power off the CCI with id ' '%s. Continue?' % cci_id): @@ -747,10 +736,9 @@ class CCIReboot(CLIRunnable): action = 'reboot' options = ['confirm'] - @classmethod - def execute(cls, client, args): - vg = client['Virtual_Guest'] - cci = CCIManager(client) + def execute(self, args): + vg = self.client['Virtual_Guest'] + cci = CCIManager(self.client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') if args['--really'] or confirm('This will reboot the CCI with id ' '%s. Continue?' % cci_id): @@ -772,10 +760,9 @@ class CCIPowerOn(CLIRunnable): """ action = 'power-on' - @classmethod - def execute(cls, client, args): - vg = client['Virtual_Guest'] - cci = CCIManager(client) + def execute(self, args): + vg = self.client['Virtual_Guest'] + cci = CCIManager(self.client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') vg.powerOn(id=cci_id) @@ -789,10 +776,9 @@ class CCIPause(CLIRunnable): action = 'pause' options = ['confirm'] - @classmethod - def execute(cls, client, args): - vg = client['Virtual_Guest'] - cci = CCIManager(client) + def execute(self, args): + vg = self.client['Virtual_Guest'] + cci = CCIManager(self.client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') if args['--really'] or confirm('This will pause the CCI with id ' @@ -810,10 +796,9 @@ class CCIResume(CLIRunnable): """ action = 'resume' - @classmethod - def execute(cls, client, args): - vg = client['Virtual_Guest'] - cci = CCIManager(client) + def execute(self, args): + vg = self.client['Virtual_Guest'] + cci = CCIManager(self.client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') vg.resume(id=cci_id) @@ -830,11 +815,10 @@ class NicEditCCI(CLIRunnable): """ action = 'nic-edit' - @classmethod - def execute(cls, client, args): + def execute(self, args): public = args['public'] - cci = CCIManager(client) + cci = CCIManager(self.client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') cci.change_port_speed(cci_id, public, args['--speed']) @@ -857,14 +841,12 @@ class CCIDNS(CLIRunnable): action = 'dns' options = ['confirm'] - @classmethod - def execute(cls, client, args, env): + def execute(self, args): args['--ttl'] = args['--ttl'] or 7200 if args['sync']: - return cls.dns_sync(client, args) + return self.dns_sync(self.client, args) - @staticmethod - def dns_sync(client, args): + def dns_sync(self, client, args): dns = DNSManager(client) cci = CCIManager(client) @@ -959,8 +941,7 @@ class EditCCI(CLIRunnable): """ action = 'edit' - @staticmethod - def execute(client, args): + def execute(self, args): data = {} if args['--userdata'] and args['--userfile']: @@ -984,7 +965,7 @@ def execute(client, args): data['hostname'] = args.get('--hostname') data['domain'] = args.get('--domain') - cci = CCIManager(client) + cci = CCIManager(self.client) cci_id = resolve_id(cci.resolve_ids, args.get(''), 'CCI') if not cci.edit(cci_id, **data): raise CLIAbort("Failed to update CCI") diff --git a/SoftLayer/CLI/modules/config.py b/SoftLayer/CLI/modules/config.py index e5ade3cd3..c40d24d8f 100644 --- a/SoftLayer/CLI/modules/config.py +++ b/SoftLayer/CLI/modules/config.py @@ -86,14 +86,13 @@ class Setup(CLIRunnable): """ action = 'setup' - @classmethod - def execute(cls, client, args): - settings = get_settings_from_client(client) + def execute(self, args): + settings = get_settings_from_client(self.client) # User Input # Ask for username while True: - username = cls.env.input( + username = self.env.input( 'Username [%s]: ' % settings['username']) \ or settings['username'] if username: @@ -101,7 +100,7 @@ def execute(cls, client, args): # Ask for 'secret' which can be api_key or their password while True: - secret = cls.env.getpass( + secret = self.env.getpass( 'API Key or Password [%s]: ' % settings['api_key']) \ or settings['api_key'] if secret: @@ -109,7 +108,8 @@ def execute(cls, client, args): # Ask for which endpoint they want to use while True: - endpoint_type = cls.env.input('Endpoint (public|private|custom): ') + endpoint_type = self.env.input( + 'Endpoint (public|private|custom): ') endpoint_type = endpoint_type.lower() if not endpoint_type: endpoint_url = API_PUBLIC_ENDPOINT @@ -121,7 +121,7 @@ def execute(cls, client, args): endpoint_url = API_PRIVATE_ENDPOINT break elif endpoint_type == 'custom': - endpoint_url = cls.env.input( + endpoint_url = self.env.input( 'Endpoint URL [%s]: ' % settings['endpoint_url'] ) or settings['endpoint_url'] break @@ -137,7 +137,7 @@ def execute(cls, client, args): path = args.get('--config') config_path = os.path.expanduser(path) - cls.env.out(format_output(config_table(settings))) + self.env.out(format_output(config_table(settings))) if not confirm('Are you sure you want to write settings to "%s"?' % config_path, default=True): @@ -174,7 +174,6 @@ class Show(CLIRunnable): """ action = 'show' - @classmethod - def execute(cls, client, args): - settings = get_settings_from_client(client) + def execute(self, args): + settings = get_settings_from_client(self.client) return config_table(settings) diff --git a/SoftLayer/CLI/modules/dns.py b/SoftLayer/CLI/modules/dns.py index c0f899f6e..e4b352d91 100755 --- a/SoftLayer/CLI/modules/dns.py +++ b/SoftLayer/CLI/modules/dns.py @@ -33,9 +33,8 @@ class DumpZone(CLIRunnable): """ action = "print" - @staticmethod - def execute(client, args): - manager = DNSManager(client) + def execute(self, args): + manager = DNSManager(self.client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') try: return manager.dump_zone(zone_id) @@ -54,9 +53,8 @@ class CreateZone(CLIRunnable): """ action = 'create' - @staticmethod - def execute(client, args): - manager = DNSManager(client) + def execute(self, args): + manager = DNSManager(self.client) manager.create_zone(args['']) @@ -72,9 +70,8 @@ class DeleteZone(CLIRunnable): action = 'delete' options = ['confirm'] - @staticmethod - def execute(client, args): - manager = DNSManager(client) + def execute(self, args): + manager = DNSManager(self.client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') if args['--really'] or no_going_back(args['']): @@ -97,16 +94,14 @@ class ListZones(CLIRunnable): """ action = 'list' - @classmethod - def execute(cls, client, args): + def execute(self, args): if args['']: - return cls.list_zone(client, args[''], args) + return self.list_zone(args) - return cls.list_all_zones(client) + return self.list_all_zones() - @staticmethod - def list_zone(client, zone, args): - manager = DNSManager(client) + def list_zone(self, args): + manager = DNSManager(self.client) t = Table([ "record", "type", @@ -123,7 +118,7 @@ def list_zone(client, zone, args): try: records = manager.get_records( zone_id, - type=args.get('--type'), + record_type=args.get('--type'), host=args.get('--record'), ttl=args.get('--ttl'), data=args.get('--data'), @@ -141,9 +136,8 @@ def list_zone(client, zone, args): return t - @staticmethod - def list_all_zones(client): - manager = DNSManager(client) + def list_all_zones(self): + manager = DNSManager(self.client) zones = manager.list_zones() t = Table([ "id", @@ -183,9 +177,8 @@ class AddRecord(CLIRunnable): """ action = 'add' - @staticmethod - def execute(client, args): - manager = DNSManager(client) + def execute(self, args): + manager = DNSManager(self.client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') args['--ttl'] = args['--ttl'] or 7200 @@ -216,9 +209,8 @@ class EditRecord(CLIRunnable): """ action = 'edit' - @staticmethod - def execute(client, args): - manager = DNSManager(client) + def execute(self, args): + manager = DNSManager(self.client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') try: @@ -252,9 +244,8 @@ class RecordRemove(CLIRunnable): action = 'remove' options = ['confirm'] - @staticmethod - def execute(client, args): - manager = DNSManager(client) + def execute(self, args): + manager = DNSManager(self.client) zone_id = resolve_id(manager.resolve_ids, args[''], name='zone') if args['--id']: diff --git a/SoftLayer/CLI/modules/firewall.py b/SoftLayer/CLI/modules/firewall.py index 0ab7b16a3..11a2b5c6a 100755 --- a/SoftLayer/CLI/modules/firewall.py +++ b/SoftLayer/CLI/modules/firewall.py @@ -22,9 +22,8 @@ class FWList(CLIRunnable): """ action = 'list' - @staticmethod - def execute(client, args): - f = FirewallManager(client) + def execute(self, args): + f = FirewallManager(self.client) fwvlans = f.get_firewalls() t = Table(['vlan', 'type', 'features']) diff --git a/SoftLayer/CLI/modules/globalip.py b/SoftLayer/CLI/modules/globalip.py index 7eae77dc0..7873f90c6 100644 --- a/SoftLayer/CLI/modules/globalip.py +++ b/SoftLayer/CLI/modules/globalip.py @@ -31,15 +31,14 @@ class GlobalIpAssign(CLIRunnable): """ action = 'assign' - @staticmethod - def execute(client, args): - mgr = NetworkManager(client) + def execute(self, args): + mgr = NetworkManager(self.client) - id = mgr.resolve_global_ip_ids(args.get('')) - if not id: + global_ip_id = mgr.resolve_global_ip_ids(args.get('')) + if not global_ip_id: raise CLIAbort("Unable to find global IP record for " + args['']) - mgr.assign_global_ip(id, args['']) + mgr.assign_global_ip(global_ip_id, args['']) class GlobalIpCancel(CLIRunnable): @@ -52,13 +51,12 @@ class GlobalIpCancel(CLIRunnable): action = 'cancel' options = ['confirm'] - @staticmethod - def execute(client, args): - mgr = NetworkManager(client) - id = mgr.resolve_global_ip_ids(args.get('')) + def execute(self, args): + mgr = NetworkManager(self.client) + global_ip_id = mgr.resolve_global_ip_ids(args.get('')) - if args['--really'] or no_going_back(id): - mgr.cancel_global_ip(id) + if args['--really'] or no_going_back(global_ip_id): + mgr.cancel_global_ip(global_ip_id) else: CLIAbort('Aborted') @@ -77,9 +75,8 @@ class GlobalIpCreate(CLIRunnable): action = 'create' options = ['confirm'] - @staticmethod - def execute(client, args): - mgr = NetworkManager(client) + def execute(self, args): + mgr = NetworkManager(self.client) version = 4 if args.get('--v6'): @@ -126,9 +123,8 @@ class GlobalIpList(CLIRunnable): """ action = 'list' - @staticmethod - def execute(client, args): - mgr = NetworkManager(client) + def execute(self, args): + mgr = NetworkManager(self.client) t = Table([ 'id', 'ip', 'assigned', 'target' @@ -174,12 +170,11 @@ class GlobalIpUnassign(CLIRunnable): """ action = 'unassign' - @staticmethod - def execute(client, args): - mgr = NetworkManager(client) + def execute(self, args): + mgr = NetworkManager(self.client) - id = mgr.resolve_global_ip_ids(args.get('')) - if not id: + global_ip_id = mgr.resolve_global_ip_ids(args.get('')) + if not global_ip_id: raise CLIAbort("Unable to find global IP record for " + args['']) - mgr.unassign_global_ip(id) + mgr.unassign_global_ip(global_ip_id) diff --git a/SoftLayer/CLI/modules/help.py b/SoftLayer/CLI/modules/help.py index 11137a4a1..f490a76de 100644 --- a/SoftLayer/CLI/modules/help.py +++ b/SoftLayer/CLI/modules/help.py @@ -17,10 +17,9 @@ class Show(CLIRunnable): __doc__ = __doc__ action = None - @classmethod - def execute(cls, client, args): - parser = CommandParser(cls.env) - cls.env.load_module(args['']) + def execute(self, args): + parser = CommandParser(self.env) + self.env.load_module(args['']) if args['']: return parser.get_command_help(args[''], args['']) elif args['']: diff --git a/SoftLayer/CLI/modules/image.py b/SoftLayer/CLI/modules/image.py index dae619a1e..49b610ee0 100644 --- a/SoftLayer/CLI/modules/image.py +++ b/SoftLayer/CLI/modules/image.py @@ -25,22 +25,21 @@ class ListImages(CLIRunnable): """ action = 'list' - @staticmethod - def execute(client, args): - account = client['Account'] + def execute(self, args): + account = self.client['Account'] neither = not any([args['--private'], args['--public']]) results = [] if args['--private'] or neither: - account = client['Account'] + account = self.client['Account'] mask = 'id,accountId,name,globalIdentifier,blockDevices,parentId' r = account.getPrivateBlockDeviceTemplateGroups(mask=mask) results.append(r) if args['--public'] or neither: - vgbd = client['Virtual_Guest_Block_Device_Template_Group'] + vgbd = self.client['Virtual_Guest_Block_Device_Template_Group'] r = vgbd.getPublicImages() results.append(r) diff --git a/SoftLayer/CLI/modules/iscsi.py b/SoftLayer/CLI/modules/iscsi.py index 216adbd60..04c1bf238 100644 --- a/SoftLayer/CLI/modules/iscsi.py +++ b/SoftLayer/CLI/modules/iscsi.py @@ -21,9 +21,8 @@ class ListISCSI(CLIRunnable): """ action = 'list' - @staticmethod - def execute(client, args): - account = client['Account'] + def execute(self, args): + account = self.client['Account'] iscsi = account.getIscsiNetworkStorage( mask='eventCount,serviceResource[datacenter.name]') diff --git a/SoftLayer/CLI/modules/messaging.py b/SoftLayer/CLI/modules/messaging.py index 63ebc288f..ae2964c21 100644 --- a/SoftLayer/CLI/modules/messaging.py +++ b/SoftLayer/CLI/modules/messaging.py @@ -50,9 +50,8 @@ class ListAccounts(CLIRunnable): """ action = 'accounts-list' - @staticmethod - def execute(client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) accounts = manager.list_accounts() t = Table([ @@ -80,9 +79,8 @@ class ListEndpoints(CLIRunnable): """ action = 'endpoints-list' - @staticmethod - def execute(client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) regions = manager.get_endpoints() t = Table([ @@ -107,9 +105,8 @@ class Ping(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'ping' - @staticmethod - def execute(client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) ok = manager.ping( datacenter=args['--datacenter'], network=args['--network']) if ok: @@ -176,9 +173,8 @@ class QueueList(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'queue-list' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) queues = mq_client.get_queues()['items'] @@ -204,9 +200,8 @@ class QueueDetail(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'queue-detail' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) queue = mq_client.get_queue(args['']) return queue_table(queue) @@ -227,9 +222,8 @@ class QueueCreate(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'queue-add' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) tags = None if args.get('--tags'): @@ -259,9 +253,8 @@ class QueueModify(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'queue-edit' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) tags = None if args.get('--tags'): @@ -289,9 +282,8 @@ class QueueDelete(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'queue-remove' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) if args['']: @@ -314,9 +306,8 @@ class QueuePush(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'queue-push' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) body = '' if args[''] is not None: @@ -340,9 +331,8 @@ class QueuePop(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'queue-pop' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) messages = mq_client.pop_message( @@ -369,9 +359,8 @@ class TopicList(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'topic-list' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) topics = mq_client.get_topics()['items'] @@ -390,9 +379,8 @@ class TopicDetail(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'topic-detail' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) topic = mq_client.get_topic(args['']) subscriptions = mq_client.get_subscriptions(args['']) @@ -411,9 +399,8 @@ class TopicCreate(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'topic-add' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) tags = None if args.get('--tags'): @@ -441,9 +428,8 @@ class TopicDelete(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'topic-remove' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) mq_client.delete_topic(args[''], args.get('--force')) @@ -464,9 +450,8 @@ class TopicSubscribe(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'topic-subscribe' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) if args['--type'] == 'queue': subscription = mq_client.create_subscription( @@ -498,9 +483,8 @@ class TopicUnsubscribe(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'topic-unsubscribe' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) mq_client.delete_subscription( @@ -518,9 +502,8 @@ class TopicPush(CLIRunnable): """ + COMMON_MESSAGING_ARGS action = 'topic-push' - @classmethod - def execute(cls, client, args): - manager = MessagingManager(client) + def execute(self, args): + manager = MessagingManager(self.client) mq_client = manager.get_connection(args['']) # the message body comes from the positional argument or stdin diff --git a/SoftLayer/CLI/modules/metadata.py b/SoftLayer/CLI/modules/metadata.py index d3553ca07..eaf91aaf9 100644 --- a/SoftLayer/CLI/modules/metadata.py +++ b/SoftLayer/CLI/modules/metadata.py @@ -35,8 +35,7 @@ class BackendMacAddresses(CLIRunnable): """ action = 'backend_mac' - @staticmethod - def execute(client, args): + def execute(self, args): return listing(MetadataManager().get('backend_mac'), separator=',') @@ -48,8 +47,7 @@ class Datacenter(CLIRunnable): """ action = 'datacenter' - @staticmethod - def execute(client, args): + def execute(self, args): return MetadataManager().get('datacenter') @@ -61,8 +59,7 @@ class DatacenterId(CLIRunnable): """ action = 'datacenter_id' - @staticmethod - def execute(client, args): + def execute(self, args): return MetadataManager().get('datacenter_id') @@ -74,8 +71,7 @@ class FrontendMacAddresses(CLIRunnable): """ action = 'frontend_mac' - @staticmethod - def execute(client, args): + def execute(self, args): return listing(MetadataManager().get('frontend_mac'), separator=',') @@ -87,8 +83,7 @@ class FullyQualifiedDomainName(CLIRunnable): """ action = 'fqdn' - @staticmethod - def execute(client, args): + def execute(self, args): return MetadataManager().get('fqdn') @@ -100,8 +95,7 @@ class Hostname(CLIRunnable): """ action = 'hostname' - @staticmethod - def execute(client, args): + def execute(self, args): return MetadataManager().get('hostname') @@ -113,8 +107,7 @@ class Id(CLIRunnable): """ action = 'id' - @staticmethod - def execute(client, args): + def execute(self, args): return MetadataManager().get('id') @@ -126,8 +119,7 @@ class PrimaryBackendIpAddress(CLIRunnable): """ action = 'backend_ip' - @staticmethod - def execute(client, args): + def execute(self, args): return MetadataManager().get('primary_backend_ip') @@ -139,8 +131,7 @@ class PrimaryIpAddress(CLIRunnable): """ action = 'ip' - @staticmethod - def execute(client, args): + def execute(self, args): return MetadataManager().get('primary_ip') @@ -152,8 +143,7 @@ class ProvisionState(CLIRunnable): """ action = 'provision_state' - @staticmethod - def execute(client, args): + def execute(self, args): return MetadataManager().get('provision_state') @@ -165,8 +155,7 @@ class Tags(CLIRunnable): """ action = 'tags' - @staticmethod - def execute(client, args): + def execute(self, args): return listing(MetadataManager().get('tags'), separator=',') @@ -178,8 +167,7 @@ class UserMetadata(CLIRunnable): """ action = 'user_data' - @staticmethod - def execute(client, args): + def execute(self, args): userdata = MetadataManager().get('user_data') if userdata: return userdata @@ -195,8 +183,7 @@ class Network(CLIRunnable): """ action = 'network' - @staticmethod - def execute(client, args): + def execute(self, args): meta = MetadataManager() if args['']: t = KeyValueTable(['Name', 'Value']) diff --git a/SoftLayer/CLI/modules/nas.py b/SoftLayer/CLI/modules/nas.py index 0bdf06dc8..0d0fe8f5c 100644 --- a/SoftLayer/CLI/modules/nas.py +++ b/SoftLayer/CLI/modules/nas.py @@ -23,9 +23,8 @@ class ListNAS(CLIRunnable): """ action = 'list' - @staticmethod - def execute(client, args): - account = client['Account'] + def execute(self, args): + account = self.client['Account'] nas = account.getNasNetworkStorage( mask='eventCount,serviceResource[datacenter.name]') diff --git a/SoftLayer/CLI/modules/rwhois.py b/SoftLayer/CLI/modules/rwhois.py index 0cf43ea86..fa840c607 100644 --- a/SoftLayer/CLI/modules/rwhois.py +++ b/SoftLayer/CLI/modules/rwhois.py @@ -39,9 +39,8 @@ class RWhoisEdit(CLIRunnable): """ action = 'edit' - @staticmethod - def execute(client, args): - mgr = NetworkManager(client) + def execute(self, args): + mgr = NetworkManager(self.client) update = { 'abuse_email': args.get('--abuse'), @@ -75,9 +74,8 @@ class RWhoisShow(CLIRunnable): """ action = 'show' - @staticmethod - def execute(client, args): - mgr = NetworkManager(client) + def execute(self, args): + mgr = NetworkManager(self.client) result = mgr.get_rwhois() t = KeyValueTable(['Name', 'Value']) diff --git a/SoftLayer/CLI/modules/server.py b/SoftLayer/CLI/modules/server.py index 116fc7fe2..8ad08ffee 100644 --- a/SoftLayer/CLI/modules/server.py +++ b/SoftLayer/CLI/modules/server.py @@ -63,9 +63,8 @@ class ListServers(CLIRunnable): """ action = 'list' - @staticmethod - def execute(client, args): - manager = HardwareManager(client) + def execute(self, args): + manager = HardwareManager(self.client) tags = None if args.get('--tags'): @@ -120,9 +119,8 @@ class ServerDetails(CLIRunnable): """ action = 'detail' - @staticmethod - def execute(client, args): - hardware = HardwareManager(client) + def execute(self, args): + hardware = HardwareManager(self.client) t = KeyValueTable(['Name', 'Value']) t.align['Name'] = 'r' @@ -179,8 +177,8 @@ def execute(client, args): t.add_row(['tags', listing(tag_row, separator=',')]) if not result['privateNetworkOnlyFlag']: - ptr_domains = client['Hardware_Server'].getReverseDomainRecords( - id=hardware_id) + ptr_domains = self.client['Hardware_Server']\ + .getReverseDomainRecords(id=hardware_id) for ptr_domain in ptr_domains: for ptr in ptr_domain['resourceRecords']: @@ -205,16 +203,15 @@ class ServerReload(CLIRunnable): action = 'reload' options = ['confirm'] - @staticmethod - def execute(client, args): - hardware = HardwareManager(client) + def execute(self, args): + hardware = HardwareManager(self.client) hardware_id = resolve_id( hardware.resolve_ids, args.get(''), 'hardware') keys = [] if args.get('--key'): for key in args.get('--key'): - key_id = resolve_id(SshKeyManager(client).resolve_ids, key, - 'SshKey') + key_id = resolve_id(SshKeyManager(self.client).resolve_ids, + key, 'SshKey') keys.append(key_id) if args['--really'] or no_going_back(hardware_id): hardware.reload(hardware_id, args['--postinstall'], keys) @@ -237,16 +234,15 @@ class CancelServer(CLIRunnable): action = 'cancel' options = ['confirm'] - @classmethod - def execute(cls, client, args): - hw = HardwareManager(client) + def execute(self, args): + hw = HardwareManager(self.client) hw_id = resolve_id( hw.resolve_ids, args.get(''), 'hardware') comment = args.get('--comment') if not comment and not args['--really']: - comment = cls.env.input("(Optional) Add a cancellation comment:") + comment = self.env.input("(Optional) Add a cancellation comment:") reason = args.get('--reason') @@ -265,13 +261,12 @@ class ServerCancelReasons(CLIRunnable): action = 'cancel-reasons' - @staticmethod - def execute(client, args): + def execute(self, args): t = Table(['Code', 'Reason']) t.align['Code'] = 'r' t.align['Reason'] = 'l' - mgr = HardwareManager(client) + mgr = HardwareManager(self.client) reasons = mgr.get_cancellation_reasons().iteritems() for code, reason in reasons: @@ -289,10 +284,9 @@ class ServerPowerOff(CLIRunnable): action = 'power-off' options = ['confirm'] - @classmethod - def execute(cls, client, args): - hw = client['Hardware_Server'] - mgr = HardwareManager(client) + def execute(self, args): + hw = self.client['Hardware_Server'] + mgr = HardwareManager(self.client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), 'hardware') if args['--really'] or confirm('This will power off the server with ' @@ -315,10 +309,9 @@ class ServerReboot(CLIRunnable): action = 'reboot' options = ['confirm'] - @classmethod - def execute(cls, client, args): - hw = client['Hardware_Server'] - mgr = HardwareManager(client) + def execute(self, args): + hw = self.client['Hardware_Server'] + mgr = HardwareManager(self.client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), 'hardware') if args['--really'] or confirm('This will power off the server with ' @@ -341,10 +334,9 @@ class ServerPowerOn(CLIRunnable): """ action = 'power-on' - @classmethod - def execute(cls, client, args): - hw = client['Hardware_Server'] - mgr = HardwareManager(client) + def execute(self, args): + hw = self.client['Hardware_Server'] + mgr = HardwareManager(self.client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), 'hardware') hw.powerOn(id=hw_id) @@ -359,10 +351,9 @@ class ServerPowerCycle(CLIRunnable): action = 'power-cycle' options = ['confirm'] - @classmethod - def execute(cls, client, args): - hw = client['Hardware_Server'] - mgr = HardwareManager(client) + def execute(self, args): + hw = self.client['Hardware_Server'] + mgr = HardwareManager(self.client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), 'hardware') @@ -386,11 +377,10 @@ class NicEditServer(CLIRunnable): """ action = 'nic-edit' - @classmethod - def execute(cls, client, args): + def execute(self, args): public = args['public'] - mgr = HardwareManager(client) + mgr = HardwareManager(self.client) hw_id = resolve_id(mgr.resolve_ids, args.get(''), 'hardware') @@ -405,13 +395,12 @@ class ListChassisServer(CLIRunnable): """ action = 'list-chassis' - @staticmethod - def execute(client, args): + def execute(self, args): t = Table(['Code', 'Chassis']) t.align['Code'] = 'r' t.align['Chassis'] = 'l' - mgr = HardwareManager(client) + mgr = HardwareManager(self.client) chassis = mgr.get_available_dedicated_server_packages() for chassis in chassis: @@ -442,9 +431,8 @@ class ServerCreateOptions(CLIRunnable): options = ['datacenter', 'cpu', 'memory', 'os', 'disk', 'nic', 'controller'] - @classmethod - def execute(cls, client, args): - mgr = HardwareManager(client) + def execute(self, args): + mgr = HardwareManager(self.client) t = KeyValueTable(['Name', 'Value']) t.align['Name'] = 'r' @@ -455,7 +443,7 @@ def execute(cls, client, args): ds_options = mgr.get_dedicated_server_create_options(chassis_id) show_all = True - for opt_name in cls.options: + for opt_name in self.options: if args.get("--" + opt_name): show_all = False break @@ -464,12 +452,12 @@ def execute(cls, client, args): show_all = True if args['--datacenter'] or show_all: - results = cls.get_create_options(ds_options, 'datacenter')[0] + results = self.get_create_options(ds_options, 'datacenter')[0] t.add_row([results[0], listing(sorted(results[1]))]) if args['--cpu'] or show_all: - results = cls.get_create_options(ds_options, 'cpu') + results = self.get_create_options(ds_options, 'cpu') cpu_table = Table(['id', 'description']) for result in sorted(results): @@ -477,13 +465,13 @@ def execute(cls, client, args): t.add_row(['cpu', cpu_table]) if args['--memory'] or show_all: - results = cls.get_create_options(ds_options, 'memory')[0] + results = self.get_create_options(ds_options, 'memory')[0] t.add_row([results[0], listing( item[0] for item in sorted(results[1]))]) if args['--os'] or show_all: - results = cls.get_create_options(ds_options, 'os') + results = self.get_create_options(ds_options, 'os') for result in results: t.add_row([ @@ -494,7 +482,7 @@ def execute(cls, client, args): )]) if args['--disk'] or show_all: - results = cls.get_create_options(ds_options, 'disk')[0] + results = self.get_create_options(ds_options, 'disk')[0] t.add_row([ results[0], @@ -504,22 +492,21 @@ def execute(cls, client, args): )]) if args['--nic'] or show_all: - results = cls.get_create_options(ds_options, 'nic') + results = self.get_create_options(ds_options, 'nic') for result in results: t.add_row([result[0], listing( item[0] for item in sorted(result[1],))]) if args['--controller'] or show_all: - results = cls.get_create_options(ds_options, 'disk_controller')[0] + results = self.get_create_options(ds_options, 'disk_controller')[0] t.add_row([results[0], listing( item[0] for item in sorted(results[1],))]) return t - @classmethod - def get_create_options(cls, ds_options, section, pretty=True): + def get_create_options(self, ds_options, section, pretty=True): """ This method can be used to parse the bare metal instance creation options into different sections. This can be useful for data validation as well as printing the options on a help screen. @@ -731,10 +718,9 @@ class CreateServer(CLIRunnable): required_params = ['--hostname', '--domain', '--chassis', '--cpu', '--memory', '--os'] - @classmethod - def execute(cls, client, args): + def execute(self, args): update_with_template_args(args) - mgr = HardwareManager(client) + mgr = HardwareManager(self.client) # Disks will be a comma-separated list. Let's make it a real list. if isinstance(args.get('--disk'), str): @@ -744,7 +730,7 @@ def execute(cls, client, args): if isinstance(args.get('--key'), str): args['--key'] = args.get('--key').split(',') - cls._validate_args(args) + self._validate_args(args) ds_options = mgr.get_dedicated_server_create_options(args['--chassis']) @@ -756,8 +742,8 @@ def execute(cls, client, args): } # Convert the OS code back into a price ID - os_price = cls._get_price_id_from_options(ds_options, 'os', - args['--os']) + os_price = self._get_price_id_from_options(ds_options, 'os', + args['--os']) if os_price: order['os'] = os_price @@ -766,39 +752,38 @@ def execute(cls, client, args): order['location'] = args['--datacenter'] or 'FIRST_AVAILABLE' order['server'] = args['--cpu'] - order['ram'] = cls._get_price_id_from_options(ds_options, 'memory', - int(args['--memory'])) + order['ram'] = self._get_price_id_from_options(ds_options, 'memory', + int(args['--memory'])) # Set the disk sizes disk_prices = [] disk_number = 0 for disk in args.get('--disk'): - disk_price = cls._get_disk_price(ds_options, disk, disk_number) + disk_price = self._get_disk_price(ds_options, disk, disk_number) disk_number += 1 if disk_price: disk_prices.append(disk_price) if not disk_prices: - disk_prices.append(cls._get_default_value(ds_options, 'disk0')) + disk_prices.append(self._get_default_value(ds_options, 'disk0')) order['disks'] = disk_prices # Set the disk controller price if args.get('--controller'): - dc_price = cls._get_price_id_from_options(ds_options, - 'disk_controller', - args.get('--controller')) + dc_price = self._get_price_id_from_options( + ds_options, 'disk_controller', args.get('--controller')) else: - dc_price = cls._get_price_id_from_options(ds_options, - 'disk_controller', - 'None') + dc_price = self._get_price_id_from_options(ds_options, + 'disk_controller', + 'None') order['disk_controller'] = dc_price # Set the port speed port_speed = args.get('--network') or '100' - nic_price = cls._get_price_id_from_options(ds_options, 'nic', - port_speed) + nic_price = self._get_price_id_from_options(ds_options, 'nic', + port_speed) if nic_price: order['port_speed'] = nic_price @@ -809,8 +794,8 @@ def execute(cls, client, args): if args.get('--key'): keys = [] for key in args.get('--key'): - key_id = resolve_id(SshKeyManager(client).resolve_ids, key, - 'SshKey') + key_id = resolve_id(SshKeyManager(self.client).resolve_ids, + key, 'SshKey') keys.append(key_id) order['ssh_keys'] = keys @@ -869,15 +854,13 @@ def execute(cls, client, args): return output - @classmethod - def _validate_args(cls, args): - invalid_args = [k for k in cls.required_params if args.get(k) is None] + def _validate_args(self, args): + invalid_args = [k for k in self.required_params if args.get(k) is None] if invalid_args: raise ArgumentError('Missing required options: %s' % ','.join(invalid_args)) - @classmethod - def _get_default_value(cls, ds_options, option): + def _get_default_value(self, ds_options, option): if option not in ds_options['categories']: return @@ -891,26 +874,24 @@ def _get_default_value(cls, ds_options, option): ]): return item['price_id'] - @classmethod - def _get_disk_price(cls, ds_options, value, number): + def _get_disk_price(self, ds_options, value, number): if not number: - return cls._get_price_id_from_options(ds_options, 'disk', value) + return self._get_price_id_from_options(ds_options, 'disk', value) # This will get the item ID for the matching identifier string, which # we can then use to get the price ID for our specific disk - item_id = cls._get_price_id_from_options(ds_options, 'disk', - value, True) + item_id = self._get_price_id_from_options(ds_options, 'disk', + value, True) key = 'disk' + str(number) if key in ds_options['categories']: for item in ds_options['categories'][key]['items']: if item['id'] == item_id: return item['price_id'] - @classmethod - def _get_price_id_from_options(cls, ds_options, option, value, + def _get_price_id_from_options(self, ds_options, option, value, item_id=False): ds_obj = ServerCreateOptions() - for k, v in ds_obj.get_create_options(ds_options, option, False): + for _, v in ds_obj.get_create_options(ds_options, option, False): for item_options in v: if item_options[0] == value: if not item_id: @@ -932,8 +913,7 @@ class EditServer(CLIRunnable): """ action = 'edit' - @staticmethod - def execute(client, args): + def execute(self, args): data = {} if args['--userdata'] and args['--userfile']: @@ -957,7 +937,7 @@ def execute(client, args): data['hostname'] = args.get('--hostname') data['domain'] = args.get('--domain') - hw = HardwareManager(client) + hw = HardwareManager(self.client) hw_id = resolve_id(hw.resolve_ids, args.get(''), 'hardware') if not hw.edit(hw_id, **data): diff --git a/SoftLayer/CLI/modules/sshkey.py b/SoftLayer/CLI/modules/sshkey.py index bd392c35b..b630b5449 100644 --- a/SoftLayer/CLI/modules/sshkey.py +++ b/SoftLayer/CLI/modules/sshkey.py @@ -41,8 +41,7 @@ class AddSshKey(CLIRunnable): """ action = 'add' - @staticmethod - def execute(client, args): + def execute(self, args): if args.get('--key'): key = args['--key'] else: @@ -50,7 +49,7 @@ def execute(client, args): key = f.read().strip() f.close() - mgr = SshKeyManager(client) + mgr = SshKeyManager(self.client) result = mgr.add_key(key, args['