Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions SoftLayer/CLI/nas/credentials.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 1 addition & 4 deletions SoftLayer/CLI/nas/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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())])

Expand Down
3 changes: 3 additions & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add a new line?

('cdn', 'SoftLayer.CLI.cdn'),
('cdn:detail', 'SoftLayer.CLI.cdn.detail:cli'),
Expand Down Expand Up @@ -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'),
Expand All @@ -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'),
Expand Down
21 changes: 21 additions & 0 deletions SoftLayer/CLI/server/credentials.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions SoftLayer/CLI/server/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
21 changes: 21 additions & 0 deletions SoftLayer/CLI/virt/credentials.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions SoftLayer/managers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
4 changes: 1 addition & 3 deletions SoftLayer/tests/CLI/modules/nas_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}])
2 changes: 1 addition & 1 deletion SoftLayer/tests/CLI/modules/server_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}]
}
Expand Down