Skip to content

Commit 816cd75

Browse files
Merge branch 'master' into issue1283
2 parents ae8bba2 + d2c5018 commit 816cd75

File tree

8 files changed

+82
-1
lines changed

8 files changed

+82
-1
lines changed

SoftLayer/CLI/routes.py

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

294295
('tags', 'SoftLayer.CLI.tags'),
295296
('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'
@@ -49,6 +52,14 @@ def cli(env, identifier, no_vs, no_hardware):
4952
table.add_row(['tags',
5053
formatting.tags(subnet.get('tagReferences'))])
5154

55+
ip_address = subnet.get('ipAddresses')
56+
57+
ip_table = formatting.KeyValueTable(['id', 'ip', 'note'])
58+
for address in ip_address:
59+
ip_table.add_row([address.get('id'), address.get('ipAddress'), address.get('note')])
60+
61+
table.add_row(['ipAddresses', ip_table])
62+
5263
if not no_vs:
5364
if subnet['virtualGuests']:
5465
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
'name': 'subnet: test tag'},
3535
}
3636
]
37+
'ipAddresses': [
38+
{'id': 123456,
39+
'ipAddress': '16.26.26.25'},
40+
{'id': 123457,
41+
'ipAddress': '16.26.26.26'}]
3742
}
3843

3944
editNote = True

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
@@ -752,3 +752,19 @@ def set_tags(self, tags, vlan_id):
752752
Just calls vlan.setTags, but if it fails from an APIError will retry.
753753
"""
754754
self.vlan.setTags(tags, id=vlan_id)
755+
756+
def get_ip_by_address(self, ip_address):
757+
"""get the ip address object
758+
759+
:param string ip_address: the ip address to edit.
760+
"""
761+
return self.client.call('SoftLayer_Network_Subnet_IpAddress', 'getByIpAddress', ip_address)
762+
763+
def set_subnet_ipddress_note(self, identifier, note):
764+
"""Set the ip address note of the subnet
765+
766+
:param integer identifier: the ip address ID to edit.
767+
:param json note: the note to edit.
768+
"""
769+
result = self.client.call('SoftLayer_Network_Subnet_IpAddress', 'editObject', note, id=identifier)
770+
return result

docs/cli/subnet.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ Subnets
2626
.. click:: SoftLayer.CLI.subnet.lookup:cli
2727
:prog: subnet lookup
2828
:show-nested:
29+
30+
.. click:: SoftLayer.CLI.subnet.edit_ip:cli
31+
:prog: subnet edit-ip
32+
:show-nested:

tests/CLI/modules/subnet_tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def test_detail(self):
4242
'tags': [
4343
'subnet: test tag'
4444
],
45+
'ipAddresses': {
46+
'123456': '16.26.26.25',
47+
'123457': '16.26.26.26'},
48+
'hardware': 'none',
49+
'usable ips': 22
4550
},
4651
json.loads(result.output))
4752

@@ -170,3 +175,13 @@ def test_edit_note_failure(self, click):
170175
click.secho.assert_called_with('Failed to edit note', fg='red')
171176
self.assert_no_fail(result)
172177
self.assert_called_with('SoftLayer_Network_Subnet', 'editNote', identifier=1234, args=("test",))
178+
179+
def test_editrou_Ip(self):
180+
result = self.run_command(['subnet', 'edit-ip', '16.26.26.26', '--note=test'])
181+
self.assert_no_fail(result)
182+
self.assertTrue(result)
183+
184+
def test_editrou_Id(self):
185+
result = self.run_command(['subnet', 'edit-ip', '123456', '--note=test'])
186+
self.assert_no_fail(result)
187+
self.assertTrue(result)

0 commit comments

Comments
 (0)