Skip to content

Commit 6f82187

Browse files
author
caberos
committed
new feature edit ip note and add ipAddress table in detail
1 parent 8e516be commit 6f82187

File tree

7 files changed

+61
-2
lines changed

7 files changed

+61
-2
lines changed

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@
289289
('subnet:detail', 'SoftLayer.CLI.subnet.detail:cli'),
290290
('subnet:list', 'SoftLayer.CLI.subnet.list:cli'),
291291
('subnet:lookup', 'SoftLayer.CLI.subnet.lookup:cli'),
292+
('subnet:edit-ip', 'SoftLayer.CLI.subnet.edit_ip:cli'),
292293

293294
('tags', 'SoftLayer.CLI.tags'),
294295
('tags:cleanup', 'SoftLayer.CLI.tags.cleanup:cli'),

SoftLayer/CLI/subnet/detail.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ def cli(env, identifier, no_vs, no_hardware):
2525
mgr = SoftLayer.NetworkManager(env.client)
2626
subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier,
2727
name='subnet')
28-
subnet = mgr.get_subnet(subnet_id)
28+
29+
mask = 'mask[ipAddresses[id, ipAddress], datacenter, virtualGuests,hardware]'
30+
31+
subnet = mgr.get_subnet(subnet_id, mask=mask)
2932

3033
table = formatting.KeyValueTable(['name', 'value'])
3134
table.align['name'] = 'r'
@@ -45,6 +48,14 @@ def cli(env, identifier, no_vs, no_hardware):
4548
table.add_row(['usable ips',
4649
subnet.get('usableIpAddressCount', formatting.blank())])
4750

51+
ip_address = subnet.get('ipAddresses')
52+
53+
ip_table = formatting.KeyValueTable(['ipAddress','value'])
54+
for address in ip_address:
55+
ip_table.add_row([address.get('id'),address.get('ipAddress')])
56+
57+
table.add_row(['ipAddresses', ip_table])
58+
4859
if not no_vs:
4960
if subnet['virtualGuests']:
5061
vs_table = formatting.Table(['hostname', 'domain', 'public_ip', 'private_ip'])

SoftLayer/CLI/subnet/edit_ip.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Edit ip note"""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
9+
10+
@click.command()
11+
@click.argument('identifier')
12+
@click.option('--ip', required=True,
13+
help='Assume the ipAddress to set the note.')
14+
@click.option('--note', help="set ip address note of subnet")
15+
@environment.pass_env
16+
def cli(env, identifier, ip, note):
17+
"""Set the note of the ipAddress subnet"""
18+
19+
data = {
20+
'note': note
21+
}
22+
mgr = SoftLayer.NetworkManager(env.client)
23+
ips = mgr.get_subnet(identifier, mask='id,ipAddresses[id,ipAddress]').get('ipAddresses')
24+
25+
for address in ips:
26+
if ip == address.get('ipAddress'):
27+
mgr.set_subnet_ipddress_note(address.get('id'), data)

SoftLayer/fixtures/SoftLayer_Network_Subnet.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@
2525
}
2626
],
2727
'hardware': [],
28-
'usableIpAddressCount': 22
28+
'usableIpAddressCount': 22,
29+
'ipAddresses': [
30+
{'id': 123456,
31+
'ipAddress': '16.26.26.25'},
32+
{'id': 123457,
33+
'ipAddress': '16.26.26.26'}]
2934
}

SoftLayer/fixtures/SoftLayer_Network_Subnet_IpAddress.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
'isReserved': False,
88
'subnetId': 5678,
99
}
10+
11+
editObject= True

SoftLayer/managers/network.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,3 +685,8 @@ def get_nas_credentials(self, identifier, **kwargs):
685685
"""
686686
result = self.network_storage.getObject(id=identifier, **kwargs)
687687
return result
688+
689+
def set_subnet_ipddress_note(self, identifier, note):
690+
"""Set the ip address note of the subnet"""
691+
result = self.client.call('SoftLayer_Network_Subnet_IpAddress','editObject', note, id=identifier)
692+
return result

tests/CLI/modules/subnet_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def test_detail(self):
3636
'private_ip': '10.0.1.2'
3737
}
3838
],
39+
'ipAddresses': {
40+
'123456': '16.26.26.25',
41+
'123457': '16.26.26.26'},
3942
'hardware': 'none',
4043
'usable ips': 22
4144
},
@@ -134,3 +137,8 @@ def test_create_subnet_static_ipv6(self, confirm_mock):
134137
]
135138

136139
self.assertEqual(output, json.loads(result.output))
140+
141+
def test_editrou_Ip(self):
142+
result = self.run_command(['subnet', 'edit-ip', '123456', '--ip=16.26.26.26', '--note=test'])
143+
self.assert_no_fail(result)
144+
self.assertTrue(result)

0 commit comments

Comments
 (0)