Skip to content

Commit 0cbcf3f

Browse files
Merge pull request softlayer#453 from Neetuj/issue431
adding credentials CLI commands for nas,vs,server
2 parents a11f2a2 + 3080ff4 commit 0cbcf3f

9 files changed

Lines changed: 83 additions & 12 deletions

File tree

SoftLayer/CLI/nas/credentials.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""List NAS account credentials."""
2+
# :license: MIT, see LICENSE for more details.
3+
import SoftLayer
4+
from SoftLayer.CLI import environment
5+
from SoftLayer.CLI import formatting
6+
7+
import click
8+
9+
10+
@click.command()
11+
@click.argument('identifier')
12+
@environment.pass_env
13+
def cli(env, identifier):
14+
"""List NAS account credentials."""
15+
16+
nw_mgr = SoftLayer.NetworkManager(env.client)
17+
result = nw_mgr.get_nas_credentials(identifier)
18+
table = formatting.Table(['username', 'password'])
19+
table.add_row([result['username'],
20+
result['password']])
21+
return table

SoftLayer/CLI/nas/list.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def cli(env):
1818
nas_accounts = account.getNasNetworkStorage(
1919
mask='eventCount,serviceResource[datacenter.name]')
2020

21-
table = formatting.Table(['id', 'datacenter', 'size', 'username',
22-
'password', 'server'])
21+
table = formatting.Table(['id', 'datacenter', 'size', 'server'])
2322

2423
for nas_account in nas_accounts:
2524
table.add_row([
@@ -31,8 +30,6 @@ def cli(env):
3130
formatting.FormattedItem(
3231
nas_account.get('capacityGb', formatting.blank()),
3332
"%dGB" % nas_account.get('capacityGb', 0)),
34-
nas_account.get('username', formatting.blank()),
35-
nas_account.get('password', formatting.blank()),
3633
nas_account.get('serviceResourceBackendIpAddress',
3734
formatting.blank())])
3835

SoftLayer/CLI/routes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
('vs:reboot', 'SoftLayer.CLI.virt.power:reboot'),
2929
('vs:reload', 'SoftLayer.CLI.virt.reload:cli'),
3030
('vs:upgrade', 'SoftLayer.CLI.virt.upgrade:cli'),
31+
('vs:credentials', 'SoftLayer.CLI.virt.credentials:cli'),
3132

3233
('cdn', 'SoftLayer.CLI.cdn'),
3334
('cdn:detail', 'SoftLayer.CLI.cdn.detail:cli'),
@@ -120,6 +121,7 @@
120121

121122
('nas', 'SoftLayer.CLI.nas'),
122123
('nas:list', 'SoftLayer.CLI.nas.list:cli'),
124+
('nas:credentials', 'SoftLayer.CLI.nas.credentials:cli'),
123125

124126
('rwhois', 'SoftLayer.CLI.rwhois'),
125127
('rwhois:edit', 'SoftLayer.CLI.rwhois.edit:cli'),
@@ -140,6 +142,7 @@
140142
('server:power-on', 'SoftLayer.CLI.server.power:power_on'),
141143
('server:reboot', 'SoftLayer.CLI.server.power:reboot'),
142144
('server:reload', 'SoftLayer.CLI.server.reload:cli'),
145+
('server:credentials', 'SoftLayer.CLI.server.credentials:cli'),
143146

144147
('snapshot', 'SoftLayer.CLI.snapshot'),
145148
('snapshot:cancel', 'SoftLayer.CLI.snapshot.cancel:cli'),
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""List virtual server credentials."""
2+
# :license: MIT, see LICENSE for more details.
3+
import SoftLayer
4+
from SoftLayer.CLI import environment
5+
from SoftLayer.CLI import formatting
6+
7+
import click
8+
9+
10+
@click.command()
11+
@click.argument('identifier')
12+
@environment.pass_env
13+
def cli(env, identifier):
14+
"""List virtual server credentials."""
15+
16+
hardware = SoftLayer.HardwareManager(env.client)
17+
result = hardware.get_hardware(identifier)
18+
table = formatting.Table(['username', 'password'])
19+
for item in result['operatingSystem']['passwords']:
20+
table.add_row([item['username'], item['password']])
21+
return table

SoftLayer/CLI/server/detail.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,10 @@ def cli(env, identifier, passwords, price):
8383
result['billingItem']['recurringFee']])
8484

8585
if passwords:
86-
user_strs = []
86+
pass_table = formatting.Table(['username', 'password'])
8787
for item in result['operatingSystem']['passwords']:
88-
user_strs.append(
89-
"%s %s" % (item['username'], item['password']))
90-
table.add_row(['users', formatting.listing(user_strs)])
88+
pass_table.add_row([item['username'], item['password']])
89+
table.add_row(['users', pass_table])
9190

9291
tag_row = []
9392
for tag in result['tagReferences']:

SoftLayer/CLI/virt/credentials.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""List virtual server credentials."""
2+
# :license: MIT, see LICENSE for more details.
3+
import SoftLayer
4+
from SoftLayer.CLI import environment
5+
from SoftLayer.CLI import formatting
6+
7+
import click
8+
9+
10+
@click.command()
11+
@click.argument('identifier')
12+
@environment.pass_env
13+
def cli(env, identifier):
14+
"""List virtual server credentials."""
15+
16+
vsi = SoftLayer.VSManager(env.client)
17+
result = vsi.get_instance(identifier)
18+
table = formatting.Table(['username', 'password'])
19+
for item in result['operatingSystem']['passwords']:
20+
table.add_row([item['username'], item['password']])
21+
return table

SoftLayer/managers/network.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(self, client):
3030
self.account = client['Account']
3131
self.vlan = client['Network_Vlan']
3232
self.subnet = client['Network_Subnet']
33+
self.network_storage = self.client['Network_Storage']
3334

3435
def add_global_ip(self, version=4, test_order=False):
3536
"""Adds a global IP address to the account.
@@ -408,3 +409,13 @@ def _list_vlans_by_name(self, name):
408409
"""
409410
results = self.list_vlans(name=name, mask='id')
410411
return [result['id'] for result in results]
412+
413+
def get_nas_credentials(self, identifier, **kwargs):
414+
"""Returns a list of IDs of VLANs which match the given VLAN name.
415+
416+
:param integer instance_id: the instance ID
417+
:returns: A dictionary containing a large amount of information about
418+
the specified instance.
419+
"""
420+
result = self.network_storage.getObject(id=identifier, **kwargs)
421+
return result

SoftLayer/tests/CLI/modules/nas_tests.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ def test_list_nas(self):
1515

1616
self.assertEqual(result.exit_code, 0)
1717
self.assertEqual(json.loads(result.output),
18-
[{'username': 'user',
19-
'datacenter': 'Dallas',
18+
[{'datacenter': 'Dallas',
2019
'server': '127.0.0.1',
21-
'password': 'pass',
2220
'id': 1,
2321
'size': 10}])

SoftLayer/tests/CLI/modules/server_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_server_details(self):
123123
'public_ip': '172.16.1.100',
124124
'status': 'ACTIVE',
125125
'tags': ['test_tag'],
126-
'users': ['root abc123'],
126+
'users': [{'password': 'abc123', 'username': 'root'}],
127127
'vlans': [{'id': 9653, 'number': 1800, 'type': 'PRIVATE'},
128128
{'id': 19082, 'number': 3672, 'type': 'PUBLIC'}]
129129
}

0 commit comments

Comments
 (0)