Skip to content

Commit d2c5018

Browse files
Merge pull request #1287 from caberos/issue1284
new feature edit ip note and add ipAddress table in detail
2 parents d863b88 + cd6134e commit d2c5018

File tree

8 files changed

+81
-2
lines changed

8 files changed

+81
-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,note], 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(['id', 'ip', 'note'])
54+
for address in ip_address:
55+
ip_table.add_row([address.get('id'), address.get('ipAddress'), address.get('note')])
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('--note', help="set ip address note of subnet")
13+
@environment.pass_env
14+
def cli(env, identifier, note):
15+
"""Set the note of the ipAddress"""
16+
17+
data = {
18+
'note': note
19+
}
20+
mgr = SoftLayer.NetworkManager(env.client)
21+
ip_id = None
22+
if str.isdigit(identifier):
23+
ip_id = identifier
24+
else:
25+
ip_object = mgr.get_ip_by_address(identifier)
26+
ip_id = ip_object.get('id')
27+
mgr.set_subnet_ipddress_note(ip_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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,3 +727,19 @@ def set_tags(self, tags, vlan_id):
727727
Just calls vlan.setTags, but if it fails from an APIError will retry.
728728
"""
729729
self.vlan.setTags(tags, id=vlan_id)
730+
731+
def get_ip_by_address(self, ip_address):
732+
"""get the ip address object
733+
734+
:param string ip_address: the ip address to edit.
735+
"""
736+
return self.client.call('SoftLayer_Network_Subnet_IpAddress', 'getByIpAddress', ip_address)
737+
738+
def set_subnet_ipddress_note(self, identifier, note):
739+
"""Set the ip address note of the subnet
740+
741+
:param integer identifier: the ip address ID to edit.
742+
:param json note: the note to edit.
743+
"""
744+
result = self.client.call('SoftLayer_Network_Subnet_IpAddress', 'editObject', note, id=identifier)
745+
return result

docs/cli/subnet.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ Subnets
2222
.. click:: SoftLayer.CLI.subnet.lookup:cli
2323
:prog: subnet lookup
2424
:show-nested:
25+
26+
.. click:: SoftLayer.CLI.subnet.edit_ip:cli
27+
:prog: subnet edit-ip
28+
:show-nested:

tests/CLI/modules/subnet_tests.py

Lines changed: 13 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,13 @@ 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', '16.26.26.26', '--note=test'])
143+
self.assert_no_fail(result)
144+
self.assertTrue(result)
145+
146+
def test_editrou_Id(self):
147+
result = self.run_command(['subnet', 'edit-ip', '123456', '--note=test'])
148+
self.assert_no_fail(result)
149+
self.assertTrue(result)

0 commit comments

Comments
 (0)