From fe270d77ed20608239b8671057e2c3f259facd73 Mon Sep 17 00:00:00 2001 From: Neetu Jain Date: Mon, 17 Nov 2014 13:53:27 -0600 Subject: [PATCH 1/6] removing credenstials from "nas list" and adding then to "nas credentials id" --- SoftLayer/CLI/nas/credentials.py | 21 +++++++++++++++++++++ SoftLayer/CLI/nas/list.py | 5 +---- SoftLayer/managers/network.py | 11 +++++++++++ SoftLayer/tests/CLI/modules/nas_tests.py | 4 +--- 4 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 SoftLayer/CLI/nas/credentials.py diff --git a/SoftLayer/CLI/nas/credentials.py b/SoftLayer/CLI/nas/credentials.py new file mode 100644 index 000000000..d72a19a45 --- /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/managers/network.py b/SoftLayer/managers/network.py index 6a275801b..658c8a6be 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 \ No newline at end of file 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}]) From 18b7f6bbb6f8f8ec9ce540f3af01f553e7b289ef Mon Sep 17 00:00:00 2001 From: Neetu Jain Date: Mon, 17 Nov 2014 15:59:57 -0600 Subject: [PATCH 2/6] add nas credentials list --- SoftLayer/CLI/nas/credentials.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/CLI/nas/credentials.py b/SoftLayer/CLI/nas/credentials.py index d72a19a45..65de4e54e 100644 --- a/SoftLayer/CLI/nas/credentials.py +++ b/SoftLayer/CLI/nas/credentials.py @@ -11,7 +11,7 @@ @click.argument('identifier') @environment.pass_env def cli(env, identifier): - """List NAS account credentials""" + """List NAS account credentials.""" nw_mgr = SoftLayer.NetworkManager(env.client) result = nw_mgr.get_nas_credentials(identifier) From 606b5fffd6541dd37a2fa38aa40417ec88944470 Mon Sep 17 00:00:00 2001 From: Neetu Jain Date: Tue, 18 Nov 2014 12:44:52 -0600 Subject: [PATCH 3/6] add credentials cli for vs, server --- SoftLayer/CLI/routes.py | 5 +++++ SoftLayer/CLI/server/credentials.py | 21 +++++++++++++++++++++ SoftLayer/CLI/server/detail.py | 7 +++---- SoftLayer/CLI/virt/credentials.py | 21 +++++++++++++++++++++ SoftLayer/managers/network.py | 2 +- 5 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 SoftLayer/CLI/server/credentials.py create mode 100644 SoftLayer/CLI/virt/credentials.py diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py index 25d116d28..58be0b062 100644 --- a/SoftLayer/CLI/routes.py +++ b/SoftLayer/CLI/routes.py @@ -28,6 +28,8 @@ ('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 +122,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 +143,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'), @@ -148,6 +152,7 @@ ('snapshot:list', 'SoftLayer.CLI.snapshot.list:cli'), ('snapshot:restore-volume', 'SoftLayer.CLI.snapshot.restore_volume:cli'), + ('sshkey', 'SoftLayer.CLI.sshkey'), ('sshkey:add', 'SoftLayer.CLI.sshkey.add:cli'), ('sshkey:remove', 'SoftLayer.CLI.sshkey.remove: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..bb9f8deab 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 658c8a6be..f544c7d39 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -418,4 +418,4 @@ def get_nas_credentials(self, identifier, **kwargs): the specified instance. """ result = self.network_storage.getObject(id=identifier, **kwargs) - return result \ No newline at end of file + return result From 7a817a393f1daf5a17974a437609479729e87b2e Mon Sep 17 00:00:00 2001 From: Neetu Jain Date: Tue, 18 Nov 2014 12:49:30 -0600 Subject: [PATCH 4/6] make test compatible --- SoftLayer/tests/CLI/modules/server_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'}] } From 9a75ddfdccd843110d7ff867a7955c2752e62377 Mon Sep 17 00:00:00 2001 From: Neetu Jain Date: Tue, 18 Nov 2014 14:13:04 -0600 Subject: [PATCH 5/6] indent --- SoftLayer/CLI/server/detail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/CLI/server/detail.py b/SoftLayer/CLI/server/detail.py index bb9f8deab..3af674683 100644 --- a/SoftLayer/CLI/server/detail.py +++ b/SoftLayer/CLI/server/detail.py @@ -85,7 +85,7 @@ def cli(env, identifier, passwords, price): if passwords: pass_table = formatting.Table(['username', 'password']) for item in result['operatingSystem']['passwords']: - pass_table.add_row([item['username'], item['password']]) + pass_table.add_row([item['username'], item['password']]) table.add_row(['users', pass_table]) tag_row = [] From 3080ff4fb6ad98eaf1cf3b419debbaf82cb3003f Mon Sep 17 00:00:00 2001 From: Neetu Jain Date: Wed, 19 Nov 2014 10:47:16 -0600 Subject: [PATCH 6/6] remove extra lines --- SoftLayer/CLI/routes.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py index 58be0b062..71be22f1e 100644 --- a/SoftLayer/CLI/routes.py +++ b/SoftLayer/CLI/routes.py @@ -30,7 +30,6 @@ ('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'), ('cdn:list', 'SoftLayer.CLI.cdn.list:cli'), @@ -152,7 +151,6 @@ ('snapshot:list', 'SoftLayer.CLI.snapshot.list:cli'), ('snapshot:restore-volume', 'SoftLayer.CLI.snapshot.restore_volume:cli'), - ('sshkey', 'SoftLayer.CLI.sshkey'), ('sshkey:add', 'SoftLayer.CLI.sshkey.add:cli'), ('sshkey:remove', 'SoftLayer.CLI.sshkey.remove:cli'),