diff --git a/SoftLayer/CLI/nas/credentials.py b/SoftLayer/CLI/nas/credentials.py new file mode 100644 index 000000000..65de4e54e --- /dev/null +++ b/SoftLayer/CLI/nas/credentials.py @@ -0,0 +1,21 @@ +"""List NAS account credentials.""" +# :license: MIT, see LICENSE for more details. +import SoftLayer +from SoftLayer.CLI import environment +from SoftLayer.CLI import formatting + +import click + + +@click.command() +@click.argument('identifier') +@environment.pass_env +def cli(env, identifier): + """List NAS account credentials.""" + + nw_mgr = SoftLayer.NetworkManager(env.client) + result = nw_mgr.get_nas_credentials(identifier) + table = formatting.Table(['username', 'password']) + table.add_row([result['username'], + result['password']]) + return table diff --git a/SoftLayer/CLI/nas/list.py b/SoftLayer/CLI/nas/list.py index 07fd46b56..fc5b3aa0c 100644 --- a/SoftLayer/CLI/nas/list.py +++ b/SoftLayer/CLI/nas/list.py @@ -18,8 +18,7 @@ def cli(env): nas_accounts = account.getNasNetworkStorage( mask='eventCount,serviceResource[datacenter.name]') - table = formatting.Table(['id', 'datacenter', 'size', 'username', - 'password', 'server']) + table = formatting.Table(['id', 'datacenter', 'size', 'server']) for nas_account in nas_accounts: table.add_row([ @@ -31,8 +30,6 @@ def cli(env): formatting.FormattedItem( nas_account.get('capacityGb', formatting.blank()), "%dGB" % nas_account.get('capacityGb', 0)), - nas_account.get('username', formatting.blank()), - nas_account.get('password', formatting.blank()), nas_account.get('serviceResourceBackendIpAddress', formatting.blank())]) diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py index 25d116d28..71be22f1e 100644 --- a/SoftLayer/CLI/routes.py +++ b/SoftLayer/CLI/routes.py @@ -28,6 +28,7 @@ ('vs:reboot', 'SoftLayer.CLI.virt.power:reboot'), ('vs:reload', 'SoftLayer.CLI.virt.reload:cli'), ('vs:upgrade', 'SoftLayer.CLI.virt.upgrade:cli'), + ('vs:credentials', 'SoftLayer.CLI.virt.credentials:cli'), ('cdn', 'SoftLayer.CLI.cdn'), ('cdn:detail', 'SoftLayer.CLI.cdn.detail:cli'), @@ -120,6 +121,7 @@ ('nas', 'SoftLayer.CLI.nas'), ('nas:list', 'SoftLayer.CLI.nas.list:cli'), + ('nas:credentials', 'SoftLayer.CLI.nas.credentials:cli'), ('rwhois', 'SoftLayer.CLI.rwhois'), ('rwhois:edit', 'SoftLayer.CLI.rwhois.edit:cli'), @@ -140,6 +142,7 @@ ('server:power-on', 'SoftLayer.CLI.server.power:power_on'), ('server:reboot', 'SoftLayer.CLI.server.power:reboot'), ('server:reload', 'SoftLayer.CLI.server.reload:cli'), + ('server:credentials', 'SoftLayer.CLI.server.credentials:cli'), ('snapshot', 'SoftLayer.CLI.snapshot'), ('snapshot:cancel', 'SoftLayer.CLI.snapshot.cancel:cli'), diff --git a/SoftLayer/CLI/server/credentials.py b/SoftLayer/CLI/server/credentials.py new file mode 100644 index 000000000..4f82ff84a --- /dev/null +++ b/SoftLayer/CLI/server/credentials.py @@ -0,0 +1,21 @@ +"""List virtual server credentials.""" +# :license: MIT, see LICENSE for more details. +import SoftLayer +from SoftLayer.CLI import environment +from SoftLayer.CLI import formatting + +import click + + +@click.command() +@click.argument('identifier') +@environment.pass_env +def cli(env, identifier): + """List virtual server credentials.""" + + hardware = SoftLayer.HardwareManager(env.client) + result = hardware.get_hardware(identifier) + table = formatting.Table(['username', 'password']) + for item in result['operatingSystem']['passwords']: + table.add_row([item['username'], item['password']]) + return table diff --git a/SoftLayer/CLI/server/detail.py b/SoftLayer/CLI/server/detail.py index b67f6745c..3af674683 100644 --- a/SoftLayer/CLI/server/detail.py +++ b/SoftLayer/CLI/server/detail.py @@ -83,11 +83,10 @@ def cli(env, identifier, passwords, price): result['billingItem']['recurringFee']]) if passwords: - user_strs = [] + pass_table = formatting.Table(['username', 'password']) for item in result['operatingSystem']['passwords']: - user_strs.append( - "%s %s" % (item['username'], item['password'])) - table.add_row(['users', formatting.listing(user_strs)]) + pass_table.add_row([item['username'], item['password']]) + table.add_row(['users', pass_table]) tag_row = [] for tag in result['tagReferences']: diff --git a/SoftLayer/CLI/virt/credentials.py b/SoftLayer/CLI/virt/credentials.py new file mode 100644 index 000000000..47b1287c8 --- /dev/null +++ b/SoftLayer/CLI/virt/credentials.py @@ -0,0 +1,21 @@ +"""List virtual server credentials.""" +# :license: MIT, see LICENSE for more details. +import SoftLayer +from SoftLayer.CLI import environment +from SoftLayer.CLI import formatting + +import click + + +@click.command() +@click.argument('identifier') +@environment.pass_env +def cli(env, identifier): + """List virtual server credentials.""" + + vsi = SoftLayer.VSManager(env.client) + result = vsi.get_instance(identifier) + table = formatting.Table(['username', 'password']) + for item in result['operatingSystem']['passwords']: + table.add_row([item['username'], item['password']]) + return table diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index 6a275801b..f544c7d39 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -30,6 +30,7 @@ def __init__(self, client): self.account = client['Account'] self.vlan = client['Network_Vlan'] self.subnet = client['Network_Subnet'] + self.network_storage = self.client['Network_Storage'] def add_global_ip(self, version=4, test_order=False): """Adds a global IP address to the account. @@ -408,3 +409,13 @@ def _list_vlans_by_name(self, name): """ results = self.list_vlans(name=name, mask='id') return [result['id'] for result in results] + + def get_nas_credentials(self, identifier, **kwargs): + """Returns a list of IDs of VLANs which match the given VLAN name. + + :param integer instance_id: the instance ID + :returns: A dictionary containing a large amount of information about + the specified instance. + """ + result = self.network_storage.getObject(id=identifier, **kwargs) + return result diff --git a/SoftLayer/tests/CLI/modules/nas_tests.py b/SoftLayer/tests/CLI/modules/nas_tests.py index 66de6c59e..7457f38b3 100644 --- a/SoftLayer/tests/CLI/modules/nas_tests.py +++ b/SoftLayer/tests/CLI/modules/nas_tests.py @@ -15,9 +15,7 @@ def test_list_nas(self): self.assertEqual(result.exit_code, 0) self.assertEqual(json.loads(result.output), - [{'username': 'user', - 'datacenter': 'Dallas', + [{'datacenter': 'Dallas', 'server': '127.0.0.1', - 'password': 'pass', 'id': 1, 'size': 10}]) diff --git a/SoftLayer/tests/CLI/modules/server_tests.py b/SoftLayer/tests/CLI/modules/server_tests.py index 81f4f91e0..f11b58a6f 100644 --- a/SoftLayer/tests/CLI/modules/server_tests.py +++ b/SoftLayer/tests/CLI/modules/server_tests.py @@ -123,7 +123,7 @@ def test_server_details(self): 'public_ip': '172.16.1.100', 'status': 'ACTIVE', 'tags': ['test_tag'], - 'users': ['root abc123'], + 'users': [{'password': 'abc123', 'username': 'root'}], 'vlans': [{'id': 9653, 'number': 1800, 'type': 'PRIVATE'}, {'id': 19082, 'number': 3672, 'type': 'PUBLIC'}] }