Skip to content

Commit a8a5058

Browse files
committed
add subnet edit
1 parent 4de733f commit a8a5058

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@
286286
('subnet', 'SoftLayer.CLI.subnet'),
287287
('subnet:cancel', 'SoftLayer.CLI.subnet.cancel:cli'),
288288
('subnet:create', 'SoftLayer.CLI.subnet.create:cli'),
289+
('subnet:edit', 'SoftLayer.CLI.subnet.edit:cli'),
289290
('subnet:detail', 'SoftLayer.CLI.subnet.detail:cli'),
290291
('subnet:list', 'SoftLayer.CLI.subnet.list:cli'),
291292
('subnet:lookup', 'SoftLayer.CLI.subnet.lookup:cli'),

SoftLayer/CLI/subnet/edit.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Edit a subnet."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import helpers
9+
10+
11+
@click.command(short_help="Edit note and tags of a subnet")
12+
@click.argument('identifier')
13+
@click.option('--tags', '-t', type=click.STRING,
14+
help='Comma separated list of tags, enclosed in quotes. "tag1, tag2"')
15+
@click.option('--note', '-n', type=click.STRING,
16+
help="The note")
17+
@environment.pass_env
18+
def cli(env, identifier, tags, note):
19+
"""Edit note and tags of a subnet."""
20+
21+
mgr = SoftLayer.NetworkManager(env.client)
22+
subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier,
23+
name='subnet')
24+
25+
if tags:
26+
result = mgr.set_tags_subnet(subnet_id, tags)
27+
print_result(result, "Set tags")
28+
29+
if note:
30+
result = mgr.edit_note_subnet(subnet_id, note)
31+
print_result(result, "Edit note")
32+
33+
34+
def print_result(result, detail):
35+
if result:
36+
click.secho("{} successfully".format(detail), fg='green')
37+
else:
38+
click.secho("Failed to {}".format(detail.lower()), fg='red')

SoftLayer/managers/network.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
'datacenter',
2525
'ipAddressCount',
2626
'virtualGuests',
27+
'id',
28+
'networkIdentifier',
29+
'cidr',
30+
'subnetType',
31+
'gateway',
32+
'broadcastAddress',
33+
'usableIpAddressCount',
34+
'note',
35+
'tagReferences[tag]',
2736
'networkVlan[id,networkSpace]'])
2837
DEFAULT_VLAN_MASK = ','.join([
2938
'firewallInterfaces',
@@ -233,6 +242,20 @@ def cancel_subnet(self, subnet_id):
233242
billing_id = subnet['billingItem']['id']
234243
return self.client['Billing_Item'].cancelService(id=billing_id)
235244

245+
def set_tags_subnet(self, subnet_id, tags):
246+
"""Tag a subnet by passing in one or more tags separated by a comma.
247+
248+
:param int subnet_id: The ID of the subnet.
249+
"""
250+
return self.subnet.setTags(tags, id=subnet_id)
251+
252+
def edit_note_subnet(self, subnet_id, note):
253+
"""Edit the note for this subnet.
254+
255+
:param int subnet_id: The ID of the subnet.
256+
"""
257+
return self.subnet.editNote(note, id=subnet_id)
258+
236259
def create_securitygroup(self, name=None, description=None):
237260
"""Creates a security group.
238261

0 commit comments

Comments
 (0)